From f28402cebb6f14195e61c0536e9481e66a1314d8 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Fri, 9 Feb 2024 17:58:28 +0500 Subject: [PATCH] bug fix: alias domains, php fetch and domain with sudo --- CLScript/CloudLinuxDomains.py | 1 + plogical/IncScheduler.py | 1 - plogical/childDomain.py | 4 +- plogical/phpUtilities.py | 8 +- plogical/processUtilities.py | 3 +- plogical/sslUtilities.py | 51 +- plogical/upgrade.py | 7 + plogical/virtualHostUtilities.py | 11 +- websiteFunctions/models.py | 2 + .../websiteFunctions/websiteFunctions.js | 645 +++++++++++++++++- .../websiteFunctions/domainAlias.html | 307 ++++++--- websiteFunctions/website.py | 62 +- 12 files changed, 955 insertions(+), 147 deletions(-) diff --git a/CLScript/CloudLinuxDomains.py b/CLScript/CloudLinuxDomains.py index 64201546e..8f0355394 100755 --- a/CLScript/CloudLinuxDomains.py +++ b/CLScript/CloudLinuxDomains.py @@ -51,6 +51,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='CyberPanel CloudLinux Manager') parser.add_argument('-o', '--owner', help='Owner') parser.add_argument('-n', '--name', help='Owner') + parser.add_argument('-p', '--with-php', help='False (X-Ray support only)') args = parser.parse_args() diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py index db13428c7..77d6c7ed2 100644 --- a/plogical/IncScheduler.py +++ b/plogical/IncScheduler.py @@ -533,7 +533,6 @@ class IncScheduler(multi.Thread): if result.find(pid) > -1 and result.find('IncScheduler.py') > -1: quit(1) - except: ### Save some important info in backup config oldJobContinue = 0 diff --git a/plogical/childDomain.py b/plogical/childDomain.py index af1e385f8..2e74af4ab 100755 --- a/plogical/childDomain.py +++ b/plogical/childDomain.py @@ -15,9 +15,9 @@ class ChildDomainManager: self.masterDomain = masterDomain self.childDomain = childDomain - def findChildDomainsJson(self): + def findChildDomainsJson(self, alias=0): master = Websites.objects.get(domain=self.masterDomain) - childDomains = master.childdomains_set.all() + childDomains = master.childdomains_set.filter(alais=alias) json_data = "[" checker = 0 diff --git a/plogical/phpUtilities.py b/plogical/phpUtilities.py index fd56ff7ba..ab318fd0a 100755 --- a/plogical/phpUtilities.py +++ b/plogical/phpUtilities.py @@ -266,7 +266,7 @@ class phpUtilities: if os.path.exists(ProcessUtilities.debugPath): logging.CyberCPLogFileWriter.writeToFile(result) - command = result + " -v | awk '/^PHP/ {print $2}'" + command = result + " -v 2>/dev/null | awk '/^PHP/ {print $2}'" php_version = ProcessUtilities.outputExecutioner(command, None, True).rstrip('\n') return f"PHP {php_version}" @@ -291,8 +291,6 @@ class phpUtilities: return PHPManager.findPHPVersions()[-2] - - @staticmethod def InstallSaidPHP(php): if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20: @@ -305,10 +303,6 @@ class phpUtilities: - - - - def main(): parser = argparse.ArgumentParser(description='CyberPanel Installer') diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index 3d6164f5b..29645ba9a 100755 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -245,8 +245,9 @@ class ProcessUtilities(multi.Thread): command = '%s-u %s %s' % (ProcessUtilities.token, user, command) else: command = '%s-u %s -d %s %s' % (ProcessUtilities.token, user, dir, command) - command = command.replace('sudo', '') + if command.startswith('sudo'): + command = command.replace('sudo', '', 1) # Replace 'sudo' with an empty string, only once if os.path.exists(ProcessUtilities.debugPath): if command.find('cat') == -1: diff --git a/plogical/sslUtilities.py b/plogical/sslUtilities.py index fa4d249b2..665d55ff5 100755 --- a/plogical/sslUtilities.py +++ b/plogical/sslUtilities.py @@ -37,6 +37,10 @@ class sslUtilities: if san_extension: # Extract and print the domains from SAN san_domains = san_extension.value.get_values_for_type(x509.DNSName) + try: + logging.CyberCPLogFileWriter.writeToFile(f'Covered domains: {str(san_domains)}') + except: + pass return 1, san_domains else: # If SAN is not present, return the Common Name as a fallback @@ -54,19 +58,51 @@ class sslUtilities: x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, open(filePath, 'r').read()) SSLProvider = x509.get_issuer().get_components()[1][1].decode('utf-8') - if SSLProvider != 'Denial': - return sslUtilities.ISSUE_SSL - else: - status, domains = sslUtilities.getDomainsCovered(filePath) + + #### totally seprate check to see if both non-www and www are covered + + if SSLProvider == "Let's Encrypt": + status, domains = sslUtilities.getDomainsCovered(filePath) if status: if len(domains) > 1: - return sslUtilities.DONT_ISSUE + ### need further checks here to see if ssl is valid for less then 15 days etc + logging.CyberCPLogFileWriter.writeToFile( + '[CheckIfSSLNeedsToBeIssued] SSL exists for %s and both versions are covered, just need to ensure if SSL is valid for less then 15 days.' % (virtualHostName), 0) + pass else: return sslUtilities.ISSUE_SSL - else: - return sslUtilities.ISSUE_SSL + ##### + + expireData = x509.get_notAfter().decode('ascii') + from datetime import datetime + finalDate = datetime.strptime(expireData, '%Y%m%d%H%M%SZ') + now = datetime.now() + diff = finalDate - now + + if int(diff.days) >= 15 and SSLProvider!='Denial': + logging.CyberCPLogFileWriter.writeToFile( + '[CheckIfSSLNeedsToBeIssued] SSL exists for %s and is not ready to fetch new SSL., skipping..' % ( + virtualHostName), 0) + + return sslUtilities.DONT_ISSUE + elif SSLProvider == 'Denial': + logging.CyberCPLogFileWriter.writeToFile( + f'[CheckIfSSLNeedsToBeIssued] Self-signed SSL found, lets issue new SSL for {virtualHostName}', 0) + return sslUtilities.ISSUE_SSL + elif SSLProvider != "Let's Encrypt": + logging.CyberCPLogFileWriter.writeToFile( + f'[CheckIfSSLNeedsToBeIssued] Custom SSL found for {virtualHostName}', 0) + return sslUtilities.DONT_ISSUE + else: + logging.CyberCPLogFileWriter.writeToFile( + f'[CheckIfSSLNeedsToBeIssued] We will issue SSL for {virtualHostName}', 0) + return sslUtilities.ISSUE_SSL + else: + logging.CyberCPLogFileWriter.writeToFile( + f'[CheckIfSSLNeedsToBeIssued] We will issue SSL for {virtualHostName}', 0) + return sslUtilities.ISSUE_SSL @staticmethod def checkIfSSLMap(virtualHostName): @@ -435,6 +471,7 @@ context /.well-known/acme-challenge { @staticmethod def obtainSSLForADomain(virtualHostName, adminEmail, sslpath, aliasDomain=None): + from plogical.acl import ACLManager from plogical.sslv2 import sslUtilities as sslv2 import json diff --git a/plogical/upgrade.py b/plogical/upgrade.py index f30779703..db6ea97a7 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -2047,6 +2047,13 @@ CREATE TABLE `websiteFunctions_backupsv2` (`id` integer AUTO_INCREMENT NOT NULL except: pass + query = "ALTER TABLE `websiteFunctions_childdomains` ADD `alais` INT NOT NULL DEFAULT '0' AFTER `master_id`; " + try: + cursor.execute(query) + except: + pass + + try: connection.close() except: diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index a5a897db7..17ba04849 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -1243,7 +1243,7 @@ class virtualHostUtilities: @staticmethod def createDomain(masterDomain, virtualHostName, phpVersion, path, ssl, dkimCheck, openBasedir, owner, apache, - tempStatusPath='/home/cyberpanel/fakePath', LimitsCheck=1): + tempStatusPath='/home/cyberpanel/fakePath', LimitsCheck=1, alias = 0): try: logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Running some checks..,0') @@ -1336,7 +1336,7 @@ class virtualHostUtilities: if LimitsCheck: website = ChildDomains(master=master, domain=virtualHostName, path=path, phpSelection=phpVersion, - ssl=ssl) + ssl=ssl, alais=alias) website.save() if ssl == 1: @@ -1852,9 +1852,14 @@ def main(): except: tempStatusPath = '/home/cyberpanel/fakePath' + try: + aliasDomain = int(args.aliasDomain) + except: + aliasDomain = 0 + virtualHostUtilities.createDomain(args.masterDomain, args.virtualHostName, args.phpVersion, args.path, int(args.ssl), dkimCheck, openBasedir, args.websiteOwner, apache, - tempStatusPath) + tempStatusPath, 1, aliasDomain) elif args.function == "issueSSL": virtualHostUtilities.issueSSL(args.virtualHostName, args.path, args.administratorEmail) elif args.function == "issueSSLv2": diff --git a/websiteFunctions/models.py b/websiteFunctions/models.py index 91c377cfa..daa46c36e 100755 --- a/websiteFunctions/models.py +++ b/websiteFunctions/models.py @@ -27,6 +27,8 @@ class ChildDomains(models.Model): path = models.CharField(max_length=200,default=None) ssl = models.IntegerField() phpSelection = models.CharField(max_length=10,default=None) + alais = models.IntegerField(default=0) + class Backups(models.Model): website = models.ForeignKey(Websites,on_delete=models.CASCADE) diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 5ba902fde..5dd72b4c9 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -4829,7 +4829,6 @@ app.controller('websitePages', function ($scope, $http, $timeout, $window) { } - $scope.changePHP = function (childDomain, phpSelection) { // notifcations @@ -5775,12 +5774,15 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind $scope.showAliasForm = function (domainName) { - $scope.domainAliasForm = false; - $scope.aliasTable = true; - $scope.addAliasButton = true; + //$scope.domainAliasForm = false; + //$scope.aliasTable = true; + //$scope.addAliasButton = true; masterDomain = domainName; + $scope.showCreateDomainForm(); + $scope.masterDomain = domainName; + }; $scope.addAliasFunc = function () { @@ -6010,6 +6012,641 @@ app.controller('manageAliasController', function ($scope, $http, $timeout, $wind }; + ////// create domain part + + $("#domainCreationForm").hide(); + + $scope.showCreateDomainForm = function () { + $("#domainCreationForm").fadeIn(); + }; + + $scope.hideDomainCreationForm = function () { + $("#domainCreationForm").fadeOut(); + }; + + $scope.masterDomain = $("#domainNamePage").text(); + + // notifcations settings + $scope.domainLoading = true; + $scope.installationDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.DomainCreateForm = true; + + var statusFile; + + + $scope.webselection = true; + $scope.WebsiteType = function () { + var type = $scope.websitetype; + if (type == 'Sub Domain') { + $scope.webselection = false; + $scope.DomainCreateForm = true; + + } else if (type == 'Addon Domain') { + $scope.DomainCreateForm = false; + $scope.webselection = true; + $scope.masterDomain = $('#defaultSite').html() + } + }; + + $scope.WebsiteSelection = function () { + $scope.DomainCreateForm = false; + }; + + $scope.createDomain = function () { + + $scope.domainLoading = false; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.currentStatus = "Starting creation.."; + $scope.DomainCreateForm = true; + + var ssl, dkimCheck, openBasedir, apacheBackend; + + if ($scope.sslCheck === true) { + ssl = 1; + } else { + ssl = 0 + } + + if ($scope.dkimCheck === true) { + dkimCheck = 1; + } else { + dkimCheck = 0 + } + + openBasedir = 0; + + + apacheBackend = 0 + + + url = "/websites/submitDomainCreation"; + var domainName = $scope.domainNameCreate; + + var path = $scope.docRootPath; + + if (typeof path === 'undefined') { + path = ""; + } + + var domainName = $scope.domainNameCreate; + + + var data = { + domainName: domainName, + ssl: ssl, + path: path, + masterDomain: $scope.masterDomain, + dkimCheck: 1, + openBasedir: 0, + alias: 1 + }; + + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + // console.log(data) + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + if (response.data.createWebSiteStatus === 1) { + statusFile = response.data.tempStatusPath; + getCreationStatus(); + } else { + + $scope.domainLoading = true; + $scope.installationDetailsForm = true; + $scope.DomainCreateForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = false; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.domainLoading = true; + $scope.installationDetailsForm = true; + $scope.DomainCreateForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + }; + + $scope.goBack = function () { + $scope.domainLoading = true; + $scope.installationDetailsForm = false; + $scope.DomainCreateForm = true; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.DomainCreateForm = 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.domainLoading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = false; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $("#installProgress").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + fetchDomains(); + + } else { + + $scope.domainLoading = true; + $scope.installationDetailsForm = true; + $scope.DomainCreateForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = false; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $scope.errorMessage = 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.domainLoading = true; + $scope.installationDetailsForm = true; + $scope.DomainCreateForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + + ////// List Domains Part + + //////////////////////// + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.childBaseDirChanged = true; + + fetchDomains(); + + $scope.showListDomains = function () { + fetchDomains(); + $("#listDomains").fadeIn(); + }; + + $scope.hideListDomains = function () { + $("#listDomains").fadeOut(); + }; + + function fetchDomains() { + $scope.domainLoading = false; + + var url = "/websites/fetchDomains"; + + var data = { + masterDomain: $("#domainNamePage").text(), + alias: 1 + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.fetchStatus === 1) { + + $scope.childDomains = JSON.parse(response.data.data); + $scope.domainLoading = true; + + + } else { + $scope.domainError = false; + $scope.errorMessage = response.data.error_message; + $scope.domainLoading = true; + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.couldNotConnect = false; + + } + + } + + $scope.changePHP = function (childDomain, phpSelection) { + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.domainLoading = false; + $scope.childBaseDirChanged = true; + + var url = "/websites/changePHP"; + + var data = { + childDomain: childDomain, + phpSelection: phpSelection, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.changePHP === 1) { + + $scope.domainLoading = true; + + $scope.changedPHPVersion = phpSelection; + + + // notifcations + + $scope.phpChanged = false; + $scope.domainError = true; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.childBaseDirChanged = true; + + + } else { + $scope.errorMessage = response.data.error_message; + $scope.domainLoading = true; + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = false; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.childBaseDirChanged = true; + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.domainLoading = true; + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = false; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.childBaseDirChanged = true; + + } + + }; + + $scope.changeChildBaseDir = function (childDomain, openBasedirValue) { + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.domainLoading = false; + $scope.childBaseDirChanged = true; + + + var url = "/websites/changeOpenBasedir"; + + var data = { + domainName: childDomain, + openBasedirValue: openBasedirValue + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.changeOpenBasedir === 1) { + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.domainLoading = true; + $scope.childBaseDirChanged = false; + + } else { + + $scope.phpChanged = true; + $scope.domainError = false; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.domainLoading = true; + $scope.childBaseDirChanged = true; + + $scope.errorMessage = response.data.error_message; + + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = false; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.domainLoading = true; + $scope.childBaseDirChanged = true; + + + } + + } + + $scope.deleteChildDomain = function (childDomain) { + $scope.domainLoading = false; + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + + url = "/websites/submitDomainDeletion"; + + var data = { + websiteName: childDomain, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.websiteDeleteStatus === 1) { + + $scope.domainLoading = true; + $scope.deletedDomain = childDomain; + + fetchDomains(); + + + // notifications + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = true; + $scope.domainDeleted = false; + $scope.sslIssued = true; + + + } else { + $scope.errorMessage = response.data.error_message; + $scope.domainLoading = true; + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = false; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + } + + + } + + function cantLoadInitialDatas(response) { + + $scope.domainLoading = true; + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = false; + $scope.domainDeleted = true; + $scope.sslIssued = true; + + } + + }; + + $scope.issueSSL = function (childDomain, path) { + $scope.domainLoading = false; + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.childBaseDirChanged = true; + + var url = "/manageSSL/issueSSL"; + + + var data = { + virtualHost: childDomain, + path: path, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + + if (response.data.SSL === 1) { + + $scope.domainLoading = true; + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = false; + $scope.childBaseDirChanged = true; + + + $scope.sslDomainIssued = childDomain; + + + } else { + $scope.domainLoading = true; + + $scope.errorMessage = response.data.error_message; + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = false; + $scope.couldNotConnect = true; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.childBaseDirChanged = true; + + } + + + } + + function cantLoadInitialDatas(response) { + + // notifcations + + $scope.phpChanged = true; + $scope.domainError = true; + $scope.couldNotConnect = false; + $scope.domainDeleted = true; + $scope.sslIssued = true; + $scope.childBaseDirChanged = true; + + + } + + + }; + + }); /* Java script code to manage cron ends here */ diff --git a/websiteFunctions/templates/websiteFunctions/domainAlias.html b/websiteFunctions/templates/websiteFunctions/domainAlias.html index 7c7ff33c4..0c5a34ea6 100755 --- a/websiteFunctions/templates/websiteFunctions/domainAlias.html +++ b/websiteFunctions/templates/websiteFunctions/domainAlias.html @@ -3,144 +3,225 @@ {% block title %}{% trans "Domain Aliases - CyberPanel" %}{% endblock %} {% block content %} -{% load static %} -{% get_current_language as LANGUAGE_CODE %} - + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + -
-
-

