diff --git a/api/views.py b/api/views.py index fac066718..88ad396e7 100644 --- a/api/views.py +++ b/api/views.py @@ -227,8 +227,11 @@ def deleteWebsite(request): website = Websites.objects.get(domain=data['websiteName']) websiteOwner = website.admin - if admin.websites_set.all().count() == 0: - websiteOwner.delete() + try: + if admin.websites_set.all().count() == 0: + websiteOwner.delete() + except: + pass ## Deleting master domain diff --git a/dockerManager/container.py b/dockerManager/container.py index fa9d4ef59..c6f9bceca 100644 --- a/dockerManager/container.py +++ b/dockerManager/container.py @@ -25,7 +25,6 @@ import requests from plogical.processUtilities import ProcessUtilities from serverStatus.serverStatusUtil import ServerStatusUtil import threading as multi -from plogical.mailUtilities import mailUtilities # Use default socket to connect diff --git a/dockerManager/dockerInstall.py b/dockerManager/dockerInstall.py index beaf3af80..66d6ce51f 100644 --- a/dockerManager/dockerInstall.py +++ b/dockerManager/dockerInstall.py @@ -18,18 +18,6 @@ class DockerInstall: logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, "Starting Docker Installation..\n", 1) - command = "sudo adduser docker" - ServerStatusUtil.executioner(command, statusFile) - - command = 'sudo groupadd docker' - ServerStatusUtil.executioner(command, statusFile) - - command = 'sudo usermod -aG docker docker' - ServerStatusUtil.executioner(command, statusFile) - - command = 'sudo usermod -aG docker cyberpanel' - ServerStatusUtil.executioner(command, statusFile) - if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'sudo yum install -y docker' else: @@ -51,9 +39,6 @@ class DockerInstall: time.sleep(2) - command = 'sudo systemctl restart gunicorn.socket' - ProcessUtilities.executioner(command) - except BaseException, msg: logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1) diff --git a/emailPremium/views.py b/emailPremium/views.py index 79a475e28..1f07bb7ae 100644 --- a/emailPremium/views.py +++ b/emailPremium/views.py @@ -15,8 +15,6 @@ from math import ceil from postfixSenderPolicy.client import cacheClient import thread from plogical.mailUtilities import mailUtilities -import subprocess -import shlex from plogical.virtualHostUtilities import virtualHostUtilities from random import randint from plogical.acl import ACLManager @@ -785,7 +783,11 @@ def installSpamAssassin(request): else: return ACLManager.loadErrorJson() try: - thread.start_new_thread(mailUtilities.installSpamAssassin, ('Install','SpamAssassin')) + + execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py" + execPath = execPath + " installSpamAssassin" + ProcessUtilities.popenExecutioner(execPath) + final_json = json.dumps({'status': 1, 'error_message': "None"}) return HttpResponse(final_json) except BaseException,msg: diff --git a/filemanager/filemanager.py b/filemanager/filemanager.py index 877b35a90..d26aa8598 100644 --- a/filemanager/filemanager.py +++ b/filemanager/filemanager.py @@ -39,7 +39,8 @@ class FileManager: if not self.data['completeStartingPath'].find(self.data['home']) > -1: 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']) + command = "sudo ls -la --group-directories-first " + self.returnPathEnclosed( + self.data['completeStartingPath']) output = ProcessUtilities.outputExecutioner(command).splitlines() counter = 0 @@ -49,16 +50,22 @@ class FileManager: currentFile = filter(lambda a: a != '', currentFile) if currentFile[-1] == '.' or currentFile[-1] == '..' or currentFile[0] == 'total': continue + + if len(currentFile) > 9: + fileName = currentFile[8:] + currentFile[-1] = " ".join(fileName) + dirCheck = 0 if currentFile[0][0] == 'd': dirCheck = 1 - size = str(int(int(currentFile[4])/float(1024))) + size = str(int(int(currentFile[4]) / float(1024))) lastModified = currentFile[5] + ' ' + currentFile[6] + ' ' + currentFile[7] - finalData[str(counter)] = [currentFile[-1], currentFile[-1], lastModified, size, currentFile[0], dirCheck] + finalData[str(counter)] = [currentFile[-1], currentFile[-1], lastModified, size, currentFile[0], + dirCheck] counter = counter + 1 - except: - continue + except BaseException, msg: + logging.writeToFile(str(msg)) json_data = json.dumps(finalData) return HttpResponse(json_data) @@ -71,7 +78,8 @@ class FileManager: finalData = {} finalData['status'] = 1 - command = "sudo ls -la --group-directories-first " + self.returnPathEnclosed(self.data['completeStartingPath']) + command = "sudo ls -la --group-directories-first " + self.returnPathEnclosed( + self.data['completeStartingPath']) output = ProcessUtilities.outputExecutioner(command).splitlines() counter = 0 @@ -83,11 +91,16 @@ class FileManager: if currentFile[-1] == '.' or currentFile[-1] == '..' or currentFile[0] == 'total': continue + if len(currentFile) > 9: + fileName = currentFile[8:] + currentFile[-1] = " ".join(fileName) + dirCheck = False if currentFile[0][0] == 'd': dirCheck = True - finalData[str(counter)] = [currentFile[-1], self.data['completeStartingPath'] + '/' + currentFile[-1], dirCheck] + finalData[str(counter)] = [currentFile[-1], + self.data['completeStartingPath'] + '/' + currentFile[-1], dirCheck] counter = counter + 1 except: continue @@ -106,10 +119,11 @@ class FileManager: if self.data['fileName'].find('..') > -1: return self.ajaxPre(0, 'Not allowed to move in this path, please choose location inside home!') + command = "sudo touch " + self.returnPathEnclosed(self.data['fileName']) ProcessUtilities.executioner(command) - self.changeOwner(self.data['fileName']) + self.changeOwner(self.returnPathEnclosed(self.data['fileName'])) json_data = json.dumps(finalData) return HttpResponse(json_data) @@ -125,7 +139,7 @@ class FileManager: command = "sudo mkdir " + self.returnPathEnclosed(self.data['folderName']) ProcessUtilities.executioner(command) - self.changeOwner(self.data['folderName']) + self.changeOwner(self.returnPathEnclosed(self.data['folderName'])) json_data = json.dumps(finalData) return HttpResponse(json_data) diff --git a/install/install.py b/install/install.py index 3015019b6..f5b0ef4e5 100644 --- a/install/install.py +++ b/install/install.py @@ -246,7 +246,7 @@ class preFlightsChecks: # self.stdOut("Error in fixing sudoers file: " + str(err), 1, 1, os.EX_OSERR) self.stdOut("Add Cyberpanel user") - command = "adduser --disabled-login cyberpanel" + command = 'adduser --disabled-login --gecos "" cyberpanel' cmd = shlex.split(command) res = subprocess.call(cmd) if res != 0 and res != 9: @@ -288,6 +288,36 @@ class preFlightsChecks: ############################### + ### Docker User/group + + if self.distro == ubuntu: + command = 'adduser --disabled-login --gecos "" docker' + else: + command = "adduser docker" + + + preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]', + 'add user cyberpanel', + 1, 0, os.EX_OSERR) + + command = 'groupadd docker' + preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]', + 'add user cyberpanel', + 1, 0, os.EX_OSERR) + + command = 'usermod -aG docker docker' + preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]', + 'add user cyberpanel', + 1, 0, os.EX_OSERR) + + command = 'usermod -aG docker cyberpanel' + preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]', + 'add user cyberpanel', + 1, 0, os.EX_OSERR) + + + ### + command = "mkdir -p /etc/letsencrypt/live/" preFlightsChecks.call(command, self.distro, '[setup_account_cyberpanel]', 'add user cyberpanel', @@ -884,8 +914,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.2.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) @@ -893,8 +923,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.2.tar.gz" + #command = "tar zxf CyberPanelTemp.tar.gz" preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]', 'Extract CyberPanel',1, 1, os.EX_OSERR) @@ -976,9 +1006,27 @@ class preFlightsChecks: preFlightsChecks.call(command, self.distro, '[download_install_CyberPanel]', 'Move static content', 1, 1, os.EX_OSERR) + try: + path = "/usr/local/CyberCP/version.txt" + writeToFile = open(path, 'w') + writeToFile.writelines('1.8\n') + writeToFile.writelines('2') + writeToFile.close() + except: + pass + def fixCyberPanelPermissions(self): + ###### fix Core CyberPanel permissions + command = "usermod -G lscpd,lsadm,nobody lscpd" + preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', + 'add lscpd to important groups', 0, 0, os.EX_OSERR) + + command = "usermod -G lscpd,lsadm,nogroup lscpd" + preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', + 'add lscpd to important groups', 0, 0, os.EX_OSERR) + command = "find /usr/local/CyberCP -type d -exec chmod 0755 {} \;" preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', 'fix permissions /usr/local/CyberCP', 1, 0, os.EX_OSERR) @@ -1015,9 +1063,9 @@ class preFlightsChecks: preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', 'fix permissions /usr/local/CyberCP', 1, 0, os.EX_OSERR) - command = "chown -R lscpd:lscpd /usr/local/CyberCP/public/rainloop/data" + command = "chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin/tmp" preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', - 'fix permissions /usr/local/CyberCP', 1, 0, os.EX_OSERR) + 'fix permissions /usr/local/CyberCP/public/phpmyadmin/tmp', 1, 0, os.EX_OSERR) ## change owner @@ -1025,6 +1073,25 @@ class preFlightsChecks: preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', 'change owner /usr/local/CyberCP', 1, 0, os.EX_OSERR) + command = "chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data" + preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', + 'change owner /usr/local/CyberCP', 1, 0, os.EX_OSERR) + + command = "chmod 700 /usr/local/CyberCP/cli/cyberPanel.py" + preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', + 'Change permissions for CLI.', 1, 0, os.EX_OSERR) + + command = "chmod 700 /usr/local/CyberCP/plogical/upgradeCritical.py" + preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', + 'Change permissions for upgrade.', 1, 0, os.EX_OSERR) + + command = "chmod 700 /usr/local/CyberCP/postfixSenderPolicy/client.py" + preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', + 'Change permissions for client.', 1, 0, os.EX_OSERR) + + command = "chmod 600 /usr/local/CyberCP/CyberCP/settings.py" + preFlightsChecks.call(command, self.distro, '[fixCyberPanelPermissions]', + 'Change permissions for client.', 1, 0, os.EX_OSERR) def install_unzip(self): self.stdOut("Install unzip") @@ -2055,10 +2122,12 @@ class preFlightsChecks: try: ####### - if not os.path.exists("/usr/local/CyberCP/public"): os.mkdir("/usr/local/CyberCP/public") + if os.path.exists("/usr/local/CyberCP/public/rainloop"): + return 0 + os.chdir("/usr/local/CyberCP/public") count = 1 @@ -2156,6 +2225,27 @@ class preFlightsChecks: break ###### + command = "mkdir -p /usr/local/lscp/cyberpanel/rainloop/data" + preFlightsChecks.call(command, self.distro, '[downoad_and_install_rainloop]', + 'rainlooop data folder', + 1, 0, os.EX_OSERR) + + path = "/usr/local/CyberCP/public/rainloop/rainloop/v/1.12.1/include.php" + + data = open(path, 'r').readlines() + writeToFile = open(path, 'w') + + for items in data: + if items.find("$sCustomDataPath = '';") > -1: + writeToFile.writelines( + " $sCustomDataPath = '/usr/local/lscp/cyberpanel/rainloop/data';\n") + else: + writeToFile.writelines(items) + + writeToFile.close() + + + except OSError, msg: logging.InstallLog.writeToFile(str(msg) + " [downoad_and_install_rainloop]") @@ -2323,7 +2413,7 @@ class preFlightsChecks: 1, 1, os.EX_OSERR) - command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /usr/local/lscp/key.pem -out /usr/local/lscp/cert.pem' + command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /usr/local/lscp/conf/key.pem -out /usr/local/lscp/conf/cert.pem' preFlightsChecks.call(command, self.distro, '[installLSCPD]', 'Install LSCPD', 1, 1, os.EX_OSERR) @@ -2359,11 +2449,16 @@ class preFlightsChecks: preFlightsChecks.call(command, self.distro, '[installLSCPD]', 'Install LSCPD', 1, 0, os.EX_OSERR) + try: + os.mkdir('/usr/local/lscp/cyberpanel') + except: + pass + try: + os.mkdir('/usr/local/lscp/cyberpanel/logs') + except: + pass - os.mkdir('/usr/local/lscp/cyberpanel') - os.mkdir('/usr/local/lscp/cyberpanel/logs') - - self.setupComodoRules() + #self.setupComodoRules() self.setupPort() self.setupPythonWSGI() @@ -2405,6 +2500,7 @@ class preFlightsChecks: modsecConfig = """ module mod_security { + ls_enabled 0 modsecurity on modsecurity_rules ` SecDebugLogLevel 0 @@ -3509,8 +3605,9 @@ def main(): checks.setup_gunicorn() import installCyberPanel + if ent == 0: - installCyberPanel.Main(cwd, mysql, distro, ent, port) + installCyberPanel.Main(cwd, mysql, distro, ent, None, port) else: installCyberPanel.Main(cwd, mysql, distro, ent, serial, port) diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index 736ab1e31..49446b374 100644 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -686,7 +686,7 @@ class InstallCyberPanel: logging.InstallLog.writeToFile(str(msg) + " [startPowerDNS]") -def Main(cwd, mysql, distro, ent, serial = None): +def Main(cwd, mysql, distro, ent, serial = None, port = "8090"): InstallCyberPanel.mysqlPassword = randomPassword.generate_pass() InstallCyberPanel.mysql_Root_password = randomPassword.generate_pass() @@ -706,7 +706,7 @@ def Main(cwd, mysql, distro, ent, serial = None): else: InstallCyberPanel.mysqlPassword = InstallCyberPanel.mysql_Root_password - installer = InstallCyberPanel("/usr/local/lsws/",cwd, distro, ent, serial) + installer = InstallCyberPanel("/usr/local/lsws/",cwd, distro, ent, serial, port) installer.installLiteSpeed() if ent == 0: diff --git a/install/lscp.tar.gz b/install/lscp.tar.gz index d25248420..13ae87653 100644 Binary files a/install/lscp.tar.gz and b/install/lscp.tar.gz differ diff --git a/loginSystem/views.py b/loginSystem/views.py index 737960567..573926253 100644 --- a/loginSystem/views.py +++ b/loginSystem/views.py @@ -202,7 +202,7 @@ def loadLoginPage(request): firstName="Cyber",lastName="Panel", acl=acl, token=token) admin.save() - vers = version(currentVersion="1.8", build=1) + vers = version(currentVersion="1.8", build=2) vers.save() package = Package(admin=admin, packageName="Default", diskSpace=1000, diff --git a/managePHP/views.py b/managePHP/views.py index 186d58250..5557e5edf 100644 --- a/managePHP/views.py +++ b/managePHP/views.py @@ -1319,10 +1319,19 @@ def getRequestStatus(request): checkCommand = 'dpkg --list' checkCommand = shlex.split(checkCommand) - requestStatus = unicode(open(phpUtilities.installLogPath, "r").read()) + command = "sudo cat " + phpUtilities.installLogPath + requestStatus = ProcessUtilities.outputExecutioner(command) + + if requestStatus.find('No such') > -1: + requestStatus = "" + requestStatusSize = len(requestStatus) if requestStatus.find("PHP Extension Installed") > -1: + + command = "sudo rm -f " + phpUtilities.installLogPath + ProcessUtilities.executioner(command) + if ProcessUtilities.outputExecutioner(checkCommand).find(extensionName) > -1: ext = installedPackages.objects.get(extensionName=extensionName) ext.status = 1 @@ -1339,10 +1348,14 @@ def getRequestStatus(request): return HttpResponse(final_json) elif requestStatus.find("Can not be installed") > -1: + command = "sudo rm -f " + phpUtilities.installLogPath + ProcessUtilities.executioner(command) + if ProcessUtilities.outputExecutioner(checkCommand).find(extensionName) > -1: ext = installedPackages.objects.get(extensionName=extensionName) ext.status = 1 ext.save() + else: ext = installedPackages.objects.get(extensionName=extensionName) ext.status = 0 @@ -1355,10 +1368,14 @@ def getRequestStatus(request): return HttpResponse(final_json) elif requestStatus.find("Can not un-install Extension") > -1: + command = "sudo rm -f " + phpUtilities.installLogPath + ProcessUtilities.executioner(command) + if ProcessUtilities.outputExecutioner(checkCommand).find(extensionName) > -1: ext = installedPackages.objects.get(extensionName=extensionName) ext.status = 1 ext.save() + else: ext = installedPackages.objects.get(extensionName=extensionName) ext.status = 0 @@ -1371,6 +1388,9 @@ def getRequestStatus(request): return HttpResponse(final_json) elif requestStatus.find("PHP Extension Removed") > -1: + command = "sudo rm -f " + phpUtilities.installLogPath + ProcessUtilities.executioner(command) + ext = installedPackages.objects.get(extensionName=extensionName) ext.status = 0 ext.save() diff --git a/manageServices/views.py b/manageServices/views.py index d9d4f0f36..7be89c030 100644 --- a/manageServices/views.py +++ b/manageServices/views.py @@ -8,7 +8,6 @@ from loginSystem.views import loadLoginPage import os import json from plogical.mailUtilities import mailUtilities -import subprocess, shlex from plogical.acl import ACLManager from models import PDNSStatus from .serviceManager import ServiceManager diff --git a/plogical/adminPass.py b/plogical/adminPass.py index 63d00e003..3a374cc8a 100644 --- a/plogical/adminPass.py +++ b/plogical/adminPass.py @@ -31,7 +31,7 @@ def main(): firstName="Cyber", lastName="Panel", acl=acl, token=token) admin.save() - vers = version(currentVersion="1.8", build=1) + vers = version(currentVersion="1.8", build=2) vers.save() package = Package(admin=admin, packageName="Default", diskSpace=1000, diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 123b1086b..744c854eb 100644 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -507,9 +507,9 @@ class ApplicationInstaller(multi.Thread): try: command = 'sudo git --help' - res = ProcessUtilities.executioner(command) + output = ProcessUtilities.outputExecutioner(command) - if res == 0: + if output.find('command not found') > -1: statusFile = open(tempStatusPath, 'w') statusFile.writelines('Installing GIT..,0') statusFile.close() @@ -721,7 +721,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 - ProcessUtilities.executioner(command) + ProcessUtilities.normalExecutioner(command) else: statusFile = open(tempStatusPath, 'w') statusFile.writelines("File already exists." + " [404]") @@ -729,12 +729,12 @@ class ApplicationInstaller(multi.Thread): return 0 command = 'unzip ' + finalPath + 'staging.zip -d ' + finalPath - ProcessUtilities.executioner(command) + ProcessUtilities.normalExecutioner(command) os.remove(finalPath + 'staging.zip') command = 'cp -r ' + finalPath + 'joomla-cms-staging/. ' + finalPath - ProcessUtilities.executioner(command) + ProcessUtilities.normalExecutioner(command) shutil.rmtree(finalPath + "joomla-cms-staging") os.rename(finalPath + "installation/configuration.php-dist", finalPath + "configuration.php") @@ -820,7 +820,7 @@ class ApplicationInstaller(multi.Thread): shutil.rmtree(finalPath + "installation") command = "sudo chown -R " + virtualHostUser + ":" + virtualHostUser + " " + finalPath - ProcessUtilities.executioner(command) + ProcessUtilities.normalExecutioner(command) vhost.addRewriteRules(domainName) diff --git a/plogical/installUtilities.py b/plogical/installUtilities.py index 4f8045e30..9afaf067b 100644 --- a/plogical/installUtilities.py +++ b/plogical/installUtilities.py @@ -161,7 +161,25 @@ class installUtilities: else: command = "sudo /usr/local/lsws/bin/lswsctrl restart" - ProcessUtilities.executioner(command) + return ProcessUtilities.executioner(command) + + except OSError, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartLiteSpeed]") + return 0 + except ValueError, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartLiteSpeed]") + return 0 + + @staticmethod + def stopLiteSpeedSocket(): + try: + + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + command = "sudo systemctl stop lsws" + else: + command = "sudo /usr/local/lsws/bin/lswsctrl stop" + + return ProcessUtilities.executioner(command) except OSError, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartLiteSpeed]") @@ -169,7 +187,6 @@ class installUtilities: except ValueError, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [reStartLiteSpeed]") return 0 - return 1 @staticmethod diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index 5ab2af9da..bb905b7c0 100644 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -68,15 +68,15 @@ class mailUtilities: path = "/usr/local/CyberCP/install/rainloop/cyberpanel.net.ini" - if not os.path.exists("/usr/local/CyberCP/public/rainloop/data/_data_/_default_/domains/"): - os.makedirs("/usr/local/CyberCP/public/rainloop/data/_data_/_default_/domains/") + if not os.path.exists("/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/"): + os.makedirs("/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/") - finalPath = "/usr/local/CyberCP/public/rainloop/data/_data_/_default_/domains/" + domain + ".ini" + finalPath = "/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/domains/" + domain + ".ini" if not os.path.exists(finalPath): shutil.copy(path, finalPath) - command = 'chown -R lscpd:lscpd /usr/local/CyberCP/public/rainloop/data/' + command = 'chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data/' ProcessUtilities.normalExecutioner(command) ## After effects ends @@ -360,8 +360,6 @@ milter_default_action = accept def installSpamAssassin(install, SpamAssassin): try: - mailUtilities.checkHome() - if ProcessUtilities.decideDistro() == ProcessUtilities.centos: command = 'sudo yum install spamassassin -y' else: @@ -397,9 +395,9 @@ milter_default_action = accept path = "/etc/mail/spamassassin/local.cf" command = "sudo cat " + path - res = subprocess.call(shlex.split(command)) + output = ProcessUtilities.outputExecutioner(command) - if res == 1: + if output.find('No such') > -1: return 0 else: return 1 @@ -606,6 +604,8 @@ def main(): mailUtilities.saveSpamAssassinConfigs(args.tempConfigPath) elif args.function == 'savePolicyServerStatus': mailUtilities.savePolicyServerStatus(args.install) + elif args.function == 'installSpamAssassin': + mailUtilities.installSpamAssassin("install", "SpamAssassin") if __name__ == "__main__": main() \ No newline at end of file diff --git a/plogical/phpUtilities.py b/plogical/phpUtilities.py index 9c10c8f17..11e093831 100644 --- a/plogical/phpUtilities.py +++ b/plogical/phpUtilities.py @@ -87,7 +87,6 @@ class phpUtilities: except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateInstall]") - @staticmethod def initiateRemoval(extension): try: diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index 8fa94750e..a87409c67 100644 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -4,6 +4,7 @@ import shlex import os import socket import threading as multi +import time class ProcessUtilities(multi.Thread): litespeedProcess = "litespeed" @@ -144,18 +145,25 @@ class ProcessUtilities(multi.Thread): @staticmethod def setupUDSConnection(): - try: - sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - sock.connect(ProcessUtilities.server_address) - return [sock, "None"] - except BaseException, msg: - logging.writeToFile(str(msg) + ". [setupUDSConnection:138]") - return [-1, str(msg)] + count = 0 + while 1: + try: + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.connect(ProcessUtilities.server_address) + return [sock, "None"] + except BaseException, msg: + if count == 3: + logging.writeToFile("Failed to connect to LSCPD socket, run 'systemctl restart lscpd' on command line to fix this issue.") + return [-1, str(msg)] + else: + count = count + 1 + + logging.writeToFile("Failed to connect to LSCPD UDS, error message:" + str(msg) + ". Attempt " + str(count) + ", we will attempt again in 2 seconds. [setupUDSConnection:138]") + time.sleep(2) @staticmethod def sendCommand(command): try: - logging.writeToFile(command) ret = ProcessUtilities.setupUDSConnection() diff --git a/plogical/upgrade.py b/plogical/upgrade.py index da126984f..58e2691e3 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -14,6 +14,8 @@ import time from baseTemplate.models import version import MySQLdb as mysql from CyberCP import settings +import random +import string class Upgrade: logPath = "/usr/local/lscp/logs/upgradeLog" @@ -49,6 +51,316 @@ class Upgrade: except: return 0 + @staticmethod + def mountTemp(): + try: + + if os.path.exists("/usr/.tempdisk"): + return 0 + + command = "dd if=/dev/zero of=/usr/.tempdisk bs=100M count=15" + Upgrade.executioner(command, 'mountTemp', 0) + + command = "mkfs.ext4 -F /usr/.tempdisk" + Upgrade.executioner(command, 'mountTemp', 0) + + command = "mkdir -p /usr/.tmpbak/" + Upgrade.executioner(command, 'mountTemp', 0) + + command = "cp -pr /tmp/* /usr/.tmpbak/" + subprocess.call(command, shell=True) + + command = "mount -o loop,rw,nodev,nosuid,noexec,nofail /usr/.tempdisk /tmp" + Upgrade.executioner(command, 'mountTemp', 0) + + command = "chmod 1777 /tmp" + Upgrade.executioner(command, 'mountTemp', 0) + + command = "cp -pr /usr/.tmpbak/* /tmp/" + subprocess.call(command, shell=True) + + command = "rm -rf /usr/.tmpbak" + Upgrade.executioner(command, 'mountTemp', 0) + + command = "mount --bind /tmp /var/tmp" + Upgrade.executioner(command, 'mountTemp', 0) + + + tmp = "/usr/.tempdisk /tmp ext4 loop,rw,noexec,nosuid,nodev,nofail 0 0\n" + varTmp = "/tmp /var/tmp none bind 0 0\n" + + fstab = "/etc/fstab" + writeToFile = open(fstab, "a") + writeToFile.writelines(tmp) + writeToFile.writelines(varTmp) + writeToFile.close() + + except BaseException, msg: + Upgrade.stdOut(str(msg) + " [mountTemp]", 0) + + @staticmethod + def setupPythonWSGI(): + try: + + cwd = os.getcwd() + + command = "wget http://www.litespeedtech.com/packages/lsapi/wsgi-lsapi-1.4.tgz" + Upgrade.executioner(command, 0) + + command = "tar xf wsgi-lsapi-1.4.tgz" + Upgrade.executioner(command, 0) + + os.chdir("wsgi-lsapi-1.4") + + command = "python ./configure.py" + Upgrade.executioner(command, 0) + + command = "make" + Upgrade.executioner(command, 0) + + command = "cp lswsgi /usr/local/CyberCP/bin/" + Upgrade.executioner(command, 0) + + os.chdir(cwd) + + except: + return 0 + + @staticmethod + def dockerUsers(): + ### Docker User/group + + command = "adduser docker" + Upgrade.executioner(command, 'adduser docker', 0) + + command = 'groupadd docker' + Upgrade.executioner(command, 'adduser docker', 0) + + command = 'usermod -aG docker docker' + Upgrade.executioner(command, 'adduser docker', 0) + + command = 'usermod -aG docker cyberpanel' + Upgrade.executioner(command, 'adduser docker', 0) + + ### + + @staticmethod + def fixSudoers(): + try: + distroPath = '/etc/lsb-release' + + if os.path.exists(distroPath): + fileName = '/etc/sudoers' + data = open(fileName, 'r').readlines() + + writeDataToFile = open(fileName, 'w') + for line in data: + if line.find("%sudo ALL=(ALL:ALL)") > -1: + continue + else: + writeDataToFile.write(line) + writeDataToFile.close() + + else: + try: + path = "/etc/sudoers" + + data = open(path, 'r').readlines() + + writeToFile = open(path, 'w') + + for items in data: + if items.find("wheel") > -1 and items.find("ALL=(ALL)"): + continue + else: + writeToFile.writelines(items) + + writeToFile.close() + except: + pass + + command = "chsh -s /bin/false cyberpanel" + Upgrade.executioner(command, 0) + except IOError as err: + pass + + @staticmethod + def download_install_phpmyadmin(): + try: + cwd = os.getcwd() + + if not os.path.exists("/usr/local/CyberCP/public"): + os.mkdir("/usr/local/CyberCP/public") + + try: + shutil.rmtree("/usr/local/CyberCP/public/phpmyadmin") + except: + pass + + os.chdir("/usr/local/CyberCP/public") + + command = '/usr/local/lsws/lsphp70/bin/php /usr/bin/composer create-project phpmyadmin/phpmyadmin' + Upgrade.executioner(command, 0) + + ## Write secret phrase + + rString = ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(32)]) + + data = open('phpmyadmin/config.sample.inc.php', 'r').readlines() + + writeToFile = open('phpmyadmin/config.inc.php', 'w') + + for items in data: + if items.find('blowfish_secret') > -1: + writeToFile.writelines( + "$cfg['blowfish_secret'] = '" + rString + "'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */\n") + else: + writeToFile.writelines(items) + + writeToFile.writelines("$cfg['TempDir'] = '/usr/local/CyberCP/public/phpmyadmin/tmp';\n") + + writeToFile.close() + + os.mkdir('/usr/local/CyberCP/public/phpmyadmin/tmp') + + os.chdir(cwd) + + except BaseException, msg: + Upgrade.stdOut(str(msg) + " [download_install_phpmyadmin]", 0) + + @staticmethod + def setupComposer(): + command = "wget https://cyberpanel.sh/composer.sh" + Upgrade.executioner(command, 0) + + command = "chmod +x composer.sh" + Upgrade.executioner(command, 0) + + command = "./composer.sh" + Upgrade.executioner(command, 0) + + @staticmethod + def downoad_and_install_raindloop(): + try: + ####### + + if os.path.exists("/usr/local/CyberCP/public/rainloop"): + + if os.path.exists("/usr/local/lscp/cyberpanel/rainloop/data"): + pass + else: + command = "mv /usr/local/CyberCP/public/rainloop/data /usr/local/lscp/cyberpanel/rainloop/data" + Upgrade.executioner(command, 0) + + command = "chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data" + Upgrade.executioner(command, 0) + + path = "/usr/local/CyberCP/public/rainloop/rainloop/v/1.12.1/include.php" + + data = open(path, 'r').readlines() + writeToFile = open(path, 'w') + + for items in data: + if items.find("$sCustomDataPath = '';") > -1: + writeToFile.writelines( + " $sCustomDataPath = '/usr/local/lscp/cyberpanel/rainloop/data';\n") + else: + writeToFile.writelines(items) + + writeToFile.close() + return 0 + + cwd = os.getcwd() + + if not os.path.exists("/usr/local/CyberCP/public"): + os.mkdir("/usr/local/CyberCP/public") + + os.chdir("/usr/local/CyberCP/public") + + count = 1 + + while (1): + command = 'wget https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip' + cmd = shlex.split(command) + res = subprocess.call(cmd) + if res != 0: + count = count + 1 + if count == 3: + break + else: + break + + ############# + + count = 0 + + while (1): + command = 'unzip rainloop-community-latest.zip -d /usr/local/CyberCP/public/rainloop' + + cmd = shlex.split(command) + res = subprocess.call(cmd) + if res != 0: + count = count + 1 + if count == 3: + break + else: + break + + os.remove("rainloop-community-latest.zip") + + ####### + + os.chdir("/usr/local/CyberCP/public/rainloop") + + count = 0 + + while (1): + command = 'find . -type d -exec chmod 755 {} \;' + cmd = shlex.split(command) + res = subprocess.call(cmd) + if res != 0: + count = count + 1 + if count == 3: + break + else: + break + + ############# + + count = 0 + + while (1): + + command = 'find . -type f -exec chmod 644 {} \;' + cmd = shlex.split(command) + res = subprocess.call(cmd) + if res != 0: + count = count + 1 + if count == 3: + break + else: + break + ###### + + path = "/usr/local/CyberCP/public/rainloop/rainloop/v/1.12.1/include.php" + + data = open(path, 'r').readlines() + writeToFile = open(path, 'w') + + for items in data: + if items.find("$sCustomDataPath = '';") > -1: + writeToFile.writelines( + " $sCustomDataPath = '/usr/local/lscp/cyberpanel/rainloop/data';\n") + else: + writeToFile.writelines(items) + + os.chdir(cwd) + + except BaseException, msg: + Upgrade.stdOut(str(msg) + " [downoad_and_install_raindloop]", 0) + + return 1 + @staticmethod def downloadLink(): try: @@ -57,6 +369,16 @@ class Upgrade: data = json.loads(r.text) version_number = str(data['version']) version_build = str(data['build']) + + try: + path = "/usr/local/CyberCP/version.txt" + writeToFile = open(path, 'w') + writeToFile.writelines(version_number + '\n') + writeToFile.writelines(version_build) + writeToFile.close() + except: + pass + return (version_number + "." + version_build + ".tar.gz") except BaseException, msg: Upgrade.stdOut(str(msg) + ' [downloadLink]') @@ -98,9 +420,6 @@ class Upgrade: command = "pip install --ignore-installed -r /usr/local/CyberCP/requirments.txt" Upgrade.executioner(command, 'CyberPanel requirements', 1) - command = "systemctl stop gunicorn.socket" - Upgrade.executioner(command, '', 0) - command = "virtualenv --system-site-packages /usr/local/CyberCP" Upgrade.executioner(command, 'Setting up VirtualEnv [Two]', 1) @@ -108,47 +427,6 @@ class Upgrade: except OSError, msg: Upgrade.stdOut(str(msg) + " [setupVirtualEnv]", 0) - @staticmethod - def updateGunicornConf(): - try: - path = '/etc/systemd/system/gunicorn.service' - - cont = """[Unit] -Description=gunicorn daemon -Requires=gunicorn.socket -After=network.target - -[Service] -PIDFile=/run/gunicorn/pid -User=cyberpanel -Group=cyberpanel -RuntimeDirectory=gunicorn -WorkingDirectory=/usr/local/CyberCP -ExecStart=/usr/local/CyberCP/bin/gunicorn --pid /run/gunicorn/gucpid --timeout 2000 --workers 2 \ - --bind 127.0.0.1:5003 CyberCP.wsgi -ExecReload=/bin/kill -s HUP $MAINPID -ExecStop=/bin/kill -s TERM $MAINPID -PrivateTmp=true - -[Install] -WantedBy=multi-user.target""" - - writeToFile = open(path, 'w') - writeToFile.write(cont) - writeToFile.close() - - ## - - command = 'systemctl daemon-reload' - Upgrade.executioner(command, 'daemon-reload', 0) - - ## - - command = 'systemctl restart gunicorn.socket' - Upgrade.executioner(command, 'restart gunicorn.socket', 0) - except BaseException, msg: - Upgrade.stdOut(str(msg) + " [updateGunicornConf]") - @staticmethod def fileManager(): ## Copy File manager files @@ -186,13 +464,16 @@ WantedBy=multi-user.target""" @staticmethod def staticContent(): - command = "rm -rf /usr/local/lscp/cyberpanel/static" + command = "rm -rf /usr/local/CyberCP/public/static" Upgrade.executioner(command, 'Remove old static content', 0) ## - command = "mv /usr/local/CyberCP/static /usr/local/lscp/cyberpanel" - Upgrade.executioner(command, 'Update new static content', 0) + if not os.path.exists("/usr/local/CyberCP/public"): + os.mkdir("/usr/local/CyberCP/public") + + + shutil.move("/usr/local/CyberCP/static", "/usr/local/CyberCP/public/") @staticmethod def upgradeVersion(): @@ -255,6 +536,13 @@ WantedBy=multi-user.target""" cursor.execute('ALTER TABLE loginSystem_administrator ADD token varchar(500)') except: pass + + + try: + cursor.execute('ALTER TABLE loginSystem_administrator ADD api integer') + except: + pass + try: cursor.execute('ALTER TABLE loginSystem_administrator ADD acl_id integer') except: @@ -968,9 +1256,6 @@ WantedBy=multi-user.target""" command = 'usermod -a -G lsadm lscpd' Upgrade.executioner(command, 'Add group LSCPD', 0) - command = 'chown -R lscpd:lscpd /usr/local/lscp/cyberpanel' - Upgrade.executioner(command, 'chown cyberpanel', 0) - command = 'systemctl daemon-reload' Upgrade.executioner(command, 'daemon-reload LSCPD', 0) @@ -990,6 +1275,15 @@ WantedBy=multi-user.target""" Upgrade.stdOut("Fixing permissions..") + + command = "usermod -G lscpd,lsadm,nobody lscpd" + Upgrade.executioner(command, 'chown core code', 0) + + command = "usermod -G lscpd,lsadm,nogroup lscpd" + Upgrade.executioner(command, 'chown core code', 0) + + ###### fix Core CyberPanel permissions + command = "find /usr/local/CyberCP -type d -exec chmod 0755 {} \;" Upgrade.executioner(command, 'chown core code', 0) @@ -999,11 +1293,50 @@ WantedBy=multi-user.target""" command = "chmod -R 755 /usr/local/CyberCP/bin" Upgrade.executioner(command, 'chown core code', 0) + ## change owner + command = "chown -R root:root /usr/local/CyberCP" Upgrade.executioner(command, 'chown core code', 0) - command = 'chown -R lscpd:lscpd /usr/local/lscp/cyberpanel' - Upgrade.executioner(command, 'chown static content', 0) + ########### Fix LSCPD + + command = "find /usr/local/lscp -type d -exec chmod 0755 {} \;" + Upgrade.executioner(command, 'chown core code', 0) + + command = "find /usr/local/lscp -type f -exec chmod 0644 {} \;" + Upgrade.executioner(command, 'chown core code', 0) + + command = "chmod -R 755 /usr/local/lscp/bin" + Upgrade.executioner(command, 'chown core code', 0) + + command = "chmod -R 755 /usr/local/lscp/fcgi-bin" + Upgrade.executioner(command, 'chown core code', 0) + + command = "chown -R lscpd:lscpd /usr/local/CyberCP/public/phpmyadmin/tmp" + Upgrade.executioner(command, 'chown core code', 0) + + ## change owner + + command = "chown -R root:root /usr/local/lscp" + Upgrade.executioner(command, 'chown core code', 0) + + command = 'openssl req -newkey rsa:1024 -new -nodes -x509 -days 3650 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout /usr/local/lscp/conf/key.pem -out /usr/local/lscp/conf/cert.pem' + Upgrade.executioner(command, 'generate cyberpanel ssl', 0) + + command = "chown -R lscpd:lscpd /usr/local/lscp/cyberpanel/rainloop/data" + Upgrade.executioner(command, 'chown core code', 0) + + command = "chmod 700 /usr/local/CyberCP/cli/cyberPanel.py" + Upgrade.executioner(command, 'chown core code', 0) + + command = "chmod 700 /usr/local/CyberCP/plogical/upgradeCritical.py" + Upgrade.executioner(command, 'chown core code', 0) + + command = "chmod 700 /usr/local/CyberCP/postfixSenderPolicy/client.py" + Upgrade.executioner(command, 'chown core code', 0) + + command = "chmod 600 /usr/local/CyberCP/CyberCP/settings.py" + Upgrade.executioner(command, 'chown core code', 0) Upgrade.stdOut("Permissions updated.") @@ -1025,21 +1358,34 @@ WantedBy=multi-user.target""" 'lsphp7?-sqlite3 lsphp7?-tidy' Upgrade.executioner(command, 'Install PHP 73, 0') + @staticmethod + def someDirectories(): + command = "mkdir -p /usr/local/lscpd/admin/" + Upgrade.executioner(command, 0) + + command = "mkdir -p /usr/local/lscp/cyberpanel/logs" + Upgrade.executioner(command, 0) + @staticmethod def upgrade(): + #Upgrade.stdOut("Upgrades are currently disabled") + #return 0 + os.chdir("/usr/local") ## Current Version Version = version.objects.get(pk=1) - command = "systemctl stop gunicorn.socket" - Upgrade.executioner(command, 'stop gunicorn', 0) - command = "systemctl stop lscpd" Upgrade.executioner(command, 'stop lscpd', 0) + Upgrade.fixSudoers() + Upgrade.mountTemp() + Upgrade.dockerUsers() + Upgrade.setupComposer() + ## versionNumbring = Upgrade.downloadLink() @@ -1056,6 +1402,8 @@ WantedBy=multi-user.target""" Upgrade.installPYDNS() Upgrade.downloadAndUpgrade(versionNumbring) + Upgrade.download_install_phpmyadmin() + Upgrade.downoad_and_install_raindloop() ## @@ -1070,7 +1418,6 @@ WantedBy=multi-user.target""" ## Upgrade.setupVirtualEnv() - Upgrade.updateGunicornConf() ## @@ -1082,6 +1429,8 @@ WantedBy=multi-user.target""" Upgrade.installPHP73() Upgrade.setupCLI() + Upgrade.setupPythonWSGI() + Upgrade.someDirectories() Upgrade.installLSCPD() Upgrade.fixPermissions() time.sleep(3) diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 4f5da1ac7..32049a76a 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -422,8 +422,8 @@ class virtualHostUtilities: def issueSSLForHostName(virtualHost, path): try: - destPrivKey = "/usr/local/lscp/key.pem" - destCert = "/usr/local/lscp/cert.pem" + destPrivKey = "/usr/local/lscp/conf/key.pem" + destCert = "/usr/local/lscp/conf/cert.pem" pathToStoreSSLFullChain = '/etc/letsencrypt/live/' + virtualHost + '/fullchain.pem' pathToStoreSSLPrivKey = '/etc/letsencrypt/live/' + virtualHost + '/privkey.pem' @@ -434,8 +434,6 @@ class virtualHostUtilities: if os.path.exists(destCert): os.remove(destCert) - - adminEmail = "email@" + virtualHost if not os.path.exists(pathToStoreSSLFullChain): @@ -1002,9 +1000,8 @@ class virtualHostUtilities: data = [int(totalUsageInMB), int(percentage)] return data - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [getDiskUsage]") - return [int(0), int(0)] + except BaseException: + return [int(totalUsageInMB), int(0)] @staticmethod def permissionControl(path): diff --git a/plogical/website.py b/plogical/website.py index cfa4b021b..426901eee 100644 --- a/plogical/website.py +++ b/plogical/website.py @@ -1437,7 +1437,7 @@ class WebsiteManager: try: statusFile = data['statusFile'] - statusData = open(statusFile, 'r').readlines() + statusData = ProcessUtilities.outputExecutioner("sudo cat " + statusFile).splitlines() lastLine = statusData[-1] @@ -1617,7 +1617,7 @@ class WebsiteManager: # return execPath - output = subprocess.Popen(shlex.split(execPath)) + ProcessUtilities.popenExecutioner(execPath) data_ret = {'status': 1, "installStatus": 1, 'tempStatusPath': tempStatusPath} json_data = json.dumps(data_ret) diff --git a/pluginInstaller/pluginInstaller.py b/pluginInstaller/pluginInstaller.py index ad83cf20e..a9cb7a2fe 100644 --- a/pluginInstaller/pluginInstaller.py +++ b/pluginInstaller/pluginInstaller.py @@ -1,10 +1,12 @@ +import sys +sys.path.append('/usr/local/CyberCP') import subprocess import shlex import argparse import os -import tarfile import shutil import time +from plogical.processUtilities import ProcessUtilities class pluginInstaller: installLogPath = "/home/cyberpanel/modSecInstallLog" @@ -285,8 +287,9 @@ class pluginInstaller: @staticmethod def restartGunicorn(): - command = 'systemctl restart gunicorn.socket' - subprocess.call(shlex.split(command)) + command = 'systemctl restart lscpd' + ProcessUtilities.normalExecutioner(command) + diff --git a/requirments.txt b/requirments.txt index ec761a32e..beea9ea4d 100644 --- a/requirments.txt +++ b/requirments.txt @@ -20,7 +20,6 @@ enum34==1.1.6 funcsigs==1.0.2 future==0.16.0 futures==3.2.0 -gunicorn==19.8.1 idna==2.6 iniparse==0.4 ipaddress==1.0.16 diff --git a/s3Backups/s3Backups.py b/s3Backups/s3Backups.py index c83f2bc7b..564fbe554 100644 --- a/s3Backups/s3Backups.py +++ b/s3Backups/s3Backups.py @@ -18,6 +18,8 @@ try: from random import randint import subprocess, shlex from plogical.processUtilities import ProcessUtilities + from websiteFunctions.models import Websites, Backups + from plogical.virtualHostUtilities import virtualHostUtilities except: import threading as multi from random import randint @@ -93,18 +95,41 @@ class S3Backups(multi.Thread): return json_data def setupCron(self): - tempPath = '/home/cyberpanel/' + str(randint(10000, 99999)) - - writeToFile = open(tempPath, 'w') - writeToFile.write('0 0 * * * /usr/local/CyberCP/bin/python2 /usr/local/CyberCP/s3Backups/s3Backups.py > /home/cyberpanel/error-logs.txt 2>&1\n') - writeToFile.close() - - command = 'sudo crontab -u cyberpanel ' + tempPath - ProcessUtilities.executioner(command) try: - os.remove(tempPath) - except: - pass + + command = "sudo cat /etc/crontab" + crons = ProcessUtilities.outputExecutioner(command).splitlines() + + cronCheck = 1 + + for items in crons: + if items.find('s3Backups.py') > -1: + cronCheck = 0 + + tempPath = '/home/cyberpanel/' + str(randint(10000, 99999)) + + writeToFile = open(tempPath, "w") + + for items in crons: + writeToFile.writelines(items + "\n") + + if cronCheck: + writeToFile.writelines("0 0 * * * root /usr/local/CyberCP/bin/python2 /usr/local/CyberCP/s3Backups/s3Backups.py > /home/cyberpanel/error-logs.txt 2>&1\n") + + writeToFile.close() + + command = 'sudo mv ' + tempPath + " /etc/crontab" + ProcessUtilities.executioner(command) + + command = 'chown root:root /etc/crontab' + ProcessUtilities.executioner(command) + + try: + os.remove(tempPath) + except: + pass + except BaseException, msg: + logging.writeToFile(str(msg) + " [S3Backups.setupCron]") def connectAccount(self): try: @@ -389,25 +414,64 @@ class S3Backups(multi.Thread): return proc.ajaxPre(0, str(msg)) def createBackup(self, virtualHost): - finalData = json.dumps({'websiteToBeBacked': virtualHost}) - r = requests.post("http://localhost:5003/backup/submitBackupCreation", data=finalData) + website = Websites.objects.get(domain=virtualHost) + # defining paths - data = json.loads(r.text) - try: - backupPath = data['tempStorage'] - except: - pass + ## /home/example.com/backup + backupPath = os.path.join("/home", virtualHost, "backup/") + domainUser = website.externalApp + backupName = 'backup-' + domainUser + "-" + time.strftime("%I-%M-%S-%a-%b-%Y") + + ## /home/example.com/backup/backup-example-06-50-03-Thu-Feb-2018 + tempStoragePath = os.path.join(backupPath, backupName) + + execPath = "sudo nice -n 10 python " + virtualHostUtilities.cyberPanel + "/plogical/backupUtilities.py" + execPath = execPath + " submitBackupCreation --tempStoragePath " + tempStoragePath + " --backupName " \ + + backupName + " --backupPath " + backupPath + ' --backupDomain ' + virtualHost + + ProcessUtilities.popenExecutioner(execPath) + + time.sleep(2) while (1): - r = requests.post("http://localhost:5003/backup/backupStatus", data=finalData) - time.sleep(2) - data = json.loads(r.text) - if data['backupStatus'] == 0: - return 0, data['error_message'] - elif data['abort'] == 1: - return 1, backupPath + backupDomain = virtualHost + status = os.path.join("/home", backupDomain, "backup/status") + backupFileNamePath = os.path.join("/home", backupDomain, "backup/backupFileName") + pid = os.path.join("/home", backupDomain, "backup/pid") + ## read file name + + try: + fileName = open(backupFileNamePath, 'r').read() + except: + fileName = "Fetching.." + + ## file name read ends + + if os.path.exists(status): + status = open(status, 'r').read() + + if status.find("Completed") > -1: + + ### Removing Files + + command = 'sudo rm -f ' + status + ProcessUtilities.normalExecutioner(command) + + command = 'sudo rm -f ' + backupFileNamePath + ProcessUtilities.normalExecutioner(command) + + command = 'sudo rm -f ' + pid + ProcessUtilities.normalExecutioner(command) + + return 1, tempStoragePath + + elif status.find("[5009]") > -1: + backupObs = Backups.objects.filter(fileName=fileName) + for items in backupObs: + items.delete() + return 0, status def forceRunAWSBackup(self): try: @@ -1310,7 +1374,7 @@ def main(): file.close() finalData = json.dumps({'randomFile': pathToFile}) - requests.post("http://localhost:5003/api/runAWSBackups", data=finalData, verify=False) + requests.post("https://localhost:8090/api/runAWSBackups", data=finalData, verify=False) if __name__ == "__main__": diff --git a/serverStatus/serverStatusUtil.py b/serverStatus/serverStatusUtil.py index 99dcce145..d3c80dcd8 100644 --- a/serverStatus/serverStatusUtil.py +++ b/serverStatus/serverStatusUtil.py @@ -37,8 +37,6 @@ class ServerStatusUtil: def installLiteSpeed(licenseKey, statusFile): try: - logging.CyberCPLogFileWriter.writeToFile(os.environ.get('TERM')) - cwd = os.getcwd() try: diff --git a/serverStatus/views.py b/serverStatus/views.py index e87be0165..56f64d523 100644 --- a/serverStatus/views.py +++ b/serverStatus/views.py @@ -8,7 +8,6 @@ from loginSystem.views import loadLoginPage import json import subprocess import psutil -import shlex import socket from plogical.acl import ACLManager import os @@ -17,6 +16,7 @@ import time import serverStatusUtil from plogical.processUtilities import ProcessUtilities from plogical.httpProc import httpProc +from plogical.installUtilities import installUtilities # Create your views here. @@ -96,12 +96,12 @@ def stopOrRestartLitespeed(request): reboot = data['reboot'] if reboot == 1: - if ProcessUtilities.restartLitespeed() == 1: + if installUtilities.reStartLiteSpeedSocket() == 1: status = {"reboot": 1, "shutdown": 0} else: status = {"reboot": 0, "shutdown": 0, "error_message": "Please see CyberCP main log file."} else: - if ProcessUtilities.stopLitespeed() == 1: + if installUtilities.stopLiteSpeedSocket() == 1: status = {"reboot": 0, "shutdown": 1} else: status = {"reboot": 0, "shutdown": 0, "error_message": "Please see CyberCP main log file."}