From 520bd2b7971edfbfc95b1794b5cf7723fab5eaba Mon Sep 17 00:00:00 2001 From: usmannasir <01-134132-158@student.bahria.edu.pk> Date: Thu, 21 Mar 2019 23:26:42 +0500 Subject: [PATCH] centralized execution ph1 --- api/views.py | 52 +--- backup/backupManager.py | 144 +++++---- baseTemplate/views.py | 3 +- cli/cliLogger.py | 4 +- cloudAPI/cloudManager.py | 14 +- containerization/views.py | 10 +- databases/databaseManager.py | 3 +- dockerManager/container.py | 2 +- emailMarketing/emailMarketing.py | 3 +- emailPremium/views.py | 14 +- filemanager/filemanager.py | 6 +- filemanager/views.py | 4 +- firewall/firewallManager.py | 88 +++--- ftp/ftpManager.py | 2 +- highAvailability/haManager.py | 8 +- install/composer.sh | 3 +- install/firewallUtilities.py | 2 +- install/install.py | 457 ++++++++++++++++++---------- install/installCyberPanel.py | 10 +- install/mysqlUtilities.py | 6 +- install/test.py | 2 +- install/unInstall.py | 12 +- loginSystem/views.py | 24 -- mailServer/mailserverManager.py | 14 +- managePHP/views.py | 10 +- manageSSL/views.py | 6 +- manageServices/serviceManager.py | 2 +- manageServices/views.py | 20 +- plogical/CyberCPLogFileWriter.py | 2 +- plogical/applicationInstaller.py | 82 ++--- plogical/backupSchedule.py | 4 +- plogical/backupUtilities.py | 24 +- plogical/csf.py | 13 +- plogical/dnsUtilities.py | 2 +- plogical/findBWUsage.py | 2 +- plogical/firewallUtilities.py | 2 +- plogical/ftpUtilities.py | 8 +- plogical/installUtilities.py | 24 +- plogical/mailUtilities.py | 64 ++-- plogical/modSec.py | 16 +- plogical/mysqlUtilities.py | 8 +- plogical/phpUtilities.py | 4 +- plogical/processUtilities.py | 36 ++- plogical/remoteBackup.py | 2 +- plogical/remoteTransferUtilities.py | 2 +- plogical/sslUtilities.py | 12 +- plogical/tuning.py | 8 +- plogical/upgrade.py | 4 +- plogical/upgradeCritical.py | 44 +++ plogical/vhost.py | 38 +-- plogical/virtualHostUtilities.py | 32 +- plogical/website.py | 74 ++--- pluginInstaller/pluginInstaller.py | 20 +- serverLogs/views.py | 4 +- serverStatus/serverStatusUtil.py | 8 +- serverStatus/views.py | 24 +- tuning/tuning.py | 4 +- 57 files changed, 813 insertions(+), 679 deletions(-) create mode 100644 plogical/upgradeCritical.py diff --git a/api/views.py b/api/views.py index e044df5d5..ac7357a90 100644 --- a/api/views.py +++ b/api/views.py @@ -21,6 +21,7 @@ from plogical.acl import ACLManager from firewall.models import FirewallRules from s3Backups.s3Backups import S3Backups from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging +from plogical.processUtilities import ProcessUtilities # Create your views here. @@ -120,8 +121,6 @@ def changeUserPassAPI(request): websiteOwn.password = hashPassword.hash_password(ownerPassword) websiteOwn.save() - - data_ret = {'changeStatus': 1, 'error_message': "None"} json_data = json.dumps(data_ret) return HttpResponse(json_data) @@ -260,7 +259,7 @@ def fetchSSHkey(request): pubKey = os.path.join("/root",".ssh",'cyberpanel.pub') execPath = "sudo cat " + pubKey - data = subprocess.check_output(shlex.split(execPath)) + data = ProcessUtilities.outputExecutioner(execPath) data_ret = { 'status': 1, @@ -313,7 +312,7 @@ def remoteTransfer(request): execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py" execPath = execPath + " remoteTransfer --ipAddress " + ipAddress + " --dir " + dir + " --accountsToTransfer " + path - subprocess.Popen(shlex.split(execPath)) + ProcessUtilities.popenExecutioner(execPath) return HttpResponse(json.dumps({"transferStatus": 1, "dir": dir})) @@ -381,8 +380,8 @@ def FetchRemoteTransferStatus(request): dir = "/home/backup/transfer-"+str(data['dir'])+"/backup_log" try: - command = "sudo cat "+ dir - status = subprocess.check_output(shlex.split(command)) + execPath = "sudo cat "+ dir + status = ProcessUtilities.outputExecutioner(execPath) admin = Administrator.objects.get(userName=username) if hashPassword.check_password(admin.password, password): @@ -418,14 +417,14 @@ def cancelRemoteTransfer(request): path = dir + "/pid" - command = "sudo cat " + path - pid = subprocess.check_output(shlex.split(command)) + execPath = "sudo cat " + path + pid = ProcessUtilities.outputExecutioner(execPath) - command = "sudo kill -KILL " + pid - subprocess.call(shlex.split(command)) + execPath = "sudo kill -KILL " + pid + ProcessUtilities.executioner(execPath) - command = "sudo rm -rf " + dir - subprocess.call(shlex.split(command)) + execPath = "sudo rm -rf " + dir + ProcessUtilities.executioner(execPath) data = {'cancelStatus': 1, 'error_message': "None"} json_data = json.dumps(data) @@ -525,9 +524,8 @@ def putSSHkey(request): ## - command = "sudo chmod g-w /home/cyberpanel" - cmd = shlex.split(command) - res = subprocess.call(cmd) + execPath = "sudo chmod g-w /home/cyberpanel" + ProcessUtilities.executioner(execPath) os.chmod(keyPath,0700) os.chmod(authorized_keys, 0600) @@ -590,30 +588,6 @@ def changeAdminPassword(request): newFWRule = FirewallRules(name="ftp", proto="tcp", port="21") newFWRule.save() - newFWRule = FirewallRules(name="smtp", proto="tcp", port="25") - newFWRule.save() - - newFWRule = FirewallRules(name="smtps", proto="tcp", port="587") - newFWRule.save() - - newFWRule = FirewallRules(name="ssmtp", proto="tcp", port="465") - newFWRule.save() - - newFWRule = FirewallRules(name="pop3", proto="tcp", port="110") - newFWRule.save() - - newFWRule = FirewallRules(name="imap", proto="tcp", port="143") - newFWRule.save() - - newFWRule = FirewallRules(name="simap", proto="tcp", port="993") - newFWRule.save() - - newFWRule = FirewallRules(name="dns", proto="udp", port="53") - newFWRule.save() - - newFWRule = FirewallRules(name="dnstcp", proto="tcp", port="53") - newFWRule.save() - newFWRule = FirewallRules(name="ftptls", proto="tcp", port="40110-40210") newFWRule.save() diff --git a/backup/backupManager.py b/backup/backupManager.py index a507412a4..31b515c42 100644 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -20,6 +20,7 @@ from random import randint import time import plogical.backupUtilities as backupUtil import requests +from plogical.processUtilities import ProcessUtilities class BackupManager: def __init__(self, domain = None, childDomain = None): @@ -61,7 +62,7 @@ class BackupManager: ext = ".tar.gz" command = 'sudo chown -R cyberpanel:cyberpanel ' + path - ACLManager.executeCall(command) + ProcessUtilities.executioner(command) files = os.listdir(path) for filename in files: @@ -144,7 +145,7 @@ class BackupManager: execPath = execPath + " submitBackupCreation --tempStoragePath " + tempStoragePath + " --backupName " \ + backupName + " --backupPath " + backupPath + ' --backupDomain ' + backupDomain - subprocess.Popen(shlex.split(execPath)) + ProcessUtilities.popenExecutioner(execPath) time.sleep(2) @@ -168,16 +169,16 @@ class BackupManager: ## read file name try: - command = "sudo cat " + backupFileNamePath - fileName = subprocess.check_output(shlex.split(command)) + execPath = "sudo cat " + backupFileNamePath + fileName = ProcessUtilities.outputExecutioner(execPath) except: fileName = "Fetching.." ## file name read ends if os.path.exists(status): - command = "sudo cat " + status - status = subprocess.check_output(shlex.split(command)) + execPath = "sudo cat " + status + status = ProcessUtilities.outputExecutioner(execPath) if status.find("Completed") > -1: @@ -201,14 +202,14 @@ class BackupManager: ### Removing Files - command = 'sudo rm -f ' + status - subprocess.call(shlex.split(command)) + execPath = 'sudo rm -f ' + status + ProcessUtilities.executioner(execPath) - command = 'sudo rm -f ' + backupFileNamePath - subprocess.call(shlex.split(command)) + execPath = 'sudo rm -f ' + backupFileNamePath + ProcessUtilities.executioner(execPath) - command = 'sudo rm -f ' + pid - subprocess.call(shlex.split(command)) + execPath = 'sudo rm -f ' + pid + ProcessUtilities.executioner(execPath) final_json = json.dumps( {'backupStatus': 1, 'error_message': "None", "status": status, "abort": 1, @@ -218,14 +219,14 @@ class BackupManager: elif status.find("[5009]") > -1: ## removing status file, so that backup can re-run try: - command = 'sudo rm -f ' + status - subprocess.call(shlex.split(command)) + execPath = 'sudo rm -f ' + status + ProcessUtilities.executioner(execPath) - command = 'sudo rm -f ' + backupFileNamePath - subprocess.call(shlex.split(command)) + execPath = 'sudo rm -f ' + backupFileNamePath + ProcessUtilities.executioner(execPath) - command = 'sudo rm -f ' + pid - subprocess.call(shlex.split(command)) + execPath = 'sudo rm -f ' + pid + ProcessUtilities.executioner(execPath) backupObs = Backups.objects.filter(fileName=fileName) for items in backupObs: @@ -260,10 +261,9 @@ class BackupManager: fileName = data['fileName'] execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py" - execPath = execPath + " cancelBackupCreation --backupCancellationDomain " + backupCancellationDomain + " --fileName " + fileName - subprocess.call(shlex.split(execPath)) + ProcessUtilities.executioner(execPath) try: backupOb = Backups.objects.get(fileName=fileName) @@ -287,8 +287,8 @@ class BackupManager: domainName = backup.website.domain path = "/home/" + domainName + "/backup/" + backup.fileName + ".tar.gz" - command = 'sudo rm -f ' + path - ACLManager.executeCall(command) + execPath = 'sudo rm -f ' + path + ProcessUtilities.executioner(execPath) backup.delete() @@ -312,7 +312,7 @@ class BackupManager: execPath = "sudo nice -n 10 python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py" execPath = execPath + " submitRestore --backupFile " + backupFile + " --dir " + dir - subprocess.Popen(shlex.split(execPath)) + ProcessUtilities.popenExecutioner(execPath) time.sleep(4) final_dic = {'restoreStatus': 1, 'error_message': "None"} @@ -340,12 +340,12 @@ class BackupManager: if os.path.exists(path): try: execPath = "sudo cat " + path + "/status" - status = subprocess.check_output(shlex.split(execPath)) + status = ProcessUtilities.outputExecutioner(execPath) if status.find("Done") > -1: - command = "sudo rm -rf " + path - subprocess.call(shlex.split(command)) + execPath = "sudo rm -rf " + path + ProcessUtilities.executioner(execPath) final_json = json.dumps( {'restoreStatus': 1, 'error_message': "None", "status": status, 'abort': 1, @@ -353,8 +353,8 @@ class BackupManager: return HttpResponse(final_json) elif status.find("[5009]") > -1: ## removing temporarily generated files while restoring - command = "sudo rm -rf " + path - subprocess.call(shlex.split(command)) + execPath = "sudo rm -rf " + path + ProcessUtilities.executioner(execPath) final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": status, 'abort': 1, 'alreadyRunning': 0, 'running': 'Error'}) @@ -428,7 +428,7 @@ class BackupManager: execPath = execPath + " submitDestinationCreation --ipAddress " + ipAddress + " --password " \ + password + " --port " + port - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(execPath) if output.find('1,') > -1: try: @@ -506,7 +506,7 @@ class BackupManager: execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py" execPath = execPath + " getConnectionStatus --ipAddress " + ipAddress - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(execPath) if output.find('1,') > -1: final_dic = {'connStatus': 1, 'error_message': "None"} @@ -664,9 +664,8 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" - - subprocess.call(shlex.split(command)) + execPath = "sudo systemctl restart crond" + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules(dest=destination, frequency=backupFreq) @@ -686,9 +685,9 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" + execPath = "sudo systemctl restart crond" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules(dest=destination, frequency=backupFreq) @@ -708,9 +707,9 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" + execPath = "sudo systemctl restart crond" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules(dest=destination, frequency=backupFreq) @@ -730,9 +729,8 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" - - subprocess.call(shlex.split(command)) + execPath = "sudo systemctl restart crond" + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules(dest=destination, frequency=backupFreq) @@ -752,9 +750,8 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" - - subprocess.call(shlex.split(command)) + execPath = "sudo systemctl restart crond" + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules(dest=destination, frequency=backupFreq) @@ -774,9 +771,8 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" - - subprocess.call(shlex.split(command)) + execPath = "sudo systemctl restart crond" + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules(dest=destination, frequency=backupFreq) @@ -796,9 +792,9 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" + execPath = "sudo systemctl restart crond" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules(dest=destination, frequency=backupFreq) @@ -818,9 +814,9 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" + execPath = "sudo systemctl restart crond" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules(dest=destination, frequency=backupFreq) @@ -862,9 +858,9 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" + execPath = "sudo systemctl restart crond" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules.objects.get(dest=destination, frequency=backupFreq) @@ -890,9 +886,9 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" + execPath = "sudo systemctl restart crond" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules.objects.get(dest=destination, frequency=backupFreq) @@ -918,9 +914,9 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" + execPath = "sudo systemctl restart crond" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules.objects.get(dest=destination, frequency=backupFreq) @@ -946,9 +942,9 @@ class BackupManager: virtualHostUtilities.leaveControl(path) - command = "sudo systemctl restart crond" + execPath = "sudo systemctl restart crond" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(execPath) destination = dest.objects.get(destLoc=backupDest) newSchedule = backupSchedules.objects.get(dest=destination, frequency=backupFreq) @@ -1054,7 +1050,7 @@ class BackupManager: execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py" execPath = execPath + " writeAuthKey --pathToKey " + pathToKey - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(execPath) if output.find("1,None") > -1: pass @@ -1129,8 +1125,8 @@ class BackupManager: localBackupDir = os.path.join("/home", "backup") if not os.path.exists(localBackupDir): - command = "sudo mkdir " + localBackupDir - subprocess.call(shlex.split(command)) + execPath = "sudo mkdir " + localBackupDir + ProcessUtilities.executioner(execPath) ## create local directory that will host backups @@ -1138,8 +1134,8 @@ class BackupManager: ## making local storage directory for backups - command = "sudo mkdir " + localStoragePath - subprocess.call(shlex.split(command)) + execPath = "sudo mkdir " + localStoragePath + ProcessUtilities.executioner(execPath) final_json = json.dumps( {'remoteTransferStatus': 1, 'error_message': "None", "dir": data['dir']}) @@ -1223,7 +1219,7 @@ class BackupManager: execPath = execPath + " remoteBackupRestore --backupDirComplete " + backupDirComplete + " --backupDir " + str( backupDir) - subprocess.Popen(shlex.split(execPath)) + ProcessUtilities.popenExecutioner(execPath) time.sleep(3) @@ -1253,18 +1249,18 @@ class BackupManager: time.sleep(3) if os.path.isfile(backupLogPath): - command = "sudo cat " + backupLogPath - status = subprocess.check_output(shlex.split(command)) + execPath = "sudo cat " + backupLogPath + status = ProcessUtilities.outputExecutioner(execPath) if status.find("completed[success]") > -1: command = "sudo rm -rf " + removalPath - # subprocess.call(shlex.split(command)) + # ProcessUtilities.executioner(shlex.split(command)) data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 1} json_data = json.dumps(data_ret) return HttpResponse(json_data) elif status.find("[5010]") > -1: command = "sudo rm -rf " + removalPath - # subprocess.call(shlex.split(command)) + # ProcessUtilities.executioner(shlex.split(command)) data = {'remoteTransferStatus': 0, 'error_message': status, "status": "None", "complete": 0} json_data = json.dumps(data) @@ -1311,14 +1307,14 @@ class BackupManager: path = "/home/backup/transfer-" + str(dir) pathpid = path + "/pid" - command = "sudo cat " + pathpid - pid = subprocess.check_output(shlex.split(command)) + execPath = "sudo cat " + pathpid + pid = ProcessUtilities.outputExecutioner(execPath) - command = "sudo kill -KILL " + pid - subprocess.call(shlex.split(command)) + execPath = "sudo kill -KILL " + pid + ProcessUtilities.executioner(execPath) - command = "sudo rm -rf " + path - subprocess.call(shlex.split(command)) + execPath = "sudo rm -rf " + path + ProcessUtilities.executioner(execPath) data = {'cancelStatus': 1, 'error_message': "None"} json_data = json.dumps(data) diff --git a/baseTemplate/views.py b/baseTemplate/views.py index 94731496c..17ca6412f 100644 --- a/baseTemplate/views.py +++ b/baseTemplate/views.py @@ -15,6 +15,7 @@ import shlex import os import plogical.CyberCPLogFileWriter as logging from plogical.acl import ACLManager +from plogical.processUtilities import ProcessUtilities # Create your views here. @@ -110,7 +111,7 @@ def upgrade(request): cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) vers = version.objects.get(pk=1) diff --git a/cli/cliLogger.py b/cli/cliLogger.py index 878f5527a..8011853c4 100644 --- a/cli/cliLogger.py +++ b/cli/cliLogger.py @@ -1,6 +1,6 @@ import subprocess import time - +from plogical.processUtilities import ProcessUtilities class cliLogger: fileName = "/home/cyberpanel/error-logs.txt" @@ -20,7 +20,7 @@ class cliLogger: def readLastNFiles(numberOfLines,fileName): try: - lastFewLines = subprocess.check_output(["tail", "-n",str(numberOfLines),fileName]) + lastFewLines = ProcessUtilities.outputExecutioner(["tail", "-n",str(numberOfLines),fileName]) return lastFewLines diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index 48606cbb0..94349d58d 100644 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -108,7 +108,7 @@ class CloudManager: 'domainName'] + " --bandwidth " + str( website.package.bandwidth) - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(execPath) bwData = output.split(",") except BaseException: bwData = [0, 0] @@ -319,8 +319,8 @@ class CloudManager: lastLine = statusData[-1] if lastLine.find('[200]') > -1: - command = 'sudo rm -f ' + statusFile - subprocess.call(shlex.split(command)) + execPath = 'sudo rm -f ' + statusFile + ProcessUtilities.outputExecutioner(execPath) data_ret = {'status': 1, 'abort': 1, 'installationProgress': "100", 'currentStatus': lastLine} json_data = json.dumps(data_ret) return HttpResponse(json_data) @@ -794,7 +794,7 @@ class CloudManager: try: pubKey = os.path.join("/root", ".ssh", 'cyberpanel.pub') execPath = "sudo cat " + pubKey - data = subprocess.check_output(shlex.split(execPath)) + data = ProcessUtilities.outputExecutioner(execPath) data_ret = { 'status': 1, @@ -1053,9 +1053,11 @@ class CloudManager: if ProcessUtilities.decideDistro() == ProcessUtilities.centos: - finalData['conf'] = subprocess.check_output(shlex.split('sudo cat /etc/my.cnf')) + execPath = 'sudo cat /etc/my.cnf' + finalData['conf'] = ProcessUtilities.outputExecutioner(execPath) else: - finalData['conf'] = subprocess.check_output(shlex.split('sudo cat /etc/mysql/my.cnf')) + execPath = 'sudo cat /etc/mysql/my.cnf' + finalData['conf'] = ProcessUtilities.outputExecutioner(execPath) finalData['status'] = 1 diff --git a/containerization/views.py b/containerization/views.py index b30a57087..4e0c8dac5 100644 --- a/containerization/views.py +++ b/containerization/views.py @@ -162,7 +162,7 @@ def saveWebsiteLimits(request): cgrules = '/etc/cgrules.conf' enforceString = '{} cpu,memory,blkio,net_cls {}/\n'.format(website.externalApp, website.externalApp) - cgrulesData = subprocess.check_output(shlex.split('sudo cat /etc/cgrules.conf')).splitlines() + cgrulesData = ProcessUtilities.outputExecutioner(shlex.split('sudo cat /etc/cgrules.conf')).splitlines() writeToFile = open(cgrulesTemp, 'w') @@ -219,7 +219,7 @@ def saveWebsiteLimits(request): cgrulesTemp = "/home/cyberpanel/" + str(randint(1000, 9999)) cgrules = '/etc/cgrules.conf' - cgrulesData = subprocess.check_output(shlex.split('sudo cat /etc/cgrules.conf')).splitlines() + cgrulesData = ProcessUtilities.outputExecutioner(shlex.split('sudo cat /etc/cgrules.conf')).splitlines() writeToFile = open(cgrulesTemp, 'w') @@ -293,7 +293,7 @@ def getUsageData(request): if type == 'memory': command = 'sudo cat /sys/fs/cgroup/memory/' + website.externalApp + '/memory.usage_in_bytes' - output = str(subprocess.check_output(command, shell=True)) + output = str(ProcessUtilities.outputExecutioner(command, shell=True)) finalData['memory'] = int(float(output)/float(1024 * 1024)) elif type == 'io': @@ -305,7 +305,7 @@ def getUsageData(request): os.mkdir(path) command = 'sudo cat /sys/fs/cgroup/blkio/' + website.externalApp + '/blkio.throttle.io_service_bytes' - output = subprocess.check_output(command, shell=True).splitlines() + output = ProcessUtilities.outputExecutioner(command, shell=True).splitlines() readCurrent = output[0].split(' ')[2] writeCurrent = output[1].split(' ')[2] @@ -333,7 +333,7 @@ def getUsageData(request): finalData['writeRate'] = 0 except: command = "sudo top -b -n 1 -u " + website.externalApp + " | awk 'NR>7 { sum += $9; } END { print sum; }'" - output = str(subprocess.check_output(command, shell=True)) + output = str(ProcessUtilities.outputExecutioner(command, shell=True)) finalData = {} if len(output) == 0: diff --git a/databases/databaseManager.py b/databases/databaseManager.py index 8cdbb7292..1ed242cf4 100644 --- a/databases/databaseManager.py +++ b/databases/databaseManager.py @@ -14,6 +14,7 @@ import plogical.CyberCPLogFileWriter as logging from plogical.mysqlUtilities import mysqlUtilities from websiteFunctions.models import Websites from databases.models import Databases +from plogical.processUtilities import ProcessUtilities class DatabaseManager: @@ -174,7 +175,7 @@ class DatabaseManager: command = 'sudo mysql -u root -p' + password + ' -e "' + passwordCMD + '"' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: data_ret = {'status': 0, 'changePasswordStatus': 0,'error_message': "Please see CyberPanel main log file."} diff --git a/dockerManager/container.py b/dockerManager/container.py index e5aff5f0c..9f2452fb7 100644 --- a/dockerManager/container.py +++ b/dockerManager/container.py @@ -64,7 +64,7 @@ class ContainerManager(multi.Thread): @staticmethod def executioner(command, statusFile): try: - res = subprocess.call(shlex.split(command), stdout=statusFile, stderr=statusFile) + res = ProcessUtilities.executioner(shlex.split(command), stdout=statusFile, stderr=statusFile) if res == 1: return 0 else: diff --git a/emailMarketing/emailMarketing.py b/emailMarketing/emailMarketing.py index 5d1ac1114..937e38751 100644 --- a/emailMarketing/emailMarketing.py +++ b/emailMarketing/emailMarketing.py @@ -12,6 +12,7 @@ import socket, smtplib import DNS from random import randint import subprocess, shlex +from plogical.processUtilities import ProcessUtilities class emailMarketing(multi.Thread): @@ -212,7 +213,7 @@ class emailMarketing(multi.Thread): messageFile.close() command = "sudo sed -i 's/{{ unsubscribeCheck }}/" + removalLink + "/g' " + tempPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) messageFile = open(tempPath, 'r') finalMessage = messageFile.read() diff --git a/emailPremium/views.py b/emailPremium/views.py index edc456b40..97df5ae0d 100644 --- a/emailPremium/views.py +++ b/emailPremium/views.py @@ -54,7 +54,7 @@ def fetchPolicyServerStatus(request): if request.method == 'POST': command = 'sudo cat /etc/postfix/main.cf' - output = subprocess.check_output(shlex.split(command)).split('\n') + output = ProcessUtilities.outputExecutioner(shlex.split(command)).split('\n') installCheck = 0 @@ -107,7 +107,7 @@ def savePolicyServerStatus(request): execPath = execPath + " savePolicyServerStatus --install " + install - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'status': 1, 'error_message': "None"} @@ -148,7 +148,7 @@ def listDomains(request): ## Check if Policy Server is installed. command = 'sudo cat /etc/postfix/main.cf' - output = subprocess.check_output(shlex.split(command)).split('\n') + output = ProcessUtilities.outputExecutioner(shlex.split(command)).split('\n') installCheck = 0 @@ -806,7 +806,7 @@ def installStatusSpamAssassin(request): if request.method == 'POST': command = "sudo cat " + mailUtilities.spamassassinInstallLogPath - installStatus = subprocess.check_output(shlex.split(command)) + installStatus = ProcessUtilities.outputExecutioner(shlex.split(command)) if installStatus.find("[200]")>-1: @@ -814,7 +814,7 @@ def installStatusSpamAssassin(request): execPath = execPath + " configureSpamAssassin" - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: pass @@ -884,7 +884,7 @@ def fetchSpamAssassinSettings(request): command = "sudo cat " + confPath - data = subprocess.check_output(shlex.split(command)).splitlines() + data = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() for items in data: if items.find('report_safe ') > -1: @@ -987,7 +987,7 @@ def saveSpamAssassinConfigurations(request): execPath = execPath + " saveSpamAssassinConfigs --tempConfigPath " + tempConfigPath - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'saveStatus': 1, 'error_message': "None"} diff --git a/filemanager/filemanager.py b/filemanager/filemanager.py index 7609d314d..fa37a9fbd 100644 --- a/filemanager/filemanager.py +++ b/filemanager/filemanager.py @@ -40,7 +40,7 @@ class FileManager: return self.ajaxPre(0, 'Not allowed to browse this path, going back home!') command = "sudo ls -la --group-directories-first " + self.returnPathEnclosed(self.data['completeStartingPath']) - output = subprocess.check_output(shlex.split(command)).splitlines() + output = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() counter = 0 for items in output: @@ -72,7 +72,7 @@ class FileManager: finalData['status'] = 1 command = "sudo ls -la --group-directories-first " + self.returnPathEnclosed(self.data['completeStartingPath']) - output = subprocess.check_output(shlex.split(command)).splitlines() + output = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() counter = 0 for items in output: @@ -225,7 +225,7 @@ class FileManager: command = 'sudo cat ' + self.returnPathEnclosed(self.data['fileName']) ProcessUtilities.executioner(command) - finalData['fileContents'] = subprocess.check_output(shlex.split(command)) + finalData['fileContents'] = ProcessUtilities.outputExecutioner(shlex.split(command)) json_data = json.dumps(finalData) return HttpResponse(json_data) diff --git a/filemanager/views.py b/filemanager/views.py index b9cfae2ea..527a4cde1 100644 --- a/filemanager/views.py +++ b/filemanager/views.py @@ -54,10 +54,10 @@ def changePermissions(request): externalApp = website.externalApp command = "sudo chown -R " + externalApp + ":" + externalApp +" /home/"+domainName - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "sudo chown -R lscpd:lscpd /home/" + domainName+"/logs" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) data_ret = {'permissionsChanged': 1, 'error_message': "None"} json_data = json.dumps(data_ret) diff --git a/firewall/firewallManager.py b/firewall/firewallManager.py index 48fbd676a..019489839 100644 --- a/firewall/firewallManager.py +++ b/firewall/firewallManager.py @@ -163,7 +163,7 @@ class FirewallManager: command = 'sudo firewall-cmd --reload' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 0: final_dic = {'reload_status': 1, 'error_message': "None"} @@ -194,7 +194,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 0: final_dic = {'start_status': 1, 'error_message': "None"} @@ -223,7 +223,7 @@ class FirewallManager: command = 'sudo systemctl stop firewalld' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 0: final_dic = {'stop_status': 1, 'error_message': "None"} @@ -252,7 +252,7 @@ class FirewallManager: command = 'sudo systemctl status firewalld' - status = subprocess.check_output(shlex.split(command)) + status = ProcessUtilities.outputExecutioner(shlex.split(command)) if status.find("active") > -1: final_dic = {'status': 1, 'error_message': "none", 'firewallStatus': 1} @@ -301,7 +301,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) pathToSSH = "/etc/ssh/sshd_config" @@ -324,7 +324,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) final_dic = {'status': 1, 'permitRootLogin': permitRootLogin, 'sshPort': sshPort} final_json = json.dumps(final_dic) @@ -337,7 +337,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) pathToKeyFile = "/root/.ssh/authorized_keys" @@ -378,7 +378,7 @@ class FirewallManager: command = 'sudo chown -R root:root /root' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) final_json = json.dumps({'status': 1, 'error_message': "None", "data": json_data}) return HttpResponse(final_json) @@ -406,7 +406,7 @@ class FirewallManager: command = 'sudo semanage port -a -t ssh_port_t -p tcp ' + sshPort cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) FirewallUtilities.addRule('tcp', sshPort, "0.0.0.0/0") @@ -428,7 +428,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) ## @@ -461,7 +461,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) ## changin back permissions @@ -469,7 +469,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) ## @@ -499,7 +499,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) ## @@ -524,7 +524,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) ## @@ -554,7 +554,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) ## @@ -597,7 +597,7 @@ class FirewallManager: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) ## @@ -624,7 +624,7 @@ class FirewallManager: confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + httpdConfig = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() modSecInstalled = 0 @@ -669,7 +669,7 @@ class FirewallManager: execPath = execPath + " installModSecConfigs" - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: pass @@ -738,7 +738,7 @@ class FirewallManager: if os.path.exists(modSecPath): command = "sudo cat " + confPath - data = subprocess.check_output(shlex.split(command)).splitlines() + data = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() for items in data: @@ -803,7 +803,7 @@ class FirewallManager: command = "sudo cat " + confPath - data = subprocess.check_output(shlex.split(command)).splitlines() + data = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() for items in data: if items.find('SecAuditEngine ') > -1: @@ -917,7 +917,7 @@ class FirewallManager: execPath = execPath + " saveModSecConfigs --tempConfigPath " + tempConfigPath - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: installUtilities.reStartLiteSpeed() @@ -973,7 +973,7 @@ class FirewallManager: execPath = execPath + " saveModSecConfigs --tempConfigPath " + tempConfigPath - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: installUtilities.reStartLiteSpeed() @@ -1004,7 +1004,7 @@ class FirewallManager: confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + httpdConfig = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() modSecInstalled = 0 @@ -1034,7 +1034,7 @@ class FirewallManager: confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + httpdConfig = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() modSecInstalled = 0 @@ -1047,7 +1047,7 @@ class FirewallManager: if modSecInstalled: command = "sudo cat " + rulesPath - currentModSecRules = subprocess.check_output(shlex.split(command)) + currentModSecRules = ProcessUtilities.outputExecutioner(shlex.split(command)) final_dic = {'modSecInstalled': 1, 'currentModSecRules': currentModSecRules} @@ -1063,7 +1063,7 @@ class FirewallManager: rulesPath = os.path.join(virtualHostUtilities.Server_root + "/conf/rules.conf") command = "sudo cat " + rulesPath - currentModSecRules = subprocess.check_output(shlex.split(command)) + currentModSecRules = ProcessUtilities.outputExecutioner(shlex.split(command)) final_dic = {'modSecInstalled': 1, 'currentModSecRules': currentModSecRules} @@ -1098,7 +1098,7 @@ class FirewallManager: execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" execPath = execPath + " saveModSecRules" - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: installUtilities.reStartLiteSpeed() @@ -1130,7 +1130,7 @@ class FirewallManager: confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + httpdConfig = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() modSecInstalled = 0 @@ -1160,7 +1160,7 @@ class FirewallManager: confPath = os.path.join(virtualHostUtilities.Server_root, "conf/httpd_config.conf") command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + httpdConfig = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() modSecInstalled = 0 @@ -1174,7 +1174,7 @@ class FirewallManager: if modSecInstalled: command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + httpdConfig = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() for items in httpdConfig: @@ -1205,7 +1205,7 @@ class FirewallManager: try: command = 'sudo cat /usr/local/lsws/conf/comodo_litespeed/rules.conf.main' - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res == 0: comodoInstalled = 1 @@ -1242,7 +1242,7 @@ class FirewallManager: execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" execPath = execPath + " " + packName - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: installUtilities.reStartLiteSpeed() @@ -1260,7 +1260,7 @@ class FirewallManager: execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/modSec.py" execPath = execPath + " " + packName - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: installUtilities.reStartLiteSpeed() @@ -1292,7 +1292,7 @@ class FirewallManager: confPath = os.path.join(virtualHostUtilities.Server_root, 'conf/httpd_config.conf') command = "sudo cat " + confPath - httpdConfig = subprocess.check_output(shlex.split(command)).splitlines() + httpdConfig = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() json_data = "[" checker = 0 @@ -1334,7 +1334,7 @@ class FirewallManager: comodoPath = '/usr/local/lsws/conf/comodo_litespeed' command = 'sudo chown -R cyberpanel:cyberpanel /usr/local/lsws/conf' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) json_data = "[" @@ -1370,7 +1370,7 @@ class FirewallManager: json_data = json_data + ',' + json.dumps(dic) command = 'sudo chown -R lsadm:lsadm /usr/local/lsws/conf' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) json_data = json_data + ']' final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data}) @@ -1403,7 +1403,7 @@ class FirewallManager: execPath = execPath + " " + functionName + ' --packName ' + packName + ' --fileName ' + fileName - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: installUtilities.reStartLiteSpeed() @@ -1433,7 +1433,7 @@ class FirewallManager: csfInstalled = 1 try: command = 'sudo csf -h' - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res == 1: csfInstalled = 0 except subprocess.CalledProcessError: @@ -1454,7 +1454,7 @@ class FirewallManager: execPath = "sudo /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/csf.py" execPath = execPath + " installCSF" - subprocess.Popen(shlex.split(execPath)) + ProcessUtilities.popenExecutioner(shlex.split(execPath)) time.sleep(2) @@ -1477,7 +1477,7 @@ class FirewallManager: if installStatus.find("[200]")>-1: command = 'sudo rm -f ' + CSF.installLogPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) final_json = json.dumps({ 'error_message': "None", @@ -1488,7 +1488,7 @@ class FirewallManager: return HttpResponse(final_json) elif installStatus.find("[404]") > -1: command = 'sudo rm -f ' + CSF.installLogPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) final_json = json.dumps({ 'abort':1, 'installed':0, @@ -1522,7 +1522,7 @@ class FirewallManager: execPath = "sudo /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/csf.py" execPath = execPath + " removeCSF" - subprocess.Popen(shlex.split(execPath)) + ProcessUtilities.popenExecutioner(shlex.split(execPath)) time.sleep(2) @@ -1581,7 +1581,7 @@ class FirewallManager: execPath = "sudo /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/csf.py" execPath = execPath + " changeStatus --controller " + controller + " --status " + status - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {"status": 1} @@ -1615,7 +1615,7 @@ class FirewallManager: execPath = "sudo /usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/csf.py" execPath = execPath + " modifyPorts --protocol " + protocol + " --ports " + ports - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {"status": 1} diff --git a/ftp/ftpManager.py b/ftp/ftpManager.py index 5935ef5ab..b05d1535c 100644 --- a/ftp/ftpManager.py +++ b/ftp/ftpManager.py @@ -85,7 +85,7 @@ class FTPManager: execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/ftpUtilities.py" execPath = execPath + " submitFTPCreation --domainName " + domainName + " --userName " + userName \ + " --password " + password + " --path " + path + " --owner " + admin.userName + ' --api ' + api - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'status': 1, 'creatFTPStatus': 1, 'error_message': 'None'} json_data = json.dumps(data_ret) diff --git a/highAvailability/haManager.py b/highAvailability/haManager.py index e83acc336..1028a5792 100644 --- a/highAvailability/haManager.py +++ b/highAvailability/haManager.py @@ -55,7 +55,7 @@ class HAManager(multi.Thread): for command in commands: try: - result = subprocess.call(command, shell=True) + result = ProcessUtilities.executioner(command, shell=True) if result != 0: logging.writeToFile(command + ' Failed.') except BaseException: @@ -99,14 +99,14 @@ class HAManager(multi.Thread): workerToken = '' command = "sudo docker swarm join-token manager" - output = subprocess.check_output(shlex.split(command)).splitlines() + output = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() for items in output: if items.find('--token') > -1: managerToken = items.split(' ')[-2] command = "sudo docker swarm join-token worker" - output = subprocess.check_output(shlex.split(command)).splitlines() + output = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() for items in output: if items.find('--token') > -1: @@ -160,7 +160,7 @@ class HAManager(multi.Thread): for command in commands: try: - result = subprocess.call(command, shell=True) + result = ProcessUtilities.executioner(command, shell=True) if result != 0: logging.writeToFile(command + ' Failed.') except BaseException, msg: diff --git a/install/composer.sh b/install/composer.sh index 64ba9fc2e..2edbd489b 100644 --- a/install/composer.sh +++ b/install/composer.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');" -cp composer.phar /usr/bin/composer \ No newline at end of file +mv composer.phar /usr/bin/composer \ No newline at end of file diff --git a/install/firewallUtilities.py b/install/firewallUtilities.py index b4bfacd54..539a4f21f 100644 --- a/install/firewallUtilities.py +++ b/install/firewallUtilities.py @@ -8,7 +8,7 @@ class FirewallUtilities: import install as inst try: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if inst.preFlightsChecks.resFailed(inst.get_distro(), res): inst.preFlightsChecks.stdOut("Failed to apply rule: " + command + " Error #" + str(res), 1) return 0 diff --git a/install/install.py b/install/install.py index 2dd6f0096..f16786f8a 100644 --- a/install/install.py +++ b/install/install.py @@ -33,6 +33,40 @@ class preFlightsChecks: self.cyberPanelPath = cyberPanelPath self.distro = distro + def mountTemp(self): + try: + command = "mkdir -p /root/images/" + ProcessUtilities.executioner(shlex.split(command)) + + command = "dd if=/dev/zero of=/root/images/tmpfile.bin bs=1 count=0 seek=4G" + ProcessUtilities.executioner(shlex.split(command)) + + command = "mkfs.ext4 /root/images/tmpfile.bin" + ProcessUtilities.executioner(shlex.split(command)) + + command = "mount -o loop,rw,nodev,nosuid,noexec /root/images/tmpfile.bin /tmp" + ProcessUtilities.executioner(shlex.split(command)) + + command = "chmod 1777 /tmp" + ProcessUtilities.executioner(shlex.split(command)) + + command = "mount -o rw,noexec,nosuid,nodev,bind /tmp /var/tmp" + ProcessUtilities.executioner(shlex.split(command)) + + tmp = "/root/images/tmpfile.bin /tmp ext4 loop,rw,noexec,nosuid,nodev 0 0\n" + varTmp = "/tmp /var/tmp none rw,noexec,nosuid,nodev,bind 0 0\n" + + fstab = "/etc/fstab" + writeToFile = open(fstab, "a") + writeToFile.writelines(tmp); + writeToFile.writelines(varTmp) + writeToFile.close() + + except BaseException, msg: + preFlightsChecks.stdOut("[Failed:mountTemp] " + str(msg)) + return 0 + + @staticmethod def stdOut(message, log=0, do_exit=0, code=os.EX_OK): print("\n\n") @@ -66,7 +100,7 @@ class preFlightsChecks: preFlightsChecks.stdOut(message + " " + bracket, log) count = 0 while True: - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(distro, res): count = count + 1 @@ -87,7 +121,7 @@ class preFlightsChecks: def checkIfSeLinuxDisabled(self): try: command = "sestatus" - output = subprocess.check_output(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(shlex.split(command)) if output.find("disabled") > -1 or output.find("permissive") > -1: logging.InstallLog.writeToFile("SELinux Check OK. [checkIfSeLinuxDisabled]") @@ -144,7 +178,7 @@ class preFlightsChecks: self.stdOut("Add Cyberpanel user") command = "useradd cyberpanel -m -U -G sudo" cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res != 0 and res != 9: logging.InstallLog.writeToFile("Can not create cyberpanel user, error #" + str(res)) preFlightsChecks.stdOut("Can not create cyberpanel user, error #" + str(res)) @@ -199,7 +233,7 @@ class preFlightsChecks: command = 'yum update -y' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -233,7 +267,7 @@ class preFlightsChecks: filename = "enable_lst_debain_repo.sh" command = "wget http://rpms.litespeedtech.com/debian/" + filename cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res != 0: logging.InstallLog.writeToFile( "Unable to download Ubuntu CyberPanel installer! [installCyberPanelRepo]:" @@ -246,7 +280,7 @@ class preFlightsChecks: command = "./" + filename cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res != 0: logging.InstallLog.writeToFile("Unable to install Ubuntu CyberPanel! [installCyberPanelRepo]:" @@ -270,7 +304,7 @@ class preFlightsChecks: cmd.append("rpm") cmd.append("-ivh") cmd.append("http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -296,7 +330,7 @@ class preFlightsChecks: cmd.append("-y") cmd.append("install") cmd.append("epel-release") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -333,7 +367,7 @@ class preFlightsChecks: command = "apt-get -y install python-pip" else: command = "yum -y install python-pip" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -355,7 +389,7 @@ class preFlightsChecks: command = "yum -y install python-devel" else: command = "apt-get -y install python-dev" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -380,7 +414,7 @@ class preFlightsChecks: command = "yum -y install gcc" else: command = "apt-get -y install gcc" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -398,7 +432,7 @@ class preFlightsChecks: count = 0 while (1): command = "yum -y install python-setuptools" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -422,10 +456,10 @@ class preFlightsChecks: ## Un-install ULRLIB3 and requests command = "pip uninstall --yes urllib3" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) command = "pip uninstall --yes requests" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) ## Install specific versions @@ -434,7 +468,7 @@ class preFlightsChecks: command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/urllib3-1.22.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -455,7 +489,7 @@ class preFlightsChecks: command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/requests-2.18.4.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -478,7 +512,7 @@ class preFlightsChecks: command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/urllib3-1.22.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -499,7 +533,7 @@ class preFlightsChecks: command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/requests-2.18.4.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -520,14 +554,14 @@ class preFlightsChecks: import pexpect command = "pip uninstall --yes pexpect" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) count = 0 while (1): command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/pexpect-4.4.0.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -547,7 +581,7 @@ class preFlightsChecks: while (1): command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/pexpect-4.4.0.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -567,7 +601,7 @@ class preFlightsChecks: while (1): command = "pip install django==1.11" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -589,7 +623,7 @@ class preFlightsChecks: command = "yum -y install MySQL-python" else: command = "apt-get -y install libmysqlclient-dev" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 preFlightsChecks.stdOut("Unable to install MySQL-python, trying again, try number: " + str(count)) @@ -605,7 +639,7 @@ class preFlightsChecks: if self.distro == ubuntu: command = "pip install MySQL-python" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res != 0: logging.InstallLog.writeToFile( "Unable to install MySQL-python, exiting installer! [install_python_mysql_library] Error: " + str( @@ -623,7 +657,7 @@ class preFlightsChecks: command = "pip install gunicorn" else: command = "easy_install gunicorn" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 preFlightsChecks.stdOut("Unable to install GUNICORN, trying again, try number: " + str(count)) @@ -661,7 +695,7 @@ class preFlightsChecks: while (1): command = "systemctl enable gunicorn.socket" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -688,12 +722,12 @@ class preFlightsChecks: ## command = "pip uninstall --yes psutil" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) count = 0 while (1): command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/psutil-5.4.3.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -711,7 +745,7 @@ class preFlightsChecks: count = 0 while (1): command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/psutil-5.4.3.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -734,7 +768,7 @@ class preFlightsChecks: cmd.append("httpd_can_network_connect") cmd.append("1") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): logging.InstallLog.writeToFile("fix_selinux_issue problem") @@ -751,7 +785,7 @@ class preFlightsChecks: command = "yum -y install psmisc" else: command = "apt-get -y install psmisc" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 preFlightsChecks.stdOut("Unable to install psmisc, trying again, try number: " + str(count)) @@ -768,7 +802,7 @@ class preFlightsChecks: try: ## On OpenVZ there is an issue with requests module, which needs to upgrade requests module - if subprocess.check_output('systemd-detect-virt').find("openvz") > -1: + if ProcessUtilities.outputExecutioner('systemd-detect-virt').find("openvz") > -1: command = "pip install --upgrade requests" preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]', 'Upgrade requests', @@ -780,8 +814,8 @@ class preFlightsChecks: os.chdir(self.path) - command = "wget http://cyberpanel.sh/CyberPanel.1.8.1.tar.gz" - #command = "wget http://cyberpanel.sh/CyberPanelTemp.tar.gz" + #command = "wget http://cyberpanel.sh/CyberPanel.1.8.1.tar.gz" + command = "wget http://cyberpanel.sh/CyberPanelTemp.tar.gz" preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]', 'CyberPanel Download', 1, 1, os.EX_OSERR) @@ -789,8 +823,8 @@ class preFlightsChecks: ## count = 0 - command = "tar zxf CyberPanel.1.8.1.tar.gz" - #command = "tar zxf CyberPanelTemp.tar.gz" + #command = "tar zxf CyberPanel.1.8.1.tar.gz" + command = "tar zxf CyberPanelTemp.tar.gz" preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]', 'Extract CyberPanel',1, 1, os.EX_OSERR) @@ -911,25 +945,12 @@ class preFlightsChecks: def download_install_phpmyadmin(self): try: + os.chdir("/usr/local/lscp/cyberpanel/") - command = 'wget https://files.phpmyadmin.net/phpMyAdmin/4.8.2/phpMyAdmin-4.8.2-all-languages.zip' + command = 'composer create-project phpmyadmin/phpmyadmin' preFlightsChecks.call(command, self.distro, '[download_install_phpmyadmin]', 'Download PHPMYAdmin', 1, 0, os.EX_OSERR) - ##### - - command = 'unzip phpMyAdmin-4.8.2-all-languages.zip' - preFlightsChecks.call(command, self.distro, '[download_install_phpmyadmin]', - 'Unzip PHPMYAdmin', 1, 0, os.EX_OSERR) - - - ### - - os.remove("phpMyAdmin-4.8.2-all-languages.zip") - - command = 'mv phpMyAdmin-4.8.2-all-languages phpmyadmin' - preFlightsChecks.call(command, self.distro, '[download_install_phpmyadmin]', - 'Move PHPMYAdmin', 1, 0, os.EX_OSERR) ## Write secret phrase @@ -953,7 +974,7 @@ class preFlightsChecks: os.mkdir('/usr/local/lscp/cyberpanel/phpmyadmin/tmp') command = 'chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/phpmyadmin' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except BaseException, msg: logging.InstallLog.writeToFile(str(msg) + " [download_install_phpmyadmin]") @@ -970,28 +991,28 @@ class preFlightsChecks: else: command = 'apt-get -y remove postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) self.stdOut("Install dovecot - do the install") count = 0 while (1): if self.distro == centos: - command = 'yum install -y http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64//postfix3-3.2.4-1.gf.el7.x86_64.rpm' + command = 'yum install -y postfix' else: command = 'apt-get -y debconf-utils' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) file_name = self.cwd + '/pf.unattend.text' pf = open(file_name, 'w') pf.write('postfix postfix/mailname string ' + str(socket.getfqdn() + '\n')) pf.write('postfix postfix/main_mailer_type string "Internet Site"\n') pf.close() command = 'debconf-set-selections ' + file_name - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'apt-get -y install postfix' # os.remove(file_name) cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1009,13 +1030,13 @@ class preFlightsChecks: while (1): if self.distro == centos: - command = 'yum install -y http://mirror.ghettoforge.org/distributions/gf/el/7/plus/x86_64//postfix3-mysql-3.2.4-1.gf.el7.x86_64.rpm' + break else: command = 'apt-get -y install dovecot-imapd dovecot-pop3d postfix-mysql' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1040,7 +1061,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1260,7 +1281,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1284,7 +1305,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1344,7 +1365,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1370,7 +1391,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1394,7 +1415,7 @@ class preFlightsChecks: command = 'chmod o= /etc/postfix/mysql-virtual_mailboxes.cf' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1419,7 +1440,7 @@ class preFlightsChecks: command = 'chmod o= /etc/postfix/mysql-virtual_email2email.cf' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1443,7 +1464,7 @@ class preFlightsChecks: command = 'chmod o= ' + main cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1469,7 +1490,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1494,7 +1515,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1516,7 +1537,7 @@ class preFlightsChecks: while (1): command = 'chgrp postfix /etc/postfix/mysql-virtual_forwardings.cf' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1539,7 +1560,7 @@ class preFlightsChecks: while (1): command = 'chgrp postfix /etc/postfix/mysql-virtual_mailboxes.cf' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1563,7 +1584,7 @@ class preFlightsChecks: command = 'chgrp postfix /etc/postfix/mysql-virtual_email2email.cf' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1585,7 +1606,7 @@ class preFlightsChecks: while (1): command = 'chgrp postfix ' + main cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1610,7 +1631,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1635,7 +1656,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1659,7 +1680,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1687,7 +1708,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1712,7 +1733,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1736,7 +1757,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1762,7 +1783,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1788,7 +1809,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1810,7 +1831,7 @@ class preFlightsChecks: while (1): command = 'systemctl start dovecot.service' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1834,7 +1855,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1857,7 +1878,7 @@ class preFlightsChecks: command = "chmod 755 " + main cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1876,18 +1897,18 @@ class preFlightsChecks: if self.distro == ubuntu: command = "mkdir -p /etc/pki/dovecot/private/" cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) command = "mkdir -p /etc/pki/dovecot/certs/" cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) command = "mkdir -p /etc/opendkim/keys/" cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) command = "sed -i 's/auth_mechanisms = plain/#auth_mechanisms = plain/g' /etc/dovecot/conf.d/10-auth.conf" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## Ubuntu 18.10 ssl_dh for dovecot 2.3.2.1 @@ -1905,7 +1926,7 @@ class preFlightsChecks: writeToFile.close() command = "systemctl restart dovecot" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) logging.InstallLog.writeToFile("Postfix and Dovecot configured") @@ -1926,7 +1947,7 @@ class preFlightsChecks: while (1): command = 'chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1953,7 +1974,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -1976,7 +1997,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2001,7 +2022,7 @@ class preFlightsChecks: while (1): command = 'find . -type d -exec chmod 755 {} \;' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2025,7 +2046,7 @@ class preFlightsChecks: command = 'find . -type f -exec chmod 644 {} \;' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2047,7 +2068,7 @@ class preFlightsChecks: command = 'chown -R lscpd:lscpd .' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2086,7 +2107,7 @@ class preFlightsChecks: cmd.append(self.server_root_path + "bin/lswsctrl") cmd.append("restart") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2110,7 +2131,7 @@ class preFlightsChecks: def removeUfw(self): try: preFlightsChecks.stdOut("Checking to see if ufw firewall is installed (will be removed)", 1) - status = subprocess.check_output(shlex.split('ufw status')) + status = ProcessUtilities.outputExecutioner(shlex.split('ufw status')) preFlightsChecks.stdOut("ufw current status: " + status + "...will be removed") except BaseException, msg: preFlightsChecks.stdOut("Expected access to ufw not available, do not need to remove it", 1) @@ -2171,14 +2192,6 @@ class preFlightsChecks: FirewallUtilities.addRule("tcp", "80") FirewallUtilities.addRule("tcp", "443") FirewallUtilities.addRule("tcp", "21") - FirewallUtilities.addRule("tcp", "25") - FirewallUtilities.addRule("tcp", "587") - FirewallUtilities.addRule("tcp", "465") - FirewallUtilities.addRule("tcp", "110") - FirewallUtilities.addRule("tcp", "143") - FirewallUtilities.addRule("tcp", "993") - FirewallUtilities.addRule("udp", "53") - FirewallUtilities.addRule("tcp", "53") FirewallUtilities.addRule("tcp", "40110-40210") logging.InstallLog.writeToFile("FirewallD installed and configured!") @@ -2214,7 +2227,7 @@ class preFlightsChecks: while (1): command = 'chmod +x /usr/local/lscp/bin/lscpdctrl' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2239,7 +2252,7 @@ class preFlightsChecks: command = 'systemctl enable lscpd.service' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2259,7 +2272,7 @@ class preFlightsChecks: # In Ubuntu, the library that lscpd looks for is libpcre.so.1, but the one it installs is libpcre.so.3... if self.distro == ubuntu: command = 'ln -s /lib/x86_64-linux-gnu/libpcre.so.3 /lib/x86_64-linux-gnu/libpcre.so.1' - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res == 0: self.stdOut("Created ubuntu symbolic link to pcre") else: @@ -2273,7 +2286,7 @@ class preFlightsChecks: command = 'systemctl start lscpd' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2314,7 +2327,7 @@ class preFlightsChecks: cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = ProcessUtilities.executioner(cmd, stdout=file) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2338,7 +2351,7 @@ class preFlightsChecks: command = 'systemctl enable cron' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = ProcessUtilities.executioner(cmd, stdout=file) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2361,7 +2374,7 @@ class preFlightsChecks: else: command = 'systemctl start cron' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = ProcessUtilities.executioner(cmd, stdout=file) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2381,11 +2394,16 @@ class preFlightsChecks: cronFile.writelines("0 * * * * root python /usr/local/CyberCP/plogical/findBWUsage.py" + "\n") cronFile.writelines("0 * * * * root /usr/local/CyberCP/postfixSenderPolicy/client.py hourlyCleanup" + "\n") cronFile.writelines("0 0 1 * * root /usr/local/CyberCP/postfixSenderPolicy/client.py monthlyCleanup" + "\n") + cronFile.writelines("0 2 * * * root /usr/local/CyberCP/plogical/upgradeCritical.py" + "\n") cronFile.close() command = 'chmod +x /usr/local/CyberCP/plogical/findBWUsage.py' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = ProcessUtilities.executioner(cmd, stdout=file) + + command = 'chmod +x /usr/local/CyberCP/plogical/upgradeCritical.py' + cmd = shlex.split(command) + res = ProcessUtilities.executioner(cmd, stdout=file) if preFlightsChecks.resFailed(self.distro, res): logging.InstallLog.writeToFile("1427 [setup_cron]") @@ -2395,7 +2413,7 @@ class preFlightsChecks: command = 'chmod +x /usr/local/CyberCP/postfixSenderPolicy/client.py' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = ProcessUtilities.executioner(cmd, stdout=file) if preFlightsChecks.resFailed(self.distro, res): logging.InstallLog.writeToFile("1428 [setup_cron]") @@ -2410,7 +2428,7 @@ class preFlightsChecks: else: command = 'systemctl restart cron.service' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=file) + res = ProcessUtilities.executioner(cmd, stdout=file) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2449,7 +2467,7 @@ class preFlightsChecks: command = "ssh-keygen -f /root/.ssh/cyberpanel -t rsa -N ''" cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2482,7 +2500,7 @@ class preFlightsChecks: command = 'apt-get -y install rsync' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2514,17 +2532,17 @@ class preFlightsChecks: except BaseException, msg: command = "pip uninstall --yes urllib3" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "pip uninstall --yes requests" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) count = 0 while (1): command = "pip install http://mirror.cyberpanel.net/urllib3-1.22.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2545,7 +2563,7 @@ class preFlightsChecks: command = "pip install http://mirror.cyberpanel.net/requests-2.18.4.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2579,16 +2597,16 @@ class preFlightsChecks: try: command = "pip uninstall --yes pyOpenSSL" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) command = "pip uninstall --yes certbot" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) count = 0 while (1): command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/pyOpenSSL-17.5.0.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2608,7 +2626,7 @@ class preFlightsChecks: while (1): command = "pip install http://" + preFlightsChecks.cyberPanelMirror + "/certbot-0.21.1.tar.gz" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2649,7 +2667,7 @@ class preFlightsChecks: while (1): command = "pip install tldextract" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2688,7 +2706,7 @@ class preFlightsChecks: command = 'apt-get -y install opendkim' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2705,13 +2723,13 @@ class preFlightsChecks: if self.distro == ubuntu: try: command = 'apt install opendkim-tools' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except: pass try: command = 'mkdir -p /etc/opendkim/keys/' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except: pass @@ -2771,15 +2789,15 @@ milter_default_action = accept #### Restarting Postfix and OpenDKIM command = "systemctl start opendkim" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "systemctl enable opendkim" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## command = "systemctl start postfix" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [configureOpenDKIM]") @@ -2796,7 +2814,7 @@ milter_default_action = accept while (1): command = "pip install dnspython" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2818,7 +2836,7 @@ milter_default_action = accept count = 0 while (1): command = "ln -s /usr/local/CyberCP/cli/cyberPanel.py /usr/bin/cyberpanel" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -2833,7 +2851,7 @@ milter_default_action = accept break command = "chmod +x /usr/local/CyberCP/cli/cyberPanel.py" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [setupCLI]") @@ -2854,23 +2872,17 @@ milter_default_action = accept os.symlink('/usr/local/lsws/lsphp72/bin/php7.2', '/usr/local/lsws/lsphp72/bin/php') command = "cp /usr/local/lsws/lsphp71/bin/php /usr/bin/" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) os.chdir(self.cwd) - if self.distro == centos: - command = "chmod +x composer.sh" - else: - command = "chmod +x composer-no-test.sh" + command = "chmod +x composer.sh" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) - if self.distro == centos: - command = "./composer.sh" - else: - command = "./composer-no-test.sh" + command = "./composer.sh" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [setupPHPAndComposer]") @@ -2878,7 +2890,7 @@ milter_default_action = accept @staticmethod def installOne(package): - res = subprocess.call(shlex.split('apt-get -y install ' + package)) + res = ProcessUtilities.executioner(shlex.split('apt-get -y install ' + package)) if res != 0: preFlightsChecks.stdOut("Error #" + str(res) + ' installing:' + package + '. This may not be an issue ' \ 'but may affect installation of something later', @@ -2926,7 +2938,7 @@ milter_default_action = accept else: while (1): command = "yum install -y libattr-devel xz-devel gpgme-devel mariadb-devel curl-devel" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(distro, res): count = count + 1 @@ -2948,7 +2960,7 @@ milter_default_action = accept count = 0 while (1): command = "pip install virtualenv" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(distro, res): count = count + 1 @@ -2969,7 +2981,7 @@ milter_default_action = accept count = 0 while (1): command = "virtualenv --system-site-packages /usr/local/CyberCP" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(distro, res): count = count + 1 @@ -2988,7 +3000,7 @@ milter_default_action = accept ## env_path = '/usr/local/CyberCP' - subprocess.call(['virtualenv', env_path]) + ProcessUtilities.executioner(['virtualenv', env_path]) activate_this = os.path.join(env_path, 'bin', 'activate_this.py') execfile(activate_this, dict(__file__=activate_this)) @@ -3011,7 +3023,7 @@ milter_default_action = accept count = 0 while (1): command = "pip install --ignore-installed -r " + install_file - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if preFlightsChecks.resFailed(distro, res): count = count + 1 @@ -3027,10 +3039,10 @@ milter_default_action = accept break command = "systemctl restart gunicorn.socket" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) command = "virtualenv --system-site-packages /usr/local/CyberCP" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) @@ -3046,10 +3058,10 @@ milter_default_action = accept if state == 'Off': command = 'sudo systemctl stop pdns' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo systemctl disable pdns' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) try: os.remove(servicePath) @@ -3072,10 +3084,10 @@ milter_default_action = accept if state == 'Off': command = 'sudo systemctl stop postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo systemctl disable postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) try: os.remove(servicePath) @@ -3098,10 +3110,10 @@ milter_default_action = accept if state == 'Off': command = 'sudo systemctl stop ' + preFlightsChecks.pureFTPDServiceName(distro) - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo systemctl disable ' + preFlightsChecks.pureFTPDServiceName(distro) - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) try: os.remove(servicePath) @@ -3116,11 +3128,120 @@ milter_default_action = accept logging.InstallLog.writeToFile(str(msg) + " [enableDisableEmail]") return 0 + def setupComodoRules(self): + try: + + os.chdir(self.cwd) + + extractLocation = "/usr/local/lscp/modsec" + + command = "mkdir -p /usr/local/lscp/modsec" + ProcessUtilities.executioner(shlex.split(command)) + + try: + if os.path.exists('comodo.tar.gz'): + os.remove('comodo.tar.gz') + except: + pass + + command = "wget https://cyberpanel.net/modsec/comodo.tar.gz" + result = ProcessUtilities.executioner(shlex.split(command)) + + if result == 1: + return 0 + + command = "tar -zxf comodo.tar.gz -C /usr/local/lscp/modsec" + result = ProcessUtilities.executioner(shlex.split(command)) + + ### + + modsecConfPath = "/usr/local/lscp/conf/myconf.conf" + + modsecConfig = """ +module mod_security { +modsecurity on +modsecurity_rules ` +SecDebugLogLevel 0 +SecDebugLog /usr/local/lscp/logs/modsec.log +SecAuditEngine on +SecAuditLogRelevantStatus "^(?:5|4(?!04))" +SecAuditLogParts AFH +SecAuditLogType Serial +SecAuditLog /usr/local/lscp/logs/auditmodsec.log +SecRuleEngine On +` + modsecurity_rules_file /usr/local/lscp/modsec/comodo/modsecurity.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/00_Init_Initialization.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/01_Init_AppsInitialization.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/02_Global_Generic.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/03_Global_Agents.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/04_Global_Domains.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/05_Global_Backdoor.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/06_XSS_XSS.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/07_Global_Other.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/08_Bruteforce_Bruteforce.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/09_HTTP_HTTP.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/10_HTTP_HTTPDoS.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/11_HTTP_Protocol.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/12_HTTP_Request.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/13_Outgoing_FilterGen.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/14_Outgoing_FilterASP.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/15_Outgoing_FilterPHP.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/16_Outgoing_FilterSQL.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/17_Outgoing_FilterOther.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/18_Outgoing_FilterInFrame.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/19_Outgoing_FiltersEnd.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/20_PHP_PHPGen.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/21_SQL_SQLi.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/22_Apps_Joomla.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/23_Apps_JComponent.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/24_Apps_WordPress.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/25_Apps_WPPlugin.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/26_Apps_WHMCS.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/27_Apps_Drupal.conf + modsecurity_rules_file /usr/local/lscp/modsec/comodo/28_Apps_OtherApps.conf +} +""" + + writeToFile = open(modsecConfPath, 'w') + writeToFile.write(modsecConfig) + writeToFile.close() + + ### + + command = "chown -R lscpd:lscpd /usr/local/lscp/modsec" + ProcessUtilities.executioner(shlex.split(command)) + + return 1 + + except BaseException, msg: + preFlightsChecks.stdOut("[Failed:setupComodoRules] " + str(msg)) + return 0 + + def setupPort(self, port): + try: + ### + bindConfPath = "/usr/local/lscp/conf/bind.conf" + + writeToFile = open(bindConfPath, 'w') + writeToFile.write(port) + writeToFile.close() + + ### + + command = "chown -R lscpd:lscpd /usr/local/lscp/modsec" + ProcessUtilities.executioner(shlex.split(command)) + + return 1 + + except: + return 0 + @staticmethod def setUpFirstAccount(): try: command = 'python /usr/local/CyberCP/plogical/adminPass.py --password 1234567' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except: pass @@ -3182,6 +3303,7 @@ def main(): parser.add_argument('--ftp', help='Enable or disable ftp Service.') parser.add_argument('--ent', help='Install LS Ent or OpenLiteSpeed') parser.add_argument('--serial', help='Install LS Ent or OpenLiteSpeed') + parser.add_argument('--port', help='Install LS Ent or OpenLiteSpeed') args = parser.parse_args() logging.InstallLog.writeToFile("Starting CyberPanel installation..") @@ -3204,6 +3326,11 @@ def main(): preFlightsChecks.stdOut("Installation failed, please specify LiteSpeed Enterprise key using --serial") os._exit(0) + if args.port == None: + port = "8090" + else: + port = args.port + ## Writing public IP try: @@ -3219,6 +3346,7 @@ def main(): distro = get_distro() checks = preFlightsChecks("/usr/local/lsws/", args.publicip, "/usr/local", cwd, "/usr/local/CyberCP", distro) + checks.mountTemp() if distro == ubuntu: os.chdir("/etc/cyberpanel") @@ -3255,6 +3383,7 @@ def main(): else: installCyberPanel.Main(cwd, mysql, distro, ent, serial) + checks.setupPHPAndComposer() checks.fix_selinux_issue() checks.install_psmisc() checks.install_postfix_davecot() @@ -3264,7 +3393,6 @@ def main(): checks.install_unzip() checks.install_zip() checks.install_rsync() - checks.downoad_and_install_raindloop() checks.download_install_phpmyadmin() @@ -3288,10 +3416,12 @@ def main(): checks.installOpenDKIM() checks.configureOpenDKIM() + checks.setupComodoRules() + checks.setupPort(port) checks.modSecPreReqs() checks.setupVirtualEnv(distro) - checks.setupPHPAndComposer() + if args.postfix != None: checks.enableDisableEmail(args.postfix) @@ -3310,6 +3440,7 @@ def main(): else: preFlightsChecks.stdOut("Pure-FTPD will be installed and enabled.") checks.enableDisableFTP('On', distro) + checks.setUpFirstAccount() logging.InstallLog.writeToFile("CyberPanel installation successfully completed!") checks.installation_successfull() diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index da04e0beb..902b33c5a 100644 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -337,7 +337,7 @@ class InstallCyberPanel: while (1): command = "systemctl start mysqld@1" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if install.preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -357,7 +357,7 @@ class InstallCyberPanel: while (1): command = "systemctl enable mysqld@1" - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if install.preFlightsChecks.resFailed(self.distro, res): count = count + 1 @@ -546,7 +546,7 @@ class InstallCyberPanel: shutil.copy(ftpdPath + "/pureftpd-mysql.conf", '/etc/pure-ftpd/db/mysql.conf') command = 'echo 1 > /etc/pure-ftpd/conf/TLS' - subprocess.call(command, shell=True) + ProcessUtilities.executioner(command, shell=True) command = 'systemctl restart pure-ftpd-mysql.service' install.preFlightsChecks.call(command, self.distro, '[installPureFTPDConfigurations]', @@ -565,12 +565,12 @@ class InstallCyberPanel: if self.distro == ubuntu: command = 'systemctl stop systemd-resolved' - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res != 0: InstallCyberPanel.stdOut('Unable to stop systemd.resolved, prohits install of PowerDNS, error #' + str(res), 1, 1, os.EX_OSERR) command = 'systemctl disable systemd-resolved.service' - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res != 0: InstallCyberPanel.stdOut( 'Unable to disable systemd.resolved, prohits install of PowerDNS, error #' + diff --git a/install/mysqlUtilities.py b/install/mysqlUtilities.py index bdab9c3d4..7d9bc6ee2 100644 --- a/install/mysqlUtilities.py +++ b/install/mysqlUtilities.py @@ -19,7 +19,7 @@ class mysqlUtilities: command = 'mysql -u root -p' + password + ' -e "' + createDB + '"' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: return 0 @@ -29,7 +29,7 @@ class mysqlUtilities: command = 'mysql -u root -p' + password + ' -e "' + createUser + '"' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: return 0 @@ -37,7 +37,7 @@ class mysqlUtilities: dropDB = "GRANT ALL PRIVILEGES ON " + dbname + ".* TO '" + dbuser + "'@'localhost'" command = 'mysql -u root -p' + password + ' -e "' + dropDB + '"' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: return 0 diff --git a/install/test.py b/install/test.py index a4ef8ee01..9ec32ec81 100644 --- a/install/test.py +++ b/install/test.py @@ -9,7 +9,7 @@ def installCertBot(): cmd.append("install") cmd.append("certbot") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) installCertBot() \ No newline at end of file diff --git a/install/unInstall.py b/install/unInstall.py index 5d14440c1..794456d35 100644 --- a/install/unInstall.py +++ b/install/unInstall.py @@ -44,7 +44,7 @@ class unInstallCyberPanel: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) shutil.rmtree("/etc/postfix") shutil.rmtree("etc/dovecot") @@ -66,7 +66,7 @@ class unInstallCyberPanel: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) shutil.rmtree("/var/lib/mysql") os.remove("/etc/my.cnf") @@ -88,7 +88,7 @@ class unInstallCyberPanel: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) shutil.rmtree("/usr/local/lsws") @@ -122,7 +122,7 @@ class unInstallCyberPanel: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) shutil.rmtree("/etc/pure-ftpd") @@ -141,7 +141,7 @@ class unInstallCyberPanel: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) shutil.rmtree("/etc/pdns") @@ -160,7 +160,7 @@ class unInstallCyberPanel: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) shutil.rmtree("/etc/pdns") diff --git a/loginSystem/views.py b/loginSystem/views.py index cf66976fc..6ae88bfc6 100644 --- a/loginSystem/views.py +++ b/loginSystem/views.py @@ -181,30 +181,6 @@ def loadLoginPage(request): newFWRule = FirewallRules(name="ftp", proto="tcp", port="21") newFWRule.save() - newFWRule = FirewallRules(name="smtp", proto="tcp", port="25") - newFWRule.save() - - newFWRule = FirewallRules(name="smtps", proto="tcp", port="587") - newFWRule.save() - - newFWRule = FirewallRules(name="ssmtp", proto="tcp", port="465") - newFWRule.save() - - newFWRule = FirewallRules(name="pop3", proto="tcp", port="110") - newFWRule.save() - - newFWRule = FirewallRules(name="imap", proto="tcp", port="143") - newFWRule.save() - - newFWRule = FirewallRules(name="simap", proto="tcp", port="993") - newFWRule.save() - - newFWRule = FirewallRules(name="dns", proto="udp", port="53") - newFWRule.save() - - newFWRule = FirewallRules(name="dnstcp", proto="tcp", port="53") - newFWRule.save() - newFWRule = FirewallRules(name="ftptls", proto="tcp", port="40110-40210") newFWRule.save() diff --git a/mailServer/mailserverManager.py b/mailServer/mailserverManager.py index f450b6040..ba214f82b 100644 --- a/mailServer/mailserverManager.py +++ b/mailServer/mailserverManager.py @@ -76,7 +76,7 @@ class MailServerManager: execPath = execPath + " createEmailAccount --domain " + domainName + " --userName " \ + userName + " --password " + password - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'status': 1, 'createEmailStatus': 1, 'error_message': "None"} @@ -391,13 +391,13 @@ class MailServerManager: try: path = "/etc/opendkim/keys/" + domainName + "/default.txt" command = "sudo cat " + path - output = subprocess.check_output(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(shlex.split(command)) leftIndex = output.index('(') + 2 rightIndex = output.rindex(')') - 1 path = "/etc/opendkim/keys/" + domainName + "/default.private" command = "sudo cat " + path - privateKey = subprocess.check_output(shlex.split(command)) + privateKey = ProcessUtilities.outputExecutioner(shlex.split(command)) data_ret = {'status': 1, 'fetchStatus': 1, 'keysAvailable': 1, 'publicKey': output[leftIndex:rightIndex], 'privateKey': privateKey, 'dkimSuccessMessage': 'Keys successfully fetched!', @@ -428,7 +428,7 @@ class MailServerManager: execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py" execPath = execPath + " generateKeys --domain " + domainName - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) admin = Administrator.objects.get(pk=userID) DNS.dnsTemplate(domainName, admin) @@ -444,7 +444,7 @@ class MailServerManager: path = "/etc/opendkim/keys/" + domainName + "/default.txt" command = "sudo cat " + path - output = subprocess.check_output(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(shlex.split(command)) leftIndex = output.index('(') + 2 rightIndex = output.rindex(')') - 1 @@ -492,7 +492,7 @@ class MailServerManager: def installStatusOpenDKIM(self): try: command = "sudo cat " + mailUtilities.installLogPath - installStatus = subprocess.check_output(shlex.split(command)) + installStatus = ProcessUtilities.outputExecutioner(shlex.split(command)) if installStatus.find("[200]") > -1: @@ -500,7 +500,7 @@ class MailServerManager: execPath = execPath + " configureOpenDKIM" - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: pass diff --git a/managePHP/views.py b/managePHP/views.py index 1020d5002..a99dd1cd1 100644 --- a/managePHP/views.py +++ b/managePHP/views.py @@ -1320,7 +1320,7 @@ def getRequestStatus(request): requestStatusSize = len(requestStatus) if requestStatus.find("PHP Extension Installed") > -1: - if subprocess.check_output(checkCommand).find(extensionName) > -1: + if ProcessUtilities.outputExecutioner(checkCommand).find(extensionName) > -1: ext = installedPackages.objects.get(extensionName=extensionName) ext.status = 1 ext.save() @@ -1337,7 +1337,7 @@ def getRequestStatus(request): return HttpResponse(final_json) elif requestStatus.find("Can not be installed") > -1: - if subprocess.check_output(checkCommand).find(extensionName) > -1: + if ProcessUtilities.outputExecutioner(checkCommand).find(extensionName) > -1: ext = installedPackages.objects.get(extensionName=extensionName) ext.status = 1 ext.save() @@ -1354,7 +1354,7 @@ def getRequestStatus(request): return HttpResponse(final_json) elif requestStatus.find("Can not un-install Extension") > -1: - if subprocess.check_output(checkCommand).find(extensionName) > -1: + if ProcessUtilities.outputExecutioner(checkCommand).find(extensionName) > -1: ext = installedPackages.objects.get(extensionName=extensionName) ext.status = 1 ext.save() @@ -1552,7 +1552,7 @@ def savePHPConfigBasic(request): execPath = execPath + " savePHPConfigBasic --phpVers " + phpVers + " --allow_url_fopen '" + allow_url_fopen + "' --display_errors '" + display_errors + "' --file_uploads '" + file_uploads + "' --allow_url_include '" + allow_url_include + "' --memory_limit " + memory_limit + " --max_execution_time " + max_execution_time + " --upload_max_filesize " + upload_max_filesize + " --max_input_time " + max_input_time + " --post_max_size " + post_max_size - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'saveStatus': 1} @@ -1650,7 +1650,7 @@ def savePHPConfigAdvance(request): execPath = execPath + " savePHPConfigAdvance --phpVers " + path + " --tempPath " + tempPath - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: status = {"saveStatus": 1, "configData": data['configData']} diff --git a/manageSSL/views.py b/manageSSL/views.py index ae7c5ef6d..f0aa267aa 100644 --- a/manageSSL/views.py +++ b/manageSSL/views.py @@ -76,7 +76,7 @@ def issueSSL(request): execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" execPath = execPath + " issueSSL --virtualHostName " + virtualHost + " --administratorEmail " + adminEmail + " --path " + path - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: pass @@ -151,7 +151,7 @@ def obtainHostNameSSL(request): execPath = execPath + " issueSSLForHostName --virtualHostName " + virtualHost + " --path " + path - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {"status": 1, "SSL": 1, @@ -221,7 +221,7 @@ def obtainMailServerSSL(request): execPath = execPath + " issueSSLForMailServer --virtualHostName " + virtualHost + " --path " + path - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {"status": 1, "SSL": 1, diff --git a/manageServices/serviceManager.py b/manageServices/serviceManager.py index a78dd1105..e2de90d4d 100644 --- a/manageServices/serviceManager.py +++ b/manageServices/serviceManager.py @@ -12,7 +12,7 @@ class ServiceManager: type = self.extraArgs['type'] path = '/etc/pdns/pdns.conf' - data = subprocess.check_output(shlex.split('sudo cat ' + path)).splitlines() + data = ProcessUtilities.outputExecutioner(shlex.split('sudo cat ' + path)).splitlines() if type == 'MASTER': counter = 0 diff --git a/manageServices/views.py b/manageServices/views.py index 94f0b0bf7..fd13e15b8 100644 --- a/manageServices/views.py +++ b/manageServices/views.py @@ -174,10 +174,10 @@ def saveStatus(request): sm.managePDNS() command = 'sudo systemctl enable pdns' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo systemctl restart pdns' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) else: @@ -186,10 +186,10 @@ def saveStatus(request): pdns.save() command = 'sudo systemctl stop pdns' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo systemctl disable pdns' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) elif service == 'postfix': @@ -199,13 +199,13 @@ def saveStatus(request): writeToFile = open(servicePath, 'w+') writeToFile.close() command = 'sudo systemctl start postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) else: command = 'sudo systemctl stop postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo systemctl disable postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) try: os.remove(servicePath) @@ -223,13 +223,13 @@ def saveStatus(request): writeToFile = open(servicePath, 'w+') writeToFile.close() command = 'sudo systemctl start ' + serviceName - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) else: command = 'sudo systemctl stop ' + serviceName - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo systemctl disable ' + serviceName - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) try: os.remove(servicePath) diff --git a/plogical/CyberCPLogFileWriter.py b/plogical/CyberCPLogFileWriter.py index 15f991e94..b93c2eb79 100644 --- a/plogical/CyberCPLogFileWriter.py +++ b/plogical/CyberCPLogFileWriter.py @@ -31,7 +31,7 @@ class CyberCPLogFileWriter: def readLastNFiles(numberOfLines,fileName): try: - lastFewLines = subprocess.check_output(["tail", "-n",str(numberOfLines),fileName]) + lastFewLines = ProcessUtilities.outputExecutioner(["tail", "-n",str(numberOfLines),fileName]) return lastFewLines diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index f7f1e2a50..392b5fd92 100644 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -48,13 +48,13 @@ class ApplicationInstaller(multi.Thread): 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)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo chmod +x wp-cli.phar' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo mv wp-cli.phar /usr/bin/wp' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except BaseException, msg: logging.writeToFile( str(msg) + ' [ApplicationInstaller.installWPCLI]') @@ -94,13 +94,13 @@ class ApplicationInstaller(multi.Thread): try: if os.path.exists("/etc/lsb-release"): command = 'apt -y install git' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) else: command = 'sudo yum -y install http://repo.iotti.biz/CentOS/7/noarch/lux-release-7-1.noarch.rpm' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo yum install git -y' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except BaseException, msg: logging.writeToFile( str(msg) + ' [ApplicationInstaller.installGit]') @@ -158,7 +158,7 @@ class ApplicationInstaller(multi.Thread): try: command = 'sudo wp --info' - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res == 1: self.installWPCLI() @@ -235,7 +235,7 @@ class ApplicationInstaller(multi.Thread): if not os.path.exists(finalPath): command = 'sudo mkdir -p ' + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## checking for directories/files @@ -249,7 +249,7 @@ class ApplicationInstaller(multi.Thread): statusFile.close() command = "sudo wp core download --allow-root --path=" + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## @@ -258,7 +258,7 @@ class ApplicationInstaller(multi.Thread): statusFile.close() command = "sudo wp core config --dbname=" + dbName + " --dbuser=" + dbUser + " --dbpass=" + dbPassword + " --dbhost=localhost --dbprefix=wp_ --allow-root --path=" + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) if home == '0': path = self.extraArgs['path'] @@ -267,7 +267,7 @@ class ApplicationInstaller(multi.Thread): finalURL = domainName command = 'sudo wp core install --url="http://' + finalURL + '" --title="' + blogTitle + '" --admin_user="' + adminUser + '" --admin_password="' + adminPassword + '" --admin_email="' + adminEmail + '" --allow-root --path=' + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## @@ -276,21 +276,21 @@ class ApplicationInstaller(multi.Thread): statusFile.close() command = "sudo wp plugin install litespeed-cache --allow-root --path=" + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) statusFile = open(tempStatusPath, 'w') statusFile.writelines('Activating LSCache Plugin,90') statusFile.close() command = "sudo wp plugin activate litespeed-cache --allow-root --path=" + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) statusFile = open(tempStatusPath, 'w') statusFile.writelines("Successfully Installed. [200]") @@ -308,7 +308,7 @@ class ApplicationInstaller(multi.Thread): command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) try: mysqlUtilities.deleteDatabase(dbName, dbUser) @@ -406,7 +406,7 @@ class ApplicationInstaller(multi.Thread): if not os.path.exists(finalPath): command = 'sudo mkdir -p ' + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## checking for directories/files @@ -420,13 +420,13 @@ class ApplicationInstaller(multi.Thread): statusFile.close() command = "sudo wget https://download.prestashop.com/download/releases/prestashop_1.7.4.2.zip" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "sudo unzip -o prestashop_1.7.4.2.zip -d " + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "sudo unzip -o " + finalPath + "prestashop.zip -d " + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## @@ -449,22 +449,22 @@ class ApplicationInstaller(multi.Thread): " --db_server=localhost --db_name=" + dbName + " --db_user=" + dbUser + " --db_password=" + dbPassword \ + " --name='" + shopName + "' --firstname=" + firstName + " --lastname=" + lastName + \ " --email=" + email + " --password=" + password - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## command = "sudo rm -rf " + finalPath + "install" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) command = "sudo rm -f prestashop_1.7.4.2.zip" cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) statusFile = open(tempStatusPath, 'w') statusFile.writelines("Successfully Installed. [200]") @@ -480,7 +480,7 @@ class ApplicationInstaller(multi.Thread): if not os.path.exists(homeDir): command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) try: mysqlUtilities.deleteDatabase(dbName, dbUser) @@ -512,7 +512,7 @@ class ApplicationInstaller(multi.Thread): try: command = 'sudo git --help' - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res == 1: statusFile = open(tempStatusPath, 'w') @@ -561,7 +561,7 @@ class ApplicationInstaller(multi.Thread): if not os.path.exists(finalPath): command = 'sudo mkdir -p ' + finalPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## checking for directories/files @@ -579,7 +579,7 @@ class ApplicationInstaller(multi.Thread): try: command = 'sudo GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no" git clone --depth 1 --no-single-branch git@' + defaultProvider +'.com:' + username + '/' + reponame + '.git -b ' + branch + ' ' + finalPath logging.writeToFile(command) - subprocess.check_output(shlex.split(command)) + ProcessUtilities.outputExecutioner(shlex.split(command)) except subprocess.CalledProcessError, msg: statusFile = open(tempStatusPath, 'w') statusFile.writelines('Failed to clone repository, make sure you deployed your key to repository. [404]') @@ -590,7 +590,7 @@ class ApplicationInstaller(multi.Thread): command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) vhost.addRewriteRules(domainName) installUtilities.reStartLiteSpeed() @@ -633,7 +633,7 @@ class ApplicationInstaller(multi.Thread): return 0 command = 'sudo git --git-dir=' + finalPath + '.git --work-tree=' + finalPath +' pull' - subprocess.check_output(shlex.split(command)) + ProcessUtilities.outputExecutioner(shlex.split(command)) ## @@ -642,7 +642,7 @@ class ApplicationInstaller(multi.Thread): command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath cmd = shlex.split(command) - subprocess.call(cmd) + ProcessUtilities.executioner(cmd) return 0 @@ -674,16 +674,16 @@ class ApplicationInstaller(multi.Thread): command = 'sudo rm -rf ' + finalPath - subprocess.check_output(shlex.split(command)) + ProcessUtilities.outputExecutioner(shlex.split(command)) command = 'sudo mkdir ' + finalPath - subprocess.check_output(shlex.split(command)) + ProcessUtilities.outputExecutioner(shlex.split(command)) ## command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath cmd = shlex.split(command) - subprocess.call(cmd) + ProcessUtilities.executioner(cmd) gitPath = '/home/cyberpanel/' + domain + '.git' @@ -731,7 +731,7 @@ class ApplicationInstaller(multi.Thread): if not os.path.exists("staging.zip"): command = 'wget --no-check-certificate https://github.com/joomla/joomla-cms/archive/staging.zip -P ' + finalPath cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) else: statusFile = open(tempStatusPath, 'w') statusFile.writelines("File already exists." + " [404]") @@ -741,12 +741,12 @@ class ApplicationInstaller(multi.Thread): command = 'unzip ' + finalPath + 'staging.zip -d ' + finalPath cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) os.remove(finalPath + 'staging.zip') command = 'cp -r ' + finalPath + 'joomla-cms-staging/. ' + finalPath cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) shutil.rmtree(finalPath + "joomla-cms-staging") os.rename(finalPath + "installation/configuration.php-dist", finalPath + "configuration.php") @@ -816,7 +816,7 @@ class ApplicationInstaller(multi.Thread): f2.close() # Restore SQL - proc = subprocess.Popen(["mysql", "--user=%s" % dbUser, "--password=%s" % dbPassword, dbName], + proc = ProcessUtilities.popenExecutioner(["mysql", "--user=%s" % dbUser, "--password=%s" % dbPassword, dbName], stdin=subprocess.PIPE, stdout=subprocess.PIPE) usercreation = """INSERT INTO `%susers` @@ -833,7 +833,7 @@ class ApplicationInstaller(multi.Thread): command = "sudo chown -R " + virtualHostUser + ":" + virtualHostUser + " " + finalPath cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) vhost.addRewriteRules(domainName) @@ -852,7 +852,7 @@ class ApplicationInstaller(multi.Thread): if not os.path.exists(homeDir): command = "sudo chown -R " + virtualHostUser + ":" + virtualHostUser + " " + homeDir cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) try: mysqlUtilities.deleteDatabase(dbName, dbUser) @@ -881,11 +881,11 @@ class ApplicationInstaller(multi.Thread): try: command = 'sudo git --git-dir=' + finalPath + '/.git checkout -b ' + githubBranch - subprocess.check_output(shlex.split(command)) + ProcessUtilities.outputExecutioner(shlex.split(command)) except: try: command = 'sudo git --git-dir=' + finalPath + '/.git checkout ' + githubBranch - subprocess.check_output(shlex.split(command)) + ProcessUtilities.outputExecutioner(shlex.split(command)) except subprocess.CalledProcessError, msg: logging.writeToFile('Failed to change branch: ' + str(msg)) return 0 diff --git a/plogical/backupSchedule.py b/plogical/backupSchedule.py index c010124ee..ff970f1b6 100644 --- a/plogical/backupSchedule.py +++ b/plogical/backupSchedule.py @@ -111,7 +111,7 @@ class backupSchedule: writeToFile = open(backupLogPath, "a") command = "sudo scp -o StrictHostKeyChecking=no -P "+port+" -i /root/.ssh/cyberpanel " + backupPath + " root@"+IPAddress+":/home/backup/" + ipAddressLocal + "/" + time.strftime("%a-%b") + "/" - subprocess.call(shlex.split(command), stdout=writeToFile) + ProcessUtilities.executioner(shlex.split(command), stdout=writeToFile) ## Remove backups already sent to remote destinations @@ -162,7 +162,7 @@ class backupSchedule: command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + ipAddress + " mkdir -p /home/backup/" + ipAddressLocal + "/" + time.strftime( "%a-%b") - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) pass for virtualHost in os.listdir("/home"): diff --git a/plogical/backupUtilities.py b/plogical/backupUtilities.py index 318cbfd8d..4ee2bb034 100644 --- a/plogical/backupUtilities.py +++ b/plogical/backupUtilities.py @@ -638,7 +638,7 @@ class backupUtilities: ## Change permissions command = "chmod -r vmail:vmail " + emailHome - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except: pass @@ -656,7 +656,7 @@ class backupUtilities: command = "chown -R " + externalApp + ":" + externalApp + " " + websiteHome cmd = shlex.split(command) - subprocess.call(cmd) + ProcessUtilities.executioner(cmd) except BaseException, msg: status = os.path.join(completPath, 'status') @@ -778,7 +778,7 @@ class backupUtilities: @staticmethod def checkIfHostIsUp(IPAddress): try: - if subprocess.check_output(['ping', IPAddress, '-c 1']).find("0% packet loss") > -1: + if ProcessUtilities.outputExecutioner(['ping', IPAddress, '-c 1']).find("0% packet loss") > -1: return 1 else: return 0 @@ -807,22 +807,22 @@ class backupUtilities: index = checkConn.expect(expectation) if index == 0: - subprocess.call(['kill', str(checkConn.pid)]) + ProcessUtilities.executioner(['kill', str(checkConn.pid)]) logging.CyberCPLogFileWriter.writeToFile("Remote Server is not able to authenticate for transfer to initiate, IP Address:" + IPAddress) return [0,"Remote Server is not able to authenticate for transfer to initiate."] elif index == 1: - subprocess.call(['kill', str(checkConn.pid)]) + ProcessUtilities.executioner(['kill', str(checkConn.pid)]) logging.CyberCPLogFileWriter.writeToFile( "Remote Server is not able to authenticate for transfer to initiate, IP Address:" + IPAddress) return [0, "Remote Server is not able to authenticate for transfer to initiate."] elif index == 2: - subprocess.call(['kill', str(checkConn.pid)]) + ProcessUtilities.executioner(['kill', str(checkConn.pid)]) return [1, "None"] elif index == 4: - subprocess.call(['kill', str(checkConn.pid)]) + ProcessUtilities.executioner(['kill', str(checkConn.pid)]) return [1, "None"] else: - subprocess.call(['kill', str(checkConn.pid)]) + ProcessUtilities.executioner(['kill', str(checkConn.pid)]) return [1, "None"] except pexpect.TIMEOUT, msg: @@ -907,13 +907,13 @@ class backupUtilities: try: command = "sudo ssh -o StrictHostKeyChecking=no -p "+ port +" -i /root/.ssh/cyberpanel root@"+IPAddress+" mkdir /home/backup" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + IPAddress + ' "cat /root/.ssh/authorized_keys /root/.ssh/temp > /root/.ssh/authorized_temp"' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "sudo ssh -o StrictHostKeyChecking=no -p " + port + " -i /root/.ssh/cyberpanel root@" + IPAddress + ' "cat /root/.ssh/authorized_temp > /root/.ssh/authorized_keys"' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createBackupDir]") @@ -923,7 +923,7 @@ class backupUtilities: def host_key_verification(IPAddress): try: command = 'sudo ssh-keygen -R ' + IPAddress - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) return 1 except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [host_key_verification]") diff --git a/plogical/csf.py b/plogical/csf.py index 703886722..5fb21e7cc 100644 --- a/plogical/csf.py +++ b/plogical/csf.py @@ -9,6 +9,7 @@ import tarfile import shutil from mailUtilities import mailUtilities import threading as multi +from plogical.processUtilities import ProcessUtilities class CSF(multi.Thread): installLogPath = "/home/cyberpanel/csfInstallLog" @@ -140,7 +141,7 @@ class CSF(multi.Thread): currentSettings = {} command = 'sudo cat /etc/csf/csf.conf' - output = subprocess.check_output(shlex.split(command)).splitlines() + output = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() for items in output: if items.find('TESTING') > -1 and items.find('=') > -1 and (items[0]!= '#') and items.find('TESTING_INTERVAL') == -1: @@ -166,7 +167,7 @@ class CSF(multi.Thread): currentSettings['firewallStatus'] = 0 command = 'sudo iptables -nv -L' - output = subprocess.check_output(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(shlex.split(command)) if output.find('0.0.0.0/0') > -1: currentSettings['firewallStatus'] = 1 @@ -258,10 +259,10 @@ class CSF(multi.Thread): def allowIP(ipAddress): try: command = 'sudo csf -dr ' + ipAddress - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo csf -a ' + ipAddress - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[allowIP]") @@ -271,10 +272,10 @@ class CSF(multi.Thread): try: command = 'sudo csf -tr ' + ipAddress - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo csf -d ' + ipAddress - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[blockIP]") diff --git a/plogical/dnsUtilities.py b/plogical/dnsUtilities.py index 209cd2717..c6e146e3d 100644 --- a/plogical/dnsUtilities.py +++ b/plogical/dnsUtilities.py @@ -326,7 +326,7 @@ class DNS: path = "/etc/opendkim/keys/" + topLevelDomain + "/default.txt" command = "sudo cat " + path - output = subprocess.check_output(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(shlex.split(command)) leftIndex = output.index('(') + 2 rightIndex = output.rindex(')') - 1 diff --git a/plogical/findBWUsage.py b/plogical/findBWUsage.py index 1a88816fe..708979ef6 100644 --- a/plogical/findBWUsage.py +++ b/plogical/findBWUsage.py @@ -127,7 +127,7 @@ class findBWUsage: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: logging.CyberCPLogFileWriter.writeToFile("1440 [setup_cron]") diff --git a/plogical/firewallUtilities.py b/plogical/firewallUtilities.py index f07aa1501..2538e41ac 100644 --- a/plogical/firewallUtilities.py +++ b/plogical/firewallUtilities.py @@ -19,7 +19,7 @@ class FirewallUtilities: def doCommand(command): try: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if FirewallUtilities.resFailed(res): logging.CyberCPLogFileWriter.writeToFile("Failed to apply rule: " + command + " Error #" + str(res)) return 0 diff --git a/plogical/ftpUtilities.py b/plogical/ftpUtilities.py index e728e8619..c2cf62602 100644 --- a/plogical/ftpUtilities.py +++ b/plogical/ftpUtilities.py @@ -32,7 +32,7 @@ class FTPUtilities: cmd.append("ftpuser:2001") cmd.append(path) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print "Permissions not changed." else: @@ -58,7 +58,7 @@ class FTPUtilities: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print "Permissions not changed." @@ -72,7 +72,7 @@ class FTPUtilities: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: return 0 @@ -96,7 +96,7 @@ class FTPUtilities: command = "chown " + externalApp + ":" + externalApp + " " + path cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) return 1,'None' diff --git a/plogical/installUtilities.py b/plogical/installUtilities.py index dfbf42fd1..652e4f541 100644 --- a/plogical/installUtilities.py +++ b/plogical/installUtilities.py @@ -19,7 +19,7 @@ class installUtilities: cmd.append("-y") cmd.append("install") cmd.append("epel-release") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") @@ -47,7 +47,7 @@ class installUtilities: cmd.append("rpm") cmd.append("-ivh") cmd.append("http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el7.noarch.rpm") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") print(" Could not add Litespeed repo " ) @@ -78,7 +78,7 @@ class installUtilities: cmd.append("install") cmd.append("openlitespeed-1.4.26") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: @@ -111,7 +111,7 @@ class installUtilities: cmd.append("/usr/local/lsws/bin/lswsctrl") cmd.append("start") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") @@ -144,7 +144,7 @@ class installUtilities: command = "sudo /usr/local/lsws/bin/lswsctrl restart" cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except OSError, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartLiteSpeed]") @@ -165,7 +165,7 @@ class installUtilities: command = "sudo /usr/local/lsws/bin/lswsctrl restart" cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") @@ -216,7 +216,7 @@ class installUtilities: cmd.append("groupinstall") cmd.append("lsphp-all") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") @@ -310,7 +310,7 @@ class installUtilities: cmd.append("remove") cmd.append("openlitespeed-1.4.26") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") @@ -338,7 +338,7 @@ class installUtilities: cmd.append("remove") cmd.append("lsphp*") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") @@ -380,7 +380,7 @@ class installUtilities: cmd.append("start") cmd.append("mariadb") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") @@ -416,7 +416,7 @@ class installUtilities: cmd.append("install") cmd.append("mariadb-server") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") @@ -456,7 +456,7 @@ class installUtilities: cmd.append("enable") cmd.append("mariadb") - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 1: print("###############################################") diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index aaf09f8e9..2c82d9e38 100644 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -80,13 +80,13 @@ class mailUtilities: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) command = 'chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data/_data_' cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) ## After effects ends @@ -159,18 +159,18 @@ class mailUtilities: FNULL = open(os.devnull, 'w') command = "opendkim-genkey -D /etc/opendkim/keys/" + virtualHostName + " -d " + virtualHostName + " -s default" - subprocess.call(shlex.split(command),stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(shlex.split(command),stdout=FNULL, stderr=subprocess.STDOUT) ## Fix permissions command = "chown -R root:opendkim /etc/opendkim/keys/" + virtualHostName - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "chmod 640 /etc/opendkim/keys/" + virtualHostName + "/default.private" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "chmod 644 /etc/opendkim/keys/" + virtualHostName + "/default.txt" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## Edit key file @@ -202,10 +202,10 @@ class mailUtilities: ## Restart postfix and OpenDKIM command = "systemctl restart opendkim" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "systemctl restart postfix" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) return 1, "None" @@ -221,7 +221,7 @@ class mailUtilities: path = "/etc/opendkim.conf" command = "sudo cat " + path - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res == 1: return 0 @@ -285,15 +285,15 @@ milter_default_action = accept #### Restarting Postfix and OpenDKIM command = "systemctl start opendkim" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "systemctl enable opendkim" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## command = "systemctl start postfix" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) print "1,None" return @@ -316,14 +316,14 @@ milter_default_action = accept FNULL = open(os.devnull, 'w') command = "sudo mkdir " + mailUtilities.cyberPanelHome - subprocess.call(shlex.split(command), stdout=FNULL) + ProcessUtilities.executioner(shlex.split(command), stdout=FNULL) command = "sudo chown -R cyberpanel:cyberpanel " + mailUtilities.cyberPanelHome - subprocess.call(shlex.split(command), stdout=FNULL) + ProcessUtilities.executioner(shlex.split(command), stdout=FNULL) except: FNULL = open(os.devnull, 'w') command = "sudo chown -R cyberpanel:cyberpanel " + mailUtilities.cyberPanelHome - subprocess.call(shlex.split(command), stdout=FNULL) + ProcessUtilities.executioner(shlex.split(command), stdout=FNULL) except BaseException,msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [checkHome]") @@ -339,7 +339,7 @@ milter_default_action = accept cmd = shlex.split(command) with open(mailUtilities.installLogPath, 'w') as f: - res = subprocess.call(cmd, stdout=f) + res = ProcessUtilities.executioner(cmd, stdout=f) if res == 1: writeToFile = open(mailUtilities.installLogPath, 'a') @@ -363,10 +363,10 @@ milter_default_action = accept def restartServices(): try: command = 'systemctl restart postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'systemctl restart dovecot' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except BaseException,msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [restartServices]") @@ -384,7 +384,7 @@ milter_default_action = accept cmd = shlex.split(command) with open(mailUtilities.spamassassinInstallLogPath, 'w') as f: - res = subprocess.call(cmd, stdout=f) + res = ProcessUtilities.executioner(cmd, stdout=f) if res == 1: writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a') @@ -411,7 +411,7 @@ milter_default_action = accept path = "/etc/mail/spamassassin/local.cf" command = "sudo cat " + path - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res == 1: return 0 @@ -443,21 +443,21 @@ milter_default_action = accept command = "groupadd spamd" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## command = "chown spamd:spamd /var/log/spamassassin" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "systemctl enable spamassassin" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "systemctl start spamassassin" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) ## Configuration to postfix @@ -478,7 +478,7 @@ milter_default_action = accept writeToFile.close() command = 'systemctl restart postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) print "1,None" @@ -531,7 +531,7 @@ milter_default_action = accept conf.close() command = 'systemctl restart spamassassin' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) print "1,None" return @@ -552,10 +552,10 @@ milter_default_action = accept shutil.copy("/usr/local/CyberCP/postfixSenderPolicy/cpecs.service", "/etc/systemd/system/cpecs.service") command = 'systemctl enable cpecs' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'systemctl start cpecs' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) writeToFile = open(postfixPath, 'a') writeToFile.writelines('smtpd_data_restrictions = check_policy_service unix:/var/log/policyServerSocket\n') @@ -563,7 +563,7 @@ milter_default_action = accept writeToFile.close() command = 'systemctl restart postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) else: data = open(postfixPath, 'r').readlines() @@ -580,10 +580,10 @@ milter_default_action = accept writeToFile.close() command = 'systemctl stop cpecs' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'systemctl restart postfix' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) print "1,None" return diff --git a/plogical/modSec.py b/plogical/modSec.py index d9d0faa9d..a0cb6797a 100644 --- a/plogical/modSec.py +++ b/plogical/modSec.py @@ -29,7 +29,7 @@ class modSec: cmd = shlex.split(command) with open(modSec.installLogPath, 'w') as f: - res = subprocess.call(cmd, stdout=f) + res = ProcessUtilities.executioner(cmd, stdout=f) if res == 1: writeToFile = open(modSec.installLogPath, 'a') @@ -230,7 +230,7 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf os.remove('comodo.tar.gz') command = "wget https://" + modSec.mirrorPath + "/modsec/comodo.tar.gz" - result = subprocess.call(shlex.split(command)) + result = ProcessUtilities.executioner(shlex.split(command)) if result == 1: return 0 @@ -250,13 +250,13 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf os.remove('cpanel_litespeed_vendor') command = "wget https://waf.comodo.com/api/cpanel_litespeed_vendor" - result = subprocess.call(shlex.split(command)) + result = ProcessUtilities.executioner(shlex.split(command)) if result == 1: return 0 command = "unzip cpanel_litespeed_vendor -d " + extractLocation - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) return 1 @@ -334,16 +334,16 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf os.remove('cpanel_litespeed_vendor') command = "wget https://waf.comodo.com/api/cpanel_litespeed_vendor" - result = subprocess.call(shlex.split(command)) + result = ProcessUtilities.executioner(shlex.split(command)) if result == 1: return 0 command = "unzip cpanel_litespeed_vendor -d " + extractLocation - result = subprocess.call(shlex.split(command)) + result = ProcessUtilities.executioner(shlex.split(command)) command = 'sudo chown -R lsadm:lsadm /usr/local/lsws/conf' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) print "1,None" return @@ -398,7 +398,7 @@ modsecurity_rules_file /usr/local/lsws/conf/modsec/rules.conf os.remove('owasp.tar.gz') command = "wget https://" + modSec.mirrorPath + "/modsec/owasp.tar.gz" - result = subprocess.call(shlex.split(command)) + result = ProcessUtilities.executioner(shlex.split(command)) if result == 1: return 0 diff --git a/plogical/mysqlUtilities.py b/plogical/mysqlUtilities.py index 88f6297eb..ea00366e4 100644 --- a/plogical/mysqlUtilities.py +++ b/plogical/mysqlUtilities.py @@ -116,7 +116,7 @@ class mysqlUtilities: cmd = shlex.split(command) with open(tempStoragePath+"/"+databaseName+'.sql', 'w') as f: - res = subprocess.call(cmd,stdout=f) + res = ProcessUtilities.executioner(cmd,stdout=f) if res == 1: logging.CyberCPLogFileWriter.writeToFile("Database: "+databaseName + "could not be backed! [createDatabaseBackup]") @@ -143,7 +143,7 @@ class mysqlUtilities: with open(tempStoragePath + "/" + databaseName + '.sql', 'r') as f: - res = subprocess.call(cmd, stdin=f) + res = ProcessUtilities.executioner(cmd, stdin=f) if res == 1: logging.CyberCPLogFileWriter.writeToFile("Could not restore MYSQL database: " +databaseName +"! [restoreDatabaseBackup]") @@ -347,7 +347,7 @@ class mysqlUtilities: command = 'sudo mv /etc/my.cnf.bak /etc/my.cnf' else: command = 'sudo mv /etc/mysql/my.cnf.bak /etc/mysql//my.cnf' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) logging.CyberCPLogFileWriter.writeToFile(str(msg)) return 0, str(msg) @@ -383,7 +383,7 @@ class mysqlUtilities: except BaseException, msg: command = 'sudo mv /etc/my.cnf.bak /etc/my.cnf' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) logging.CyberCPLogFileWriter.writeToFile(str(msg)) return 0, str(msg) diff --git a/plogical/phpUtilities.py b/plogical/phpUtilities.py index 93ee79911..26bfc8b1d 100644 --- a/plogical/phpUtilities.py +++ b/plogical/phpUtilities.py @@ -27,7 +27,7 @@ class phpUtilities: try: with open(phpUtilities.installLogPath, 'w') as f: - subprocess.call(cmd, stdout=f) + ProcessUtilities.executioner(cmd, stdout=f) writeToFile = open(phpUtilities.installLogPath, 'a') writeToFile.writelines("PHP Extension Installed.\n") @@ -59,7 +59,7 @@ class phpUtilities: try: with open(phpUtilities.installLogPath, 'w') as f: - subprocess.call(cmd, stdout=f) + ProcessUtilities.executioner(cmd, stdout=f) writeToFile = open(phpUtilities.installLogPath, 'a') writeToFile.writelines("PHP Extension Removed.\n") diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index 6176c7b94..e539604dc 100644 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -39,7 +39,7 @@ class ProcessUtilities: command = "sudo /usr/local/lsws/bin/lswsctrl restart" cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 0: return 1 @@ -58,7 +58,7 @@ class ProcessUtilities: command = "sudo /usr/local/lsws/bin/lswsctrl stop" cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) if res == 0: return 1 @@ -68,17 +68,6 @@ class ProcessUtilities: except subprocess.CalledProcessError, msg: logging.writeToFile(str(msg) + "[stopLitespeed]") - @staticmethod - def executioner(command): - try: - res = subprocess.call(shlex.split(command)) - if res == 0: - return 1 - else: - return 0 - except BaseException, msg: - return 0 - @staticmethod def killLiteSpeed(): try: @@ -118,7 +107,7 @@ class ProcessUtilities: def containerCheck(): try: command = 'sudo cat /etc/cgrules.conf' - result = subprocess.call(shlex.split(command)) + result = ProcessUtilities.executioner(shlex.split(command)) if result == 1: return 0 else: @@ -126,5 +115,24 @@ class ProcessUtilities: except BaseException: return 0 + @staticmethod + def executioner(command): + try: + res = subprocess.call(shlex.split(command)) + if res == 0: + return 1 + else: + return 0 + except BaseException, msg: + return 0 + + @staticmethod + def outputExecutioner(command): + return subprocess.check_output(shlex.split(command)) + + @staticmethod + def popenExecutioner(command): + return subprocess.Popen(shlex.split(command)) + diff --git a/plogical/remoteBackup.py b/plogical/remoteBackup.py index e45f11bda..45a1577b8 100644 --- a/plogical/remoteBackup.py +++ b/plogical/remoteBackup.py @@ -220,7 +220,7 @@ class remoteBackup: ## complete path is a path to the file need to send command = 'sudo rsync -avz -e "ssh -i /root/.ssh/cyberpanel -o StrictHostKeyChecking=no" ' + completedPathToSend + ' root@' + IPAddress + ':/home/backup/transfer-'+folderNumber - subprocess.call(shlex.split(command), stdout=writeToFile) + ProcessUtilities.executioner(shlex.split(command), stdout=writeToFile) os.remove(completedPathToSend) except BaseException, msg: diff --git a/plogical/remoteTransferUtilities.py b/plogical/remoteTransferUtilities.py index c8dfa758a..1200b6b6f 100644 --- a/plogical/remoteTransferUtilities.py +++ b/plogical/remoteTransferUtilities.py @@ -213,7 +213,7 @@ class remoteTransferUtilities: ## complete path is a path to the file need to send command = "sudo scp -o StrictHostKeyChecking=no -i /root/.ssh/cyberpanel " + completedPathToSend + " root@" + IPAddress + ":/home/backup/transfer-" + folderNumber + "/" - subprocess.call(shlex.split(command), stdout=writeToFile) + ProcessUtilities.executioner(shlex.split(command), stdout=writeToFile) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]") diff --git a/plogical/sslUtilities.py b/plogical/sslUtilities.py index d2508f47d..dee1d399a 100644 --- a/plogical/sslUtilities.py +++ b/plogical/sslUtilities.py @@ -236,14 +236,14 @@ class sslUtilities: if not os.path.exists(acmePath): command = 'wget -O - https://get.acme.sh | sh' - subprocess.call(command, shell=True) + ProcessUtilities.executioner(command, shell=True) if aliasDomain == None: existingCertPath = '/etc/letsencrypt/live/' + virtualHostName if not os.path.exists(existingCertPath): command = 'mkdir -p ' + existingCertPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) try: logging.CyberCPLogFileWriter.writeToFile("Trying to obtain SSL for: " + virtualHostName + " and: www." + virtualHostName) @@ -252,7 +252,7 @@ class sslUtilities: + ' --cert-file ' + existingCertPath + '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \ + ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + ' -w ' + sslpath + ' --force' - output = subprocess.check_output(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(shlex.split(command)) logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName + " and: www." + virtualHostName) @@ -265,7 +265,7 @@ class sslUtilities: command = acmePath + " --issue -d " + virtualHostName + ' --cert-file ' + existingCertPath \ + '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \ + ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + ' -w ' + sslpath + ' --force' - output = subprocess.check_output(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(shlex.split(command)) logging.CyberCPLogFileWriter.writeToFile("Successfully obtained SSL for: " + virtualHostName) except subprocess.CalledProcessError: logging.CyberCPLogFileWriter.writeToFile('Failed to obtain SSL, issuing self-signed SSL for: ' + virtualHostName) @@ -275,7 +275,7 @@ class sslUtilities: existingCertPath = '/etc/letsencrypt/live/' + virtualHostName if not os.path.exists(existingCertPath): command = 'mkdir -p ' + existingCertPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) try: logging.CyberCPLogFileWriter.writeToFile( @@ -286,7 +286,7 @@ class sslUtilities: + ' --cert-file ' + existingCertPath + '/cert.pem' + ' --key-file ' + existingCertPath + '/privkey.pem' \ + ' --fullchain-file ' + existingCertPath + '/fullchain.pem' + ' -w ' + sslpath + ' --force' - output = subprocess.check_output(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(shlex.split(command)) logging.CyberCPLogFileWriter.writeToFile( "Successfully obtained SSL for: " + virtualHostName + ", www." + virtualHostName + ", " + aliasDomain + "and www." + aliasDomain + ",") diff --git a/plogical/tuning.py b/plogical/tuning.py index 313789244..4953439e6 100644 --- a/plogical/tuning.py +++ b/plogical/tuning.py @@ -15,7 +15,7 @@ class tuning: try: dataToReturn = {} command = "sudo cat /usr/local/lsws/conf/httpd_config.conf" - datas = subprocess.check_output(shlex.split(command)).split("\n") + datas = ProcessUtilities.outputExecutioner(shlex.split(command)).split("\n") for items in datas: if items.find("maxConnections")>-1: @@ -58,7 +58,7 @@ class tuning: dataToReturn = {} command = "sudo cat /usr/local/lsws/conf/httpd_config.xml" - datas = subprocess.check_output(shlex.split(command)) + datas = ProcessUtilities.outputExecutioner(shlex.split(command)) comTree = ElementTree.fromstring(datas) tuningData = comTree.find('tuning') @@ -187,7 +187,7 @@ class tuning: path = installUtilities.Server_root_path + "/conf/vhosts/"+virtualHost+"/vhost.conf" command = "sudo cat "+path - datas = subprocess.check_output(shlex.split(command)).split("\n") + datas = ProcessUtilities.outputExecutioner(shlex.split(command)).split("\n") dataToReturn = {} @@ -230,7 +230,7 @@ class tuning: else: try: command = "sudo cat /usr/local/lsws/conf/httpd_config.xml" - datas = subprocess.check_output(shlex.split(command)) + datas = ProcessUtilities.outputExecutioner(shlex.split(command)) comTree = ElementTree.fromstring(datas) extProcessorList = comTree.findall('extProcessorList/extProcessor') diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 657f3bd84..51ad50731 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -35,7 +35,7 @@ class Upgrade: try: count = 0 while True: - res = subprocess.call(shlex.split(command)) + res = ProcessUtilities.executioner(shlex.split(command)) if res != 0: count = count + 1 Upgrade.stdOut(component + ' failed, trying again, try number: ' + str(count), 0) @@ -89,7 +89,7 @@ class Upgrade: ## env_path = '/usr/local/CyberCP' - subprocess.call(['virtualenv', env_path]) + ProcessUtilities.executioner(['virtualenv', env_path]) activate_this = os.path.join(env_path, 'bin', 'activate_this.py') execfile(activate_this, dict(__file__=activate_this)) diff --git a/plogical/upgradeCritical.py b/plogical/upgradeCritical.py new file mode 100644 index 000000000..1df6719d6 --- /dev/null +++ b/plogical/upgradeCritical.py @@ -0,0 +1,44 @@ +#!/usr/local/CyberCP/bin/python2 +import sys +sys.path.append('/usr/local/CyberCP') +import subprocess, shlex +import os + + +class UpgradeCritical: + @staticmethod + def executioner(command): + try: + FNULL = open(os.devnull, 'w') + + res = ProcessUtilities.executioner(shlex.split(command), stdout=FNULL) + if res == 0: + return 1 + else: + return 0 + except BaseException, msg: + return 0 + + @staticmethod + def UpgradeImportantPackages(): + if os.path.exists('/etc/lsb-release'): + + command = "DEBIAN_FRONTEND=noninteractive apt-get install --only-upgrade pdns-server pdns-backend-mysql install dovecot-imapd dovecot-pop3d postfix-mysql pure-ftpd postfix dovecot-mysql -y" + UpgradeCritical.executioner(command) + else: + + command = "yum update" + UpgradeCritical.executioner(command) + + command = "yum -y upgrade pdns pdns-backend-mysql pure-ftpd postfix dovecot dovecot-mysql" + UpgradeCritical.executioner(command) + + + +def main(): + + UpgradeCritical.UpgradeImportantPackages() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/plogical/vhost.py b/plogical/vhost.py index 3269060cc..2396e1947 100644 --- a/plogical/vhost.py +++ b/plogical/vhost.py @@ -39,15 +39,15 @@ class vhost: command = "adduser " + virtualHostUser + " -M -d " + path cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) command = "groupadd " + virtualHostUser cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) command = "usermod -a -G " + virtualHostUser + " " + virtualHostUser cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [addingUsers]") @@ -60,7 +60,7 @@ class vhost: try: command = 'chmod 711 /home' cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except: pass @@ -69,11 +69,11 @@ class vhost: command = "chown " + virtualHostUser + ":" + virtualHostUser + " " + path cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) command = "chmod 711 " + path cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except OSError, msg: logging.CyberCPLogFileWriter.writeToFile( @@ -85,7 +85,7 @@ class vhost: command = "chown " + virtualHostUser + ":" + virtualHostUser + " " + pathHTML cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except OSError, msg: logging.CyberCPLogFileWriter.writeToFile( @@ -97,7 +97,7 @@ class vhost: command = "chown " + "lscpd" + ":" + "lscpd" + " " + pathLogs cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) if ProcessUtilities.decideServer() == ProcessUtilities.OLS: @@ -106,7 +106,7 @@ class vhost: command = "chmod -R 755 " + pathLogs cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except OSError, msg: logging.CyberCPLogFileWriter.writeToFile( @@ -127,7 +127,7 @@ class vhost: command = "chown " + "lsadm" + ":" + "lsadm" + " " + completePathToConfigFile cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except IOError, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [createDirectories]]") @@ -149,13 +149,13 @@ class vhost: command = "chown " + virtualHostUser + ":" + virtualHostUser + " " + "/home/" + virtualHostName + "/public_html/index.html" cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) vhostPath = vhost.Server_root + "/conf/vhosts" command = "chown -R " + "lsadm" + ":" + "lsadm" + " " + vhostPath cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [finalizeVhostCreation]") @@ -332,7 +332,7 @@ class vhost: ## Delete mail accounts command = "sudo rm -rf /home/vmail/" + virtualHostName - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [Not able to remove virtual host configuration from main configuration file.]") return 0 @@ -368,7 +368,7 @@ class vhost: ## Delete mail accounts command = "sudo rm -rf /home/vmail/" + virtualHostName - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + " [Not able to remove virtual host configuration from main configuration file.]") @@ -596,7 +596,7 @@ class vhost: try: command = 'sudo chown -R cyberpanel:cyberpanel ' + path cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) @@ -607,7 +607,7 @@ class vhost: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) @@ -673,12 +673,12 @@ class vhost: command = "chown " + virtualHostUser + ":" + virtualHostUser + " " + path + "/index.html" cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) vhostPath = vhost.Server_root + "/conf/vhosts" command = "chown -R " + "lsadm" + ":" + "lsadm" + " " + vhostPath cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [finalizeDomainCreation]") @@ -696,7 +696,7 @@ class vhost: os.makedirs(path) command = "chown " + virtualHostUser + ":" + virtualHostUser + " " + path cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except OSError, msg: logging.CyberCPLogFileWriter.writeToFile( str(msg) + "329 [Not able to create directories for virtual host [createDirectoryForDomain]]") diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 6108892b2..fc95715b5 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -166,10 +166,10 @@ class virtualHostUtilities: def getAccessLogs(fileName, page): try: - numberOfTotalLines = int(subprocess.check_output(["wc", "-l", fileName]).split(" ")[0]) + numberOfTotalLines = int(ProcessUtilities.outputExecutioner(["wc", "-l", fileName]).split(" ")[0]) if numberOfTotalLines < 25: - data = subprocess.check_output(["cat", fileName]) + data = ProcessUtilities.outputExecutioner(["cat", fileName]) else: if page == 1: end = numberOfTotalLines @@ -199,10 +199,10 @@ class virtualHostUtilities: def getErrorLogs(fileName, page): try: - numberOfTotalLines = int(subprocess.check_output(["wc", "-l", fileName]).split(" ")[0]) + numberOfTotalLines = int(ProcessUtilities.outputExecutioner(["wc", "-l", fileName]).split(" ")[0]) if numberOfTotalLines < 25: - data = subprocess.check_output(["cat", fileName]) + data = ProcessUtilities.outputExecutioner(["cat", fileName]) else: if page == 1: end = numberOfTotalLines @@ -303,13 +303,13 @@ class virtualHostUtilities: if not os.path.exists("latest.tar.gz"): command = 'wget --no-check-certificate http://wordpress.org/latest.tar.gz -O latest.tar.gz' cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) command = 'tar -xzvf latest.tar.gz -C ' + finalPath cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) ## Get plugin @@ -318,13 +318,13 @@ class virtualHostUtilities: cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) command = 'unzip litespeed-cache.1.1.5.1.zip -d ' + finalPath cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) root = finalPath @@ -368,7 +368,7 @@ class virtualHostUtilities: cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) vhost.addRewriteRules(domainName) @@ -392,7 +392,7 @@ class virtualHostUtilities: os.mkdir(homeDir) command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + homeDir cmd = shlex.split(command) - res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + res = ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) print "0," + str(msg) return @@ -454,7 +454,7 @@ class virtualHostUtilities: command = 'systemctl restart lscpd' cmd = shlex.split(command) - subprocess.call(cmd) + ProcessUtilities.executioner(cmd) print "1,None" return 1,'None' @@ -838,7 +838,7 @@ class virtualHostUtilities: pathToStoreSSL = '/etc/letsencrypt/live/' + virtualHost command = 'mkdir -p ' + pathToStoreSSL - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) pathToStoreSSLPrivKey = pathToStoreSSL + "/privkey.pem" pathToStoreSSLFullChain = pathToStoreSSL + "/fullchain.pem" @@ -863,7 +863,7 @@ class virtualHostUtilities: command = "chown " + "lsadm" + ":" + "lsadm" + " " + pathToStoreSSL cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) print "1,None" @@ -1002,7 +1002,7 @@ class virtualHostUtilities: def getDiskUsage(path, totalAllowed): try: - totalUsageInMB = subprocess.check_output(["sudo", "du", "-hs", path, "--block-size=1M"]).split()[0] + totalUsageInMB = ProcessUtilities.outputExecutioner(["sudo", "du", "-hs", path, "--block-size=1M"]).split()[0] percentage = float(100) / float(totalAllowed) @@ -1021,7 +1021,7 @@ class virtualHostUtilities: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) @@ -1033,7 +1033,7 @@ class virtualHostUtilities: cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) diff --git a/plogical/website.py b/plogical/website.py index 7fcf72a3b..9e955e508 100644 --- a/plogical/website.py +++ b/plogical/website.py @@ -296,7 +296,7 @@ class WebsiteManager: execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" execPath = execPath + " deleteVirtualHostConfigurations --virtualHostName " + websiteName - subprocess.check_output(shlex.split(execPath)) + ProcessUtilities.outputExecutioner(shlex.split(execPath)) data_ret = {'status': 1, 'websiteDeleteStatus': 1, 'error_message': "None"} json_data = json.dumps(data_ret) @@ -321,7 +321,7 @@ class WebsiteManager: execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" execPath = execPath + " deleteDomain --virtualHostName " + websiteName - subprocess.check_output(shlex.split(execPath)) + ProcessUtilities.outputExecutioner(shlex.split(execPath)) data_ret = {'status': 1, 'websiteDeleteStatus': 1, 'error_message': "None"} json_data = json.dumps(data_ret) @@ -346,18 +346,18 @@ class WebsiteManager: if state == "Suspend": confPath = virtualHostUtilities.Server_root + "/conf/vhosts/" + websiteName command = "sudo mv " + confPath + " " + confPath + "-suspended" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) installUtilities.reStartLiteSpeed() website.state = 0 else: confPath = virtualHostUtilities.Server_root + "/conf/vhosts/" + websiteName command = "sudo mv " + confPath + "-suspended" + " " + confPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "chown -R " + "lsadm" + ":" + "lsadm" + " " + confPath cmd = shlex.split(command) - subprocess.call(cmd) + ProcessUtilities.executioner(cmd) installUtilities.reStartLiteSpeed() website.state = 1 @@ -506,7 +506,7 @@ class WebsiteManager: execPath = execPath + " changePHP --phpVersion '" + phpVersion + "' --path " + completePathToConfigFile - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: pass @@ -574,7 +574,7 @@ class WebsiteManager: execPath = execPath + " findDomainBW --virtualHostName " + self.domain + " --bandwidth " + str( website.package.bandwidth) - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) bwData = output.split(",") except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) @@ -639,7 +639,7 @@ class WebsiteManager: execPath = execPath + " findDomainBW --virtualHostName " + self.domain + " --bandwidth " + str( website.package.bandwidth) - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) bwData = output.split(",") except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) @@ -695,7 +695,7 @@ class WebsiteManager: execPath = execPath + " getAccessLogs --path " + fileName + " --page " + str(page) - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: final_json = json.dumps( @@ -757,7 +757,7 @@ class WebsiteManager: execPath = execPath + " getErrorLogs --path " + fileName + " --page " + str(page) - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: final_json = json.dumps( @@ -783,7 +783,7 @@ class WebsiteManager: filePath = installUtilities.Server_root_path + "/conf/vhosts/" + self.domain + "/vhost.conf" command = 'sudo cat ' + filePath - configData = subprocess.check_output(shlex.split(command)) + configData = ProcessUtilities.outputExecutioner(shlex.split(command)) if len(configData) == 0: status = {'status': 0, "configstatus": 0, "error_message": "Configuration file is currently empty!"} @@ -825,7 +825,7 @@ class WebsiteManager: execPath = execPath + " saveVHostConfigs --path " + filePath + " --tempPath " + tempPath - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: status = {"configstatus": 1} @@ -908,7 +908,7 @@ class WebsiteManager: execPath = execPath + " saveRewriteRules --virtualHostName " + self.domain + " --path " + filePath + " --tempPath " + tempPath - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: status = {"rewriteStatus": 1, 'error_message': output} @@ -953,7 +953,7 @@ class WebsiteManager: execPath = execPath + " saveSSL --virtualHostName " + self.domain + " --tempKeyPath " + tempKeyPath + " --tempCertPath " + tempCertPath - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'sslStatus': 1, 'error_message': "None"} @@ -986,7 +986,7 @@ class WebsiteManager: execPath = execPath + " changePHP --phpVersion '" + phpVersion + "' --path " + completePathToConfigFile - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: pass @@ -1036,8 +1036,8 @@ class WebsiteManager: crons = [] try: - # f = subprocess.check_output(["sudo", "cat", cronPath]) - f = subprocess.check_output(["sudo", "crontab", "-u", website.externalApp, "-l"]) + # f = ProcessUtilities.outputExecutioner(["sudo", "cat", cronPath]) + f = ProcessUtilities.outputExecutioner(["sudo", "crontab", "-u", website.externalApp, "-l"]) except subprocess.CalledProcessError as error: dic = {'getWebsiteCron': 0, 'error_message': 'Unable to access Cron file'} json_data = json.dumps(dic) @@ -1093,8 +1093,8 @@ class WebsiteManager: crons = [] try: - # f = subprocess.check_output(["sudo", "cat", cronPath]) - f = subprocess.check_output(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) + # f = ProcessUtilities.outputExecutioner(["sudo", "cat", cronPath]) + f = ProcessUtilities.outputExecutioner(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) print f except subprocess.CalledProcessError as error: dic = {'getWebsiteCron': 0, 'error_message': 'Unable to access Cron file'} @@ -1161,7 +1161,7 @@ class WebsiteManager: finalCron = "%s %s %s %s %s %s" % (minute, hour, monthday, month, weekday, command) - output = subprocess.check_output(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) + output = ProcessUtilities.outputExecutioner(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) if "no crontab for" in output: data_ret = {'addNewCron': 0, 'error_message': 'crontab file does not exists for user'} @@ -1172,7 +1172,7 @@ class WebsiteManager: file.write(output) # Confirming that directory is read/writable - o = subprocess.call(['sudo', 'chown', 'cyberpanel:cyberpanel', tempPath]) + o = ProcessUtilities.executioner(['sudo', 'chown', 'cyberpanel:cyberpanel', tempPath]) if o is not 0: data_ret = {'addNewCron': 0, 'error_message': 'Error Changing Permissions'} final_json = json.dumps(data_ret) @@ -1186,7 +1186,7 @@ class WebsiteManager: with open(tempPath, 'w') as file: file.writelines(data) - output = subprocess.call(["sudo", "/usr/bin/crontab", "-u", website.externalApp, tempPath]) + output = ProcessUtilities.executioner(["sudo", "/usr/bin/crontab", "-u", website.externalApp, tempPath]) os.remove(tempPath) if output != 0: @@ -1222,7 +1222,7 @@ class WebsiteManager: line -= 1 website = Websites.objects.get(domain=self.domain) - output = subprocess.check_output(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) + output = ProcessUtilities.outputExecutioner(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) if "no crontab for" in output: data_ret = {'addNewCron': 0, 'error_message': 'No Cron exists for this user'} @@ -1235,7 +1235,7 @@ class WebsiteManager: file.write(output) # Confirming that directory is read/writable - o = subprocess.call(['sudo', 'chown', 'cyberpanel:cyberpanel', tempPath]) + o = ProcessUtilities.executioner(['sudo', 'chown', 'cyberpanel:cyberpanel', tempPath]) if o is not 0: data_ret = {'addNewCron': 0, 'error_message': 'Error Changing Permissions'} final_json = json.dumps(data_ret) @@ -1249,7 +1249,7 @@ class WebsiteManager: with open(tempPath, 'w') as file: file.writelines(data) - output = subprocess.call(["sudo", "/usr/bin/crontab", "-u", website.externalApp, tempPath]) + output = ProcessUtilities.executioner(["sudo", "/usr/bin/crontab", "-u", website.externalApp, tempPath]) os.remove(tempPath) if output != 0: @@ -1291,23 +1291,23 @@ class WebsiteManager: website = Websites.objects.get(domain=self.domain) try: - output = subprocess.check_output(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) + output = ProcessUtilities.outputExecutioner(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) except: try: - subprocess.call(('sudo', 'crontab', '-u', website.externalApp, '-')) + ProcessUtilities.executioner(('sudo', 'crontab', '-u', website.externalApp, '-')) except: data_ret = {'addNewCron': 0, 'error_message': 'Unable to initialise crontab file for user'} final_json = json.dumps(data_ret) return HttpResponse(final_json) - output = subprocess.check_output(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) + output = ProcessUtilities.outputExecutioner(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) if "no crontab for" in output: echo = subprocess.Popen((['cat', '/dev/null']), stdout=subprocess.PIPE) - subprocess.call(('sudo', 'crontab', '-u', website.externalApp, '-'), stdin=echo.stdout) + ProcessUtilities.executioner(('sudo', 'crontab', '-u', website.externalApp, '-'), stdin=echo.stdout) echo.wait() echo.stdout.close() - output = subprocess.check_output(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) + output = ProcessUtilities.outputExecutioner(["sudo", "/usr/bin/crontab", "-u", website.externalApp, "-l"]) if "no crontab for" in output: data_ret = {'addNewCron': 0, 'error_message': 'Unable to initialise crontab file for user'} final_json = json.dumps(data_ret) @@ -1320,7 +1320,7 @@ class WebsiteManager: with open(tempPath, "a") as file: file.write(output + finalCron + "\n") - output = subprocess.call(["sudo", "/usr/bin/crontab", "-u", website.externalApp, tempPath]) + output = ProcessUtilities.executioner(["sudo", "/usr/bin/crontab", "-u", website.externalApp, tempPath]) os.remove(tempPath) if output != 0: @@ -1363,7 +1363,7 @@ class WebsiteManager: execPath = execPath + " createAlias --masterDomain " + self.domain + " --aliasDomain " + aliasDomain + " --ssl " + str( ssl) + " --sslPath " + sslpath + " --administratorEmail " + admin.email + ' --websiteOwner ' + admin.userName - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: pass @@ -1408,7 +1408,7 @@ class WebsiteManager: execPath = execPath + " issueAliasSSL --masterDomain " + self.domain + " --aliasDomain " + aliasDomain + " --sslPath " + sslpath + " --administratorEmail " + admin.email - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'sslStatus': 1, 'error_message': "None", "existsStatus": 0} @@ -1444,7 +1444,7 @@ class WebsiteManager: execPath = execPath + " deleteAlias --masterDomain " + self.domain + " --aliasDomain " + aliasDomain - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'deleteAlias': 1, 'error_message': "None", "existsStatus": 0} @@ -1478,7 +1478,7 @@ class WebsiteManager: execPath = execPath + " changeOpenBasedir --virtualHostName '" + self.domain + "' --openBasedirValue " + openBasedirValue - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: pass @@ -1566,7 +1566,7 @@ class WebsiteManager: if lastLine.find('[200]') > -1: command = 'sudo rm -f ' + statusFile - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) data_ret = {'abort': 1, 'installStatus': 1, 'installationProgress': "100", 'currentStatus': 'Successfully Installed.'} json_data = json.dumps(data_ret) @@ -1802,7 +1802,7 @@ Host gitlab.com ProcessUtilities.executioner(command) command = 'sudo cat /root/.ssh/git.pub' - deploymentKey = subprocess.check_output(shlex.split(command)).strip('\n') + deploymentKey = ProcessUtilities.outputExecutioner(shlex.split(command)).strip('\n') return render(request, 'websiteFunctions/setupGit.html', {'domainName': self.domain, 'deploymentKey': deploymentKey, 'installed': 0}) diff --git a/pluginInstaller/pluginInstaller.py b/pluginInstaller/pluginInstaller.py index ad83cf20e..d86e1e50e 100644 --- a/pluginInstaller/pluginInstaller.py +++ b/pluginInstaller/pluginInstaller.py @@ -26,7 +26,7 @@ class pluginInstaller: def extractPlugin(pluginName): pathToPlugin = pluginName + '.zip' command = 'unzip ' + pathToPlugin + ' -d /usr/local/CyberCP' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) @staticmethod def upgradingSettingsFile(pluginName): @@ -65,7 +65,7 @@ class pluginInstaller: pluginFile = pluginPath + '/' + pluginName command = 'touch ' + pluginFile - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) @staticmethod def addInterfaceLink(pluginName): @@ -87,15 +87,15 @@ class pluginInstaller: currentDir = os.getcwd() command = "rm -rf /usr/local/lscp/cyberpanel/static" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) os.chdir('/usr/local/CyberCP') command = "python manage.py collectstatic --noinput" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = "mv /usr/local/CyberCP/static /usr/local/lscp/cyberpanel" - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) os.chdir(currentDir) @@ -106,10 +106,10 @@ class pluginInstaller: if os.path.exists(pluginHome + '/pre_install'): command = 'chmod +x ' + pluginHome + '/pre_install' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = pluginHome + '/pre_install' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) @staticmethod def postScript(pluginName): @@ -117,10 +117,10 @@ class pluginInstaller: if os.path.exists(pluginHome + '/post_install'): command = 'chmod +x ' + pluginHome + '/post_install' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = pluginHome + '/post_install' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) @staticmethod @@ -286,7 +286,7 @@ class pluginInstaller: @staticmethod def restartGunicorn(): command = 'systemctl restart gunicorn.socket' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) diff --git a/serverLogs/views.py b/serverLogs/views.py index bd314c6c7..555cd150b 100644 --- a/serverLogs/views.py +++ b/serverLogs/views.py @@ -139,7 +139,7 @@ def getLogsFromFile(request): try: command = "sudo tail -50 " + fileName - fewLinesOfLogFile = subprocess.check_output(shlex.split(command)) + fewLinesOfLogFile = ProcessUtilities.outputExecutioner(shlex.split(command)) status = {"status": 1, "logstatus": 1, "logsdata": fewLinesOfLogFile} final_json = json.dumps(status) return HttpResponse(final_json) @@ -175,7 +175,7 @@ def clearLogFile(request): execPath = execPath + " cleanLogFile --fileName " + fileName - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'cleanStatus': 1, 'error_message': "None"} diff --git a/serverStatus/serverStatusUtil.py b/serverStatus/serverStatusUtil.py index 9dcfd25f4..262460013 100644 --- a/serverStatus/serverStatusUtil.py +++ b/serverStatus/serverStatusUtil.py @@ -24,7 +24,7 @@ class ServerStatusUtil: @staticmethod def executioner(command, statusFile): try: - res = subprocess.call(shlex.split(command), stdout=statusFile, stderr=statusFile) + res = ProcessUtilities.executioner(shlex.split(command), stdout=statusFile, stderr=statusFile) if res == 1: return 0 else: @@ -94,7 +94,7 @@ class ServerStatusUtil: try: command = 'chown -R lsadm:lsadm ' + confPath - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) except: pass @@ -172,7 +172,7 @@ class ServerStatusUtil: FNULL = open(os.devnull, 'w') command = "chown -R " + "lsadm" + ":" + "lsadm" + " " + vhostPath cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) @@ -209,7 +209,7 @@ class ServerStatusUtil: FNULL = open(os.devnull, 'w') command = "chown -R " + "lsadm" + ":" + "lsadm" + " " + vhostPath cmd = shlex.split(command) - subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + ProcessUtilities.executioner(cmd, stdout=FNULL, stderr=subprocess.STDOUT) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) diff --git a/serverStatus/views.py b/serverStatus/views.py index 781cf2602..fe4dea6f5 100644 --- a/serverStatus/views.py +++ b/serverStatus/views.py @@ -46,7 +46,7 @@ def litespeedStatus(request): OLS = 1 try: - versionInformation = subprocess.check_output(["/usr/local/lsws/bin/lshttpd", "-v"]).split("\n") + versionInformation = ProcessUtilities.outputExecutioner(["/usr/local/lsws/bin/lshttpd", "-v"]).split("\n") lsversion = versionInformation[0] modules = versionInformation[1] @@ -193,7 +193,7 @@ def servicesStatus(request): mailStatus = [] dockerStatus = [] - processlist = subprocess.check_output(['ps', '-A']) + processlist = ProcessUtilities.outputExecutioner(['ps', '-A']) def getServiceStats(service): if service in processlist: @@ -309,7 +309,7 @@ def servicesAction(request): command = 'sudo systemctl %s %s' % (action, service) cmd = shlex.split(command) - res = subprocess.call(cmd) + res = ProcessUtilities.executioner(cmd) p = subprocess.Popen(cmd, stdout=subprocess.PIPE) result = p.communicate()[0] @@ -366,7 +366,7 @@ def switchTOLSWSStatus(request): try: command = 'sudo cat ' + serverStatusUtil.ServerStatusUtil.lswsInstallStatusPath - output = subprocess.check_output(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(shlex.split(command)) if output.find('[404]') > -1: data_ret = {'abort': 1, 'requestStatus': output, 'installed': 0} @@ -400,10 +400,10 @@ def licenseStatus(request): return ACLManager.loadErrorJson('status', 0) command = 'sudo cat /usr/local/lsws/conf/serial.no' - serial = subprocess.check_output(shlex.split(command)) + serial = ProcessUtilities.outputExecutioner(shlex.split(command)) command = 'sudo /usr/local/lsws/bin/lshttpd -V' - expiration = subprocess.check_output(shlex.split(command)) + expiration = ProcessUtilities.outputExecutioner(shlex.split(command)) final_dic = {'status': 1, "erroMessage": 0, 'lsSerial': serial, 'lsexpiration': expiration} final_json = json.dumps(final_dic) @@ -435,7 +435,7 @@ def changeLicense(request): newKey = data['newKey'] command = 'sudo chown -R cyberpanel:cyberpanel /usr/local/lsws/conf' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) serialPath = '/usr/local/lsws/conf/serial.no' serialFile = open(serialPath, 'w') @@ -443,13 +443,13 @@ def changeLicense(request): serialFile.close() command = 'sudo chown -R lsadm:lsadm /usr/local/lsws/conf' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo /usr/local/lsws/bin/lshttpd -r' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) command = 'sudo /usr/local/lsws/bin/lswsctrl restart' - subprocess.call(shlex.split(command)) + ProcessUtilities.executioner(shlex.split(command)) final_dic = {'status': 1, "erroMessage": 'None'} final_json = json.dumps(final_dic) @@ -488,7 +488,7 @@ def topProcessesStatus(request): try: with open("/home/cyberpanel/top", "w") as outfile: - subprocess.call("sudo top -n1 -b", shell=True, stdout=outfile) + ProcessUtilities.executioner("sudo top -n1 -b", shell=True, stdout=outfile) data = open('/home/cyberpanel/top', 'r').readlines() @@ -574,7 +574,7 @@ def topProcessesStatus(request): ## CPU Details command = 'sudo cat /proc/cpuinfo' - output = subprocess.check_output(shlex.split(command)).splitlines() + output = ProcessUtilities.outputExecutioner(shlex.split(command)).splitlines() import psutil diff --git a/tuning/tuning.py b/tuning/tuning.py index f6f7207f9..3773a7b39 100644 --- a/tuning/tuning.py +++ b/tuning/tuning.py @@ -121,7 +121,7 @@ class tuningManager: execPath = execPath + " saveTuningDetails --maxConn " + maxConn + " --maxSSLConn " + maxSSLConn + " --connTime " + connTime + " --keepAlive " + keepAlive + " --inMemCache '" + inMemCache + "' --gzipCompression " + gzipCompression - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'fetch_status': 1, 'error_message': "None", 'tuneStatus': 1} @@ -166,7 +166,7 @@ class tuningManager: execPath = execPath + " tunePHP --virtualHost " + domainSelection + " --initTimeout " + initTimeout + " --maxConns " + maxConns + " --memSoftLimit " + memSoftLimit + " --memHardLimit '" + memHardLimit + "' --procSoftLimit " + procSoftLimit + " --procHardLimit " + procHardLimit + " --persistConn " + persistConn - output = subprocess.check_output(shlex.split(execPath)) + output = ProcessUtilities.outputExecutioner(shlex.split(execPath)) if output.find("1,None") > -1: data_ret = {'tuneStatus': 1, 'fetch_status': 0, 'error_message': "None"}