diff --git a/install/install.py b/install/install.py index 48d37e65a..c1f3afeb4 100644 --- a/install/install.py +++ b/install/install.py @@ -1013,9 +1013,9 @@ class preFlightsChecks: while (1): if self.distro == centos: - command = 'yum -y install zip' + command = 'yum -y install unzip' else: - command = 'apt-get -y install zip' + command = 'apt-get -y install unzip' cmd = shlex.split(command) res = subprocess.call(cmd) diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index 14f3c85f2..d591262cd 100644 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -225,16 +225,15 @@ class InstallCyberPanel: def installAllPHPVersions(self): try: count = 0 + while (1): if self.distro == ubuntu: command = 'DEBIAN_FRONTEND=noninteractive apt-get -y install ' \ 'lsphp7? lsphp7?-common lsphp7?-curl lsphp7?-dev lsphp7?-imap lsphp7?-intl lsphp7?-json ' \ 'lsphp7?-ldap lsphp7?-mysql lsphp7?-opcache lsphp7?-pspell lsphp7?-recode ' \ - 'lsphp7?-sqlite3 lsphp7?-tidy >> /var/log/installPHPs 2>&1' + 'lsphp7?-sqlite3 lsphp7?-tidy' res = os.system(command) - if res != 0: - res = 1 # Force a retry else: command = 'yum -y groupinstall lsphp-all' cmd = shlex.split(command) diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index e86a1b081..a53a2b77e 100644 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -95,7 +95,7 @@ class ProcessUtilities: def decideServer(): entPath = '/usr/local/lsws/bin/lshttpd' - if os.readlink(entPath) == '/usr/local/lsws/bin/lshttpd/openlitespeed': + if os.path.exists('/usr/local/lsws/bin/openlitespeed'): return ProcessUtilities.OLS else: return ProcessUtilities.ent diff --git a/plogical/tuning.py b/plogical/tuning.py index 62ff27d88..313789244 100644 --- a/plogical/tuning.py +++ b/plogical/tuning.py @@ -3,224 +3,386 @@ from installUtilities import installUtilities import argparse import subprocess import shlex +from processUtilities import ProcessUtilities +from xml.etree import ElementTree class tuning: @staticmethod def fetchTuningDetails(): + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: + dataToReturn = {} + command = "sudo cat /usr/local/lsws/conf/httpd_config.conf" + datas = subprocess.check_output(shlex.split(command)).split("\n") - try: - dataToReturn = {} + for items in datas: + if items.find("maxConnections")>-1: + data = items.split() + dataToReturn['maxConnections'] = data[1] - command = "sudo cat /usr/local/lsws/conf/httpd_config.conf" - datas = subprocess.check_output(shlex.split(command)).split("\n") + if items.find("maxSSLConnections") > -1: + data = items.split() + dataToReturn['maxSSLConnections'] = data[1] - for items in datas: - if items.find("maxConnections")>-1: - data = items.split() - dataToReturn['maxConnections'] = data[1] - - if items.find("maxSSLConnections") > -1: - data = items.split() - dataToReturn['maxSSLConnections'] = data[1] - - if items.find("connTimeout") > -1: - data = items.split() - dataToReturn['connTimeout'] = data[1] + if items.find("connTimeout") > -1: + data = items.split() + dataToReturn['connTimeout'] = data[1] - if items.find("maxConnections")>-1: - data = items.split() - dataToReturn['maxConnections'] = data[1] + if items.find("maxConnections")>-1: + data = items.split() + dataToReturn['maxConnections'] = data[1] - if items.find("keepAliveTimeout") > -1: - data = items.split() - dataToReturn['keepAliveTimeout'] = data[1] + if items.find("keepAliveTimeout") > -1: + data = items.split() + dataToReturn['keepAliveTimeout'] = data[1] - if items.find("totalInMemCacheSize") > -1: - data = items.split() - dataToReturn['totalInMemCacheSize'] = data[1] + if items.find("totalInMemCacheSize") > -1: + data = items.split() + dataToReturn['totalInMemCacheSize'] = data[1] - if items.find("enableGzipCompress") > -1: - data = items.split() - dataToReturn['enableGzipCompress'] = data[1] + if items.find("enableGzipCompress") > -1: + data = items.split() + dataToReturn['enableGzipCompress'] = data[1] - return dataToReturn + return dataToReturn + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [fetchTuningDetails]") + return 0 + else: + try: + dataToReturn = {} - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile( - str(msg) + " [fetchTuningDetails]") - return 0 + command = "sudo cat /usr/local/lsws/conf/httpd_config.xml" + datas = subprocess.check_output(shlex.split(command)) + comTree = ElementTree.fromstring(datas) + tuningData = comTree.find('tuning') + + dataToReturn['maxConnections'] = tuningData.find('maxConnections').text + dataToReturn['maxSSLConnections'] = tuningData.find('maxSSLConnections').text + dataToReturn['connTimeout'] = tuningData.find('connTimeout').text + dataToReturn['keepAliveTimeout'] = tuningData.find('keepAliveTimeout').text + dataToReturn['totalInMemCacheSize'] = tuningData.find('totalInMemCacheSize').text + dataToReturn['enableGzipCompress'] = tuningData.find('enableGzipCompress').text + + return dataToReturn + + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [fetchTuningDetails]") + return 0 @staticmethod def saveTuningDetails(maxConnections,maxSSLConnections,connectionTimeOut,keepAliveTimeOut,cacheSizeInMemory,gzipCompression): + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: + datas = open("/usr/local/lsws/conf/httpd_config.conf").readlines() + writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf","w") - try: - datas = open("/usr/local/lsws/conf/httpd_config.conf").readlines() - writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf","w") - - if gzipCompression == "Enable": - gzip = 1 - else: - gzip = 0 - - - for items in datas: - if items.find("maxConnections") > -1: - data = " maxConnections "+str(maxConnections)+"\n" - writeDataToFile.writelines(data) - continue - - elif items.find("maxSSLConnections") > -1: - data = " maxSSLConnections "+str(maxSSLConnections) + "\n" - writeDataToFile.writelines(data) - continue - - elif items.find("connTimeout") > -1: - data =" connTimeout "+str(connectionTimeOut)+"\n" - writeDataToFile.writelines(data) - continue - - elif items.find("keepAliveTimeout") > -1: - data = " keepAliveTimeout " + str(keepAliveTimeOut) + "\n" - writeDataToFile.writelines(data) - continue - - elif items.find("totalInMemCacheSize") > -1: - data = " totalInMemCacheSize " + str(cacheSizeInMemory) + "\n" - writeDataToFile.writelines(data) - continue - - elif items.find("enableGzipCompress") > -1: - data = " enableGzipCompress " + str(gzip) + "\n" - writeDataToFile.writelines(data) - continue + if gzipCompression == "Enable": + gzip = 1 else: - writeDataToFile.writelines(items) + gzip = 0 - writeDataToFile.close() - print "1,None" + for items in datas: + if items.find("maxConnections") > -1: + data = " maxConnections "+str(maxConnections)+"\n" + writeDataToFile.writelines(data) + continue - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile( - str(msg) + " [saveTuningDetails]") - print "0," + str(msg) + elif items.find("maxSSLConnections") > -1: + data = " maxSSLConnections "+str(maxSSLConnections) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("connTimeout") > -1: + data =" connTimeout "+str(connectionTimeOut)+"\n" + writeDataToFile.writelines(data) + continue + + elif items.find("keepAliveTimeout") > -1: + data = " keepAliveTimeout " + str(keepAliveTimeOut) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("totalInMemCacheSize") > -1: + data = " totalInMemCacheSize " + str(cacheSizeInMemory) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("enableGzipCompress") > -1: + data = " enableGzipCompress " + str(gzip) + "\n" + writeDataToFile.writelines(data) + continue + else: + writeDataToFile.writelines(items) + + writeDataToFile.close() + + print "1,None" + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [saveTuningDetails]") + print "0," + str(msg) + else: + try: + datas = open("/usr/local/lsws/conf/httpd_config.xml").readlines() + writeDataToFile = open("/usr/local/lsws/conf/httpd_config.xml", "w") + + if gzipCompression == "Enable": + gzip = 1 + else: + gzip = 0 + + for items in datas: + if items.find("maxConnections") > -1: + data = " " + str(maxConnections) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("maxSSLConnections") > -1: + data = " " + str(maxSSLConnections) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("") > -1: + data = " " + str(connectionTimeOut) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("") > -1: + data = " " + str(keepAliveTimeOut) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("") > -1: + data = " " + str(cacheSizeInMemory) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("") > -1: + data = " " + str(gzip) + "\n" + writeDataToFile.writelines(data) + continue + else: + writeDataToFile.writelines(items) + writeDataToFile.close() + print "1,None" + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [saveTuningDetails]") + print "0," + str(msg) @staticmethod def fetchPHPDetails(virtualHost): - try: - path = installUtilities.Server_root_path + "/conf/vhosts/"+virtualHost+"/vhost.conf" + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: + path = installUtilities.Server_root_path + "/conf/vhosts/"+virtualHost+"/vhost.conf" - command = "sudo cat "+path - datas = subprocess.check_output(shlex.split(command)).split("\n") + command = "sudo cat "+path + datas = subprocess.check_output(shlex.split(command)).split("\n") - dataToReturn = {} + dataToReturn = {} - for items in datas: - if items.find("maxConns")>-1: - data = items.split() - dataToReturn['maxConns'] = data[1] + for items in datas: + if items.find("maxConns")>-1: + data = items.split() + dataToReturn['maxConns'] = data[1] - if items.find("initTimeout") > -1: - data = items.split() - dataToReturn['initTimeout'] = data[1] + if items.find("initTimeout") > -1: + data = items.split() + dataToReturn['initTimeout'] = data[1] - if items.find("persistConn") > -1: - data = items.split() - dataToReturn['persistConn'] = data[1] + if items.find("persistConn") > -1: + data = items.split() + dataToReturn['persistConn'] = data[1] - if items.find("memSoftLimit")>-1: - data = items.split() - dataToReturn['memSoftLimit'] = data[1] + if items.find("memSoftLimit")>-1: + data = items.split() + dataToReturn['memSoftLimit'] = data[1] - if items.find("memHardLimit") > -1: - data = items.split() - dataToReturn['memHardLimit'] = data[1] + if items.find("memHardLimit") > -1: + data = items.split() + dataToReturn['memHardLimit'] = data[1] - if items.find("procSoftLimit") > -1: - data = items.split() - dataToReturn['procSoftLimit'] = data[1] + if items.find("procSoftLimit") > -1: + data = items.split() + dataToReturn['procSoftLimit'] = data[1] - if items.find("procHardLimit") > -1: - data = items.split() - dataToReturn['procHardLimit'] = data[1] + if items.find("procHardLimit") > -1: + data = items.split() + dataToReturn['procHardLimit'] = data[1] - return dataToReturn + return dataToReturn + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [fetchPHPDetails]") + return 0 + else: + try: + command = "sudo cat /usr/local/lsws/conf/httpd_config.xml" + datas = subprocess.check_output(shlex.split(command)) + comTree = ElementTree.fromstring(datas) + extProcessorList = comTree.findall('extProcessorList/extProcessor') - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile( - str(msg) + " [fetchPHPDetails]") - return 0 + dataToReturn = {} + + for extProcessor in extProcessorList: + if extProcessor.find('name').text == virtualHost: + dataToReturn['maxConns'] = extProcessor.find('maxConns').text + dataToReturn['initTimeout'] = extProcessor.find('initTimeout').text + dataToReturn['persistConn'] = extProcessor.find('persistConn').text + dataToReturn['memSoftLimit'] = extProcessor.find('memSoftLimit').text + dataToReturn['memHardLimit'] = extProcessor.find('memHardLimit').text + dataToReturn['procSoftLimit'] = extProcessor.find('procSoftLimit').text + dataToReturn['procHardLimit'] = extProcessor.find('procHardLimit').text + break + + return dataToReturn + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [fetchPHPDetails]") + return 0 @staticmethod def tunePHP(virtualHost,maxConns,initTimeout,persistConn,memSoftLimit,memHardLimit,procSoftLimit,procHardLimit): + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + try: + path = installUtilities.Server_root_path + "/conf/vhosts/" + virtualHost + "/vhost.conf" + datas = open(path).readlines() + + writeDataToFile = open(path,"w") - try: - path = installUtilities.Server_root_path + "/conf/vhosts/" + virtualHost + "/vhost.conf" - datas = open(path).readlines() + for items in datas: + if items.find("maxConns") > -1: + data = " maxConns "+str(maxConns)+"\n" + writeDataToFile.writelines(data) + continue - writeDataToFile = open(path,"w") + elif items.find("initTimeout") > -1: + data = " initTimeout "+str(initTimeout) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("memSoftLimit") > -1: + data =" memSoftLimit "+str(memSoftLimit)+"\n" + writeDataToFile.writelines(data) + continue + + elif items.find("memHardLimit") > -1: + data = " memHardLimit " + str(memHardLimit) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("procSoftLimit") > -1: + data = " procSoftLimit " + str(procSoftLimit) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("procHardLimit") > -1: + data = " procHardLimit " + str(procHardLimit) + "\n" + writeDataToFile.writelines(data) + continue + elif items.find("persistConn") > -1: + if persistConn == "Enable": + persist = 1 + else: + persist = 0 - for items in datas: - if items.find("maxConns") > -1: - data = " maxConns "+str(maxConns)+"\n" - writeDataToFile.writelines(data) - continue - - elif items.find("initTimeout") > -1: - data = " initTimeout "+str(initTimeout) + "\n" - writeDataToFile.writelines(data) - continue - - elif items.find("memSoftLimit") > -1: - data =" memSoftLimit "+str(memSoftLimit)+"\n" - writeDataToFile.writelines(data) - continue - - elif items.find("memHardLimit") > -1: - data = " memHardLimit " + str(memHardLimit) + "\n" - writeDataToFile.writelines(data) - continue - - elif items.find("procSoftLimit") > -1: - data = " procSoftLimit " + str(procSoftLimit) + "\n" - writeDataToFile.writelines(data) - continue - - elif items.find("procHardLimit") > -1: - data = " procHardLimit " + str(procHardLimit) + "\n" - writeDataToFile.writelines(data) - continue - elif items.find("persistConn") > -1: - if persistConn == "Enable": - persist = 1 + data = " persistConn " + str(persist) + "\n" + writeDataToFile.writelines(data) + continue else: - persist = 0 + writeDataToFile.writelines(items) + writeDataToFile.close() - data = " persistConn " + str(persist) + "\n" - writeDataToFile.writelines(data) - continue - else: - writeDataToFile.writelines(items) + print "1,None" + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [saveTuningDetails]") + print "0,"+str(msg) + else: + try: + path = "/usr/local/lsws/conf/httpd_config.xml" + datas = open(path).readlines() - writeDataToFile.close() + writeDataToFile = open(path, "w") + activate = 0 - print "1,None" + for items in datas: + if items.find(virtualHost) > -1: + writeDataToFile.writelines(items) + activate = 1 + continue - except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile( - str(msg) + " [saveTuningDetails]") - print "0,"+str(msg) + elif activate == 1: + if items.find('') > -1: + writeDataToFile.writelines(items) + activate = 0 + continue + if items.find("") > -1: + data = " " + str(maxConns) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("") > -1: + data = " " + str(initTimeout) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("memSoftLimit") > -1: + data = " " + str(memSoftLimit) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("") > -1: + data = " " + str(memHardLimit) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("") > -1: + data = " " + str(procSoftLimit) + "\n" + writeDataToFile.writelines(data) + continue + + elif items.find("") > -1: + data = " " + str(procHardLimit) + "\n" + writeDataToFile.writelines(data) + continue + elif items.find("") > -1: + if persistConn == "Enable": + persist = 1 + else: + persist = 0 + + data = " " + str(persist) + "\n" + writeDataToFile.writelines(data) + continue + else: + writeDataToFile.writelines(items) + else: + writeDataToFile.writelines(items) + + writeDataToFile.close() + + print "1,None" + + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [saveTuningDetails]") + print "0," + str(msg) def main(): diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index f11e0187e..a790edba5 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -98,6 +98,14 @@ class virtualHostUtilities: if retValues[0] == 0: raise BaseException(retValues[1]) + selectedPackage = Package.objects.get(packageName=packageName) + + website = Websites(admin=admin, package=selectedPackage, domain=virtualHostName, + adminEmail=administratorEmail, + phpSelection=phpVersion, ssl=ssl, externalApp=virtualHostUser) + + website.save() + if ssl == 1: sslPath = "/home/" + virtualHostName + "/public_html" @@ -124,14 +132,6 @@ class virtualHostUtilities: if dkimCheck == 1: DNS.createDKIMRecords(virtualHostName) - selectedPackage = Package.objects.get(packageName=packageName) - - website = Websites(admin=admin, package=selectedPackage, domain=virtualHostName, - adminEmail=administratorEmail, - phpSelection=phpVersion, ssl=ssl, externalApp=virtualHostUser) - - website.save() - logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Website successfully created. [200]') return 1, 'None' @@ -844,6 +844,9 @@ class virtualHostUtilities: ## Now restart litespeed after initial configurations are done + website = ChildDomains(master=master, domain=virtualHostName, path=path, phpSelection=phpVersion, ssl=ssl) + website.save() + if ssl == 1: logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Creating SSL..,50') installUtilities.installUtilities.reStartLiteSpeed() @@ -864,10 +867,6 @@ class virtualHostUtilities: DNS.createDKIMRecords(virtualHostName) - website = ChildDomains(master=master, domain=virtualHostName, path=path, phpSelection=phpVersion, ssl=ssl) - website.save() - - logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Domain successfully created. [200]') return 1, "None" diff --git a/serverStatus/serverStatusUtil.py b/serverStatus/serverStatusUtil.py index 9b8328a7e..41da83b0c 100644 --- a/serverStatus/serverStatusUtil.py +++ b/serverStatus/serverStatusUtil.py @@ -10,6 +10,11 @@ import argparse import shutil import plogical.CyberCPLogFileWriter as logging from plogical.processUtilities import ProcessUtilities +from websiteFunctions.models import Websites, ChildDomains, aliasDomains +from plogical.virtualHostUtilities import virtualHostUtilities +from plogical.sslUtilities import sslUtilities +from plogical.vhost import vhost + class ServerStatusUtil: @@ -21,7 +26,7 @@ class ServerStatusUtil: try: res = subprocess.call(shlex.split(command), stdout=statusFile, stderr=statusFile) if res == 1: - raise 0 + return 0 else: return 1 except BaseException, msg: @@ -137,6 +142,94 @@ class ServerStatusUtil: if os.path.exists('/usr/local/usr'): shutil.rmtree('/usr/local/usr') + @staticmethod + def createWebsite(website): + try: + virtualHostName = website.domain + + confPath = vhost.Server_root + "/conf/vhosts/" + virtualHostName + FNULL = open(os.devnull, 'w') + if not os.path.exists(confPath): + command = 'mkdir -p ' + confPath + ServerStatusUtil.executioner(command, FNULL) + + completePathToConfigFile = confPath + "/vhost.conf" + + if vhost.perHostVirtualConf(completePathToConfigFile, website.adminEmail , website.externalApp, website.phpSelection, + virtualHostName, 1) == 1: + pass + else: + return 0 + + retValues = vhost.createConfigInMainVirtualHostFile(virtualHostName) + if retValues[0] == 0: + return 0 + + if os.path.exists('/etc/letsencrypt/live/' + virtualHostName): + sslUtilities.installSSLForDomain(virtualHostUtilities, website.adminEmail) + + vhostPath = vhost.Server_root + "/conf/vhosts" + FNULL = open(os.devnull, 'w') + command = "chown -R " + "lsadm" + ":" + "lsadm" + " " + vhostPath + cmd = shlex.split(command) + subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return 0 + + @staticmethod + def createDomain(website): + try: + virtualHostName = website.domain + + confPath = vhost.Server_root + "/conf/vhosts/" + virtualHostName + completePathToConfigFile = confPath + "/vhost.conf" + + confPath = vhost.Server_root + "/conf/vhosts/" + virtualHostName + FNULL = open(os.devnull, 'w') + if not os.path.exists(confPath): + command = 'mkdir -p ' + confPath + ServerStatusUtil.executioner(command, FNULL) + + if vhost.perHostDomainConf(website.path, website.master.domain, virtualHostName, completePathToConfigFile, website.master.adminEmail, website.master.externalApp, + website.phpSelection, 1) == 1: + pass + else: + return 0 + + retValues = vhost.createConfigInMainDomainHostFile(virtualHostName, website.master.domain) + + if retValues[0] == 0: + return 0 + + if os.path.exists('/etc/letsencrypt/live/' + virtualHostName): + sslUtilities.installSSLForDomain(virtualHostUtilities, website.adminEmail) + + vhostPath = vhost.Server_root + "/conf/vhosts" + FNULL = open(os.devnull, 'w') + command = "chown -R " + "lsadm" + ":" + "lsadm" + " " + vhostPath + cmd = shlex.split(command) + subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return 0 + + @staticmethod + def rebuildvConf(): + try: + allWebsites = Websites.objects.all() + for website in allWebsites: + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "Building vhost conf for:" + website.domain + ".\n") + ServerStatusUtil.createWebsite(website) + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "vhost conf successfully built for:" + website.domain + ".\n") + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return 0 + @staticmethod def switchTOLSWS(licenseKey): try: @@ -189,6 +282,15 @@ class ServerStatusUtil: ServerStatusUtil.recover() return 0 + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "Rebuilding vhost conf..\n") + + ServerStatusUtil.rebuildvConf() + + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, + "vhost conf successfully built.\n") + + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,"Successfully switched to LITESPEED ENTERPRISE WEB SERVER. [200]\n") except BaseException, msg: diff --git a/static/images/agreement.png b/static/images/agreement.png new file mode 100644 index 000000000..a2fabeef4 Binary files /dev/null and b/static/images/agreement.png differ diff --git a/static/images/change.png b/static/images/change.png new file mode 100644 index 000000000..657733415 Binary files /dev/null and b/static/images/change.png differ diff --git a/static/serverStatus/serverStatus.js b/static/serverStatus/serverStatus.js index 99b324364..d0286b787 100644 --- a/static/serverStatus/serverStatus.js +++ b/static/serverStatus/serverStatus.js @@ -73,7 +73,6 @@ app.controller('litespeedStatus', function ($scope, $http) { }; - $scope.stopLitespeed = function () { @@ -134,6 +133,127 @@ app.controller('litespeedStatus', function ($scope, $http) { }; + /// License Manager + + $scope.cpLoading = true; + $scope.fetchedData = true; + $scope.changeSerialBox = true; + + $scope.hideLicenseStatus = function () { + $scope.fetchedData = true; + }; + + $scope.licenseStatus = function () { + + $scope.cpLoading = false; + $scope.changeSerialBox = true; + + var url = "/serverstatus/licenseStatus"; + + var data = {}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + $scope.cpLoading = true; + $scope.fetchedData = false; + new PNotify({ + title: 'Success!', + text: 'Status successfully fetched', + type: 'success' + }); + $scope.lsSerial = response.data.lsSerial; + $scope.lsexpiration = response.data.lsexpiration; + } + else { + $scope.cpLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.erroMessage, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.cpLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + } + + + }; + $scope.showSerialBox = function () { + $scope.fetchedData = true; + $scope.changeSerialBox = false; + }; + $scope.changeLicense = function () { + + $scope.cpLoading = false; + + var url = "/serverstatus/changeLicense"; + + var data = {newKey: $scope.newKey}; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.status === 1) { + $scope.cpLoading = true; + new PNotify({ + title: 'Success!', + text: 'License successfully Updated', + type: 'success' + }); + } + else { + $scope.cpLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: response.data.erroMessage, + type: 'error' + }); + } + + } + + function cantLoadInitialDatas(response) { + $scope.cpLoading = true; + new PNotify({ + title: 'Operation Failed!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + + } + + + }; + }); /* Java script code to start/stop litespeed */ diff --git a/tuning/templates/tuning/phpTuning.html b/tuning/templates/tuning/phpTuning.html index 9af64a4dd..eda3d6f5d 100644 --- a/tuning/templates/tuning/phpTuning.html +++ b/tuning/templates/tuning/phpTuning.html @@ -3,144 +3,285 @@ {% block title %}{% trans "PHP Tuning - CyberPanel" %}{% endblock %} {% block content %} -{% load static %} -{% get_current_language as LANGUAGE_CODE %} - + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + + {% if OLS %} +
+
+

{% trans "PHP Tuning" %}

+

{% trans "Set how each version of PHP behaves in your server here." %}

+
+
+
+

+ {% trans "Select PHP Version" %} +

+
-
-
-

{% trans "PHP Tuning" %}

-

{% trans "Set how each version of PHP behaves in your server here." %}

-
-
-
-

- {% trans "Select PHP Version" %} -

-
+
- +
+ +
+ +
+
+ + + + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
{% trans "Currently:" %} {$ persistStatus $}
+
+ + + +
+ +
+ + +
+
+ +
+ +
+
+

{% trans "Cannot fetch details. Error message:" %} {$ errorMessage $}

+
+ +
+

{% trans "Cannot tune. Error message:" %} {$ errorMessage $}

+
+ + +
+

{% trans "Details Successfully fetched." %}

+
+ +
+

{% trans "PHP for " %}{$ phpVersionTuned + $} {% trans "Successfully tuned." %}

+
+
+ + +
+ + +
-
- -
-
-
- - - - -
- -
- -
-
- -
- -
- -
-
- - -
- -
- -
-
- -
- -
- -
-
- - -
- -
- -
-
- -
- -
- -
-
- - -
- -
- -
-
{% trans "Currently:" %} {$ persistStatus $}
-
- - - -
- -
- -
-
- -
-
+ +
+ {% else %} +
+
+