{% trans "Domain Aliases" %}

-

{% trans "With Domain Aliases you can visit example.com using example.net and view the same content." %}

-
+
+
+

{% trans "Domain Aliases" %}

+

{% trans "With Domain Aliases you can visit example.com using example.net and view the same content." %}

+
-
-
-

- {% trans "Domain Aliases" %} -

-
+
+
+

+ {% trans "Domain Aliases" %} +

+
-
+ - -
-
- -
-
- - - - - - - - - - - + - {% if noAlias == 1 %} - - {% for alias in aliases %} - - - - - - - - - {% endfor %} - {% else %} - - - - - - - - {% endif %} - - -
{% trans "Master Domain" %}{% trans "Alias" %}{% trans "File System Path" %}{% trans "SSL" %}{% trans "Delete" %}
{{ masterDomain }}{{ alias }}{{ path }} - -
{{ masterDomain }}{% trans 'Domain Aliases not found.' %}
- - - -
- - - -
- -
- + +
+
+
-
- -
-
- + + + +
+
+ +
+ +
+ +
+
+ +

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

{$ currentStatus $}

+
+ +
+
+ 70% Complete
-
-
- -
- -
- -
+
+

{% trans "Error message:" %} {$ errorMessage $}

+
+ +
+

{% trans "Website succesfully created." %}

+
+ + +
+

{% trans "Could not connect to server. Please refresh this page." %}

+
+ + +
+
+ +
+ +
+ +
+
+ + +
-
-
- -
-
-

{% trans "Operation failed. Error message:" %} {$ errorMessage $}

+ + + + +
+ +
+ + +
+

{% trans "PHP Version Changed to:" %} {$ changedPHPVersion $}

+
+ +
+

{% trans "Deleted:" %} {$ deletedDomain $}

+
+ +
+

{% trans "SSL Issued:" %} {$ sslDomainIssued $}

+
+ +
+

{% trans "Changes applied successfully." %}

+
+ + +
+

{$ errorMessage $}

+
+ + +
+

{% trans "Could not connect to server. Please refresh this page." %}

+
+ + +
+ +
+
-
-

{% trans "Alias successfully created. Refreshing page in 3 seconds..." %}

+ -
-

{% trans "Operation Successfull." %}

-
-
-

{% trans "Could not connect to server. Please refresh this page." %}

+
+ + + + + + + + + + + + + + + + + + + +
DomainLaunchPathSSLDelete
+ + + + +
-
+
+ + + + +
+ +
- - - - - - - +
+ +
-
- - -
{% endblock %} \ No newline at end of file diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 1b0a402c0..31e243d9f 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -2241,10 +2241,29 @@ class WebsiteManager: currentACL = ACLManager.loadedACL(userID) admin = Administrator.objects.get(pk=userID) + try: + alias = data['alias'] + except: + alias = 0 + masterDomain = data['masterDomain'] domain = data['domainName'] - phpSelection = data['phpSelection'] - path = data['path'] + + + if alias == 0: + phpSelection = data['phpSelection'] + path = data['path'] + else: + + ### if master website have apache then create this sub-domain also as ols + apache + + apachePath = ApacheVhost.configBasePath + masterDomain + '.conf' + + if os.path.exists(apachePath): + data['apacheBackend'] = 1 + + phpSelection = Websites.objects.get(domain=masterDomain).phpSelection + tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999)) if not validators.domain(domain): @@ -2281,11 +2300,15 @@ class WebsiteManager: if currentACL['admin'] != 1: data['openBasedir'] = 1 - if len(path) > 0: - path = path.lstrip("/") - path = "/home/" + masterDomain + "/" + path + if alias == 0: + + if len(path) > 0: + path = path.lstrip("/") + path = "/home/" + masterDomain + "/" + path + else: + path = "/home/" + masterDomain + "/" + domain else: - path = "/home/" + masterDomain + "/" + domain + path = f'/home/{masterDomain}/public_html' try: apacheBackend = str(data['apacheBackend']) @@ -2298,7 +2321,7 @@ class WebsiteManager: " --phpVersion '" + phpSelection + "' --ssl " + str(data['ssl']) + " --dkimCheck " + str( data['dkimCheck']) \ + " --openBasedir " + str(data['openBasedir']) + ' --path ' + path + ' --websiteOwner ' \ - + admin.userName + ' --tempStatusPath ' + tempStatusPath + " --apache " + apacheBackend + + admin.userName + ' --tempStatusPath ' + tempStatusPath + " --apache " + apacheBackend + f' --aliasDomain {str(alias)}' ProcessUtilities.popenExecutioner(execPath) time.sleep(2) @@ -2320,13 +2343,18 @@ class WebsiteManager: admin = Administrator.objects.get(pk=userID) masterDomain = data['masterDomain'] + try: + alias = data['alias'] + except: + alias = 0 + if ACLManager.checkOwnership(masterDomain, admin, currentACL) == 1: pass else: return ACLManager.loadErrorJson('fetchStatus', 0) cdManager = ChildDomainManager(masterDomain) - json_data = cdManager.findChildDomainsJson() + json_data = cdManager.findChildDomainsJson(alias) final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": json_data}) return HttpResponse(final_json) @@ -2441,7 +2469,7 @@ class WebsiteManager: childDomains = [] for web in websites: - for child in web.childdomains_set.all(): + for child in web.childdomains_set.filter(alais=0): if child.domain == f'mail.{web.domain}': pass else: @@ -3499,6 +3527,22 @@ class WebsiteManager: website = Websites.objects.get(domain=self.domain) website.phpSelection = data['phpSelection'] website.save() + + ### check if there are any alias domains under the main website and then change php for them too + + for alias in website.childdomains_set.filter(alais=1): + + try: + + confPath = virtualHostUtilities.Server_root + "/conf/vhosts/" + alias.domain + completePathToConfigFile = confPath + "/vhost.conf" + execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" + execPath = execPath + " changePHP --phpVersion '" + phpVersion + "' --path " + completePathToConfigFile + ProcessUtilities.popenExecutioner(execPath) + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile(f'Error changing PHP for alias: {str(msg)}') + + except: website = ChildDomains.objects.get(domain=self.domain) website.phpSelection = data['phpSelection']