diff --git a/plogical/cPanelImporter.py b/plogical/cPanelImporter.py index 6d9d4dc64..54c3ba268 100644 --- a/plogical/cPanelImporter.py +++ b/plogical/cPanelImporter.py @@ -70,7 +70,7 @@ class cPanelImporter: if value[2] == 'main': self.MainSite = value self.PHPVersion = value[9] - self.InheritPHP = self.PHPDecider() + self.InheritPHP = self.PHPDecider(key) else: self.OtherDomainNames.append(key) self.OtherDomains.append(value) @@ -78,7 +78,7 @@ class cPanelImporter: except BaseException as msg: print(str(msg)) - def PHPDecider(self): + def PHPDecider(self, domainName): if self.PHPVersion == 'inherit': self.PHPVersion = 'PHP 7.4' @@ -104,6 +104,8 @@ class cPanelImporter: self.PHPVersion = 'PHP 8.0' elif self.PHPVersion.find('81') > -1: self.PHPVersion = 'PHP 8.1' + elif self.PHPVersion.find('82') > -1: + self.PHPVersion = 'PHP 8.2' if self.PHPVersion == '': if self.InheritPHP != '': @@ -111,6 +113,22 @@ class cPanelImporter: else: self.PHPVersion = 'PHP 7.4' + ### if the PHP Version extracted from file is not available then change it to next available + + try: + + from plogical.phpUtilities import phpUtilities + + completePathToConfigFile = f'/usr/local/lsws/conf/vhosts/{domainName}/vhost.conf' + + phpVersion = phpUtilities.FindIfSaidPHPIsAvaiableOtherwiseMaketheNextOneAvailableToUse(completePathToConfigFile, self.PHPVersion) + + if phpVersion != self.PHPVersion: + logging.statusWriter(self.logFile, f'PHP version for {self.mainDomain} has been changed from {self.PHPVersion} to {phpVersion}.', 1) + self.PHPVersion = phpVersion + except: + pass + return self.PHPVersion def SetupSSL(self, path, domain): @@ -207,7 +225,7 @@ class cPanelImporter: logging.statusWriter(self.logFile, message, 1) self.PHPVersion = self.MainSite[9] - self.PHPDecider() + self.PHPDecider(self.mainDomain) message = 'PHP version of %s is %s.' % (DomainName, self.PHPVersion) logging.statusWriter(self.logFile, message, 1) @@ -355,7 +373,7 @@ class cPanelImporter: ## Find PHP Version self.PHPVersion = self.OtherDomains[counter][9] - self.PHPDecider() + self.PHPDecider(items) message = 'Calling core to create %s.' % (items) logging.statusWriter(self.logFile, message, 1) diff --git a/plogical/phpUtilities.py b/plogical/phpUtilities.py index ceb06415d..fc642d25b 100755 --- a/plogical/phpUtilities.py +++ b/plogical/phpUtilities.py @@ -226,13 +226,13 @@ class phpUtilities: return result else: - command = f'grep -Eo -m 1 "php[0-9]+" {vhFile}' + command = f'grep -Po "php\d+" {vhFile} | head -n 1' result = ProcessUtilities.outputExecutioner(command, None, True).rstrip('\n') result = f'/usr/local/lsws/ls{result}/bin/lsphp' result = result.rsplit("lsphp", 1)[0] + "php" return result - + ## returns something like PHP 8.2 @staticmethod def WrapGetPHPVersionFromFileToGetVersionWithPHP(vhFile): result = phpUtilities.GetPHPVersionFromFile(vhFile) @@ -240,6 +240,17 @@ class phpUtilities: php_version = ProcessUtilities.outputExecutioner(command, None, True).rstrip('\n') return f"PHP {php_version}" + @staticmethod + def FindIfSaidPHPIsAvaiableOtherwiseMaketheNextOneAvailableToUse(vhFile, phpVersion): + result = phpUtilities.GetPHPVersionFromFile(vhFile) + + if os.path.exists(result): + return phpVersion + else: + from managePHP.phpManager import PHPManager + return PHPManager.findPHPVersions()[-2] + + @staticmethod diff --git a/plogical/vhost.py b/plogical/vhost.py index 1cff43495..83f37b842 100755 --- a/plogical/vhost.py +++ b/plogical/vhost.py @@ -5,7 +5,6 @@ import sys import django from plogical.acl import ACLManager - sys.path.append('/usr/local/CyberCP') os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") try: @@ -629,6 +628,10 @@ class vhost: #HomePath = website.externalApp virtualHostUser = externalApp + from plogical.phpUtilities import phpUtilities + + phpVersion = phpUtilities.FindIfSaidPHPIsAvaiableOtherwiseMaketheNextOneAvailableToUse(vhFile, phpVersion) + phpDetachUpdatePath = '/home/%s/.lsphp_restart.txt' % (vhFile.split('/')[-2]) if ProcessUtilities.decideServer() == ProcessUtilities.OLS: try: