def testThree(self): """Test Hash Authentication""" raised = False try: pycpanel.conn(hostname=hostname, hash=hash) except: raised = True self.assertFalse(raised, 'Exception raised')
def servers (request): if request.method == "POST" and request.is_ajax(): all_servers=Server.objects.all() print "start" server_list=[] for curr_server in all_servers: server = pycpanel.conn(hostname=curr_server.name, username=curr_server.login, password=curr_server.password) #Basic user/password authentication checking_data='No data' try: account_list=server.api('listaccts')['acct'] server_list.append([curr_server.name, len(account_list)]) print "processed server ", curr_server.name checking_data=len(account_list) except: while checking_data=='No data': account_list=server.api('listaccts')['acct'] server_list.append([curr_server.name,len(account_list)]) checking_data=len(account_list) time.sleep(2) print "processed server ", curr_server.name # return JsonResponse({"server_list":server_list}) return HttpResponse(json.dumps({"server_list":server_list}), content_type="application/json") else: return render_to_response("servers.html", context_instance=RequestContext(request))
def handle_noargs(self, **options): all_servers=Server.objects.all() for curr_server in all_servers: server = pycpanel.conn(hostname=curr_server.name, username=curr_server.login, password=curr_server.password) #Basic user/password authentication curr_server.checking_by_cron='No data' try: account_list=server.api('listaccts')['acct'] curr_server.checking_by_cron=str(len(account_list)) curr_server.save() except: while curr_server.checking_by_cron=='No data': account_list=server.api('listaccts')['acct'] curr_server.checking_by_cron=str(len(account_list)) curr_server.save() time.sleep(2) try: CronTime.objects.get(id=1).save() except CronTime.DoesNotExist: CronTime.objects.create()
def handle_noargs(self, **options): all_servers = Server.objects.all() for curr_server in all_servers: server = pycpanel.conn(hostname=curr_server.name, username=curr_server.login, password=curr_server.password ) #Basic user/password authentication curr_server.checking_by_cron = 'No data' try: account_list = server.api('listaccts')['acct'] curr_server.checking_by_cron = str(len(account_list)) curr_server.save() except: while curr_server.checking_by_cron == 'No data': account_list = server.api('listaccts')['acct'] curr_server.checking_by_cron = str(len(account_list)) curr_server.save() time.sleep(2) try: CronTime.objects.get(id=1).save() except CronTime.DoesNotExist: CronTime.objects.create()
def accountlist(request): if request.method == 'POST': nm = request.POST.get('nm') ps = request.POST.get('ps') try: server = pycpanel.conn( hostname=nm, password=ps, ) li = [] dom = server.api('listaccts')['acct'] for i in range(190): det = dom[i]['domain'] li.append(det) res = li return render(request, 'accountlist.html', {'dom': res}) except: return render( request, 'wrong.html', ) else: return render(request, 'server.html')
def email(request): if request.method == 'POST': dnm = request.POST.get('nm') enm = request.POST.get('ce') unm = request.POST.get('unm') characters = string.ascii_letters + string.punctuation + string.digits ps = "".join(choice(characters) for x in range(randint(8, 16))) server = pycpanel.conn( hostname='hostname.com', password='******', ) params = { 'email': enm, 'password': ps, 'domain': dnm, 'quota': 500, } res = server.cpanel_api('Email', 'addpop', unm, params=params) return render(request, 'detail.html', {'result': res}) else: if usr == 'none': return render(request, 'wrong.html') else: return render(request, 'addemail.html')
temp_flag += 1 if temp_flag > 0: os.remove("add_ip_tempfile") sys.exit(0) os.remove("add_ip_tempfile") ip_list = [] input_ips = open("input_ips", "r") for line in input_ips: ip_list.append(line.strip()) if "List of ip address has been successfully added" in ip_list[-1]: print "List of ip address has already been successfully added - make changes to the list" sys.exit(0) input_ips.close() server = pycpanel.conn( hostname=server_name, username=admin_login, password=admin_password ) # Basic user/password authentication for index, curr_ip in enumerate(ip_list): params = {"api.version": 1, "ips": curr_ip, "netmask": netmask} out_info_dict = server.api("addips", params=params) if int(out_info_dict["metadata"]["result"]) == 1: print curr_ip + " successfully added" else: print "ERROR " + curr_ip + " " + out_info_dict["metadata"]["reason"] sys.exit(0) print "processed line № ", index + 1 print "----------------------" open("input_ips", "a").write("List of ip address has been successfully added")
print ("Could not get any cPanel Server information from %s." % (cpanel_config)) sys.exit(0) # Try to get the cPanel user try: cpanel_user = config.get('cpanel', 'user') except Exception, e: print ("Could not get any cPanel user information from %s." % (cpanel_config)) sys.exit(0) # Try to get the cPanel user password try: cpanel_password = config.get('cpanel', 'password') except Exception, e: print ("Could not get any cPanel password information from %s." % (cpanel_config)) sys.exit(0) server = pycpanel.conn(hostname=cpanel_server, username=cpanel_user, hash=None, password=cpanel_password, ssl=True, verify=False, check_conn=False) params = { 'domain' : str(sys.argv[1]), 'rootdomain' : str(sys.argv[1]) } res = server.cpanel_api('SubDomain', 'addsubdomain', str(sys.argv[3]), params=params) data = json.loads(json.dumps(res[0])) if data['result'] == 1: print "Sub domain %s.%s created successfully" % (str(sys.argv[1]), str(sys.argv[2])) else: print "Sub domain %s.%s is not created due to %s" % (str(sys.argv[1]), str(sys.argv[2]), data['reason']) if __name__ == "__main__": main()
print("Could not get any cPanel user information from %s." % (cpanel_config)) sys.exit(0) # Try to get the cPanel user password try: cpanel_password = config.get('cpanel', 'password') except Exception, e: print("Could not get any cPanel password information from %s." % (cpanel_config)) sys.exit(0) server = pycpanel.conn(hostname=cpanel_server, username=cpanel_user, hash=None, password=cpanel_password, ssl=True, verify=False, check_conn=False) params = {'domain': str(sys.argv[1]), 'rootdomain': str(sys.argv[1])} res = server.cpanel_api('SubDomain', 'addsubdomain', str(sys.argv[3]), params=params) data = json.loads(json.dumps(res[0])) if data['result'] == 1: print "Sub domain %s.%s created successfully" % (str( sys.argv[1]), str(sys.argv[2])) else: print "Sub domain %s.%s is not created due to %s" % (str(
import pycpanel, yaml, urllib2 # Read the cpanel hash for the connection hashFile = open('cpanel-hash') cpanel_hash = hashFile.read() hashFile.close() # Read the configuration file configFile = open('config.yaml') configMap = yaml.safe_load(configFile) configFile.close() # Connect to the server print "[+] Connecting to cpanel server (" + configMap['cpanel']['hostname'] + ")" server = pycpanel.conn(configMap['cpanel']['hostname'], configMap['cpanel']['username'], cpanel_hash, password=None, ssl=True, verify=True, check_conn=True) # Params for the first connection (Get the line number to edit) params = { 'domain' : configMap['ddns']['domain'] } dumpzone = server.api('dumpzone', params=params) found = False for line in dumpzone['result'][0]['record']: if 'name' in line: if line['name'] == configMap['ddns']['name']: found = True break if not found: print "Requested record not found"
def adddom(request): if request.method == 'POST': nm = request.POST.get('nm') em = request.POST.get('ce') msg = request.POST.get('msg') pn = request.POST.get('pn') un = nm.split(".")[0] li = [] characters = string.ascii_letters + string.punctuation + string.digits ps = "".join(choice(characters) for x in range(randint(8, 16))) server = pycpanel.conn( hostname='hostname.com', password='******', ) if pn != 'none': param = { 'username': un, 'domain': nm, 'contactemail': "*****@*****.**", 'password': ps, 'pkgname': pn } r = (server.api('createacct', param)) rs = json.dumps(r, indent=4) try: rst = rs.rsplit("New Account Info")[1] re = rst.rsplit("Language: en")[0] for i in range(1, 15): resu = re.rsplit("\\n|")[i] li.append(resu) res = li except: res = rs if str(em) != 'None': characters = string.ascii_letters + string.punctuation + string.digits ps = "".join(choice(characters) for x in range(randint(8, 16))) params = { 'email': em, 'password': ps, 'domain': nm, 'quota': 500, } ed = server.cpanel_api('Email', 'addpop', un, params=params) else: ed = None td = whmcs.OpenTicket(deptid='2', subject='new account created', message=msg, name=un, email=nm) return render(request, 'detail.html', { "result": res, "td": td, "ed": ed }) else: return render(request, 'login.html') else: if usr == 'none': return render(request, 'wrong.html') else: return render(request, 'adddomain.html')
def setUp(self): """Test Password Authentication""" self.server = pycpanel.conn(hostname=hostname, password=password)