diff --git a/ApachController/ApacheController.py b/ApachController/ApacheController.py index 51a390c15..38da58bc0 100755 --- a/ApachController/ApacheController.py +++ b/ApachController/ApacheController.py @@ -15,6 +15,7 @@ class ApacheController: serverRootPath = '/etc/httpd' configBasePath = '/etc/httpd/conf.d/' + phpBasepath = '/etc/opt/remi' php54Path = '/opt/remi/php54/root/etc/php-fpm.d/' php55Path = '/opt/remi/php55/root/etc/php-fpm.d/' php56Path = '/etc/opt/remi/php56/php-fpm.d/' @@ -37,6 +38,8 @@ class ApacheController: serverRootPath = '/etc/apache2' configBasePath = '/etc/apache2/sites-enabled/' + phpBasepath = '/etc/php' + php54Path = '/etc/php/5.4/fpm/pool.d/' php55Path = '/etc/php/5.5/fpm/pool.d/' php56Path = '/etc/php/5.6/fpm/pool.d/' diff --git a/ApachController/ApacheVhosts.py b/ApachController/ApacheVhosts.py index e43672bf4..80f3e4d0f 100755 --- a/ApachController/ApacheVhosts.py +++ b/ApachController/ApacheVhosts.py @@ -143,6 +143,12 @@ class ApacheVhost: if os.path.exists(ApacheVhost.php83Path + virtualHostName): return ApacheVhost.php83Path + virtualHostName + if os.path.exists(ApacheVhost.php84Path + virtualHostName): + return ApacheVhost.php84Path + virtualHostName + + if os.path.exists(ApacheVhost.php85Path + virtualHostName): + return ApacheVhost.php85Path + virtualHostName + @staticmethod diff --git a/managePHP/phpManager.py b/managePHP/phpManager.py index c81bef0be..b04872672 100755 --- a/managePHP/phpManager.py +++ b/managePHP/phpManager.py @@ -31,12 +31,72 @@ class PHPManager: lsphp_lines = [line for line in result.split('\n') if 'lsphp' in line] + if os.path.exists(ProcessUtilities.debugPath): + from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging + logging.writeToFile(f'Found PHP lines in findPHPVersions: {lsphp_lines}') + + # Extract the version from the lines and format it as 'PHP x.y' php_versions = ['PHP ' + line.split()[8][5] + '.' + line.split()[8][6:] for line in lsphp_lines] + finalPHPVersions = [] + for php in php_versions: + phpString = PHPManager.getPHPString(php) + + if os.path.exists("/usr/local/lsws/lsphp" + str(phpString) + "/bin/lsphp"): + finalPHPVersions.append(php) + if os.path.exists(ProcessUtilities.debugPath): from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging - logging.writeToFile(f'Found PHP versions in findPHPVersions: {php_versions}') + logging.writeToFile(f'Found PHP versions in findPHPVersions: {finalPHPVersions}') + + # Now php_versions contains the formatted PHP versions + return finalPHPVersions + except BaseException as msg: + from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging + logging.writeToFile(f'Error while finding php versions on system: {str(msg)}') + return ['PHP 7.0', 'PHP 7.1', 'PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1'] + + @staticmethod + def findApachePHPVersions(): + # distro = ProcessUtilities.decideDistro() + # if distro == ProcessUtilities.centos: + # return ['PHP 5.3', 'PHP 5.4', 'PHP 5.5', 'PHP 5.6', 'PHP 7.0', 'PHP 7.1', 'PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1'] + # elif distro == ProcessUtilities.cent8: + # return ['PHP 7.1','PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1'] + # elif distro == ProcessUtilities.ubuntu20: + # return ['PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1'] + # else: + # return ['PHP 7.0', 'PHP 7.1', 'PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1'] + + try: + + # Run the shell command and capture the output + from ApachController.ApacheController import ApacheController as ApachController + result = ProcessUtilities.outputExecutioner(f'ls -la {ApachController.phpBasepath}') + + # Get the lines containing 'lsphp' in the output + lsphp_lines = [line for line in result.split('\n') if 'php' in line] + + if os.path.exists(ProcessUtilities.debugPath): + from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging + logging.writeToFile(f'Found PHP lines in findApachePHPVersions: {lsphp_lines}') + + # Extract the version from the lines and format it as 'PHP x.y' + # Extract and format PHP versions + php_versions = [] + for entry in lsphp_lines: + # Find substring starting with 'php' and extract the version part + version = entry.split('php')[1] + # Format version as PHP X.Y + formatted_version = f"PHP {version[0]}.{version[1]}" + php_versions.append(formatted_version) + + + + if os.path.exists(ProcessUtilities.debugPath): + from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging + logging.writeToFile(f'Found PHP versions in findApachePHPVersions: {php_versions}') # Now php_versions contains the formatted PHP versions return php_versions diff --git a/managePHP/views.py b/managePHP/views.py index 1816f029b..db9ad4a47 100755 --- a/managePHP/views.py +++ b/managePHP/views.py @@ -1269,11 +1269,18 @@ def installExtensions(request): except: pass - # apache = ApacheController.checkIfApacheInstalled() - apache = 1 - + apache = ApacheController.checkIfApacheInstalled() + + if apache: + if request.GET.get('apache', None) == None: + phps = PHPManager.findPHPVersions() + else: + phps = PHPManager.findApachePHPVersions() + else: + phps = PHPManager.findPHPVersions() + proc = httpProc(request, 'managePHP/installExtensions.html', - {'phps': PHPManager.findPHPVersions(), 'apache': apache}, 'admin') + {'phps': phps, 'apache': apache}, 'admin') return proc.render() except KeyError: @@ -1674,10 +1681,18 @@ def getRequestStatusApache(request): def editPHPConfigs(request): try: - #apache = ApacheController.checkIfApacheInstalled() - apache = 1 + apache = ApacheController.checkIfApacheInstalled() + + if apache: + if request.GET.get('apache', None) == None: + phps = PHPManager.findPHPVersions() + else: + phps = PHPManager.findApachePHPVersions() + else: + phps = PHPManager.findPHPVersions() + proc = httpProc(request, 'managePHP/editPHPConfig.html', - {'phps': PHPManager.findPHPVersions(), 'apache': apache}, 'admin') + {'phps': phps, 'apache': apache}, 'admin') return proc.render() except KeyError: diff --git a/websiteFunctions/templates/websiteFunctions/ApacheManager.html b/websiteFunctions/templates/websiteFunctions/ApacheManager.html index 6229ac5e6..eaba4f1bb 100755 --- a/websiteFunctions/templates/websiteFunctions/ApacheManager.html +++ b/websiteFunctions/templates/websiteFunctions/ApacheManager.html @@ -162,7 +162,7 @@
diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 3ff9deb46..c71a62576 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -6677,6 +6677,7 @@ StrictHostKeyChecking no return ACLManager.loadError() phps = PHPManager.findPHPVersions() + apachePHPs = PHPManager.findApachePHPVersions() if ACLManager.CheckForPremFeature('all'): apachemanager = 1 @@ -6684,7 +6685,7 @@ StrictHostKeyChecking no apachemanager = 0 proc = httpProc(request, 'websiteFunctions/ApacheManager.html', - {'domainName': self.domain, 'phps': phps, 'apachemanager': apachemanager}) + {'domainName': self.domain, 'phps': phps, 'apachemanager': apachemanager, 'apachePHPs': apachePHPs}) return proc.render() def saveApacheConfigsToFile(self, userID=None, data=None):