Last active
May 20, 2016 22:41
-
-
Save rymcol/c6df7de6243ddf72012c5f5e5aba87fd to your computer and use it in GitHub Desktop.
Creates cPanel Accounts from a txt file list of domains
This file contains 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 | |
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/createacct?' + 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