diff --git a/install/lscache-1.3.1.zip b/install/lscache-1.3.1.zip new file mode 100644 index 000000000..95711264a Binary files /dev/null and b/install/lscache-1.3.1.zip differ diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 8d42a05a7..b7fbe839f 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -9,15 +9,14 @@ django.setup() import threading as multi from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging import subprocess -from plogical.vhost import vhost from websiteFunctions.models import ChildDomains, Websites from plogical import randomPassword from plogical.mysqlUtilities import mysqlUtilities from databases.models import Databases from plogical.installUtilities import installUtilities -import shutil from plogical.processUtilities import ProcessUtilities from random import randint +import hashlib class ApplicationInstaller(multi.Thread): @@ -828,16 +827,10 @@ $parameters = array( try: - domainName = self.extraArgs['domainName'] - finalPath = self.extraArgs['finalPath'] - virtualHostUser = self.extraArgs['virtualHostUser'] - dbName = self.extraArgs['dbName'] - dbUser = self.extraArgs['dbUser'] - dbPassword = self.extraArgs['dbPassword'] - username = self.extraArgs['username'] + domainName = self.extraArgs['domain'] password = self.extraArgs['password'] prefix = self.extraArgs['prefix'] - sitename = self.extraArgs['sitename'] + home = self.extraArgs['home'] tempStatusPath = self.extraArgs['tempStatusPath'] self.tempStatusPath = tempStatusPath @@ -847,135 +840,153 @@ $parameters = array( command = 'chmod 755 %s' % (permPath) ProcessUtilities.executioner(command) - if not os.path.exists(finalPath): - os.makedirs(finalPath) + ## Get Joomla - ## checking for directories/files + try: + website = ChildDomains.objects.get(domain=domainName) + externalApp = website.master.externalApp + self.masterDomain = website.master.domain + + if home == '0': + path = self.extraArgs['path'] + finalPath = website.path.rstrip('/') + "/" + path + "/" + else: + finalPath = website.path + "/" + + if website.master.package.dataBases > website.master.databases_set.all().count(): + pass + else: + raise BaseException("Maximum database limit reached for this website.") + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Setting up Database,20') + statusFile.close() + + dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website.master) + self.permPath = website.path + + except: + website = Websites.objects.get(domain=domainName) + externalApp = website.externalApp + self.masterDomain = website.domain + + if home == '0': + path = self.extraArgs['path'] + finalPath = "/home/" + domainName + "/public_html/" + path + "/" + else: + finalPath = "/home/" + domainName + "/public_html/" + + if website.package.dataBases > website.databases_set.all().count(): + pass + else: + raise BaseException("Maximum database limit reached for this website.") + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Installing Joomla Console..,30') + statusFile.close() + + dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website) + self.permPath = '/home/%s/public_html' % (website.domain) + + ## Dataloss check + + command = 'ls -la %s' % (finalPath) + result = ProcessUtilities.outputExecutioner(command, externalApp) + + if result.find('No such file or directory') > -1: + command = 'mkdir %s' % (finalPath) + ProcessUtilities.executioner(command, externalApp) if self.dataLossCheck(finalPath, tempStatusPath) == 0: raise BaseException('Directory is not empty.') - ## Get Joomla + command = 'composer global require joomlatools/console' + ProcessUtilities.outputExecutioner(command, externalApp, None, self.permPath) - os.chdir(finalPath) - - if not os.path.exists("staging.zip"): - command = 'wget --no-check-certificate https://github.com/joomla/joomla-cms/archive/staging.zip -P ' + finalPath - ProcessUtilities.executioner(command, virtualHostUser) - else: - raise BaseException('File already exists.') - - command = 'unzip ' + finalPath + 'staging.zip -d ' + finalPath - ProcessUtilities.executioner(command, virtualHostUser) - - command = 'rm -f %s' % (finalPath + 'staging.zip') - ProcessUtilities.executioner(command, virtualHostUser) - - command = 'cp -r ' + finalPath + 'joomla-cms-staging/. ' + finalPath - ProcessUtilities.executioner(command, virtualHostUser) - - command = 'chown -R cyberpanel:cyberpanel %s' % (finalPath) - ProcessUtilities.executioner(command) - - shutil.rmtree(finalPath + "joomla-cms-staging") - os.rename(finalPath + "installation/configuration.php-dist", finalPath + "configuration.php") - os.rename(finalPath + "robots.txt.dist", finalPath + "robots.txt") - os.rename(finalPath + "htaccess.txt", finalPath + ".htaccess") - - ## edit config file + ## Run the install command statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Creating configuration files.,40') + statusFile.writelines('Installing Joomla..,40') statusFile.close() - configfile = finalPath + "configuration.php" + command = '/home/%s/.composer/vendor/bin/joomla site:create %s --mysql-login %s:%s --mysql-database %s --mysql_db_prefix=%s --www %s --sample-data=blog --skip-create-statement' % (self.masterDomain, dbUser, dbUser, dbPassword, dbName, prefix , finalPath) - data = open(configfile, "r").readlines() + result = ProcessUtilities.outputExecutioner(command, externalApp) - writeDataToFile = open(configfile, "w") + if result.find('admin/admin') == -1: + raise BaseException(result) - secret = randomPassword.generate_pass() - - defDBName = " public $user = '" + dbName + "';" + "\n" - defDBUser = " public $db = '" + dbUser + "';" + "\n" - defDBPassword = " public $password = '" + dbPassword + "';" + "\n" - secretKey = " public $secret = '" + secret + "';" + "\n" - logPath = " public $log_path = '" + finalPath + "administrator/logs';" + "\n" - tmpPath = " public $tmp_path = '" + finalPath + "administrator/tmp';" + "\n" - dbprefix = " public $dbprefix = '" + prefix + "';" + "\n" - sitename = " public $sitename = '" + sitename + "';" + "\n" - - for items in data: - if items.find("public $user ") > -1: - writeDataToFile.writelines(defDBUser) - elif items.find("public $password ") > -1: - writeDataToFile.writelines(defDBPassword) - elif items.find("public $db ") > -1: - writeDataToFile.writelines(defDBName) - elif items.find("public $log_path ") > -1: - writeDataToFile.writelines(logPath) - elif items.find("public $tmp_path ") > -1: - writeDataToFile.writelines(tmpPath) - elif items.find("public $secret ") > -1: - writeDataToFile.writelines(secretKey) - elif items.find("public $dbprefix ") > -1: - writeDataToFile.writelines(dbprefix) - elif items.find("public $sitename ") > -1: - writeDataToFile.writelines(sitename) - elif items.find("/*") > -1: - pass - elif items.find(" *") > -1: - pass - else: - writeDataToFile.writelines(items) - - writeDataToFile.close() + ### Update password as per user requirments statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Creating default user..,70') + statusFile.writelines('Updating admin password..,70') statusFile.close() - # Rename SQL db prefix + try: - f1 = open(finalPath + 'installation/sql/mysql/joomla.sql', 'r') - f2 = open(finalPath + 'installation/sql/mysql/joomlaInstall.sql', 'w') - for line in f1: - f2.write(line.replace('#__', prefix)) - f1.close() - f2.close() + salt = randomPassword.generate_pass(32) + # return salt + password_hash = hashlib.md5((password + salt).encode('utf-8')).hexdigest() + password = password_hash + ":" + salt - # Restore SQL - proc = subprocess.Popen(["mysql", "--user=%s" % dbUser, "--password=%s" % dbPassword, dbName], - stdin=subprocess.PIPE, stdout=subprocess.PIPE) + import MySQLdb.cursors as cursors + import MySQLdb as mysql - usercreation = """INSERT INTO `%susers` - (`name`, `username`, `password`, `params`) - VALUES ('Administrator', '%s', - '%s', ''); - INSERT INTO `%suser_usergroup_map` (`user_id`,`group_id`) - VALUES (LAST_INSERT_ID(),'8');""" % (prefix, username, password, prefix) + conn = mysql.connect(host='localhost', user=dbUser, passwd=dbPassword, port=3306, + cursorclass=cursors.SSCursor) + cursor = conn.cursor() - out, err = proc.communicate( - open(finalPath + 'installation/sql/mysql/joomlaInstall.sql', 'rb').read() + ("\n" + usercreation).encode('utf-8')) + cursor.execute("use %s;UPDATE j_users SET password = '%s' where username = 'admin';FLUSH PRIVILEGES;" % (dbName, password)) - shutil.rmtree(finalPath + "installation") + conn.close() + except BaseException as msg: + logging.writeToFile(str(msg)) - if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: - groupName = 'nobody' - else: - groupName = 'nogroup' + try: + os.remove('/usr/local/CyberCP/joomla.zip') + os.remove('/usr/local/CyberCP/lscache_plugin.zip') + os.remove('/usr/local/CyberCP/com_lscache.zip') + except: + pass - command = "chown -R " + virtualHostUser + ":" + groupName + " " + finalPath + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Installing LiteSpeed Cache Joomla plugin..,80') + statusFile.close() + + + command = 'wget https://raw.githubusercontent.com/litespeedtech/lscache-joomla/master/package/lscache-1.3.1.zip -O /usr/local/CyberCP/joomla.zip' ProcessUtilities.executioner(command) - vhost.addRewriteRules(domainName) + command = 'unzip /usr/local/CyberCP/joomla.zip -d /usr/local/CyberCP/' + ProcessUtilities.executioner(command) + + command = '/home/%s/.composer/vendor/bin/joomla extension:installfile %s --www %s /usr/local/CyberCP/lscache_plugin.zip' % (self.masterDomain, dbUser, finalPath) + ProcessUtilities.executioner(command) + + command = '/home/%s/.composer/vendor/bin/joomla extension:installfile %s --www %s /usr/local/CyberCP/com_lscache.zip' % (self.masterDomain, dbUser, finalPath) + ProcessUtilities.executioner(command) + + command = '/home/%s/.composer/vendor/bin/joomla extension:enable %s --www %s lscache' % (self.masterDomain, dbUser, finalPath) + ProcessUtilities.executioner(command) + + command = 'mv %s%s/* %s' % (finalPath, dbUser, finalPath) + ProcessUtilities.executioner(command) + + command = 'mv %s%s/.[^.]* %s' % (finalPath, dbUser, finalPath) + ProcessUtilities.executioner(command) + + command = "sed -i 's|$debug = 1|$debug = 0|g' %sconfiguration.php" % (finalPath) + ProcessUtilities.executioner(command) + + ## + + from filemanager.filemanager import FileManager + + fm = FileManager(None, None) + fm.fixPermissions(self.masterDomain) installUtilities.reStartLiteSpeedSocket() - permPath = '/home/%s/public_html' % (domainName) - command = 'chmod 750 %s' % (permPath) - ProcessUtilities.executioner(command) - statusFile = open(tempStatusPath, 'w') statusFile.writelines("Successfully Installed. [200]") statusFile.close() @@ -984,16 +995,10 @@ $parameters = array( except BaseException as msg: # remove the downloaded files - homeDir = "/home/" + domainName + "/public_html" + from filemanager.filemanager import FileManager - if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: - groupName = 'nobody' - else: - groupName = 'nogroup' - - if not os.path.exists(homeDir): - command = "chown -R " + virtualHostUser + ":" + groupName + " " + homeDir - ProcessUtilities.executioner(command) + fm = FileManager(None, None) + fm.fixPermissions(self.masterDomain) try: mysqlUtilities.deleteDatabase(dbName, dbUser) diff --git a/static/websiteFunctions/websiteFunctions.js b/static/websiteFunctions/websiteFunctions.js index efd6556d3..f23ccbeca 100644 --- a/static/websiteFunctions/websiteFunctions.js +++ b/static/websiteFunctions/websiteFunctions.js @@ -1723,8 +1723,7 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { var domain = $("#domainNamePage").text(); var path = $scope.installPath; - var sitename = $scope.sitename; - var username = $scope.username; + var username = 'admin'; var password = $scope.password; var prefix = $scope.prefix; @@ -1742,8 +1741,6 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { domain: domain, home: home, path: path, - sitename: sitename, - username: username, password: password, prefix: prefix, }; diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index efd6556d3..f23ccbeca 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -1723,8 +1723,7 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { var domain = $("#domainNamePage").text(); var path = $scope.installPath; - var sitename = $scope.sitename; - var username = $scope.username; + var username = 'admin'; var password = $scope.password; var prefix = $scope.prefix; @@ -1742,8 +1741,6 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { domain: domain, home: home, path: path, - sitename: sitename, - username: username, password: password, prefix: prefix, }; diff --git a/websiteFunctions/templates/websiteFunctions/installJoomla.html b/websiteFunctions/templates/websiteFunctions/installJoomla.html index 153795f0a..7c552fecf 100755 --- a/websiteFunctions/templates/websiteFunctions/installJoomla.html +++ b/websiteFunctions/templates/websiteFunctions/installJoomla.html @@ -24,17 +24,10 @@
-
- -
- -
-
-
- +
@@ -48,7 +41,7 @@
- +
diff --git a/websiteFunctions/templates/websiteFunctions/launchChild.html b/websiteFunctions/templates/websiteFunctions/launchChild.html index a487bd158..dd057a69e 100755 --- a/websiteFunctions/templates/websiteFunctions/launchChild.html +++ b/websiteFunctions/templates/websiteFunctions/launchChild.html @@ -688,7 +688,7 @@ - +
website.master.databases_set.all().count(): - pass - else: - data_ret = {'status': 0, 'installStatus': 0, - 'error_message': "0,Maximum database limit reached for this website."} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - if home == '0': - path = data['path'] - finalPath = website.path.rstrip('/') + "/" + path + "/" - else: - finalPath = website.path + "/" - - db = Databases(website=website.master, dbName=dbName, dbUser=dbUser) - db.save() - - except: - website = Websites.objects.get(domain=domainName) - externalApp = website.externalApp - - if website.package.dataBases > website.databases_set.all().count(): - pass - else: - data_ret = {'status': 0, 'installStatus': 0, - 'error_message': "0,Maximum database limit reached for this website."} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - if home == '0': - path = data['path'] - finalPath = "/home/" + domainName + "/public_html/" + path + "/" - else: - finalPath = "/home/" + domainName + "/public_html/" - - db = Databases(website=website, dbName=dbName, dbUser=dbUser) - db.save() - - if finalPath.find("..") > -1: - data_ret = {'status': 0, 'installStatus': 0, - 'error_message': "Specified path must be inside virtual host home!"} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) - - ## Installation - salt = randomPassword.generate_pass(32) - # return salt - password_hash = hashlib.md5((password + salt).encode('utf-8')).hexdigest() - password = password_hash + ":" + salt - - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Downloading Joomla Core..,20') - statusFile.close() - - virtualHostUtilities.installJoomla(domainName, finalPath, externalApp, dbName, dbUser, dbPassword, username, password, prefix, sitename, tempStatusPath) - - data_ret = {'status': 1, "installStatus": 1, 'tempStatusPath': tempStatusPath} + data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None', + 'tempStatusPath': extraArgs['tempStatusPath']} json_data = json.dumps(data_ret) return HttpResponse(json_data)