From 0faa12414027f1c7e6b05064bc3feacbc6951e63 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Thu, 7 Nov 2019 09:37:06 +0500 Subject: [PATCH] magento installer --- CyberCP/secMiddleware.py | 11 +- plogical/applicationInstaller.py | 219 ++++++++++++++++-- static/images/icons/magento.png | Bin 0 -> 2451 bytes .../websiteFunctions/websiteFunctions.js | 199 +++++++++++++++- .../websiteFunctions/installMagento.html | 160 +++++++++++++ .../websiteFunctions/launchChild.html | 17 +- .../templates/websiteFunctions/website.html | 11 + websiteFunctions/urls.py | 5 + websiteFunctions/views.py | 16 ++ websiteFunctions/website.py | 69 +++++- 10 files changed, 679 insertions(+), 28 deletions(-) create mode 100644 static/images/icons/magento.png create mode 100755 websiteFunctions/templates/websiteFunctions/installMagento.html diff --git a/CyberCP/secMiddleware.py b/CyberCP/secMiddleware.py index 7616412a5..b6de2c7ac 100755 --- a/CyberCP/secMiddleware.py +++ b/CyberCP/secMiddleware.py @@ -96,9 +96,14 @@ class secMiddleware: response = self.get_response(request) - #response['Strict-Transport-Security'] = "max-age=31536000; includeSubDomains; preload" response['X-XSS-Protection'] = "1; mode=block" + #response['Strict-Transport-Security'] = "max-age=31536000; includeSubDomains; preload" response['X-Frame-Options'] = "sameorigin" - response['Content-Security-Policy'] = "frame-ancestors jsdelivr.com" + response['Content-Security-Policy'] = "script-src 'self' https://www.jsdelivr.com" + response['Content-Security-Policy'] = "connect-src *;" + response['Content-Security-Policy'] = "font-src 'self' 'unsafe-inline' https://www.jsdelivr.com https://fonts.googleapis.com" + response['Content-Security-Policy'] = "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://www.jsdelivr.com https://cdnjs.cloudflare.com https://maxcdn.bootstrapcdn.com https://cdn.jsdelivr.net" + response['X-Content-Type-Options'] = "nosniff" + response['Referrer-Policy'] = "same-origin" - return response + return response \ No newline at end of file diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index a016aeb74..ac596f79c 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -1,7 +1,9 @@ #!/usr/local/CyberCP/bin/python2 -import os,sys +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 @@ -17,6 +19,7 @@ import shutil from plogical.mailUtilities import mailUtilities from plogical.processUtilities import ProcessUtilities + class ApplicationInstaller(multi.Thread): def __init__(self, installApp, extraArgs): @@ -40,9 +43,11 @@ class ApplicationInstaller(multi.Thread): self.changeBranch() elif self.installApp == 'prestashop': self.installPrestaShop() + elif self.installApp == 'magento': + self.installMagento() except BaseException, msg: - logging.writeToFile( str(msg) + ' [ApplicationInstaller.run]') + logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]') def installWPCLI(self): try: @@ -56,7 +61,7 @@ class ApplicationInstaller(multi.Thread): ProcessUtilities.executioner(command) except BaseException, msg: - logging.writeToFile( str(msg) + ' [ApplicationInstaller.installWPCLI]') + logging.writeToFile(str(msg) + ' [ApplicationInstaller.installWPCLI]') def dataLossCheck(self, finalPath, tempStatusPath): @@ -102,7 +107,7 @@ class ApplicationInstaller(multi.Thread): ProcessUtilities.executioner(command) except BaseException, msg: - logging.writeToFile( str(msg) + ' [ApplicationInstaller.installGit]') + logging.writeToFile(str(msg) + ' [ApplicationInstaller.installGit]') def dbCreation(self, tempStatusPath, website): try: @@ -182,7 +187,6 @@ class ApplicationInstaller(multi.Thread): else: finalPath = website.path - if website.master.package.dataBases > website.master.databases_set.all().count(): pass else: @@ -208,13 +212,12 @@ class ApplicationInstaller(multi.Thread): else: finalPath = "/home/" + domainName + "/public_html/" - if website.package.dataBases > website.databases_set.all().count(): pass else: statusFile = open(tempStatusPath, 'w') statusFile.writelines( - "Maximum database limit reached for this website." + " [404]") + "Maximum database limit reached for this website." + " [404]") statusFile.close() return 0 @@ -286,7 +289,6 @@ class ApplicationInstaller(multi.Thread): ## - command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath ProcessUtilities.executioner(command, externalApp) @@ -303,7 +305,6 @@ class ApplicationInstaller(multi.Thread): homeDir = "/home/" + domainName + "/public_html" if not os.path.exists(homeDir): - command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir ProcessUtilities.executioner(command, externalApp) @@ -383,7 +384,7 @@ class ApplicationInstaller(multi.Thread): else: statusFile = open(tempStatusPath, 'w') statusFile.writelines( - "Maximum database limit reached for this website." + " [404]") + "Maximum database limit reached for this website." + " [404]") statusFile.close() return 0 @@ -416,7 +417,8 @@ class ApplicationInstaller(multi.Thread): statusFile.writelines('Downloading and extracting PrestaShop Core..,30') statusFile.close() - command = "sudo wget https://download.prestashop.com/download/releases/prestashop_1.7.4.2.zip -P %s" % (finalPath) + command = "sudo wget https://download.prestashop.com/download/releases/prestashop_1.7.4.2.zip -P %s" % ( + finalPath) ProcessUtilities.executioner(command, externalApp) command = "sudo unzip -o %sprestashop_1.7.4.2.zip -d " % (finalPath) + finalPath @@ -433,7 +435,7 @@ class ApplicationInstaller(multi.Thread): if home == '0': path = self.extraArgs['path'] - #finalURL = domainName + '/' + path + # finalURL = domainName + '/' + path finalURL = domainName else: finalURL = domainName @@ -541,8 +543,6 @@ class ApplicationInstaller(multi.Thread): externalApp = website.externalApp finalPath = "/home/" + domainName + "/public_html/" - - ## Security Check if finalPath.find("..") > -1: @@ -551,7 +551,6 @@ class ApplicationInstaller(multi.Thread): statusFile.close() return 0 - command = 'sudo mkdir -p ' + finalPath ProcessUtilities.executioner(command, externalApp) @@ -567,11 +566,12 @@ class ApplicationInstaller(multi.Thread): statusFile.close() try: - command = 'git clone --depth 1 --no-single-branch git@' + defaultProvider +'.com:' + username + '/' + reponame + '.git -b ' + branch + ' ' + finalPath + command = 'git clone --depth 1 --no-single-branch git@' + defaultProvider + '.com:' + username + '/' + reponame + '.git -b ' + branch + ' ' + finalPath ProcessUtilities.executioner(command, externalApp) except subprocess.CalledProcessError, msg: statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Failed to clone repository, make sure you deployed your key to repository. [404]') + statusFile.writelines( + 'Failed to clone repository, make sure you deployed your key to repository. [404]') statusFile.close() return 0 @@ -622,7 +622,7 @@ class ApplicationInstaller(multi.Thread): logging.writeToFile('Git is not setup for this website.') return 0 - command = 'sudo git --git-dir=' + finalPath + '.git --work-tree=' + finalPath +' pull' + command = 'sudo git --git-dir=' + finalPath + '.git --work-tree=' + finalPath + ' pull' ProcessUtilities.executioner(command, externalApp) ## @@ -637,7 +637,7 @@ class ApplicationInstaller(multi.Thread): except BaseException, msg: - logging.writeToFile(str(msg)+ " [ApplicationInstaller.gitPull]") + logging.writeToFile(str(msg) + " [ApplicationInstaller.gitPull]") return 0 def detachRepo(self): @@ -661,7 +661,6 @@ class ApplicationInstaller(multi.Thread): childDomain = ChildDomains.objects.get(domain=domain) finalPath = childDomain.path - command = 'sudo rm -rf ' + finalPath ProcessUtilities.executioner(command, website.externalApp) @@ -681,7 +680,7 @@ class ApplicationInstaller(multi.Thread): except BaseException, msg: - logging.writeToFile(str(msg)+ " [ApplicationInstaller.gitPull]") + logging.writeToFile(str(msg) + " [ApplicationInstaller.gitPull]") return 0 def installJoomla(self): @@ -871,9 +870,185 @@ class ApplicationInstaller(multi.Thread): command = 'sudo git --git-dir=' + finalPath + '/.git checkout ' + githubBranch ProcessUtilities.executioner(command, externalApp) except subprocess.CalledProcessError, msg: - logging.writeToFile('Failed to change branch: ' + str(msg)) + logging.writeToFile('Failed to change branch: ' + str(msg)) return 0 return 0 except BaseException, msg: logging.writeToFile('Failed to change branch: ' + str(msg)) return 0 + + def installMagento(self): + try: + + username = self.extraArgs['username'] + domainName = self.extraArgs['domainName'] + home = self.extraArgs['home'] + firstName = self.extraArgs['firstName'] + lastName = self.extraArgs['lastName'] + email = self.extraArgs['email'] + password = self.extraArgs['password'] + tempStatusPath = self.extraArgs['tempStatusPath'] + sampleData = self.extraArgs['sampleData'] + + FNULL = open(os.devnull, 'w') + + ## Open Status File + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Setting up paths,0') + statusFile.close() + + finalPath = '' + + try: + website = ChildDomains.objects.get(domain=domainName) + externalApp = website.master.externalApp + + 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: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines( + "Maximum database limit reached for this website." + " [404]") + statusFile.close() + return 0 + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Setting up Database,20') + statusFile.close() + + dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website.master) + + except: + website = Websites.objects.get(domain=domainName) + externalApp = website.externalApp + + 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: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines( + "Maximum database limit reached for this website." + " [404]") + statusFile.close() + return 0 + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Setting up Database,20') + statusFile.close() + + dbName, dbUser, dbPassword = self.dbCreation(tempStatusPath, website) + + ## 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 + + if not os.path.exists(finalPath): + command = 'sudo mkdir -p ' + finalPath + ProcessUtilities.executioner(command, externalApp) + + ## checking for directories/files + + if self.dataLossCheck(finalPath, tempStatusPath) == 0: + return 0 + + #### + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Downloading and extracting Magento Core..,30') + statusFile.close() + + if sampleData: + command = "sudo wget http://cyberpanelsh.b-cdn.net/latest-sample.tar.gz -P %s" % (finalPath) + else: + command = "sudo wget http://cyberpanelsh.b-cdn.net/latest.tar.gz -P %s" % (finalPath) + + ProcessUtilities.executioner(command, externalApp) + + if sampleData: + command = 'tar -xf %slatest-sample.tar.gz --directory %s' % (finalPath, finalPath) + else: + command = 'tar -xf %slatest.tar.gz --directory %s' % (finalPath, finalPath) + + ProcessUtilities.executioner(command, externalApp) + + ## + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Configuring the installation,40') + statusFile.close() + + if home == '0': + path = self.extraArgs['path'] + # finalURL = domainName + '/' + path + finalURL = domainName + else: + finalURL = domainName + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Installing and configuring Magento..,60') + statusFile.close() + + command = '/usr/local/lsws/lsphp72/bin/php -d memory_limit=512M %sbin/magento setup:install --backend-frontname="admin" ' \ + '--db-host="localhost" --db-name="%s" --db-user="%s" --db-password="%s" ' \ + '--base-url="http://%s" --base-url-secure="https://%s/" --admin-user="%s" ' \ + '--admin-password="%s" --admin-email="%s" --admin-firstname="%s" --admin-lastname="%s"' \ + % (finalPath, dbName, dbUser, dbPassword, finalURL, finalURL, username, password, email, firstName, lastName) + result = ProcessUtilities.outputExecutioner(command, externalApp) + logging.writeToFile(result) + + ## + + if sampleData: + command = 'rm -rf %slatest-sample.tar.gz' % (finalPath) + else: + command = 'rm -rf %slatest.tar.gz' % (finalPath) + + ProcessUtilities.executioner(command, externalApp) + + ## + + command = "sudo chown -R " + externalApp + ":" + externalApp + " " + finalPath + ProcessUtilities.executioner(command, externalApp) + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines("Successfully Installed. [200]") + statusFile.close() + return 0 + + + except BaseException, msg: + # remove the downloaded files + + homeDir = "/home/" + domainName + "/public_html" + + if not os.path.exists(homeDir): + command = "sudo chown -R " + externalApp + ":" + externalApp + " " + homeDir + ProcessUtilities.executioner(command, externalApp) + + 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/static/images/icons/magento.png b/static/images/icons/magento.png new file mode 100644 index 0000000000000000000000000000000000000000..d32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unctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 9f22ba41b..9700d7d3d 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -634,6 +634,7 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { $scope.joomlaInstallURL = $("#domainNamePage").text() + "/joomlaInstall"; $scope.setupGit = $("#domainNamePage").text() + "/setupGit"; $scope.installPrestaURL = $("#domainNamePage").text() + "/installPrestaShop"; + $scope.installMagentoURL = $("#domainNamePage").text() + "/installMagento"; $scope.domainAliasURL = "/websites/" + $("#domainNamePage").text() + "/domainAlias"; $scope.previewUrl = "/preview/" + $("#domainNamePage").text() + "/"; @@ -3099,6 +3100,7 @@ app.controller('launchChild', function ($scope, $http) { $scope.joomlaInstallURL = "/websites/" + $("#childDomain").text() + "/joomlaInstall"; $scope.setupGit = "/websites/" + $("#childDomain").text() + "/setupGit"; $scope.installPrestaURL = "/websites/" + $("#childDomain").text() + "/installPrestaShop"; + $scope.installMagentoURL = "/websites/" + $("#childDomain").text() + "/installMagento"; var logType = 0; $scope.pageNumber = 1; @@ -5238,4 +5240,199 @@ app.controller('syncWebsite', function ($scope, $http, $timeout, $window) { } }); -/* Java script code to syncWebsite ends here */ \ No newline at end of file +/* Java script code to syncWebsite ends here */ + + +app.controller('installMagentoCTRL', 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; + + $scope.databasePrefix = 'ps_'; + + 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%"); + }; + + 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.installMagento = 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/magentoInstall"; + + var home = "1"; + + if (typeof path !== 'undefined') { + home = "0"; + } + var sampleData; + if ($scope.sampleData === true) { + sampleData = 1; + } else { + sampleData = 0 + } + + + var data = { + domain: domain, + home: home, + path: path, + firstName: $scope.firstName, + lastName: $scope.lastName, + username: $scope.username, + email: $scope.email, + passwordByPass: $scope.password, + sampleData: sampleData + }; + + 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) { + } + + }; + + +}); \ No newline at end of file diff --git a/websiteFunctions/templates/websiteFunctions/installMagento.html b/websiteFunctions/templates/websiteFunctions/installMagento.html new file mode 100755 index 000000000..2235b8c82 --- /dev/null +++ b/websiteFunctions/templates/websiteFunctions/installMagento.html @@ -0,0 +1,160 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Install Magento - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + +
+
+

