Skip to content

Instantly share code, notes, and snippets.

@rymcol
Created May 20, 2016 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rymcol/b9be1a88d6f2b2c1015d6e646e1d11e0 to your computer and use it in GitHub Desktop.
Save rymcol/b9be1a88d6f2b2c1015d6e646e1d11e0 to your computer and use it in GitHub Desktop.
Bulk Password Reset for WHM/cPanel in Python
#!/usr/bin/env python
from urllib import urlencode
import httplib2, base64, json
filewithdomains = '/path/to/domains.txt'
resellerlogin = 'root'
resellerpass = 'password'
whmip = '123.456.789.000'
h = httplib2.Http(disable_ssl_certificate_validation=True)
auth = base64.encodestring(resellerlogin + ':' + resellerpass).decode('utf-8')
for line in open(filewithdomains):
domain = line.rstrip() #removing line feed
user = ''.join(e for e in domain[:domain.rfind('.')] if e.isalnum()).lstrip('0123456789')[:8] #removing first level domain, special characters and numbers from start of line, cutting by 8 chars
params = {'username': user, 'domain': domain}
resp, content = h.request('https://'+whmip+':2087/json-api/passwd?' + urlencode(params), 'GET',
headers = {'Authorization': 'Basic ' + auth})
answer = json.loads(content.decode('utf-8'))
if 'status' in answer:
result = answer #there is no result in answer (permission denied for example)
else:
result = answer['result'][0]
if result['status']:
passpos = result['rawout'].find('PassWord:') #getting password from whm output
password = result['rawout'][passpos+10:passpos+24]
else:
password = '' #in case of error ther is no password
print user+'\t', domain+'\t', password+'\t', result['statusmsg']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment