diff --git a/baseTemplate/static/baseTemplate/assets/themes/admin/color-schemes/default.css b/baseTemplate/static/baseTemplate/assets/themes/admin/color-schemes/default.css index b7810574d..d38caa513 100755 --- a/baseTemplate/static/baseTemplate/assets/themes/admin/color-schemes/default.css +++ b/baseTemplate/static/baseTemplate/assets/themes/admin/color-schemes/default.css @@ -134,4 +134,5 @@ h1, h2, h3, h4, h5, h6, /* Admin responsive */ -@media only screen and (min-width:20em){#header-logo,#theme-options{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:hidden}#page-content{margin-left:0}}@media only screen and (min-width:56.25em){#header-logo,#page-sidebar.collapse,#theme-options{display:block}#mobile-navigation{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:visible}#page-content{margin-left:260px}}@media only screen and (max-width:760px){#cloud-btn,#header-nav-right #fullscreen-btn{display:none}}@media only screen and (max-width:630px){#page-header .user-account-btn>a.user-profile span{display:none}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:56px}}@media only screen and (max-width:545px){#header-nav-right #chatbox-btn{display:none}}@media only screen and (max-width:520px){#dashnav-btn,#page-header .user-account-btn>a.user-profile span{display:none}.popover{width:100%;border-radius:0}.box-md{width:auto}}@media only screen and (max-width:460px){.box-sm,.timeline-box .popover{width:auto}#page-content{padding:10px}#page-title{padding:10px 0 15px;text-align:center}.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{margin-bottom:20px}.content-box{margin-top:0!important}.row.mrg20B{margin-bottom:0!important}#page-title p,#progress-btn,.dashboard-box .list-grade,.header-buttons-separator,.todo-box .bs-label,.todo-box .btn,.tooltip .tooltip-arrow{display:none}}@media only screen and (max-width:410px){#header-nav-right #logout-btn,#notifications-btn{display:none}#header-nav-left{float:right}#header-nav-right{margin-right:0;margin-left:15px;float:left}.dropdown-menu{position:fixed;left:0!important;width:100%;border-radius:0}#page-header .user-account-btn .dropdown-menu{top:65px}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:auto;right:24px}} \ No newline at end of file +@media only screen and (min-width:20em){#header-logo,#theme-options{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:hidden}#page-content{margin-left:0}}@media only screen and (min-width:56.25em){#header-logo,#page-sidebar.collapse,#theme-options{display:block}#mobile-navigation{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:visible}#page-content{margin-left:260px}}@media only screen and (max-width:760px){#cloud-btn,#header-nav-right #fullscreen-btn{display:none}}@media only screen and (max-width:630px){#page-header .user-account-btn>a.user-profile span{display:none}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:56px}}@media only screen and (max-width:545px){#header-nav-right #chatbox-btn{display:none}}@media only screen and (max-width:520px){#dashnav-btn,#page-header .user-account-btn>a.user-profile span{display:none}.popover{width:100%;border-radius:0}.box-md{width:auto}}@media only screen and (max-width:460px){.box-sm,.timeline-box .popover{width:auto}#page-content{padding:10px}#page-title{padding:10px 0 15px;text-align:center}.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{margin-bottom:20px}.content-box{margin-top:0!important}.row.mrg20B{margin-bottom:0!important}#page-title p,#progress-btn,.dashboard-box .list-grade,.header-buttons-separator,.todo-box .bs-label,.todo-box .btn,.tooltip .tooltip-arrow{display:none}}@media only screen and (max-width:410px){#header-nav-right #logout-btn,#notifications-btn{display:none}#header-nav-left{float:right}#header-nav-right{margin-right:0;margin-left:15px;float:left}.dropdown-menu{position:fixed;left:0!important;width:100%;border-radius:0}#page-header .user-account-btn .dropdown-menu{top:65px}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:auto;right:24px}} + diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index a7fbeedbd..8ea3f9d40 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -269,7 +269,7 @@ -
+
diff --git a/databases/templates/databases/createDatabase.html b/databases/templates/databases/createDatabase.html index 2b133932d..957435aef 100644 --- a/databases/templates/databases/createDatabase.html +++ b/databases/templates/databases/createDatabase.html @@ -21,7 +21,7 @@
-
+
diff --git a/emailPremium/views.py b/emailPremium/views.py index 7b5bf0d45..5dc7a9ee8 100644 --- a/emailPremium/views.py +++ b/emailPremium/views.py @@ -32,7 +32,7 @@ def listDomains(request): admin = Administrator.objects.get(pk=request.session['userID']) if admin.type == 1: - websites = Websites.objects.all() + websites = DomainLimits.objects.all() else: return HttpResponse("Only administrator can view this page.") @@ -44,7 +44,7 @@ def listDomains(request): installCheck = 0 for items in output: - if items.find('check_policy_service inet:localhost:1089') > -1: + if items.find('check_policy_service unix:/var/log/policyServerSocket') > -1: installCheck = 1 break @@ -81,10 +81,9 @@ def listDomains(request): def getFurtherDomains(request): try: val = request.session['userID'] - try: - admin = Administrator.objects.get(pk=request.session['userID']) + admin = Administrator.objects.get(pk=val) if request.method == 'POST': try: @@ -124,7 +123,7 @@ def getFurtherDomains(request): else: json_data = json_data +',' + json.dumps(dic) except BaseException, msg: - logging.CyberCPLogFileWriter.writeToFile(str(msg)) + pass json_data = json_data + ']' final_dic = {'listWebSiteStatus': 1, 'error_message': "None", "data": json_data} @@ -953,7 +952,7 @@ def fetchPolicyServerStatus(request): installCheck = 0 for items in output: - if items.find('check_policy_service inet:localhost:1089') > -1: + if items.find('check_policy_service unix:/var/log/policyServerSocket') > -1: installCheck = 1 break diff --git a/firewall/views.py b/firewall/views.py index 849022036..44e3f73b6 100644 --- a/firewall/views.py +++ b/firewall/views.py @@ -127,7 +127,7 @@ def addRule(request): def deleteRule(request): try: val = request.session['userID'] - admin = Administrator.objects.get(val=val) + admin = Administrator.objects.get(pk=val) try: if request.method == 'POST': diff --git a/install/FileManager/.idea/workspace.xml b/install/FileManager/.idea/workspace.xml index 15d96b1e2..026ca8720 100644 --- a/install/FileManager/.idea/workspace.xml +++ b/install/FileManager/.idea/workspace.xml @@ -14,8 +14,8 @@ - - + + @@ -176,16 +176,15 @@ - + - - @@ -575,8 +574,8 @@ - - + + diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py new file mode 100644 index 000000000..c1ba9b2a1 --- /dev/null +++ b/plogical/applicationInstaller.py @@ -0,0 +1,281 @@ +#!/usr/local/CyberCP/bin/python2 +import os,sys +sys.path.append('/usr/local/CyberCP') +import django +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") +django.setup() +import threading as multi +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging +import subprocess +import shlex +from vhost import vhost +from loginSystem.models import Administrator +from websiteFunctions.models import ChildDomains, Websites +import randomPassword +from mysqlUtilities import mysqlUtilities +from databases.models import Databases +from installUtilities import installUtilities +import shutil + + +class ApplicationInstaller(multi.Thread): + + def __init__(self, installApp, extraArgs): + multi.Thread.__init__(self) + self.installApp = installApp + self.extraArgs = extraArgs + + def run(self): + try: + if self.installApp == 'wordpress': + self.installWordPress() + + except BaseException, msg: + logging.writeToFile( str(msg) + ' [ApplicationInstaller.run]') + + + def installWPCLI(self): + try: + command = 'sudo wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar' + subprocess.call(shlex.split(command)) + + command = 'sudo chmod +x wp-cli.phar' + subprocess.call(shlex.split(command)) + + command = 'sudo mv wp-cli.phar /usr/bin/wp' + subprocess.call(shlex.split(command)) + + except BaseException, msg: + logging.writeToFile( str(msg) + ' [ApplicationInstaller.installWPCLI]') + + + + def installWordPress(self): + try: + + admin = self.extraArgs['admin'] + domainName = self.extraArgs['domainName'] + home = self.extraArgs['home'] + tempStatusPath = self.extraArgs['tempStatusPath'] + blogTitle = self.extraArgs['blogTitle'] + adminUser = self.extraArgs['adminUser'] + adminPassword = self.extraArgs['adminPassword'] + adminEmail = self.extraArgs['adminEmail'] + + + ### Check WP CLI + + try: + command = 'sudo wp --info' + res = subprocess.call(shlex.split(command)) + + if res == 1: + self.installWPCLI() + except subprocess.CalledProcessError: + self.installWPCLI() + + ## Open Status File + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Setting up paths,0') + statusFile.close() + + try: + website = ChildDomains.objects.get(domain=domainName) + externalApp = website.master.externalApp + + if admin.type != 1: + if website.master.admin != admin: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("You do not own this website." + " [404]") + statusFile.close() + return 0 + + except: + website = Websites.objects.get(domain=domainName) + externalApp = website.externalApp + + if admin.type != 1: + if website.admin != admin: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("You do not own this website." + " [404]") + statusFile.close() + return 0 + + finalPath = "" + + + if home == '0': + path = self.extraArgs['path'] + finalPath = "/home/" + domainName + "/public_html/" + path + "/" + else: + finalPath = "/home/" + domainName + "/public_html/" + + + ## Security Check + + if finalPath.find("..") > -1: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("Specified path must be inside virtual host home." + " [404]") + statusFile.close() + return 0 + + FNULL = open(os.devnull, 'w') + + if not os.path.exists(finalPath): + command = 'sudo mkdir -p ' + finalPath + subprocess.call(shlex.split(command)) + + ## checking for directories/files + + dirFiles = os.listdir(finalPath) + + if len(dirFiles) == 1: + if dirFiles[0] == ".well-known": + pass + else: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("Target directory should be empty before installation, otherwise data loss could occur." + " [404]") + statusFile.close() + return 0 + elif len(dirFiles) == 0: + pass + else: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines( + "Target directory should be empty before installation, otherwise data loss could occur." + " [404]") + statusFile.close() + return 0 + + + + + ## DB Creation + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Setting up Database,20') + statusFile.close() + + dbName = randomPassword.generate_pass() + dbUser = dbName + dbPassword = randomPassword.generate_pass() + + ## DB Creation + + if website.package.dataBases > website.databases_set.all().count(): + pass + else: + raise BaseException("Maximum database limit reached for this website.") + + if Databases.objects.filter(dbName=dbName).exists() or Databases.objects.filter( + dbUser=dbUser).exists(): + raise BaseException("This database or user is already taken.") + + result = mysqlUtilities.createDatabase(dbName, dbUser, dbPassword) + + if result == 1: + pass + else: + raise BaseException("Not able to create database.") + + db = Databases(website=website, dbName=dbName, dbUser=dbUser) + db.save() + + + #### + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Downloading WordPress Core,30') + statusFile.close() + + command = "sudo wp core download --allow-root --path=" + finalPath + subprocess.call(shlex.split(command)) + + ## + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Configuring the installation,40') + 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)) + + if home == '0': + path = self.extraArgs['path'] + finalURL = domainName + '/' + path + else: + 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)) + + ## + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Installing LSCache Plugin,80') + statusFile.close() + + command = "sudo wp plugin install litespeed-cache --allow-root --path=" + finalPath + subprocess.call(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)) + + + + ## + + + command = "sudo chown -R " + externalApp + ":" + externalApp + " " + "/home/" + domainName + "/public_html/" + cmd = shlex.split(command) + res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + + vhost.addRewriteRules(domainName) + installUtilities.reStartLiteSpeed() + + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("Successfully Installed. [200]") + statusFile.close() + return 0 + + + except BaseException, msg: + # remove the downloaded files + try: + + command = "sudo rm -rf " + finalPath + cmd = shlex.split(command) + res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + + except BaseException, msg: + logging.writeToFile(str(msg) + " [installWordPress]") + + homeDir = "/home/" + domainName + "/public_html" + + if not os.path.exists(homeDir): + FNULL = open(os.devnull, 'w') + + command = 'sudo mkdir ' + homeDir + subprocess.call(shlex.split(command)) + + + command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir + cmd = shlex.split(command) + res = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) + + try: + mysqlUtilities.deleteDatabase(dbName, dbUser) + db = Databases.objects.get(dbName=dbName) + db.delete() + except: + pass + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines(str(msg) + " [404]") + statusFile.close() + return 0 diff --git a/plogical/letsEncrypt.py b/plogical/letsEncrypt.py new file mode 100644 index 000000000..e69de29bb diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index ac8fc1793..24a2625ab 100644 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -534,7 +534,7 @@ milter_default_action = accept subprocess.call(shlex.split(command)) writeToFile = open(postfixPath, 'a') - writeToFile.writelines('smtpd_data_restrictions = check_policy_service inet:localhost:1089\n') + writeToFile.writelines('smtpd_data_restrictions = check_policy_service unix:/var/log/policyServerSocket\n') writeToFile.close() command = 'systemctl restart postfix' @@ -545,7 +545,7 @@ milter_default_action = accept writeToFile = open(postfixPath, 'w') for items in data: - if items.find('check_policy_service inet:localhost:1089') > -1: + if items.find('check_policy_service unix:/var/log/policyServerSocket') > -1: continue else: writeToFile.writelines(items) diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index e32f367ee..04cf86d60 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -39,10 +39,12 @@ class virtualHostUtilities: try: if Websites.objects.filter(domain=virtualHostName).count() > 0: - raise BaseException("This website already exists.") + print "0, This website already exists." + return 0, "This website already exists." if ChildDomains.objects.filter(domain=virtualHostName).count() > 0: - raise BaseException("This website already exists as child domain.") + print "0, This website already exists as child domain." + return 0, "This website already exists as child domain." ####### Limitations Check End @@ -55,10 +57,12 @@ class virtualHostUtilities: ## zone creation if vhost.checkIfVirtualHostExists(virtualHostName) == 1: - raise BaseException("Virtual Host Directory already exists!") + print "0, Virtual Host Directory already exists!" + return 0, "Virtual Host Directory already exists!" if vhost.checkIfAliasExists(virtualHostName) == 1: - raise BaseException("This domain exists as Alias.") + print "0, This domain exists as Alias." + return 0, "This domain exists as Alias." if dkimCheck == 1: if mailUtilities.checkIfDKIMInstalled() == 0: @@ -924,10 +928,12 @@ class virtualHostUtilities: DNS.dnsTemplate(virtualHostName, admin) if Websites.objects.filter(domain=virtualHostName).count() > 0: - raise BaseException("This Domain already exists as a website.") + print "0, This Domain already exists as a website." + return 0, "This Domain already exists as a website." if ChildDomains.objects.filter(domain=virtualHostName).count() > 0: - raise BaseException("This domain already exists as child domain.") + print "0, This domain already exists as child domain." + return 0, "This domain already exists as child domain." ####### Limitations check @@ -939,16 +945,20 @@ class virtualHostUtilities: elif domainsInPackage > master.childdomains_set.all().count(): pass else: - raise BaseException("Exceeded maximum number of domains for this package") + print "0, Exceeded maximum number of domains for this package" + return 0, "Exceeded maximum number of domains for this package" + ####### Limitations Check End if vhost.checkIfVirtualHostExists(virtualHostName) == 1: - raise BaseException("Virtual Host Directory already exists!") + print "0, Virtual Host Directory already exists!" + return 0, "Virtual Host Directory already exists!" if vhost.checkIfAliasExists(virtualHostName) == 1: - raise BaseException("This domain exists as Alias.") + print "0, This domain exists as Alias." + return 0, "This domain exists as Alias." if dkimCheck == 1: if mailUtilities.checkIfDKIMInstalled() == 0: diff --git a/postfixSenderPolicy/accept_traffic.py b/postfixSenderPolicy/accept_traffic.py index 5d0b1837d..b00724016 100755 --- a/postfixSenderPolicy/accept_traffic.py +++ b/postfixSenderPolicy/accept_traffic.py @@ -57,7 +57,6 @@ class HandleRequest(multi.Thread): except BaseException, msg: logging.writeToFile( str(msg) + ' [HandleRequest.run]') - finally: limitThreads.release() @@ -67,7 +66,7 @@ class HandleRequest(multi.Thread): for items in completeData: tempData = items.split('=') - if tempData[0] == 'sasl_username': + if tempData[0] == 'sender': emailAddress = tempData[1] domainName = emailAddress.split('@')[1] elif tempData[0] == 'recipient': @@ -120,5 +119,5 @@ class HandleRequest(multi.Thread): except BaseException, msg: + logging.writeToFile(str(msg) + " [HandleRequest.manageRequest]") self.connection.sendall('action=defer_if_permit Service temporarily unavailable\n\n') - logging.writeToFile(str(msg) + " [HandleRequest.manageRequest") diff --git a/postfixSenderPolicy/cacheManager.py b/postfixSenderPolicy/cacheManager.py index 239d33884..cb1d19669 100755 --- a/postfixSenderPolicy/cacheManager.py +++ b/postfixSenderPolicy/cacheManager.py @@ -31,7 +31,7 @@ class cacheManager: dbEmail.save() except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.flushCache]') @staticmethod def disableEnableLogs(self, emailAddress, operationValue): @@ -45,7 +45,7 @@ class cacheManager: emailOBJ.logStatus = operationValue except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.disableEnableLogs]') @staticmethod def purgeLog(command): @@ -60,7 +60,7 @@ class cacheManager: emailOBJ.logStatus = operationVal except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.purgeLog]') @staticmethod def purgeLimit(command): @@ -75,7 +75,7 @@ class cacheManager: emailOBJ.limitStatus = operationVal except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.purgeLimit]') @staticmethod def purgeLimitDomain(command): @@ -88,7 +88,7 @@ class cacheManager: domainOBJ.limitStatus = operationVal except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.purgeLimitDomain]') @staticmethod def updateDomainLimit(command): @@ -101,7 +101,7 @@ class cacheManager: domainOBJ.monthlyLimits = newLimit except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.updateDomainLimit]') @staticmethod def purgeLimitEmail(command): @@ -118,7 +118,7 @@ class cacheManager: emailOBJ.hourlyLimits = hourlyLimit except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.purgeLimitEmail]') @staticmethod def hourlyCleanUP(): @@ -141,7 +141,7 @@ class cacheManager: dbEmail.save() except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.hourlyCleanUP]') @staticmethod def monthlyCleanUP(): @@ -166,7 +166,7 @@ class cacheManager: dbDomain.save() except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.monthlyCleanUP]') @staticmethod @@ -197,5 +197,5 @@ class cacheManager: except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheManager.handlePurgeRequest]') diff --git a/postfixSenderPolicy/client.py b/postfixSenderPolicy/client.py index 76b331964..40599be6f 100755 --- a/postfixSenderPolicy/client.py +++ b/postfixSenderPolicy/client.py @@ -13,13 +13,12 @@ class cacheClient: def handleCachePurgeRequest(command): try: mailUtilities.checkHome() - writeToFile = open(cacheClient.cleaningPath, 'w') writeToFile.write(command) writeToFile.close() except BaseException, msg: - logging.writeToFile(str(msg)) + logging.writeToFile(str(msg) + ' [cacheClient.handleCachePurgeRequest]') def main(): diff --git a/postfixSenderPolicy/cpecs.service b/postfixSenderPolicy/cpecs.service index 27bb40665..4b05d53b3 100755 --- a/postfixSenderPolicy/cpecs.service +++ b/postfixSenderPolicy/cpecs.service @@ -5,7 +5,7 @@ Description = CyberPanel Email Policy Control Daemon Type=forking ExecStart = /usr/local/CyberCP/postfixSenderPolicy/policyCTRL.py start ExecStop = /usr/local/CyberCP/postfixSenderPolicy/policyCTRL.py stop -Restart= /usr/local/CyberCP/postfixSenderPolicy/policyCTRL.py restart +Restart = /usr/local/CyberCP/postfixSenderPolicy/policyCTRL.py restart Restart=on-abnormal [Install] diff --git a/postfixSenderPolicy/policyCTRL.py b/postfixSenderPolicy/policyCTRL.py index 4401d8b02..a7a29a6b4 100755 --- a/postfixSenderPolicy/policyCTRL.py +++ b/postfixSenderPolicy/policyCTRL.py @@ -31,7 +31,6 @@ class policyCTRL: path = policyCTRL.applicationPath if os.path.exists(path): - pid = open(path, "r").readlines()[0] try: os.kill(int(pid), signal.SIGTERM) diff --git a/postfixSenderPolicy/startServer.py b/postfixSenderPolicy/startServer.py index ca5eac8c2..4e5800f6f 100755 --- a/postfixSenderPolicy/startServer.py +++ b/postfixSenderPolicy/startServer.py @@ -5,45 +5,64 @@ import django os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") django.setup() import socket - import os import accept_traffic as handle from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging from signal import * from cacheManager import cacheManager +import pwd +import grp class SetupConn: cleaningPath = '/home/cyberpanel/purgeCache' - server_address = ('localhost', 1089) - cleaning_server = ('localhost', 1090) applicationPath = '/usr/local/CyberCP/postfixSenderPolicy/pid' - cleaningServerPID = '/usr/local/CyberCP/postfixSenderPolicy/cpid' + serverAddress = '/var/log/policyServerSocket' def __init__(self, serv_addr): self.server_addr = serv_addr - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) def setup_conn(self): - logging.writeToFile('Starting CyberPanel Email Policy Server!') - self.sock.bind(self.server_addr) - logging.writeToFile('CyberPanel Email Policy Server Successfully started!') + try: + logging.writeToFile('Starting CyberPanel Email Policy Server!') + + try: + os.unlink(self.server_addr) + except OSError: + if os.path.exists(self.server_addr): + raise + + self.sock.bind(self.server_addr) + + uid = pwd.getpwnam("postfix").pw_uid + gid = grp.getgrnam("postfix").gr_gid + os.chown(self.server_addr, uid, gid) + + os.chmod(self.server_addr, 0755) + + logging.writeToFile('CyberPanel Email Policy Server Successfully started!') + except BaseException, msg: + logging.writeToFile(str(msg) + ' [SetupConn.setup_conn]') def start_listening(self): - self.sock.listen(5) - while True: - # Wait for a connection - if os.path.exists(SetupConn.cleaningPath): - readFromFile = open(SetupConn.cleaningPath, 'r') - command = readFromFile.read() - cacheManager.handlePurgeRequest(command) - readFromFile.close() - os.remove(SetupConn.cleaningPath) + try: + self.sock.listen(5) + while True: + # Wait for a connection + if os.path.exists(SetupConn.cleaningPath): + readFromFile = open(SetupConn.cleaningPath, 'r') + command = readFromFile.read() + cacheManager.handlePurgeRequest(command) + readFromFile.close() + os.remove(SetupConn.cleaningPath) - connection, client_address = self.sock.accept() - background = handle.HandleRequest(connection) - background.start() + connection, client_address = self.sock.accept() + background = handle.HandleRequest(connection) + background.start() + except BaseException, msg: + logging.writeToFile(str(msg) + ' [SetupConn.start_listening]') def __del__(self): @@ -61,7 +80,7 @@ def Main(): writeToFile.write(str(os.getpid())) writeToFile.close() - listenConn = SetupConn(SetupConn.server_address) + listenConn = SetupConn(SetupConn.serverAddress) listenConn.setup_conn() listenConn.start_listening() diff --git a/static/baseTemplate/assets/themes/admin/color-schemes/default.css b/static/baseTemplate/assets/themes/admin/color-schemes/default.css index b7810574d..d38caa513 100644 --- a/static/baseTemplate/assets/themes/admin/color-schemes/default.css +++ b/static/baseTemplate/assets/themes/admin/color-schemes/default.css @@ -134,4 +134,5 @@ h1, h2, h3, h4, h5, h6, /* Admin responsive */ -@media only screen and (min-width:20em){#header-logo,#theme-options{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:hidden}#page-content{margin-left:0}}@media only screen and (min-width:56.25em){#header-logo,#page-sidebar.collapse,#theme-options{display:block}#mobile-navigation{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:visible}#page-content{margin-left:260px}}@media only screen and (max-width:760px){#cloud-btn,#header-nav-right #fullscreen-btn{display:none}}@media only screen and (max-width:630px){#page-header .user-account-btn>a.user-profile span{display:none}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:56px}}@media only screen and (max-width:545px){#header-nav-right #chatbox-btn{display:none}}@media only screen and (max-width:520px){#dashnav-btn,#page-header .user-account-btn>a.user-profile span{display:none}.popover{width:100%;border-radius:0}.box-md{width:auto}}@media only screen and (max-width:460px){.box-sm,.timeline-box .popover{width:auto}#page-content{padding:10px}#page-title{padding:10px 0 15px;text-align:center}.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{margin-bottom:20px}.content-box{margin-top:0!important}.row.mrg20B{margin-bottom:0!important}#page-title p,#progress-btn,.dashboard-box .list-grade,.header-buttons-separator,.todo-box .bs-label,.todo-box .btn,.tooltip .tooltip-arrow{display:none}}@media only screen and (max-width:410px){#header-nav-right #logout-btn,#notifications-btn{display:none}#header-nav-left{float:right}#header-nav-right{margin-right:0;margin-left:15px;float:left}.dropdown-menu{position:fixed;left:0!important;width:100%;border-radius:0}#page-header .user-account-btn .dropdown-menu{top:65px}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:auto;right:24px}} \ No newline at end of file +@media only screen and (min-width:20em){#header-logo,#theme-options{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:hidden}#page-content{margin-left:0}}@media only screen and (min-width:56.25em){#header-logo,#page-sidebar.collapse,#theme-options{display:block}#mobile-navigation{display:none}#page-sidebar{transform:translateX(0);-ms-transform:translateX(0);-o-transform:translateX(0);-webkit-transform:translateX(0);visibility:visible}#page-content{margin-left:260px}}@media only screen and (max-width:760px){#cloud-btn,#header-nav-right #fullscreen-btn{display:none}}@media only screen and (max-width:630px){#page-header .user-account-btn>a.user-profile span{display:none}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:56px}}@media only screen and (max-width:545px){#header-nav-right #chatbox-btn{display:none}}@media only screen and (max-width:520px){#dashnav-btn,#page-header .user-account-btn>a.user-profile span{display:none}.popover{width:100%;border-radius:0}.box-md{width:auto}}@media only screen and (max-width:460px){.box-sm,.timeline-box .popover{width:auto}#page-content{padding:10px}#page-title{padding:10px 0 15px;text-align:center}.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{margin-bottom:20px}.content-box{margin-top:0!important}.row.mrg20B{margin-bottom:0!important}#page-title p,#progress-btn,.dashboard-box .list-grade,.header-buttons-separator,.todo-box .bs-label,.todo-box .btn,.tooltip .tooltip-arrow{display:none}}@media only screen and (max-width:410px){#header-nav-right #logout-btn,#notifications-btn{display:none}#header-nav-left{float:right}#header-nav-right{margin-right:0;margin-left:15px;float:left}.dropdown-menu{position:fixed;left:0!important;width:100%;border-radius:0}#page-header .user-account-btn .dropdown-menu{top:65px}#page-header .user-account-btn .dropdown-menu:after,#page-header .user-account-btn .dropdown-menu:before{left:auto;right:24px}} + diff --git a/static/websiteFunctions/websiteFunctions.css b/static/websiteFunctions/websiteFunctions.css index bc1818f18..f48300f48 100644 --- a/static/websiteFunctions/websiteFunctions.css +++ b/static/websiteFunctions/websiteFunctions.css @@ -9,4 +9,6 @@ .website-content-box{ border-radius: 25px; border-color:#3498db -} \ No newline at end of file +} + + diff --git a/static/websiteFunctions/websiteFunctions.js b/static/websiteFunctions/websiteFunctions.js index 271eb4446..fcfaa695a 100644 --- a/static/websiteFunctions/websiteFunctions.js +++ b/static/websiteFunctions/websiteFunctions.js @@ -456,6 +456,7 @@ app.controller('websitePages', function($scope,$http) { }; $scope.fileManagerURL = "/filemanager/"+$("#domainNamePage").text(); + $scope.wordPressInstallURL = $("#domainNamePage").text() + "/wordpressInstall"; $scope.domainAliasURL = "/websites/"+$("#domainNamePage").text()+"/domainAlias"; $scope.previewUrl = "/preview/"+$("#domainNamePage").text()+"/"; @@ -3835,7 +3836,294 @@ app.controller('launchChild', function($scope,$http) { } +}); +/* Application Installer */ + + +app.controller('installWordPressCTRL', function($scope, $http, $timeout) { + + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = true; + + var statusFile; + var domain = $("#domainNamePage").text(); + var path; + + + + $scope.goBack = function () { + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = true; + $("#installProgress").css("width", "0%"); + }; + + + + + $scope.installWordPress = function(){ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = false; + $scope.goBackDisable = true; + $scope.currentStatus = "Starting installation.."; + + path = $scope.installPath; + + + url = "/websites/installWordpress"; + + var home = "1"; + + if (typeof path !== 'undefined'){ + home = "0"; + } + + + var data = { + domain: domain, + home:home, + path:path, + blogTitle: $scope.blogTitle, + adminUser: $scope.adminUser, + adminPassword: $scope.adminPassword, + adminEmail: $scope.adminEmail + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.installStatus === 1) + { + statusFile = response.data.tempStatusPath; + getInstallStatus(); + } + else{ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + } + + + } + function cantLoadInitialDatas(response) { + + + + } + + }; + + function getInstallStatus(){ + + url = "/websites/installWordpressStatus"; + + var data = { + statusFile: statusFile, + domainName: domain + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if(response.data.abort === 1){ + + if(response.data.installStatus === 1){ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = false; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = false; + + if (typeof path !== 'undefined'){ + $scope.installationURL = "http://"+domain+"/"+path; + } + else{ + $scope.installationURL = domain; + } + + + $("#installProgress").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + } + else{ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + $("#installProgress").css("width", "0%"); + $scope.installPercentage = "0"; + + } + + } + else{ + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + + $timeout(getInstallStatus,1000); + + + + } + + } + function cantLoadInitialDatas(response) { + + $scope.canNotFetch = true; + $scope.couldNotConnect = false; + + + } + + + } + + $scope.installJoomla = function(){ + + + $scope.installationDetailsFormJoomla = false; + $scope.applicationInstallerLoading = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + + var domain = $("#domainNamePage").text(); + var path = $scope.installPath; + var sitename = $scope.sitename + var username = $scope.username + var password = $scope.password + var prefix = $scope.prefix + + + url = "/websites/installJoomla"; + + var home = "1"; + + if (typeof path != 'undefined'){ + home = "0"; + } + + + var data = { + domain: domain, + home:home, + path:path, + sitename:sitename, + username:username, + password:password, + prefix:prefix, + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.installStatus == 1) + { + if (typeof path != 'undefined'){ + $scope.installationURL = "http://"+domain+"/"+path; + } + else{ + $scope.installationURL = domain; + } + + $scope.installationDetailsFormJoomla = false; + $scope.applicationInstallerLoading = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = false; + $scope.couldNotConnect = true; + + } + else{ + + $scope.installationDetailsFormJoomla = false; + $scope.applicationInstallerLoading = true; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + + $scope.errorMessage = response.data.error_message; + + } + + + } + function cantLoadInitialDatas(response) { + + $scope.installationDetailsFormJoomla = false; + $scope.applicationInstallerLoading = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = false; + + } + + }; + + }); \ No newline at end of file diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.css b/websiteFunctions/static/websiteFunctions/websiteFunctions.css index bc1818f18..f48300f48 100644 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.css +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.css @@ -9,4 +9,6 @@ .website-content-box{ border-radius: 25px; border-color:#3498db -} \ No newline at end of file +} + + diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 271eb4446..fcfaa695a 100644 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -456,6 +456,7 @@ app.controller('websitePages', function($scope,$http) { }; $scope.fileManagerURL = "/filemanager/"+$("#domainNamePage").text(); + $scope.wordPressInstallURL = $("#domainNamePage").text() + "/wordpressInstall"; $scope.domainAliasURL = "/websites/"+$("#domainNamePage").text()+"/domainAlias"; $scope.previewUrl = "/preview/"+$("#domainNamePage").text()+"/"; @@ -3835,7 +3836,294 @@ app.controller('launchChild', function($scope,$http) { } +}); +/* Application Installer */ + + +app.controller('installWordPressCTRL', function($scope, $http, $timeout) { + + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = true; + + var statusFile; + var domain = $("#domainNamePage").text(); + var path; + + + + $scope.goBack = function () { + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = true; + $("#installProgress").css("width", "0%"); + }; + + + + + $scope.installWordPress = function(){ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = false; + $scope.goBackDisable = true; + $scope.currentStatus = "Starting installation.."; + + path = $scope.installPath; + + + url = "/websites/installWordpress"; + + var home = "1"; + + if (typeof path !== 'undefined'){ + home = "0"; + } + + + var data = { + domain: domain, + home:home, + path:path, + blogTitle: $scope.blogTitle, + adminUser: $scope.adminUser, + adminPassword: $scope.adminPassword, + adminEmail: $scope.adminEmail + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.installStatus === 1) + { + statusFile = response.data.tempStatusPath; + getInstallStatus(); + } + else{ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + } + + + } + function cantLoadInitialDatas(response) { + + + + } + + }; + + function getInstallStatus(){ + + url = "/websites/installWordpressStatus"; + + var data = { + statusFile: statusFile, + domainName: domain + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if(response.data.abort === 1){ + + if(response.data.installStatus === 1){ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = false; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = false; + + if (typeof path !== 'undefined'){ + $scope.installationURL = "http://"+domain+"/"+path; + } + else{ + $scope.installationURL = domain; + } + + + $("#installProgress").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + } + else{ + + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + $scope.wpInstallLoading = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + $("#installProgress").css("width", "0%"); + $scope.installPercentage = "0"; + + } + + } + else{ + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + + $timeout(getInstallStatus,1000); + + + + } + + } + function cantLoadInitialDatas(response) { + + $scope.canNotFetch = true; + $scope.couldNotConnect = false; + + + } + + + } + + $scope.installJoomla = function(){ + + + $scope.installationDetailsFormJoomla = false; + $scope.applicationInstallerLoading = false; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + + var domain = $("#domainNamePage").text(); + var path = $scope.installPath; + var sitename = $scope.sitename + var username = $scope.username + var password = $scope.password + var prefix = $scope.prefix + + + url = "/websites/installJoomla"; + + var home = "1"; + + if (typeof path != 'undefined'){ + home = "0"; + } + + + var data = { + domain: domain, + home:home, + path:path, + sitename:sitename, + username:username, + password:password, + prefix:prefix, + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.installStatus == 1) + { + if (typeof path != 'undefined'){ + $scope.installationURL = "http://"+domain+"/"+path; + } + else{ + $scope.installationURL = domain; + } + + $scope.installationDetailsFormJoomla = false; + $scope.applicationInstallerLoading = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = false; + $scope.couldNotConnect = true; + + } + else{ + + $scope.installationDetailsFormJoomla = false; + $scope.applicationInstallerLoading = true; + $scope.installationFailed = false; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = true; + + $scope.errorMessage = response.data.error_message; + + } + + + } + function cantLoadInitialDatas(response) { + + $scope.installationDetailsFormJoomla = false; + $scope.applicationInstallerLoading = true; + $scope.installationFailed = true; + $scope.installationSuccessfull = true; + $scope.couldNotConnect = false; + + } + + }; + + }); \ No newline at end of file diff --git a/websiteFunctions/templates/websiteFunctions/applicationInstaller.html b/websiteFunctions/templates/websiteFunctions/applicationInstaller.html new file mode 100644 index 000000000..cd78fad79 --- /dev/null +++ b/websiteFunctions/templates/websiteFunctions/applicationInstaller.html @@ -0,0 +1,62 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Application Installer - CyberPanel" %}{% endblock %} +{% block content %} + +{% load static %} +{% get_current_language as LANGUAGE_CODE %} + + + +
+ +
+

{% trans "Application Installer" %}

+

{% trans "One-click application install." %}

+
+ +
+ +
+

+ {% trans "Application Installer" %} +

+ + + +
+
+ + + +{% endblock %} \ No newline at end of file diff --git a/websiteFunctions/templates/websiteFunctions/createWebsite.html b/websiteFunctions/templates/websiteFunctions/createWebsite.html index 66ceb257a..517c7ed77 100644 --- a/websiteFunctions/templates/websiteFunctions/createWebsite.html +++ b/websiteFunctions/templates/websiteFunctions/createWebsite.html @@ -51,7 +51,7 @@
- +
{% trans "Invalid Domain (Note: You don't need to add 'http' or 'https')" %}
@@ -115,7 +115,7 @@
- +
diff --git a/websiteFunctions/templates/websiteFunctions/installWordPress.html b/websiteFunctions/templates/websiteFunctions/installWordPress.html new file mode 100644 index 000000000..30150819e --- /dev/null +++ b/websiteFunctions/templates/websiteFunctions/installWordPress.html @@ -0,0 +1,127 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Install WordPress - CyberPanel" %}{% endblock %} +{% block content %} + +{% load static %} +{% get_current_language as LANGUAGE_CODE %} + + +
+
+

{% trans "Install WordPress" %}

+

{% trans "Install WordPress with LSCache." %}

+
+ + +
+
+

+ {{ domainName }} - {% trans "Installation Details" %} +

+
+ + + + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + + +
+ +
+ +
+
+ + + +
+ +
+ +
+

{$ currentStatus $}

+
+ +
+
+ 70% Complete +
+
+ + + + +
+

{% trans "Installation failed. Error message:" %} {$ errorMessage $}

+
+ +
+

{% trans "Installation successful. Visit:" %} {$ installationURL $}

+
+ + + +
+

{% trans "Could not connect to server. Please refresh this page." %}

+
+ + +
+
+ +
+ +
+ +
+
+ + + + +
+
+
+ + + +
+ + +{% endblock %} \ No newline at end of file diff --git a/websiteFunctions/templates/websiteFunctions/website.html b/websiteFunctions/templates/websiteFunctions/website.html index 1ad48373a..34db89882 100644 --- a/websiteFunctions/templates/websiteFunctions/website.html +++ b/websiteFunctions/templates/websiteFunctions/website.html @@ -940,10 +940,10 @@
- + - + {% trans "Wordpress with LSCache" %} diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index ef00bddb1..405bbb18e 100644 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -30,7 +30,7 @@ urlpatterns = [ url(r'^fetchErrorLogs', views.fetchErrorLogs, name='fetchErrorLogs'), - url(r'^installWordpress', views.installWordpress, name='installWordpress'), + url(r'^installWordpress$', views.installWordpress, name='installWordpress'), url(r'^installJoomla', views.installJoomla, name='installJoomla'), url(r'^getDataFromConfigFile', views.getDataFromConfigFile, name='getDataFromConfigFile'), @@ -76,4 +76,10 @@ urlpatterns = [ url(r'^changeOpenBasedir$',views.changeOpenBasedir,name="changeOpenBasedir"), + ## Application Installer + + url(r'^applicationInstaller$',views.applicationInstaller,name="applicationInstaller"), + url(r'^(?P([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?)/wordpressInstall$', views.wordpressInstall, name='wordpressInstall'), + url(r'^installWordpressStatus$',views.installWordpressStatus,name="installWordpressStatus"), + ] \ No newline at end of file diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index c4577bf8e..936f95150 100644 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -25,6 +25,7 @@ from random import randint import hashlib from xml.etree import ElementTree from plogical.mailUtilities import mailUtilities +from plogical.applicationInstaller import ApplicationInstaller # Create your views here. @@ -1061,127 +1062,6 @@ def fetchErrorLogs(request): final_json = json.dumps({'logstatus': 0, 'error_message': str(msg)}) return HttpResponse(final_json) -def installWordpress(request): - try: - val = request.session['userID'] - - if request.method == 'POST': - try: - data = json.loads(request.body) - domainName = data['domain'] - home = data['home'] - - finalPath = "" - - if home == '0': - path = data['path'] - finalPath = "/home/" + domainName + "/public_html/" + path + "/" - else: - finalPath = "/home/" + domainName + "/public_html/" - - ## Security Check - - if finalPath.find("..") > -1: - data_ret = {'installStatus': 0, - 'error_message': "Specified path must be inside virtual host home!"} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - admin = Administrator.objects.get(pk=val) - - try: - website = ChildDomains.objects.get(domain=domainName) - externalApp = website.master.externalApp - - if admin.type != 1: - if website.master.admin != admin: - data_ret = {'installStatus': 0, - 'error_message': "You do not own this website!"} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - except: - website = Websites.objects.get(domain=domainName) - externalApp = website.externalApp - - if admin.type != 1: - if website.admin != admin: - data_ret = {'installStatus': 0, - 'error_message': "You do not own this website!"} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - - ## DB Creation - - dbName = randomPassword.generate_pass() - dbUser = dbName - dbPassword = randomPassword.generate_pass() - - ## DB Creation - - if website.package.dataBases > website.databases_set.all().count(): - pass - else: - data_ret = {'installStatus': 0, 'error_message': "0,Maximum database limit reached for this website."} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - if Databases.objects.filter(dbName=dbName).exists() or Databases.objects.filter( - dbUser=dbUser).exists(): - - data_ret = {'installStatus': 0, - 'error_message': "0,This database or user is already taken."} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - result = mysqlUtilities.createDatabase(dbName, dbUser, dbPassword) - - if result == 1: - pass - else: - data_ret = {'installStatus': 0, - 'error_message': "0,Not able to create database."} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - db = Databases(website=website, dbName=dbName, dbUser=dbUser) - db.save() - - ## Installation - - execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" - - execPath = execPath + " installWordPress --virtualHostName " + domainName + " --virtualHostUser " + externalApp + " --path " + finalPath + " --dbName " + dbName + " --dbUser " + dbUser + " --dbPassword " + dbPassword - - - output = subprocess.check_output(shlex.split(execPath)) - - if output.find("1,None") > -1: - data_ret = {"installStatus": 1} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - else: - mysqlUtilities.deleteDatabase(dbName, dbUser) - db = Databases.objects.get(dbName=dbName) - db.delete() - data_ret = {'installStatus': 0, 'error_message': output} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - ## Installation ends - - except BaseException, msg: - data_ret = {'installStatus': 0, 'error_message': str(msg)} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - - except KeyError, msg: - status = {"installStatus":0,"error":str(msg)} - logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installWordpress]") - return HttpResponse("Not Logged in as admin") - def installJoomla(request): try: val = request.session['userID'] @@ -2450,4 +2330,138 @@ def changeOpenBasedir(request): except KeyError,msg: data_ret = {'changeOpenBasedir': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + +def applicationInstaller(request): + try: + val = request.session['userID'] + try: + + admin = Administrator.objects.get(pk=val) + + if admin.type != 1: + website = Websites.objects.get(domain=domain) + if website.admin != admin: + raise BaseException('You do not own this website.') + + + return render(request, 'websiteFunctions/applicationInstaller.html') + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return HttpResponse(str(msg)) + except KeyError: + return redirect(loadLoginPage) + + +def wordpressInstall(request, domain): + try: + val = request.session['userID'] + admin = Administrator.objects.get(pk=val) + try: + if admin.type != 1: + website = Websites.objects.get(domain=domain) + if website.admin != admin: + raise BaseException('You do not own this website.') + + + return render(request, 'websiteFunctions/installWordPress.html', {'domainName' : domain}) + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return HttpResponse(str(msg)) + except KeyError: + return redirect(loadLoginPage) + +def installWordpress(request): + try: + val = request.session['userID'] + admin = Administrator.objects.get(pk=val) + + if request.method == 'POST': + try: + data = json.loads(request.body) + + mailUtilities.checkHome() + + extraArgs = {} + extraArgs['admin'] = admin + extraArgs['domainName'] = data['domain'] + extraArgs['home'] = data['home'] + extraArgs['blogTitle'] = data['blogTitle'] + extraArgs['adminUser'] = data['adminUser'] + extraArgs['adminPassword'] = data['adminPassword'] + extraArgs['adminEmail'] = data['adminEmail'] + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + + if data['home'] == '0': + extraArgs['path'] = data['path'] + + + background = ApplicationInstaller('wordpress', extraArgs) + background.start() + + data_ret = {'installStatus': 1, 'error_message': 'None', 'tempStatusPath': extraArgs['tempStatusPath']} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + except BaseException, msg: + data_ret = {'installStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + except KeyError, msg: + status = {"installStatus":0,"error":str(msg)} + logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installWordpress]") + return HttpResponse("Not Logged in as admin") + + +def installWordpressStatus(request): + try: + val = request.session['userID'] + admin = Administrator.objects.get(pk=val) + + if request.method == 'POST': + try: + data = json.loads(request.body) + + + domainName = data['domainName'] + statusFile = data['statusFile'] + + if admin.type != 1: + website = Websites.objects.get(domain=domainName) + if website.admin != admin: + raise BaseException('You do not own this website.') + + statusData = open(statusFile, 'r').readlines() + + lastLine = statusData[-1] + + if lastLine.find('[200]') > -1: + data_ret = { 'abort':1, 'installStatus': 1, 'installationProgress': "100", 'currentStatus': 'Successfully Installed.' } + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + elif lastLine.find('[404]') > -1: + data_ret = {'abort': 1, 'installStatus': 0, 'installationProgress': "0", 'error_message': lastLine} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + progress = lastLine.split(',') + currentStatus = progress[0] + installationProgress = progress[1] + data_ret = {'abort': 0, 'installStatus': 0, 'installationProgress': installationProgress, 'currentStatus': currentStatus} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException, msg: + data_ret = {'abort': 1, 'installStatus': 0, 'installationProgress': "0", 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + + except KeyError, msg: + data_ret = {'abort': 1, 'installStatus': 0, 'installationProgress': "0", 'error_message': str(msg)} + json_data = json.dumps(data_ret) return HttpResponse(json_data) \ No newline at end of file