{% trans "PHP Tuning" %}

+

{% trans "Set how each version of PHP behaves in your server here." %}

+
+
+
+

+ {% trans "Select PHP Version" %} +

+
+ + +
+ + +
+ +
+ +
+
+ + + + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+ +
+ +
+
{% trans "Currently:" %} {$ persistStatus $}
+
+ + + +
+ +
+ + +
+
+ +
+ +
+

{% trans "Cannot fetch details. Error message:" %} {$ errorMessage $}

-
+
-
+

{% trans "Cannot tune. Error message:" %} {$ errorMessage $}

-
+
-
+

{% trans "Details Successfully fetched." %}

+
+ +
+

{% trans "PHP for " %}{$ phpVersionTuned + $} {% trans "Successfully tuned." %}

+
+
+ +
-
-

{% trans "PHP for " %}{$ phpVersionTuned $} {% trans "Successfully tuned." %}

-
+ +
+ +
- - -
- - - - - +
-
-
- - -
- + {% endif %} {% endblock %} \ No newline at end of file diff --git a/tuning/tuning.py b/tuning/tuning.py new file mode 100644 index 000000000..f6f7207f9 --- /dev/null +++ b/tuning/tuning.py @@ -0,0 +1,185 @@ +#!/usr/local/CyberCP/bin/python2 +import os.path +import sys +import django +sys.path.append('/usr/local/CyberCP') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") +django.setup() +from django.shortcuts import render,redirect +from django.http import HttpResponse +import json +import plogical.CyberCPLogFileWriter as logging +from plogical.tuning import tuning +from loginSystem.views import loadLoginPage +from plogical.virtualHostUtilities import virtualHostUtilities +import subprocess +import shlex +from plogical.acl import ACLManager +from plogical.processUtilities import ProcessUtilities + + +class tuningManager: + def loadTuningHome(self, request, userID): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + return render(request, 'tuning/index.html', {}) + except KeyError: + return redirect(loadLoginPage) + + def liteSpeedTuning(self, request, userID): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + return render(request, 'tuning/liteSpeedTuning.html', {}) + except KeyError: + return redirect(loadLoginPage) + + def phpTuning(self, request, userID): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: + websitesName = ACLManager.findAllSites(currentACL, userID) + OLS = 1 + return render(request, 'tuning/phpTuning.html', {'websiteList': websitesName, 'OLS': OLS}) + else: + OLS = 0 + return render(request, 'tuning/phpTuning.html', {'OLS': OLS}) + + except KeyError: + return redirect(loadLoginPage) + + def tuneLitespeed(self, userID, data): + try: + + status = data['status'] + if status == "fetch": + + json_data = json.dumps(tuning.fetchTuningDetails()) + + data_ret = {'fetch_status': 1, 'error_message': "None", "tuning_data": json_data, + 'tuneStatus': 0} + + final_json = json.dumps(data_ret) + return HttpResponse(final_json) + + else: + if not data['maxConn']: + data_ret = {'fetch_status': 1, 'error_message': "Provide Max Connections", 'tuneStatus': 0} + final_json = json.dumps(data_ret) + return HttpResponse(final_json) + + if not data['maxSSLConn']: + data_ret = {'fetch_status': 1, 'error_message': "Provide Max SSL Connections", + 'tuneStatus': 0} + final_json = json.dumps(data_ret) + return HttpResponse(final_json) + + if not data['keepAlive']: + data_ret = {'fetch_status': 1, 'error_message': "Provide Keep Alive", 'tuneStatus': 0} + final_json = json.dumps(data_ret) + return HttpResponse(final_json) + + if not data['inMemCache']: + data_ret = {'fetch_status': 1, 'error_message': "Provide Cache Size in memory", + 'tuneStatus': 0} + final_json = json.dumps(data_ret) + return HttpResponse(final_json) + + if not data['gzipCompression']: + data_ret = {'fetch_status': 1, 'error_message': "Provide Enable GZIP Compression", + 'tuneStatus': 0} + final_json = json.dumps(data_ret) + return HttpResponse(final_json) + + maxConn = data['maxConn'] + maxSSLConn = data['maxSSLConn'] + connTime = data['connTime'] + keepAlive = data['keepAlive'] + inMemCache = data['inMemCache'] + gzipCompression = data['gzipCompression'] + + execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py" + + execPath = execPath + " saveTuningDetails --maxConn " + maxConn + " --maxSSLConn " + maxSSLConn + " --connTime " + connTime + " --keepAlive " + keepAlive + " --inMemCache '" + inMemCache + "' --gzipCompression " + gzipCompression + + output = subprocess.check_output(shlex.split(execPath)) + + if output.find("1,None") > -1: + data_ret = {'fetch_status': 1, 'error_message': "None", 'tuneStatus': 1} + final_json = json.dumps(data_ret) + return HttpResponse(final_json) + else: + data_ret = {'fetch_status': 1, 'error_message': "None", 'tuneStatus': 0} + final_json = json.dumps(data_ret) + return HttpResponse(final_json) + + except BaseException, msg: + data_ret = {'fetch_status': 0, 'error_message': str(msg), 'tuneStatus': 0} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + def tunePHP(self, userID, data): + try: + status = data['status'] + domainSelection = str(data['domainSelection']) + + if status == "fetch": + + json_data = json.dumps(tuning.fetchPHPDetails(domainSelection)) + + data_ret = {'fetch_status': 1, 'error_message': "None", "tuning_data": json_data, + 'tuneStatus': 0} + + final_json = json.dumps(data_ret) + + return HttpResponse(final_json) + + else: + initTimeout = str(data['initTimeout']) + maxConns = str(data['maxConns']) + memSoftLimit = data['memSoftLimit'] + memHardLimit = data['memHardLimit'] + procSoftLimit = str(data['procSoftLimit']) + procHardLimit = str(data['procHardLimit']) + persistConn = data['persistConn'] + + execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py" + + 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)) + + if output.find("1,None") > -1: + data_ret = {'tuneStatus': 1, 'fetch_status': 0, 'error_message': "None"} + final_json = json.dumps(data_ret) + return HttpResponse(final_json) + else: + data_ret = {'fetch_status': 0, 'error_message': output, 'tuneStatus': 0} + logging.CyberCPLogFileWriter.writeToFile(output + " [tunePHP]]") + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException, msg: + data_ret = {'fetch_status': 0, 'error_message': str(msg), 'tuneStatus': 0} + logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [tunePHP]]") + json_data = json.dumps(data_ret) + return HttpResponse(json_data) \ No newline at end of file diff --git a/tuning/views.py b/tuning/views.py index 382eba79a..01c7ed72b 100644 --- a/tuning/views.py +++ b/tuning/views.py @@ -11,198 +11,46 @@ from plogical.virtualHostUtilities import virtualHostUtilities import subprocess import shlex from plogical.acl import ACLManager +from tuning import tuningManager # Create your views here. def loadTuningHome(request): try: userID = request.session['userID'] - currentACL = ACLManager.loadedACL(userID) - - if currentACL['admin'] == 1: - pass - else: - return ACLManager.loadError() - - return render(request,'tuning/index.html',{}) + tm = tuningManager() + return tm.loadTuningHome(request, userID) except KeyError: return redirect(loadLoginPage) - def liteSpeedTuning(request): try: userID = request.session['userID'] - currentACL = ACLManager.loadedACL(userID) - - if currentACL['admin'] == 1: - pass - else: - return ACLManager.loadError() - return render(request,'tuning/liteSpeedTuning.html',{}) + tm = tuningManager() + return tm.liteSpeedTuning(request, userID) except KeyError: return redirect(loadLoginPage) - def phpTuning(request): try: userID = request.session['userID'] - currentACL = ACLManager.loadedACL(userID) - - if currentACL['admin'] == 1: - pass - else: - return ACLManager.loadError() - - websitesName = ACLManager.findAllSites(currentACL, userID) - - return render(request,'tuning/phpTuning.html',{'websiteList':websitesName}) + tm = tuningManager() + return tm.phpTuning(request, userID) except KeyError: return redirect(loadLoginPage) - def tuneLitespeed(request): - try: userID = request.session['userID'] - currentACL = ACLManager.loadedACL(userID) - - if currentACL['admin'] == 1: - pass - else: - return ACLManager.loadErrorJson('fetch_status', 0) - try: - - if request.method == 'POST': - data = json.loads(request.body) - status = data['status'] - - if status == "fetch": - - json_data = json.dumps(tuning.fetchTuningDetails()) - - data_ret = {'fetch_status': 1, 'error_message': "None", "tuning_data": json_data, 'tuneStatus': 0} - - final_json = json.dumps(data_ret) - return HttpResponse(final_json) - - else: - if not data['maxConn']: - data_ret = {'fetch_status': 1, 'error_message': "Provide Max Connections", 'tuneStatus': 0} - final_json = json.dumps(data_ret) - return HttpResponse(final_json) - - if not data['maxSSLConn']: - data_ret = {'fetch_status': 1, 'error_message': "Provide Max SSL Connections", 'tuneStatus': 0} - final_json = json.dumps(data_ret) - return HttpResponse(final_json) - - if not data['keepAlive']: - data_ret = {'fetch_status': 1, 'error_message': "Provide Keep Alive", 'tuneStatus': 0} - final_json = json.dumps(data_ret) - return HttpResponse(final_json) - - if not data['inMemCache']: - data_ret = {'fetch_status': 1, 'error_message': "Provide Cache Size in memory", 'tuneStatus': 0} - final_json = json.dumps(data_ret) - return HttpResponse(final_json) - - if not data['gzipCompression']: - data_ret = {'fetch_status': 1, 'error_message': "Provide Enable GZIP Compression", - 'tuneStatus': 0} - final_json = json.dumps(data_ret) - return HttpResponse(final_json) - - maxConn = data['maxConn'] - maxSSLConn = data['maxSSLConn'] - connTime = data['connTime'] - keepAlive = data['keepAlive'] - inMemCache = data['inMemCache'] - gzipCompression = data['gzipCompression'] - - execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py" - - execPath = execPath + " saveTuningDetails --maxConn " + maxConn + " --maxSSLConn " + maxSSLConn + " --connTime " + connTime + " --keepAlive " + keepAlive + " --inMemCache '" + inMemCache + "' --gzipCompression " + gzipCompression - - output = subprocess.check_output(shlex.split(execPath)) - - if output.find("1,None") > -1: - data_ret = {'fetch_status': 1, 'error_message': "None", 'tuneStatus': 1} - final_json = json.dumps(data_ret) - return HttpResponse(final_json) - else: - data_ret = {'fetch_status': 1, 'error_message': "None", 'tuneStatus': 0} - final_json = json.dumps(data_ret) - return HttpResponse(final_json) - - except BaseException,msg: - data_ret = {'fetch_status': 0, 'error_message': str(msg), 'tuneStatus': 0} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - + tm = tuningManager() + return tm.tuneLitespeed(userID, json.loads(request.body)) except KeyError: - data_ret = {'fetch_status': 0, 'error_message': "not logged in as admin",'fetch_status': 0} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - + return redirect(loadLoginPage) def tunePHP(request): try: userID = request.session['userID'] - currentACL = ACLManager.loadedACL(userID) - - if currentACL['admin'] == 1: - pass - else: - return ACLManager.loadErrorJson('fetch_status', 0) - try: - if request.method == 'POST': - data = json.loads(request.body) - status = data['status'] - domainSelection = str(data['domainSelection']) - - if status == "fetch": - - json_data = json.dumps(tuning.fetchPHPDetails(domainSelection)) - - data_ret = {'fetch_status': 1, 'error_message': "None", "tuning_data": json_data, 'tuneStatus': 0} - - final_json = json.dumps(data_ret) - - return HttpResponse(final_json) - - else: - initTimeout = str(data['initTimeout']) - maxConns = str(data['maxConns']) - memSoftLimit = data['memSoftLimit'] - memHardLimit = data['memHardLimit'] - procSoftLimit = str(data['procSoftLimit']) - procHardLimit = str(data['procHardLimit']) - persistConn = data['persistConn'] - - execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/tuning.py" - - 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)) - - if output.find("1,None") > -1: - data_ret = {'tuneStatus': 1, 'fetch_status': 0, 'error_message': "None"} - final_json = json.dumps(data_ret) - return HttpResponse(final_json) - else: - data_ret = {'fetch_status': 0, 'error_message': output, 'tuneStatus': 0} - logging.CyberCPLogFileWriter.writeToFile(output + " [tunePHP]]") - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - except BaseException,msg: - data_ret = {'fetch_status': 0, 'error_message': str(msg),'tuneStatus': 0} - logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [tunePHP]]") - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - + tm = tuningManager() + return tm.tunePHP(userID, json.loads(request.body)) except KeyError: - data_ret = {'tuneStatus': 0, 'error_message': "not logged in as admin",'fetch_status': 0} - logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [tunePHP]]") - json_data = json.dumps(data_ret) - return HttpResponse(json_data) + return redirect(loadLoginPage) \ No newline at end of file