Skip to content

Commit

Permalink
bug fix cPanel importer internal ticket: https://app.clickup.com/t/86…
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Sep 3, 2023
1 parent 7f7d25d commit b59de61
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
26 changes: 22 additions & 4 deletions plogical/cPanelImporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def LoadDomains(self):
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)

except BaseException as msg:
print(str(msg))

def PHPDecider(self):
def PHPDecider(self, domainName):

if self.PHPVersion == 'inherit':
self.PHPVersion = 'PHP 7.4'
Expand All @@ -104,13 +104,31 @@ def PHPDecider(self):
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 != '':
self.PHPVersion = self.InheritPHP
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):
Expand Down Expand Up @@ -207,7 +225,7 @@ def CreateMainWebsite(self):
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)
Expand Down Expand Up @@ -355,7 +373,7 @@ def CreateChildDomains(self):
## 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)
Expand Down
15 changes: 13 additions & 2 deletions plogical/phpUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,31 @@ def GetPHPVersionFromFile(vhFile):
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)
command = result + " -v | awk '/^PHP/ {print $2}'"
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
Expand Down
5 changes: 4 additions & 1 deletion plogical/vhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import django

from plogical.acl import ACLManager

sys.path.append('/usr/local/CyberCP')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
try:
Expand Down Expand Up @@ -629,6 +628,10 @@ def changePHP(vhFile, phpVersion):
#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:
Expand Down

0 comments on commit b59de61

Please sign in to comment.