{% trans "Install Magento" %}

+

{% trans "One-click Magento Install!" %}

+
+ + +
+
+

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

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

+ LiteMage + Cache + Plugin {% trans "does not work on OpenLiteSpeed. It is highly recommended to use this installer with LiteSpeed Enterprise only." %} +

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

{$ 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/launchChild.html b/websiteFunctions/templates/websiteFunctions/launchChild.html index 2fd80a79c..8015d430d 100755 --- a/websiteFunctions/templates/websiteFunctions/launchChild.html +++ b/websiteFunctions/templates/websiteFunctions/launchChild.html @@ -26,7 +26,10 @@

{% trans "Resource Usage" %} - {% trans "Copy/Sync to Master" %} + {% trans "Copy/Sync to Master" %}

@@ -716,6 +719,18 @@
+ + + diff --git a/websiteFunctions/templates/websiteFunctions/website.html b/websiteFunctions/templates/websiteFunctions/website.html index 5db506f98..abd8ad9bc 100755 --- a/websiteFunctions/templates/websiteFunctions/website.html +++ b/websiteFunctions/templates/websiteFunctions/website.html @@ -1024,6 +1024,17 @@ + + diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index 08beb86e8..5441dddf2 100755 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -88,6 +88,11 @@ urlpatterns = [ url(r'^prestaShopInstall$', views.prestaShopInstall, name='prestaShopInstall'), url(r'^(?P(.*))/installPrestaShop$', views.installPrestaShop, name='installPrestaShop'), + ## magento + + url(r'^(?P(.*))/installMagento$', views.installMagento, name='installMagento'), + url(r'^magentoInstall$', views.magentoInstall, name='magentoInstall'), + ## Git url(r'^(?P(.*))/setupGit$', views.setupGit, name='setupGit'), diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 16c12fff5..0528ee6a7 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -606,6 +606,22 @@ def installPrestaShop(request, domain): except KeyError: return redirect(loadLoginPage) +def installMagento(request, domain): + try: + userID = request.session['userID'] + wm = WebsiteManager(domain) + return wm.installMagento(request, userID) + except KeyError: + return redirect(loadLoginPage) + +def magentoInstall(request): + try: + userID = request.session['userID'] + wm = WebsiteManager() + return wm.magentoInstall(userID, json.loads(request.body)) + except KeyError: + return redirect(loadLoginPage) + def prestaShopInstall(request): try: userID = request.session['userID'] diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 5496397e0..b3a32ec80 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -2020,6 +2020,68 @@ StrictHostKeyChecking no except BaseException, msg: return HttpResponse(str(msg)) + def installMagento(self, request=None, userID=None, data=None): + try: + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadError() + + return render(request, 'websiteFunctions/installMagento.html', {'domainName': self.domain}) + except BaseException, msg: + return HttpResponse(str(msg)) + + + def magentoInstall(self, userID=None, data=None): + try: + + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + self.domain = data['domain'] + + if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadErrorJson('installStatus', 0) + + mailUtilities.checkHome() + + extraArgs = {} + extraArgs['admin'] = admin + extraArgs['domainName'] = data['domain'] + extraArgs['home'] = data['home'] + extraArgs['firstName'] = data['firstName'] + extraArgs['lastName'] = data['lastName'] + extraArgs['username'] = data['username'] + extraArgs['email'] = data['email'] + extraArgs['password'] = data['passwordByPass'] + extraArgs['sampleData'] = data['sampleData'] + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + + if data['home'] == '0': + extraArgs['path'] = data['path'] + + background = ApplicationInstaller('magento', extraArgs) + background.start() + + time.sleep(2) + + data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None', + 'tempStatusPath': extraArgs['tempStatusPath']} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + ## Installation ends + + except BaseException, msg: + data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + def prestaShopInstall(self, userID=None, data=None): try: @@ -2086,6 +2148,11 @@ StrictHostKeyChecking no except: websitesLimit = 1 + try: + apiACL = data['acl'] + except: + apiACL = 'user' + admin = Administrator.objects.get(userName=adminUser) if hashPassword.check_password(admin.password, adminPass): @@ -2094,7 +2161,7 @@ StrictHostKeyChecking no data['adminEmail'] = "usman@cyberpersons.com" try: - acl = ACL.objects.get(name='user') + acl = ACL.objects.get(name=apiACL) websiteOwn = Administrator(userName=websiteOwner, password=hashPassword.hash_password(ownerPassword), email=adminEmail, type=3, owner=admin.pk,