diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index d7ee38f6a..b42ef1356 100644 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -39,6 +39,8 @@ class ApplicationInstaller(multi.Thread): self.detachRepo() elif self.installApp == 'changeBranch': self.changeBranch() + elif self.installApp == 'prestashop': + self.installPrestaShop() except BaseException, msg: logging.writeToFile( str(msg) + ' [ApplicationInstaller.run]') @@ -309,6 +311,242 @@ class ApplicationInstaller(multi.Thread): statusFile.close() return 0 + def installPrestaShop(self): + try: + + admin = self.extraArgs['admin'] + domainName = self.extraArgs['domainName'] + home = self.extraArgs['home'] + shopName = self.extraArgs['shopName'] + firstName = self.extraArgs['firstName'] + lastName = self.extraArgs['lastName'] + databasePrefix = self.extraArgs['databasePrefix'] + email = self.extraArgs['email'] + password = self.extraArgs['password'] + tempStatusPath = self.extraArgs['tempStatusPath'] + + + ### Check WP CLI + + + ## 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: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines( + "Maximum database limit reached for this website." + " [404]") + statusFile.close() + return 0 + + if Databases.objects.filter(dbName=dbName).exists() or Databases.objects.filter( + dbUser=dbUser).exists(): + statusFile = open(tempStatusPath, 'w') + statusFile.writelines( + "This database or user is already taken." + " [404]") + statusFile.close() + return 0 + + result = mysqlUtilities.createDatabase(dbName, dbUser, dbPassword) + + if result == 1: + pass + else: + statusFile = open(tempStatusPath, 'w') + statusFile.writelines( + "Not able to create database." + " [404]") + statusFile.close() + return 0 + + db = Databases(website=website, dbName=dbName, dbUser=dbUser) + db.save() + + + #### + + statusFile = open(tempStatusPath, 'w') + 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" + subprocess.call(shlex.split(command)) + + command = "sudo unzip -o prestashop_1.7.4.2.zip -d " + finalPath + subprocess.call(shlex.split(command)) + + command = "sudo unzip -o " + finalPath + "prestashop.zip -d " + finalPath + subprocess.call(shlex.split(command)) + + ## + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Configuring the installation,40') + statusFile.close() + + if home == '0': + path = self.extraArgs['path'] + finalURL = domainName + '/' + path + else: + finalURL = domainName + + statusFile = open(tempStatusPath, 'w') + statusFile.writelines('Installing and configuring PrestaShop..,60') + statusFile.close() + + command = "sudo php " + finalPath + "install/index_cli.php --domain=" + finalURL + \ + " --db_server=localhost --db_name=" + dbName + " --db_user=" + dbUser + " --db_password=" + dbPassword \ + + " --name='" + shopName + "' --firstname=" + firstName + " --lastname=" + lastName + \ + " --email=" + email + " --password=" + password + subprocess.call(shlex.split(command)) + + ## + + command = "sudo rm -rf" + finalPath + "install" + 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) + + command = "sudo rm -f prestashop_1.7.4.2.zip" + 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 + def setupGit(self): try: admin = self.extraArgs['admin'] diff --git a/static/images/icons/prestashop.png b/static/images/icons/prestashop.png new file mode 100644 index 000000000..0ab1d644c Binary files /dev/null and b/static/images/icons/prestashop.png differ diff --git a/static/websiteFunctions/websiteFunctions.js b/static/websiteFunctions/websiteFunctions.js index 9f1f53619..5ddcd5a96 100644 --- a/static/websiteFunctions/websiteFunctions.js +++ b/static/websiteFunctions/websiteFunctions.js @@ -566,6 +566,7 @@ app.controller('websitePages', function($scope, $http, $timeout, $window) { $scope.wordPressInstallURL = $("#domainNamePage").text() + "/wordpressInstall"; $scope.joomlaInstallURL = $("#domainNamePage").text() + "/joomlaInstall"; $scope.setupGit = $("#domainNamePage").text() + "/setupGit"; + $scope.installPrestaURL = $("#domainNamePage").text() + "/installPrestaShop"; $scope.domainAliasURL = "/websites/"+$("#domainNamePage").text()+"/domainAlias"; $scope.previewUrl = "/preview/"+$("#domainNamePage").text()+"/"; @@ -1443,6 +1444,7 @@ app.controller('websitePages', function($scope, $http, $timeout, $window) { }; + //////// SSL Part $scope.sslSaved = true; @@ -4720,4 +4722,197 @@ app.controller('setupGit', function($scope, $http, $timeout, $window) { }; +}); + +app.controller('installPrestaShopCTRL', 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.installPrestShop = 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/prestaShopInstall"; + + var home = "1"; + + if (typeof path !== 'undefined'){ + home = "0"; + } + + + var data = { + domain: domain, + home:home, + path:path, + shopName: $scope.shopName, + firstName: $scope.firstName, + lastName: $scope.lastName, + databasePrefix: $scope.databasePrefix, + email: $scope.email, + password: $scope.password + }; + + 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/static/images/icons/prestashop.png b/websiteFunctions/static/images/icons/prestashop.png new file mode 100644 index 000000000..0ab1d644c Binary files /dev/null and b/websiteFunctions/static/images/icons/prestashop.png differ diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 9f1f53619..5ddcd5a96 100644 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -566,6 +566,7 @@ app.controller('websitePages', function($scope, $http, $timeout, $window) { $scope.wordPressInstallURL = $("#domainNamePage").text() + "/wordpressInstall"; $scope.joomlaInstallURL = $("#domainNamePage").text() + "/joomlaInstall"; $scope.setupGit = $("#domainNamePage").text() + "/setupGit"; + $scope.installPrestaURL = $("#domainNamePage").text() + "/installPrestaShop"; $scope.domainAliasURL = "/websites/"+$("#domainNamePage").text()+"/domainAlias"; $scope.previewUrl = "/preview/"+$("#domainNamePage").text()+"/"; @@ -1443,6 +1444,7 @@ app.controller('websitePages', function($scope, $http, $timeout, $window) { }; + //////// SSL Part $scope.sslSaved = true; @@ -4720,4 +4722,197 @@ app.controller('setupGit', function($scope, $http, $timeout, $window) { }; +}); + +app.controller('installPrestaShopCTRL', 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.installPrestShop = 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/prestaShopInstall"; + + var home = "1"; + + if (typeof path !== 'undefined'){ + home = "0"; + } + + + var data = { + domain: domain, + home:home, + path:path, + shopName: $scope.shopName, + firstName: $scope.firstName, + lastName: $scope.lastName, + databasePrefix: $scope.databasePrefix, + email: $scope.email, + password: $scope.password + }; + + 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/installPrestaShop.html b/websiteFunctions/templates/websiteFunctions/installPrestaShop.html new file mode 100644 index 000000000..ef2a28091 --- /dev/null +++ b/websiteFunctions/templates/websiteFunctions/installPrestaShop.html @@ -0,0 +1,141 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Install PrestaShop - CyberPanel" %}{% endblock %} +{% block content %} + +{% load static %} +{% get_current_language as LANGUAGE_CODE %} + + +
+
+

