From 0b758982ff3c2009b7e41c733930de7a782fefa5 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sun, 24 Nov 2019 12:14:18 +0500 Subject: [PATCH] test_installJoomla --- plogical/applicationInstaller.py | 38 ++++--- plogical/processUtilities.py | 31 +++--- plogical/virtualHostUtilities.py | 2 + .../websiteFunctions/websiteFunctions.js | 4 +- websiteFunctions/tests.py | 104 +++++++++++++----- websiteFunctions/website.py | 12 +- 6 files changed, 118 insertions(+), 73 deletions(-) diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index b773e2800..bba893afa 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -236,7 +236,7 @@ class ApplicationInstaller(multi.Thread): return 0 if not os.path.exists(finalPath): - command = 'sudo mkdir -p ' + finalPath + command = 'mkdir -p ' + finalPath ProcessUtilities.executioner(command, externalApp) ## checking for directories/files @@ -250,7 +250,7 @@ class ApplicationInstaller(multi.Thread): statusFile.writelines('Downloading WordPress Core,30') statusFile.close() - command = "sudo wp core download --allow-root --path=" + finalPath + command = "wp core download --allow-root --path=" + finalPath ProcessUtilities.executioner(command, externalApp) ## @@ -259,7 +259,7 @@ class ApplicationInstaller(multi.Thread): 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 + command = "wp core config --dbname=" + dbName + " --dbuser=" + dbUser + " --dbpass=" + dbPassword + " --dbhost=localhost --dbprefix=wp_ --allow-root --path=" + finalPath ProcessUtilities.executioner(command, externalApp) if home == '0': @@ -268,7 +268,7 @@ class ApplicationInstaller(multi.Thread): 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 + command = 'wp core install --url="http://' + finalURL + '" --title="' + blogTitle + '" --admin_user="' + adminUser + '" --admin_password="' + adminPassword + '" --admin_email="' + adminEmail + '" --allow-root --path=' + finalPath ProcessUtilities.executioner(command, externalApp) ## @@ -277,19 +277,19 @@ class ApplicationInstaller(multi.Thread): statusFile.writelines('Installing LSCache Plugin,80') statusFile.close() - command = "sudo wp plugin install litespeed-cache --allow-root --path=" + finalPath + command = "wp plugin install litespeed-cache --allow-root --path=" + finalPath ProcessUtilities.executioner(command, externalApp) statusFile = open(tempStatusPath, 'w') statusFile.writelines('Activating LSCache Plugin,90') statusFile.close() - command = "sudo wp plugin activate litespeed-cache --allow-root --path=" + finalPath + command = "wp plugin activate litespeed-cache --allow-root --path=" + finalPath ProcessUtilities.executioner(command, externalApp) ## - command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath + command = "chown -R " + externalApp + ":" + externalApp + " " + finalPath ProcessUtilities.executioner(command, externalApp) statusFile = open(tempStatusPath, 'w') @@ -305,7 +305,7 @@ class ApplicationInstaller(multi.Thread): homeDir = "/home/" + domainName + "/public_html" if not os.path.exists(homeDir): - command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir + command = "chown -R " + externalApp + ":" + externalApp + " " + homeDir ProcessUtilities.executioner(command, externalApp) try: @@ -715,7 +715,7 @@ class ApplicationInstaller(multi.Thread): if not os.path.exists("staging.zip"): command = 'wget --no-check-certificate https://github.com/joomla/joomla-cms/archive/staging.zip -P ' + finalPath - ProcessUtilities.normalExecutioner(command) + ProcessUtilities.executioner(command, virtualHostUser) else: statusFile = open(tempStatusPath, 'w') statusFile.writelines("File already exists." + " [404]") @@ -723,12 +723,16 @@ class ApplicationInstaller(multi.Thread): return 0 command = 'unzip ' + finalPath + 'staging.zip -d ' + finalPath - ProcessUtilities.normalExecutioner(command) + ProcessUtilities.executioner(command, virtualHostUser) - os.remove(finalPath + 'staging.zip') + command = 'rm -f %s' % (finalPath + 'staging.zip') + ProcessUtilities.executioner(command, virtualHostUser) command = 'cp -r ' + finalPath + 'joomla-cms-staging/. ' + finalPath - ProcessUtilities.normalExecutioner(command) + 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") @@ -791,7 +795,7 @@ class ApplicationInstaller(multi.Thread): # Rename SQL db prefix f1 = open(finalPath + 'installation/sql/mysql/joomla.sql', 'r') - f2 = open('installation/sql/mysql/joomlaInstall.sql', 'w') + f2 = open(finalPath + 'installation/sql/mysql/joomlaInstall.sql', 'w') for line in f1: f2.write(line.replace('#__', prefix)) f1.close() @@ -813,12 +817,12 @@ class ApplicationInstaller(multi.Thread): shutil.rmtree(finalPath + "installation") - command = "sudo chown -R " + virtualHostUser + ":" + virtualHostUser + " " + finalPath - ProcessUtilities.normalExecutioner(command) + command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + finalPath + ProcessUtilities.executioner(command) vhost.addRewriteRules(domainName) - installUtilities.reStartLiteSpeed() + installUtilities.reStartLiteSpeedSocket() statusFile = open(tempStatusPath, 'w') statusFile.writelines("Successfully Installed. [200]") @@ -831,7 +835,7 @@ class ApplicationInstaller(multi.Thread): homeDir = "/home/" + domainName + "/public_html" if not os.path.exists(homeDir): - command = "sudo chown -R " + virtualHostUser + ":" + virtualHostUser + " " + homeDir + command = "chown -R " + virtualHostUser + ":" + virtualHostUser + " " + homeDir ProcessUtilities.executioner(command) try: diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index 8df579340..c3061bb6a 100755 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -169,6 +169,11 @@ class ProcessUtilities(multi.Thread): @staticmethod def sendCommand(command, user=None): try: + # if user == None: + # pass + # else: + # cmd = 'usermod -a -G %s %s' % ('cyberpanel', user) + # ProcessUtilities.executioner(cmd) ret = ProcessUtilities.setupUDSConnection() @@ -181,26 +186,12 @@ class ProcessUtilities(multi.Thread): sock = ret[0] - # SplittedCommand = command.split(' ') - # if SplittedCommand[0] == 'sudo': - # finalCommand = SplittedCommand[1:] - # else: - # finalCommand = SplittedCommand - # - # CommandArgs = finalCommand[1:] - # - # finalCommand = finalCommand[0] - # - # for items in CommandArgs: - # finalCommand = '%s %s' % (finalCommand, items) - - if user == None: #logging.writeToFile(ProcessUtilities.token + command) sock.sendall(ProcessUtilities.token + command) else: command = '%s-u %s %s' % (ProcessUtilities.token, user, command) - #logging.writeToFile(command) + #logging.writeToFile(ProcessUtilities.token + command) command = command.replace('sudo', '') sock.sendall(command) @@ -213,6 +204,13 @@ class ProcessUtilities(multi.Thread): data = data + currentData sock.close() + + # if user == None: + # pass + # else: + # cmd = 'deluser %s cyberpanel' % (user) + # ProcessUtilities.executioner(cmd) + return data except BaseException, msg: logging.writeToFile(str(msg) + " [sendCommand]") @@ -231,10 +229,8 @@ class ProcessUtilities(multi.Thread): exitCode = int(exitCode.encode('hex'), 16) if exitCode == 0: - #logging.writeToFile("Command: " + command + ", resturn code: " + str(exitCode) + ".") return 1 else: - #logging.writeToFile("Command: " + command + ", resturn code: " + str(exitCode) + ".") return 0 except BaseException, msg: @@ -280,7 +276,6 @@ class ProcessUtilities(multi.Thread): except BaseException, msg: logging.writeToFile(str(msg) + " [popenExecutioner]") - @staticmethod def BuildCommand(path, functionName, parameters): execPath = "/usr/local/CyberCP/bin/python2 %s %s " % (path, functionName) diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 79bed1d49..b0bc609e3 100755 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -6,10 +6,12 @@ import django sys.path.append('/usr/local/CyberCP') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") + try: django.setup() except: pass + import shutil import argparse import installUtilities diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 9700d7d3d..c02d78505 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -1345,7 +1345,7 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { function ListInitialDatas(response) { - if (response.data.installStatus == 1) { + if (response.data.installStatus === 1) { if (typeof path != 'undefined') { $scope.installationURL = "http://" + domain + "/" + path; } else { @@ -1432,7 +1432,7 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { function ListInitialDatas(response) { - if (response.data.installStatus == 1) { + if (response.data.installStatus === 1) { if (typeof path != 'undefined') { $scope.installationURL = "http://" + domain + "/" + path; } else { diff --git a/websiteFunctions/tests.py b/websiteFunctions/tests.py index f546f35e5..fcb476632 100755 --- a/websiteFunctions/tests.py +++ b/websiteFunctions/tests.py @@ -1,14 +1,14 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.test import TestCase, Client -from django.urls import reverse +from django.test import TestCase import json -from loginSystem.models import Administrator, ACL from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging import requests import time -import ftp +from plogical.processUtilities import ProcessUtilities +import urllib3 +urllib3.disable_warnings() # Create your tests here. @@ -28,7 +28,7 @@ class TestWebsiteManagement(TestCase): def setUp(self): ## Verify login - data_ret = {'username': 'admin', 'password': 'hello122'} + data_ret = {'username': 'admin', 'password': '1234567'} response = self.MakeRequest('verifyLogin', data_ret) self.assertEqual(response['loginStatus'], 1) @@ -51,19 +51,27 @@ class TestWebsiteManagement(TestCase): self.assertEqual(exists, 1) + def test_submitWebsiteDeletion(self): + + ## Login + + data_ret = {'websiteName': 'hello.cyberpanel.xyz'} + + response = self.MakeRequest('websites/submitWebsiteDeletion', data_ret) + time.sleep(10) + + self.assertEqual(response['status'], 1) + + def test_submitWebsiteModify(self): + data_ret = {'domainName': 'hey.cyberpanel.xyz', 'adminEmail': 'usman@cyberpersons.com', 'phpSelection': 'PHP 7.1', 'package': 'Default', 'websiteOwner': 'admin', 'ssl': 0, 'dkimCheck': 0, 'openBasedir': 0} self.MakeRequest('websites/submitWebsiteCreation', data_ret) - data_ret = {'domainName': 'suspend.cyberpanel.xyz', 'adminEmail': 'usman@cyberpersons.com', - 'phpSelection': 'PHP 7.1', - 'package': 'Default', 'websiteOwner': 'admin', 'ssl': 0, 'dkimCheck': 0, 'openBasedir': 0} - self.MakeRequest('websites/submitWebsiteCreation', data_ret) + time.sleep(10) - def test_submitWebsiteModify(self): - - ## Login + ## data_ret = {'domain': 'hey.cyberpanel.xyz', 'email': 'usman@cyberpersons.com' , 'phpVersion': 'PHP 7.3', 'packForWeb': 'Default', 'admin': 'admin'} @@ -92,19 +100,13 @@ phpinfo(); self.assertEqual(exists, 1) - def test_submitWebsiteDeletion(self): - - ## Login - - data_ret = {'websiteName': 'hello.cyberpanel.xyz'} - - response = self.MakeRequest('websites/submitWebsiteDeletion', data_ret) - time.sleep(5) - - self.assertEqual(response['status'], 1) - def test_submitWebsiteStatus(self): + data_ret = {'domainName': 'suspend.cyberpanel.xyz', 'adminEmail': 'usman@cyberpersons.com', + 'phpSelection': 'PHP 7.1', + 'package': 'Default', 'websiteOwner': 'admin', 'ssl': 0, 'dkimCheck': 0, 'openBasedir': 0} + self.MakeRequest('websites/submitWebsiteCreation', data_ret) + ## Suspend check data_ret = {'websiteName': 'suspend.cyberpanel.xyz', 'state': 'Suspend'} @@ -154,12 +156,20 @@ phpinfo(); def test_installWordpress(self): + command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz') + ProcessUtilities.normalExecutioner(command) + + command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz') + ProcessUtilities.normalExecutioner(command) + + command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz') + ProcessUtilities.normalExecutioner(command) + ## Suspend check data_ret = {'domain': 'cyberpanel.xyz', 'home': '1', 'blogTitle': 'Unit Test', 'adminUser': 'cyberpanel', 'passwordByPass': 'helloworld', 'adminEmail': 'usman@cyberpersons.com'} response = self.MakeRequest('websites/installWordpress', data_ret) - logging.writeToFile(str(response)) time.sleep(2) @@ -168,7 +178,7 @@ phpinfo(); ## Wait for install to complete - data_ret = {'statusFile': tempStatusPath} + data_ret = {'statusFile': tempStatusPath, 'domainName': 'cyberpanel.xyz'} while True: response = self.MakeRequest('websites/installWordpressStatus', data_ret) @@ -187,6 +197,50 @@ phpinfo(); self.assertEqual(exists, 1) + def test_installJoomla(self): + + command = 'rm -rf /home/%s/public_html/' % ('cyberpanel.xyz') + ProcessUtilities.normalExecutioner(command) + + command = 'mkdir /home/%s/public_html/' % ('cyberpanel.xyz') + ProcessUtilities.normalExecutioner(command) + + command = 'chown cyberpa:cyberpa /home/%s/public_html/' % ('cyberpanel.xyz') + ProcessUtilities.normalExecutioner(command) + + ## Suspend check + data_ret = {'domain': 'cyberpanel.xyz', 'home': '1', 'sitename': 'Unit Test Joomla', 'username': 'cyberpanel', + 'passwordByPass': 'helloworld', 'prefix': 'db_'} + + response = self.MakeRequest('websites/installJoomla', data_ret) + logging.writeToFile('jl: ' + str(response)) + time.sleep(2) + + self.assertEqual(response['status'], 1) + tempStatusPath = response['tempStatusPath'] + + ## Wait for install to complete + + data_ret = {'statusFile': tempStatusPath, 'domainName': 'cyberpanel.xyz'} + + while True: + response = self.MakeRequest('websites/installWordpressStatus', data_ret) + time.sleep(1) + if response['abort'] == 1: + if response['installStatus'] == 1: + break + else: + logging.writeToFile(response['error_message']) + break + + + exists = 0 + + if self.MakeRequestRaw('http://cyberpanel.xyz').find('Unit Test Joomla') > -1: + exists = 1 + + self.assertEqual(exists, 1) + diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 986c9f2e5..38043a3b4 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -1804,17 +1804,7 @@ class WebsiteManager: statusFile.writelines('Downloading Joomla Core..,20') statusFile.close() - execPath = "/usr/local/CyberCP/bin/python2 " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" - - execPath = execPath + " installJoomla --virtualHostName " + domainName + \ - " --virtualHostUser " + externalApp + " --path " + finalPath + " --dbName " + dbName + \ - " --dbUser " + dbUser + " --dbPassword " + dbPassword + " --username " + username + \ - " --password " + password + " --prefix " + prefix + " --sitename '" + sitename + "'" \ - + " --tempStatusPath " + tempStatusPath - - # return execPath - - ProcessUtilities.popenExecutioner(execPath, externalApp) + virtualHostUtilities.installJoomla(domainName, finalPath, externalApp, dbName, dbUser, dbPassword, username, password, prefix, sitename, tempStatusPath) data_ret = {'status': 1, "installStatus": 1, 'tempStatusPath': tempStatusPath} json_data = json.dumps(data_ret)