Skip to content

Instantly share code, notes, and snippets.

@rymcol
Created January 9, 2019 13:26
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/be61d09890548666e07814722d8d45ef to your computer and use it in GitHub Desktop.
Save rymcol/be61d09890548666e07814722d8d45ef to your computer and use it in GitHub Desktop.
Deletes accounts from a cPanel server
#!/usr/bin/env python
# encoding=utf8
from urllib import urlencode
import httplib2, base64, json
filewithaccts = '/path/to/txt/full/of/usernames/accts.txt'
#WARNING THIS WILL DELETE ACCOUNTS
resellerlogin = 'root' #YOU MUST USE ROOT FOR THE SERVER
resellerpass = ''
whmip = ''
#WARNING THIS WILL DELETE ACCOUNTS
h = httplib2.Http(disable_ssl_certificate_validation=True)
auth = base64.encodestring(resellerlogin + ':' + resellerpass).decode('utf-8')
for line in open(filewithaccts):
acct = line.rstrip() #removing line feed
params = {'user': acct}
resp, content = h.request('https://'+whmip+':2087/json-api/removeacct?' + 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]
print result['statusmsg']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment