diff --git a/ApachController/ApacheController.py b/ApachController/ApacheController.py index dedc77ecc..51a390c15 100755 --- a/ApachController/ApacheController.py +++ b/ApachController/ApacheController.py @@ -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 diff --git a/ApachController/ApacheVhosts.py b/ApachController/ApacheVhosts.py index 60c01fdb5..e43672bf4 100755 --- a/ApachController/ApacheVhosts.py +++ b/ApachController/ApacheVhosts.py @@ -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 @@ def deletePHPPath(virtualHostName): @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 @@ def changePHP(phpVersion, vhFile): 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}" diff --git a/plogical/phpUtilities.py b/plogical/phpUtilities.py index ab318fd0a..e25fd1939 100755 --- a/plogical/phpUtilities.py +++ b/plogical/phpUtilities.py @@ -273,7 +273,8 @@ def WrapGetPHPVersionFromFileToGetVersionWithPHP(vhFile): @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 diff --git a/plogical/renew.py b/plogical/renew.py index c283673df..4f2193652 100644 --- a/plogical/renew.py +++ b/plogical/renew.py @@ -21,7 +21,7 @@ def SSLObtainer(self): ## 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) diff --git a/plogical/test.py b/plogical/test.py index a8aa96142..e69de29bb 100644 --- a/plogical/test.py +++ b/plogical/test.py @@ -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('/', '/') - - - - diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 38e5d5f5b..c5fc57797 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -3098,8 +3098,13 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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 @@ def CreateMissingPoolsforFPM(): 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): diff --git a/plogical/vhost.py b/plogical/vhost.py index d85405456..b73329db9 100755 --- a/plogical/vhost.py +++ b/plogical/vhost.py @@ -629,6 +629,8 @@ def changePHP(vhFile, phpVersion): #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 @@ def changePHP(vhFile, phpVersion): 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) diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index c63ce0bf8..cd8fff680 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -163,7 +163,7 @@ def OnBoardingHostName(Domain, tempStatusPath, skipRDNSCheck): 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 @@ def setupAutoDiscover(mailDomain, tempStatusPath, virtualHostName, admin): content = """\nlocal_name %s { ssl_cert =