multiple bug fixes to apache manager on al9

This commit is contained in:
usmannasir
2024-09-26 22:10:44 +05:00
parent dcf8967cdc
commit a989d9900f
8 changed files with 142 additions and 110 deletions

View File

@@ -12,6 +12,7 @@ class ApacheController:
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
serverRootPath = '/etc/httpd'
configBasePath = '/etc/httpd/conf.d/'
php54Path = '/opt/remi/php54/root/etc/php-fpm.d/'
@@ -28,6 +29,7 @@ class ApacheController:
php82Path = '/etc/opt/remi/php82/php-fpm.d/'
php83Path = '/etc/opt/remi/php83/php-fpm.d/'
php84Path = '/etc/opt/remi/php84/php-fpm.d/'
php85Path = '/etc/opt/remi/php85/php-fpm.d/'
serviceName = 'httpd'
@@ -48,6 +50,10 @@ class ApacheController:
php81Path = '/etc/php/8.1/fpm/pool.d/'
php82Path = '/etc/php/8.2/fpm/pool.d/'
php83Path = '/etc/php/8.3/fpm/pool.d/'
php84Path = '/etc/php/8.4/fpm/pool.d/'
php85Path = '/etc/php/8.5/fpm/pool.d/'
serviceName = 'apache2'
mpmConfigs = """# Select the MPM module which should be used by uncommenting exactly

View File

@@ -33,6 +33,9 @@ class ApacheVhost:
php80Path = '/etc/opt/remi/php80/php-fpm.d/'
php81Path = '/etc/opt/remi/php81/php-fpm.d/'
php82Path = '/etc/opt/remi/php82/php-fpm.d/'
php83Path = '/etc/opt/remi/php83/php-fpm.d/'
php84Path = '/etc/opt/remi/php84/php-fpm.d/'
php85Path = '/etc/opt/remi/php85/php-fpm.d/'
serviceName = 'httpd'
@@ -54,6 +57,7 @@ class ApacheVhost:
php82Path = '/etc/php/8.2/fpm/pool.d/'
php83Path = '/etc/php/8.3/fpm/pool.d/'
php84Path = '/etc/php/8.4/fpm/pool.d/'
php85Path = '/etc/php/8.5/fpm/pool.d/'
serviceName = 'apache2'
@@ -528,6 +532,7 @@ class ApacheVhost:
@staticmethod
def changePHP(phpVersion, vhFile):
try:
logging.writeToFile(f"PHP version passed to Apache function: {phpVersion}")
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
sockPath = '/var/run/php-fpm/'
@@ -569,6 +574,14 @@ class ApacheVhost:
confFile.write(currentConf)
### minor bug fix of updating default php conf user in selected fpm
if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8:
defaultConfPath = finalConfPath.replace(virtualHostName, 'www')
command = f"sed -i 's/www-data/apache/g' {defaultConfPath}"
ProcessUtilities.executioner(command)
phpService = ApacheVhost.DecideFPMServiceName(phpVersion)
command = f"systemctl stop {phpService}"

View File

@@ -273,7 +273,8 @@ class phpUtilities:
@staticmethod
def FindIfSaidPHPIsAvaiableOtherwiseMaketheNextOneAvailableToUse(vhFile, phpVersion):
if vhFile != None:
result = phpUtilities.GetPHPVersionFromFile(vhFile)
virtualHostName = vhFile.split('/')[6]
result = phpUtilities.GetPHPVersionFromFile(vhFile, virtualHostName)
if os.path.exists(result):
return phpVersion

View File

@@ -21,7 +21,7 @@ class Renew:
## For Non-suspended websites only
for website in Websites.objects.filter(status=1):
for website in Websites.objects.filter(state=1):
logging.writeToFile('Checking SSL for %s.' % (website.domain), 0)
filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (website.domain)

View File

@@ -1,61 +0,0 @@
import os
import shutil
import subprocess
def edit_fstab(mount_point, options_to_add):
# Backup the original fstab file
fstab_path = '/etc/fstab'
backup_path = fstab_path + '.bak'
if not os.path.exists(backup_path):
shutil.copy(fstab_path, backup_path)
# Read the fstab file
with open(fstab_path, 'r') as file:
lines = file.readlines()
# Modify the appropriate line
WriteToFile = open(fstab_path, 'w')
for i, line in enumerate(lines):
if line.find('\t') > -1:
parts = line.split('\t')
else:
parts = line.split(' ')
#print(parts)
try:
if parts[1] == '/' and parts[3].find('usrquota,grpquota') == -1:
parts[3] = f'{parts[3]},usrquota,grpquota'
finalString = '\t'.join(parts)
#print(finalString)
WriteToFile.write(finalString)
else:
WriteToFile.write(line)
except:
WriteToFile.write(line)
WriteToFile.close()
try:
command = "find /lib/modules/ -type f -name '*quota_v*.ko*'"
result = subprocess.run(command, capture_output=True, text=True, shell=True)
print(repr(result.stdout))
# Only if the first command works, run the rest
if result.returncode == 0:
command = "echo '{}' | sed -n 's|/lib/modules/\\([^/]*\\)/.*|\\1|p' | sort -u".format(result.stdout)
result = subprocess.run(command, capture_output=True, text=True, shell=True)
print(repr(result.stdout.rstrip('\n')))
except subprocess.CalledProcessError as e:
print("Error:", e.output.decode())
edit_fstab('/', '/')

View File

@@ -3098,8 +3098,13 @@ vmail
php81Path = '/etc/opt/remi/php81/php-fpm.d/'
php82Path = '/etc/opt/remi/php82/php-fpm.d/'
php83Path = '/etc/opt/remi/php83/php-fpm.d/'
php84Path = '/etc/opt/remi/php84/php-fpm.d/'
php85Path = '/etc/opt/remi/php85/php-fpm.d/'
serviceName = 'httpd'
sockPath = '/var/run/php-fpm/'
runAsUser = 'apache'
else:
serverRootPath = '/etc/apache2'
configBasePath = '/etc/apache2/sites-enabled/'
@@ -3116,9 +3121,13 @@ vmail
php80Path = '/etc/php/8.0/fpm/pool.d/'
php81Path = '/etc/php/8.1/fpm/pool.d/'
php82Path = '/etc/php/8.2/fpm/pool.d/'
php83Path = '/etc/php/8.3/fpm/pool.d/'
php84Path = '/etc/php/8.4/fpm/pool.d/'
php85Path = '/etc/php/8.5/fpm/pool.d/'
serviceName = 'apache2'
sockPath = '/var/run/php/'
runAsUser = 'www-data'
#####
@@ -3128,11 +3137,11 @@ vmail
if os.path.exists(php54Path):
content = f"""
[php54default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php5.4-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3146,11 +3155,11 @@ pm.max_spare_servers = 3
if os.path.exists(php55Path):
content = f'''
[php55default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php5.5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3164,11 +3173,11 @@ pm.max_spare_servers = 3
if os.path.exists(php56Path):
content = f'''
[php56default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php5.6-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3182,11 +3191,11 @@ pm.max_spare_servers = 3
if os.path.exists(php70Path):
content = f'''
[php70default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php7.0-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3200,11 +3209,11 @@ pm.max_spare_servers = 3
if os.path.exists(php71Path):
content = f'''
[php71default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php7.1-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3218,11 +3227,11 @@ pm.max_spare_servers = 3
if os.path.exists(php72Path):
content = f'''
[php72default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php7.2-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3236,11 +3245,11 @@ pm.max_spare_servers = 3
if os.path.exists(php73Path):
content = f'''
[php73default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php7.3-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3254,11 +3263,11 @@ pm.max_spare_servers = 3
if os.path.exists(php74Path):
content = f'''
[php74default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php7.4-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3272,11 +3281,11 @@ pm.max_spare_servers = 3
if os.path.exists(php80Path):
content = f'''
[php80default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php8.0-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3291,11 +3300,11 @@ pm.max_spare_servers = 3
if os.path.exists(php81Path):
content = f'''
[php81default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php8.1-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3309,11 +3318,11 @@ pm.max_spare_servers = 3
if os.path.exists(php82Path):
content = f'''
[php82default]
user = www-data
group = www-data
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php8.2-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
@@ -3325,6 +3334,60 @@ pm.max_spare_servers = 3
WriteToFile.write(content)
WriteToFile.close()
if os.path.exists(php83Path):
content = f'''
[php83default]
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php8.3-fpm.sock
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
'''
WriteToFile = open(f'{php83Path}www.conf', 'w')
WriteToFile.write(content)
WriteToFile.close()
if os.path.exists(php84Path):
content = f'''
[php84default]
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php8.4-fpm.sock
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
'''
WriteToFile = open(f'{php84Path}www.conf', 'w')
WriteToFile.write(content)
WriteToFile.close()
if os.path.exists(php85Path):
content = f'''
[php85default]
user = {runAsUser}
group = {runAsUser}
listen ={sockPath}php8.5-fpm.sock
listen.owner = {runAsUser}
listen.group = {runAsUser}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
'''
WriteToFile = open(f'{php85Path}www.conf', 'w')
WriteToFile.write(content)
WriteToFile.close()
@staticmethod
def upgrade(branch):

View File

@@ -629,6 +629,8 @@ class vhost:
#HomePath = website.externalApp
virtualHostUser = externalApp
logging.CyberCPLogFileWriter.writeToFile(f"PHP version before making sure its available or not: {phpVersion} and vhFile: {vhFile}")
from plogical.phpUtilities import phpUtilities
phpVersion = phpUtilities.FindIfSaidPHPIsAvaiableOtherwiseMaketheNextOneAvailableToUse(vhFile, phpVersion)
@@ -649,6 +651,8 @@ class vhost:
path = " path /usr/local/lsws/lsphp" + str(php) + "/bin/lsphp\n"
logging.CyberCPLogFileWriter.writeToFile(f"PHP String to be written {path}")
for items in data:
if items.find("/usr/local/lsws/lsphp") > -1 and items.find("path") > -1:
writeDataToFile.writelines(path)

View File

@@ -163,7 +163,7 @@ class virtualHostUtilities:
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, message)
logging.CyberCPLogFileWriter.writeToFile(message)
command = 'systemctl restart postfix && systemctl restart dovecot && postmap -F hash:/etc/postfix/vmail_ssl.map'
command = 'postmap -F hash:/etc/postfix/vmail_ssl.map && systemctl restart postfix && systemctl restart dovecot'
ProcessUtilities.executioner(command, 'root', True)
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Completed. [200]')
else:
@@ -324,12 +324,18 @@ class virtualHostUtilities:
content = """\nlocal_name %s {
ssl_cert = </etc/letsencrypt/live/%s/fullchain.pem
ssl_key = </etc/letsencrypt/live/%s/privkey.pem
}\n""" % (childDomain, childDomain, childDomain)
}
local_name %s {
ssl_cert = </etc/letsencrypt/live/%s/fullchain.pem
ssl_key = </etc/letsencrypt/live/%s/privkey.pem
}
\n""" % (childDomain, childDomain, childDomain, virtualHostName, virtualHostName, virtualHostName)
writeToFile = open(dovecotPath, 'a')
writeToFile.write(content)
writeToFile.close()
command = 'systemctl restart dovecot'
ProcessUtilities.executioner(command)
@@ -351,7 +357,7 @@ class virtualHostUtilities:
postfixMapFileContent = ''
if postfixMapFileContent.find('/live/%s/' % (childDomain)) == -1:
mapContent = '%s /etc/letsencrypt/live/%s/privkey.pem /etc/letsencrypt/live/%s/fullchain.pem\n' % (
mapContent = f'%s /etc/letsencrypt/live/%s/privkey.pem /etc/letsencrypt/live/%s/fullchain.pem\n{virtualHostName} /etc/letsencrypt/live/{virtualHostName}/privkey.pem /etc/letsencrypt/live/{virtualHostName}/fullchain.pem\n' % (
childDomain, childDomain, childDomain)
writeToFile = open(postfixMapFile, 'a')