diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 76e547948..79ec37dd8 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -20,12 +20,14 @@ from plogical.mailUtilities import mailUtilities from plogical.processUtilities import ProcessUtilities + class ApplicationInstaller(multi.Thread): def __init__(self, installApp, extraArgs): multi.Thread.__init__(self) self.installApp = installApp self.extraArgs = extraArgs + self.tempStatusPath = self.extraArgs['tempStatusPath'] def run(self): try: @@ -45,10 +47,91 @@ class ApplicationInstaller(multi.Thread): self.installPrestaShop() elif self.installApp == 'magento': self.installMagento() + elif self.installApp == 'convertDomainToSite': + self.convertDomainToSite() except BaseException as msg: logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]') + def convertDomainToSite(self): + try: + + from websiteFunctions.website import WebsiteManager + import json, time + + request = self.extraArgs['request'] + + ## + + statusFile = open(self.tempStatusPath, 'w') + statusFile.writelines('Deleting domain as child..,20') + statusFile.close() + + data = json.loads(request.body) + + domainName = data['domainName'] + + childDomain = ChildDomains.objects.get(domain=domainName) + path = childDomain.path + + wm = WebsiteManager() + + wm.submitDomainDeletion(request.session['userID'], {'websiteName': domainName}) + time.sleep(5) + + ## + + statusFile = open(self.tempStatusPath, 'w') + statusFile.writelines('Creating domain as website..,40') + statusFile.close() + + resp = wm.submitWebsiteCreation(request.session['userID'], data) + respData = json.loads(resp.content.decode('utf-8')) + + ## + + while True: + respDataStatus = ProcessUtilities.outputExecutioner("cat " + respData['tempStatusPath']) + + if respDataStatus.find('[200]') > -1: + break + elif respDataStatus.find('[404]') > -1: + statusFile = open(self.tempStatusPath, 'w') + statusFile.writelines(respDataStatus['currentStatus'] + ' [404]') + statusFile.close() + return 0 + else: + statusFile = open(self.tempStatusPath, 'w') + statusFile.writelines(respDataStatus) + statusFile.close() + time.sleep(1) + + statusFile = open(self.tempStatusPath, 'w') + statusFile.writelines('Moving data..,80') + statusFile.close() + + + command = 'rm -rf /home/%s/public_html' % (domainName) + ProcessUtilities.executioner(command) + + command = 'mv %s /home/%s/public_html' % (path, domainName) + ProcessUtilities.executioner(command) + + website = Websites.objects.get(domain=domainName) + + command = 'chown %s:%s /home/%s/public_html' % (website.externalApp, website.externalApp, domainName) + ProcessUtilities.executioner(command) + + statusFile = open(self.tempStatusPath, 'w') + statusFile.writelines('Successfully converted. [200]') + statusFile.close() + + except BaseException as msg: + statusFile = open(self.tempStatusPath, 'w') + statusFile.writelines(str(msg) + " [404]") + statusFile.close() + return 0 + def installWPCLI(self): try: command = 'sudo wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar' diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 4dc95911a..f39abf516 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -378,7 +378,7 @@ app.controller('listWebsites', function ($scope, $http) { }); -app.controller('listChildDomainsMain', function ($scope, $http) { +app.controller('listChildDomainsMain', function ($scope, $http, $timeout) { $scope.currentPage = 1; @@ -525,6 +525,174 @@ app.controller('listChildDomainsMain', function ($scope, $http) { }; + $scope.initConvert = function(virtualHost){ + $scope.domainName = virtualHost; + }; + + var statusFile; + + $scope.installationProgress = true; + + $scope.convert = function () { + + $scope.cyberPanelLoading = false; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = true; + + $scope.currentStatus = "Starting creation.."; + + var ssl, dkimCheck, openBasedir; + + if ($scope.sslCheck === true) { + ssl = 1; + } else { + ssl = 0 + } + + if ($scope.dkimCheck === true) { + dkimCheck = 1; + } else { + dkimCheck = 0 + } + + if ($scope.openBasedir === true) { + openBasedir = 1; + } else { + openBasedir = 0 + } + + url = "/websites/convertDomainToSite"; + + + var data = { + package: $scope.packageForWebsite, + domainName: $scope.domainName, + adminEmail: $scope.adminEmail, + phpSelection: $scope.phpSelection, + websiteOwner: $scope.websiteOwner, + ssl: ssl, + dkimCheck: dkimCheck, + openBasedir: openBasedir + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.createWebSiteStatus === 1) { + statusFile = response.data.tempStatusPath; + getCreationStatus(); + } else { + + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + $scope.currentStatus = response.data.error_message; + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + } + + + }; + $scope.goBack = function () { + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.goBackDisable = true; + $("#installProgress").css("width", "0%"); + }; + + function getCreationStatus() { + + url = "/websites/installWordpressStatus"; + + var data = { + statusFile: statusFile + }; + + 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.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + $("#installProgress").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + } else { + + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + $scope.currentStatus = response.data.error_message; + + $("#installProgress").css("width", "0%"); + $scope.installPercentage = "0"; + $scope.goBackDisable = false; + + } + + } else { + $("#installProgress").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + } + + } + + function cantLoadInitialDatas(response) { + + $scope.cyberPanelLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.goBackDisable = false; + + } + + + } + }); diff --git a/websiteFunctions/templates/websiteFunctions/listChildDomains.html b/websiteFunctions/templates/websiteFunctions/listChildDomains.html index 06d738d57..668a9e0e6 100755 --- a/websiteFunctions/templates/websiteFunctions/listChildDomains.html +++ b/websiteFunctions/templates/websiteFunctions/listChildDomains.html @@ -15,137 +15,243 @@
- {% trans "On this page you can launch, list, modify and delete child domains from your server." %}
-
+ {% trans "On this page you can launch, list, modify and delete child domains from your server." %}