Skip to content

Instantly share code, notes, and snippets.

@spookyahell
Last active December 19, 2018 22:46
Show Gist options
  • Save spookyahell/00ef2c74ab62d18003dda2674de8af6d to your computer and use it in GitHub Desktop.
Save spookyahell/00ef2c74ab62d18003dda2674de8af6d to your computer and use it in GitHub Desktop.
Send new password to nzbget RPC by either account or servername
import requests
from sys import argv, exit as sexy_exit
#~ Script to update the password on a NZBget server by finding a very specific username
def setPassword(printX, serverURL = None, username = None, password = None, servername = None):
r = requests.post(serverURL, json = {'method':'loadconfig','params':[]})
if r.status_code != 200:
printX('Assuming auth misconfig')
return False
o = r.json()
lookingFor = None
for item in o['result']:
if username:
if item['Name'].endswith('.Username'):
if item['Value'] == username:
lookingFor = item['Name'].replace('Username','Password')
elif servername:
if item['Name'].endswith('.Name'):
if item['Value'] == servername:
lookingFor = item['Name'].replace('Name','Password')
else:
printX('Need either servername or username of the account to change the password. FATAL ERROR.')
return False
if not lookingFor:
printX('Server details not found. This script can not create servers (yet), it only updates existing user with the correct password...')
return False
for item in o['result']:
if item['Name'] == lookingFor:
item['Value'] = password
printX(f'Password of set to {password!r}, sending config')
params = o['result']
r = requests.post(serverURL, json = {'method':'saveconfig','params':[params]})
o = r.json()
if o['result'] is True:
r = requests.post(serverURL, json = {'method':'reload','params':[]})
o = r.json()
if o['result'] is True:
printX('nzbget reloaded with new password set')
return True
else:
printX(r.text)
return False
if __name__ == '__main__':
if len(argv) != 3:
print('Not the corrrect number of arguements...')
def printX(s):
print(s)
serverURL = 'http://nzbget:tegbzn6789@SERVERDOMAIN.tld:6789/jsonrpc'
x = setPassword(printX, serverURL, username = argv[1], password = argv[2])
if x is False:
x = setPassword(printX, serverURL, servername = argv[1], password = argv[2])
if x is False:
print('No server was found with this method')
sexy_exit(1)
@spookyahell
Copy link
Author

Used for "evil" on my end, how about you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment