Skip to content

Commit

Permalink
feature: support upto php 8.4 on apache manager
Browse files Browse the repository at this point in the history
  • Loading branch information
usmannasir committed Sep 27, 2024
1 parent a989d99 commit 8bfe914
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 10 deletions.
3 changes: 3 additions & 0 deletions ApachController/ApacheController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand All @@ -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/'
Expand Down
6 changes: 6 additions & 0 deletions ApachController/ApacheVhosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def whichPHPExists(virtualHostName):
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
Expand Down
62 changes: 61 additions & 1 deletion managePHP/phpManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,72 @@ def findPHPVersions():
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: {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 findPHPVersions: {php_versions}')
logging.writeToFile(f'Found PHP versions in findApachePHPVersions: {php_versions}')

# Now php_versions contains the formatted PHP versions
return php_versions
Expand Down
29 changes: 22 additions & 7 deletions managePHP/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4 class="modal-title" id="myLargeModalLabel">{$ functionStatus $} <img
<div class="form-group mb-3">
<label for="example-select">PHP</label>
<select ng-model="phpSelection" class="form-control" id="example-select">
{% for php in phps %}
{% for php in apachePHPs %}
<option>{{ php }}</option>
{% endfor %}
</select>
Expand Down
3 changes: 2 additions & 1 deletion websiteFunctions/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -6677,14 +6677,15 @@ def ApacheManager(self, request=None, userID=None, data=None):
return ACLManager.loadError()

phps = PHPManager.findPHPVersions()
apachePHPs = PHPManager.findApachePHPVersions()

if ACLManager.CheckForPremFeature('all'):
apachemanager = 1
else:
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):
Expand Down

0 comments on commit 8bfe914

Please sign in to comment.