def setUpDataNode(self): try: userID = self.request.session['userID'] currentACL = ACLManager.loadedACL(userID) proc = httpProc(self.request, None, None) if currentACL['admin'] == 0: return proc.ajax(0, 'Only administrators can create clusters.') composePath = '/home/cyberpanel/composePath' if not os.path.exists(composePath): os.mkdir(composePath) composeFile = composePath + '/docker-compose.yml' compose = open(composeFile, 'w') for items in self.data['composeData']: compose.writelines(items) compose.close() return proc.ajax(1, None) except BaseException, msg: logging.writeToFile(str(msg)) proc = httpProc(self.request, None, None) return proc.ajax(0, str(msg))
def gitPull(self): try: domain = self.extraArgs['domain'] try: website = Websites.objects.get(domain=domain) finalPath = "/home/" + domain + "/public_html/" externalApp = website.externalApp except: childDomain = ChildDomains.objects.get(domain=domain) finalPath = childDomain.path externalApp = website.externalApp path = '/home/cyberpanel/' + domain + '.git' if not os.path.exists(path): logging.writeToFile('Git is not setup for this website.') return 0 command = 'sudo git --git-dir=' + finalPath + '.git --work-tree=' + finalPath + ' pull' ProcessUtilities.executioner(command, externalApp) ## website = Websites.objects.get(domain=domain) externalApp = website.externalApp command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath ProcessUtilities.executioner(command, externalApp) return 0 except BaseException, msg: logging.writeToFile(str(msg) + " [ApplicationInstaller.gitPull]") return 0
def changeBranch(self): try: domainName = self.extraArgs['domainName'] githubBranch = self.extraArgs['githubBranch'] admin = self.extraArgs['admin'] try: website = Websites.objects.get(domain=domainName) finalPath = "/home/" + domainName + "/public_html/" externalApp = website.externalApp except: childDomain = ChildDomains.objects.get(domain=domainName) finalPath = childDomain.path externalApp = childDomain.master.externalApp try: command = 'sudo git --git-dir=' + finalPath + '/.git checkout -b ' + githubBranch ProcessUtilities.executioner(command, externalApp) except: try: command = 'sudo git --git-dir=' + finalPath + '/.git checkout ' + githubBranch ProcessUtilities.executioner(command, externalApp) except subprocess.CalledProcessError, msg: logging.writeToFile('Failed to change branch: ' + str(msg)) return 0 return 0
def submitEditCluster(self): try: userID = self.request.session['userID'] currentACL = ACLManager.loadedACL(userID) proc = httpProc(self.request, None, None) if currentACL['admin'] == 0: return proc.ajax(0, 'Only administrators can create clusters.') composePath = '/home/cyberpanel/composePath' composeFile = composePath + '/docker-compose.yml' data = open(composeFile, 'r').readlines() compose = open(composeFile, 'w') for items in data: if items.find('replicas') > -1: compose.writelines(' replicas: ' + str(self.data['containers']) + '\n') elif items.find('memory') > -1: compose.writelines(' memory: ' + self.data['containerRam'] + '\n') elif items.find('cpus:') > -1: compose.writelines(' cpus: "' + self.data['containerCPU'] + '"\n') else: compose.writelines(items) compose.close() return proc.ajax(1, None) except BaseException, msg: logging.writeToFile(str(msg)) proc = httpProc(self.request, None, None) return proc.ajax(0, str(msg))
def dbCreation(self, tempStatusPath, website): try: dbName = randomPassword.generate_pass() dbUser = dbName dbPassword = randomPassword.generate_pass() ## DB Creation if Databases.objects.filter( dbName=dbName).exists() or Databases.objects.filter( dbUser=dbUser).exists(): statusFile = open(tempStatusPath, 'w') statusFile.writelines( "This database or user is already taken." + " [404]") statusFile.close() return 0 result = mysqlUtilities.createDatabase(dbName, dbUser, dbPassword) if result == 1: pass else: statusFile = open(tempStatusPath, 'w') statusFile.writelines("Not able to create database." + " [404]") statusFile.close() return 0 db = Databases(website=website, dbName=dbName, dbUser=dbUser) db.save() return dbName, dbUser, dbPassword except BaseException, msg: logging.writeToFile(str(msg) + '[ApplicationInstallerdbCreation]')
def restoreRemoteBackups(request): try: userID = request.session['userID'] currentACL = ACLManager.loadedACL(userID) if ACLManager.currentContextPermission(currentACL, 'createBackup') == 0: return ACLManager.loadError() websitesName = ACLManager.findAllSites(currentACL, userID) destinations = [] path = '/home/cyberpanel/sftp' if os.path.exists(path): for items in os.listdir(path): destinations.append('sftp:%s' % (items)) path = '/home/cyberpanel/aws' if os.path.exists(path): for items in os.listdir(path): destinations.append('s3:s3.amazonaws.com/%s' % (items)) return defRenderer(request, 'IncBackups/restoreRemoteBackups.html', { 'websiteList': websitesName, 'destinations': destinations }) except BaseException, msg: logging.writeToFile(str(msg)) return redirect(loadLoginPage)
def __call__(self, request): if request.method == 'POST': if request.body.find(';') > -1 or request.body.find( '&&') > -1 or request.body.find( '|') > -1 or request.body.find('...') > -1: logging.writeToFile('Bad Input on.') response = self.get_response(request) return response
def run(self): try: if self.function == 'startCloning': self.startCloning() elif self.function == 'startSyncing': self.startSyncing() except BaseException, msg: logging.writeToFile(str(msg) + ' [StagingSetup.run]')
def run(self): try: if self.function == 'setupNode': self.setupNode() elif self.function == 'addManager': self.setupNode() except BaseException, msg: logging.writeToFile(str(msg) + ' [HAManager.run]')
def stop(self): path = policyCTRL.applicationPath if os.path.exists(path): pid = open(path, "r").readlines()[0] try: os.kill(int(pid), signal.SIGTERM) except BaseException, msg: logging.writeToFile(str(msg))
def run(self): try: if self.installApp == 'wordpress': self.installWordPress() elif self.installApp == 'joomla': self.installJoomla() except BaseException, msg: logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]')
def handleCachePurgeRequest(command): try: mailUtilities.checkHome() writeToFile = open(cacheClient.cleaningPath, 'w') writeToFile.write(command) writeToFile.close() except BaseException, msg: logging.writeToFile(str(msg) + ' [cacheClient.handleCachePurgeRequest]')
def localInitiate(request): try: data = json.loads(request.body) randomFile = data['randomFile'] if os.path.exists(randomFile): wm = BackupManager() return wm.submitBackupCreation(1, json.loads(request.body)) except BaseException, msg: logging.writeToFile(str(msg))
def test_submitACLModifications(self): self.test_createACLFunc() data_ret = {'aclToModify': 'hello', 'adminStatus':1, 'createNewUser': 1, 'versionManagement': 1, 'listUsers': 1, 'resellerCenter': 1, 'deleteUser': 1, 'changeUserACL': 1, 'createWebsite': 1, 'modifyWebsite': 1, 'suspendWebsite': 1, 'deleteWebsite': 1, 'createPackage': 1, 'listPackages': 1, 'deletePackage': 1, 'modifyPackage': 1, 'createDatabase': 1, 'deleteDatabase': 1, 'listDatabases': 1, 'createNameServer': 1, 'createDNSZone': 1, 'deleteZone': 1, 'addDeleteRecords': 1, 'createEmail': 1, 'listEmails': 1, 'deleteEmail': 1, 'emailForwarding': 1, 'changeEmailPassword': 1, 'dkimManager': 1, 'createFTPAccount': 1, 'deleteFTPAccount': 1, 'listFTPAccounts': 1, 'createBackup': 1, 'restoreBackup': 1, 'addDeleteDestinations': 1, 'scheDuleBackups': 1, 'remoteBackups': 1, 'manageSSL': 1, 'hostnameSSL': 1, 'mailServerSSL': 0} json_data = json.dumps(data_ret) ## Modification response = self.client.post(self.submitACLModifications, json_data, content_type="application/json") logging.writeToFile(response.content) json_data = json.loads(response.content) self.assertEqual(json_data['status'], 1) self.assertEqual(ACL.objects.get(name='hello').mailServerSSL, 0) self.assertEqual(ACL.objects.get(name='hello').hostnameSSL, 1)
def purgeLimitDomain(command): try: domain = command[2] operationVal = int(command[3]) if domain in cacheManager.domains: domainOBJ = cacheManager.domains[domain] domainOBJ.limitStatus = operationVal except BaseException, msg: logging.writeToFile(str(msg) + ' [cacheManager.purgeLimitDomain]')
def updateDomainLimit(command): try: domain = command[2] newLimit = int(command[3]) if domain in cacheManager.domains: domainOBJ = cacheManager.domains[domain] domainOBJ.monthlyLimits = newLimit except BaseException, msg: logging.writeToFile(str(msg) + ' [cacheManager.updateDomainLimit]')
def runAWSBackups(request): try: data = json.loads(request.body) randomFile = data['randomFile'] if os.path.exists(randomFile): s3 = S3Backups(request, None, 'runAWSBackups') s3.start() except BaseException, msg: logging.writeToFile(str(msg) + ' [API.runAWSBackups]')
def disableEnableLogs(self, emailAddress, operationValue): try: domainName = emailAddress.split('@')[1] if domainName in cacheManager.domains: domainOBJ = cacheManager.domains[domainName] if emailAddress in domainOBJ.emails: emailOBJ = domainOBJ.emails[emailAddress] emailOBJ.logStatus = operationValue except BaseException, msg: logging.writeToFile(str(msg) + ' [cacheManager.disableEnableLogs]')
def purgeLimit(command): try: email = command[2] operationVal = int(command[3]) domain = email.split('@')[1] if domain in cacheManager.domains: domainOBJ = cacheManager.domains[domain] emailOBJ = domainOBJ.emails[email] emailOBJ.limitStatus = operationVal except BaseException, msg: logging.writeToFile(str(msg) + ' [cacheManager.purgeLimit]')
def installWPCLI(self): try: command = 'sudo wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar' subprocess.call(shlex.split(command)) command = 'sudo chmod +x wp-cli.phar' subprocess.call(shlex.split(command)) command = 'sudo mv wp-cli.phar /usr/bin/wp' subprocess.call(shlex.split(command)) except BaseException, msg: logging.writeToFile( str(msg) + ' [ApplicationInstaller.installWPCLI]')
def wrap(request, *args, **kwargs): try: userID = request.session['userID'] except KeyError: return redirect(loadLoginPage) currentACL = ACLManager.loadedACL(userID) if request.method == "POST": isPost = True else: isPost = False # check if docker is installed dockerInstallPath = '/usr/bin/docker' if not os.path.exists(dockerInstallPath): if isPost: data_ret = { 'status': 0, 'error_message': 'Docker not installed' } json_data = json.dumps(data_ret) return HttpResponse(json_data) else: return render(request, 'dockerManager/install.html', { 'status': currentACL['admin'], 'conErr': 0 }) # Check if docker is running and we are able to connect try: client = docker.from_env() client.ping() except BaseException, msg: logging.writeToFile(str(msg)) if isPost: data_ret = { 'status': 0, 'error_message': 'Docker daemon not running or not responsive' } json_data = json.dumps(data_ret) return HttpResponse(json_data) else: return render(request, 'dockerManager/install.html', { 'status': currentACL['admin'], 'conErr': 1 })
def DeleteApacheVhost(virtualHostName): try: finalConfPath = ApacheVhost.configBasePath + virtualHostName + '.conf' if os.path.exists(finalConfPath): os.remove(finalConfPath) ApacheVhost.deletePHPPath(virtualHostName) command = "systemctl restart httpd" ProcessUtilities.normalExecutioner(command) except BaseException, msg: logging.writeToFile(str(msg))
def restorePoint(request): try: userID = request.session['userID'] currentACL = ACLManager.loadedACL(userID) admin = Administrator.objects.get(pk=userID) data = json.loads(request.body) backupDomain = data['websiteToBeBacked'] jobid = data['jobid'] if ACLManager.checkOwnership(backupDomain, admin, currentACL) == 1: pass else: return ACLManager.loadErrorJson('metaStatus', 0) tempPath = "/home/cyberpanel/" + str(randint(1000, 9999)) if data['reconstruct'] == 'remote': extraArgs = {} extraArgs['website'] = backupDomain extraArgs['jobid'] = jobid extraArgs['tempPath'] = tempPath extraArgs['reconstruct'] = data['reconstruct'] extraArgs['backupDestinations'] = data['backupDestinations'] extraArgs['password'] = data['password'] extraArgs['path'] = data['path'] else: extraArgs = {} extraArgs['website'] = backupDomain extraArgs['jobid'] = jobid extraArgs['tempPath'] = tempPath extraArgs['reconstruct'] = data['reconstruct'] startJob = IncJobs('restorePoint', extraArgs) startJob.start() time.sleep(2) final_json = json.dumps({ 'status': 1, 'error_message': "None", 'tempPath': tempPath }) return HttpResponse(final_json) except BaseException, msg: logging.writeToFile(str(msg)) final_dic = {'status': 0, 'metaStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json)
def backupDestinations(request): try: userID = request.session['userID'] currentACL = ACLManager.loadedACL(userID) if ACLManager.currentContextPermission(currentACL, 'addDeleteDestinations') == 0: return ACLManager.loadError() return defRenderer(request, 'IncBackups/incrementalDestinations.html', {}) except BaseException, msg: logging.writeToFile(str(msg)) return redirect(loadLoginPage)
def installGit(self): try: if os.path.exists("/etc/lsb-release"): command = 'apt -y install git' ProcessUtilities.executioner(command) else: command = 'sudo yum -y install http://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm' ProcessUtilities.executioner(command) command = 'sudo yum install git -y' ProcessUtilities.executioner(command) except BaseException, msg: logging.writeToFile( str(msg) + ' [ApplicationInstaller.installGit]')
def submitBackupCreation(request): try: userID = request.session['userID'] result = pluginManager.preSubmitBackupCreation(request) if result != 200: return result wm = BackupManager() coreResult = wm.submitBackupCreation(userID, json.loads(request.body)) return coreResult except BaseException, msg: logging.writeToFile(str(msg))
def purgeLimitEmail(command): try: email = command[2] monthlyLimit = int(command[3]) hourlyLimit = int(command[4]) domain = email.split('@')[1] if domain in cacheManager.domains: domainOBJ = cacheManager.domains[domain] emailOBJ = domainOBJ.emails[email] emailOBJ.monthlyLimits = monthlyLimit emailOBJ.hourlyLimits = hourlyLimit except BaseException, msg: logging.writeToFile(str(msg) + ' [cacheManager.purgeLimitEmail]')
def listForTable(self): try: finalData = {} finalData['status'] = 1 domainName = self.data['domainName'] website = Websites.objects.get(domain=domainName) if not self.data['completeStartingPath'].find( self.data['home']) > -1: return self.ajaxPre( 0, 'Not allowed to browse this path, going back home!') command = "ls -la --group-directories-first " + self.returnPathEnclosed( self.data['completeStartingPath']) output = ProcessUtilities.outputExecutioner( command, website.externalApp).splitlines() counter = 0 for items in output: try: currentFile = items.split(' ') currentFile = filter(lambda a: a != '', currentFile) if currentFile[-1] == '.' or currentFile[ -1] == '..' or currentFile[0] == 'total': continue if len(currentFile) > 9: fileName = currentFile[8:] currentFile[-1] = " ".join(fileName) dirCheck = 0 if currentFile[0][0] == 'd': dirCheck = 1 size = str(int(int(currentFile[4]) / float(1024))) lastModified = currentFile[5] + ' ' + currentFile[ 6] + ' ' + currentFile[7] finalData[str(counter)] = [ currentFile[-1], currentFile[-1], lastModified, size, currentFile[0], dirCheck ] counter = counter + 1 except BaseException, msg: logging.writeToFile(str(msg)) json_data = json.dumps(finalData) return HttpResponse(json_data)
def fetchCurrentBackups(self): try: self.website = self.extraArgs['website'] self.backupDestinations = self.extraArgs['backupDestinations'] self.passwordFile = self.extraArgs['password'] result = self.getRemoteBackups() activator = 0 json_data = "[" checker = 0 if result[0].find('unable to open config file') == -1: for items in reversed(result): if items.find('---------------') > -1: if activator == 0: activator = 1 continue else: activator = 0 if activator: entry = items.split(' ') dic = { 'id': entry[0], 'date': "%s %s" % (entry[2], entry[3]), 'host': entry[5], 'path': entry[-1] } if checker == 0: json_data = json_data + json.dumps(dic) checker = 1 else: json_data = json_data + ',' + json.dumps(dic) json_data = json_data + ']' final_json = json.dumps({ 'status': 1, 'error_message': "None", "data": json_data }) return HttpResponse(final_json) except BaseException, msg: logging.writeToFile(str(msg))
def hourlyCleanUP(): try: for domain, domainOBJ in cacheManager.domains.iteritems(): for email, emailOBJ in domainOBJ.emails.iteritems(): emailID = EUsers.objects.get(email=email) dbEmail = EmailLimits.objects.get(email=emailID) dbEmail.hourlyUsed = 0 dbEmail.save() dbEmail.hourlyUsed = 0 emailOBJ.hourlyUsed = 0 except BaseException, msg: logging.writeToFile(str(msg) + ' [cacheManager.hourlyCleanUP]')