{% trans "Install PrestaShop" %}

+

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

+
+ + +
+
+

+ {{ 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 a9a1577c8..6b2be8bb6 100644 --- a/websiteFunctions/templates/websiteFunctions/website.html +++ b/websiteFunctions/templates/websiteFunctions/website.html @@ -966,10 +966,10 @@
- + - + {% trans "Joomla" %} @@ -988,6 +988,19 @@
+ +
+ + + + + + {% trans "Prestashop" %} + + +
+ + diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index a6f46f6d0..da55fb78c 100644 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -88,6 +88,11 @@ urlpatterns = [ url(r'^installJoomla$', views.installJoomla, name='installJoomla'), url(r'^(?P([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?)/joomlaInstall$', views.joomlaInstall, name='joomlaInstall'), + ## PrestaShop Install + + url(r'^prestaShopInstall$', views.prestaShopInstall, name='prestaShopInstall'), + url(r'^(?P([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?)/installPrestaShop$', views.installPrestaShop, name='installPrestaShop'), + ## Git url(r'^(?P([\da-z\.-]+\.[a-z\.]{2,12}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?)/setupGit$', views.setupGit, name='setupGit'), diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index e5ed1809c..c50d0fbdf 100644 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -2345,7 +2345,6 @@ def joomlaInstall(request, domain): except KeyError: return redirect(loadLoginPage) - def installJoomla(request): try: val = request.session['userID'] @@ -2672,4 +2671,70 @@ def changeBranch(request): except KeyError, msg: status = {"status":0,"error":str(msg)} logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installWordpress]") + return HttpResponse("Not Logged in as admin") + +def installPrestaShop(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/installPrestaShop.html', {'domainName' : domain}) + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return HttpResponse(str(msg)) + except KeyError: + return redirect(loadLoginPage) + +def prestaShopInstall(request): + try: + val = request.session['userID'] + admin = Administrator.objects.get(id=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['shopName'] = data['shopName'] + extraArgs['firstName'] = data['firstName'] + extraArgs['lastName'] = data['lastName'] + extraArgs['databasePrefix'] = data['databasePrefix'] + extraArgs['email'] = data['email'] + extraArgs['password'] = data['password'] + extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) + + if data['home'] == '0': + extraArgs['path'] = data['path'] + + background = ApplicationInstaller('prestashop', extraArgs) + background.start() + + time.sleep(2) + + data_ret = {'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 = {'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) + "[installJoomla]") return HttpResponse("Not Logged in as admin") \ No newline at end of file