Created
January 9, 2019 13:26
-
-
Save rymcol/be61d09890548666e07814722d8d45ef to your computer and use it in GitHub Desktop.
Deletes accounts from a cPanel server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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