diff --git a/plogical/vhost.py b/plogical/vhost.py index 540d72ec2..8acdb347a 100644 --- a/plogical/vhost.py +++ b/plogical/vhost.py @@ -1075,6 +1075,7 @@ class vhost: currentConf = vhostConfs.olsChildConf currentConf = currentConf.replace('{path}', path) currentConf = currentConf.replace('{masterDomain}', masterDomain) + currentConf = currentConf.replace('{virtualHostName}', domain) currentConf = currentConf.replace('{adminEmails}', administratorEmail) currentConf = currentConf.replace('{externalApp}', externalApp) currentConf = currentConf.replace('{externalAppMaster}', virtualHostUser) @@ -1087,6 +1088,30 @@ class vhost: currentConf = currentConf.replace('{open_basedir}', 'php_admin_value open_basedir "/tmp:$VH_ROOT"') else: currentConf = currentConf.replace('{open_basedir}', '') + + # Ensure log directory exists in master domain's home directory + masterLogDir = f"/home/{masterDomain}/logs" + try: + if not os.path.exists(masterLogDir): + os.makedirs(masterLogDir, exist_ok=True) + command = f"chown -R {virtualHostUser}:{virtualHostUser} {masterLogDir}" + ProcessUtilities.executioner(command) + + # Create empty log files for the child domain + error_log_path = f"{masterLogDir}/{domain}.error_log" + access_log_path = f"{masterLogDir}/{domain}.access_log" + + for log_path in [error_log_path, access_log_path]: + if not os.path.exists(log_path): + with open(log_path, 'w') as f: + f.write('') + command = f"chown {virtualHostUser}:{virtualHostUser} {log_path}" + ProcessUtilities.executioner(command) + command = f"chmod 644 {log_path}" + ProcessUtilities.executioner(command) + except Exception as logErr: + logging.CyberCPLogFileWriter.writeToFile( + f'Error creating log files for child domain {domain}: {str(logErr)}') confFile = open(vhFile, "w+") confFile.write(currentConf) @@ -1116,6 +1141,30 @@ class vhost: confFile.write(currentConf) confFile.close() + + # Ensure log directory exists in master domain's home directory and create log files + masterLogDir = f"/home/{masterDomain}/logs" + try: + if not os.path.exists(masterLogDir): + os.makedirs(masterLogDir, exist_ok=True) + command = f"chown -R {virtualHostUser}:{virtualHostUser} {masterLogDir}" + ProcessUtilities.executioner(command) + + # Create empty log files for the child domain + error_log_path = f"{masterLogDir}/{domain}.error_log" + access_log_path = f"{masterLogDir}/{domain}.access_log" + + for log_path in [error_log_path, access_log_path]: + if not os.path.exists(log_path): + with open(log_path, 'w') as f: + f.write('') + command = f"chown {virtualHostUser}:{virtualHostUser} {log_path}" + ProcessUtilities.executioner(command) + command = f"chmod 644 {log_path}" + ProcessUtilities.executioner(command) + except Exception as logErr: + logging.CyberCPLogFileWriter.writeToFile( + f'Error creating log files for child domain {domain}: {str(logErr)}') else: @@ -1134,6 +1183,28 @@ class vhost: command = 'redis-cli set %s' % (currentConf) ProcessUtilities.executioner(command) + + # Ensure log directory exists in master domain's home directory and create log files + masterLogDir = f"/home/{masterDomain}/logs" + try: + if not os.path.exists(masterLogDir): + os.makedirs(masterLogDir, exist_ok=True) + command = f"chown -R {virtualHostUser}:{virtualHostUser} {masterLogDir}" + ProcessUtilities.executioner(command) + + # Create empty log files for the child domain (non-www) + access_log_path = f"{masterLogDir}/{domain}.access_log" + + if not os.path.exists(access_log_path): + with open(access_log_path, 'w') as f: + f.write('') + command = f"chown {virtualHostUser}:{virtualHostUser} {access_log_path}" + ProcessUtilities.executioner(command) + command = f"chmod 644 {access_log_path}" + ProcessUtilities.executioner(command) + except Exception as logErr: + logging.CyberCPLogFileWriter.writeToFile( + f'Error creating log files for child domain {domain} (redis non-www): {str(logErr)}') ## www @@ -1150,6 +1221,9 @@ class vhost: command = 'redis-cli set %s' % (currentConf) ProcessUtilities.executioner(command) + + # Note: Log files already created for non-www version above + # The www version shares the same log files except BaseException as msg: logging.CyberCPLogFileWriter.writeToFile( diff --git a/plogical/vhostConfs.py b/plogical/vhostConfs.py index d8a99cb27..f8fbb2f9a 100644 --- a/plogical/vhostConfs.py +++ b/plogical/vhostConfs.py @@ -204,7 +204,7 @@ context /.well-known/acme-challenge { SuexecUserGroup {externalApp} {externalApp} DocumentRoot {path} Alias /.well-known/acme-challenge /usr/local/lsws/Example/html/.well-known/acme-challenge - CustomLog /home/{virtualHostName}/logs/{virtualHostName}.access_log combined + CustomLog /home/{masterDomain}/logs/{virtualHostName}.access_log combined AddHandler application/x-httpd-php{php} .php .php7 .phtml CacheRoot lscache @@ -474,7 +474,7 @@ pm.max_spare_servers = {pmMaxSpareServers} "phpVersion": {php}, "custom_conf": { ServerAdmin {administratorEmail} - CustomLog /home/{virtualHostName}/logs/{virtualHostName}.access_log combined + CustomLog /home/{masterDomain}/logs/{virtualHostName}.access_log combined CacheRoot /home/{masterDomain}/lscache @@ -489,7 +489,7 @@ pm.max_spare_servers = {pmMaxSpareServers} "phpVersion": {php}, "custom_conf": { ServerAdmin {administratorEmail} - CustomLog /home/{virtualHostName}/logs/{virtualHostName}.access_log combined + CustomLog /home/{masterDomain}/logs/{virtualHostName}.access_log combined CacheRoot /home/{masterDomain}/lscache