diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index f7938c7b0..c4fa10c9d 100644 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -15,6 +15,7 @@ django.setup() import json from plogical.acl import ACLManager import plogical.CyberCPLogFileWriter as logging +from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter from websiteFunctions.models import Websites, ChildDomains, GitLogs, wpplugins, WPSites, WPStaging, WPSitesBackup, \ RemoteBackupConfig, RemoteBackupSchedule, RemoteBackupsites, DockerPackages, PackageAssignment, DockerSites from plogical.virtualHostUtilities import virtualHostUtilities @@ -2762,134 +2763,161 @@ Require valid-user if state == "Suspend": confPath = virtualHostUtilities.Server_root + "/conf/vhosts/" + websiteName - vhostConfPath = confPath + "/vhconf.conf" + vhostConfPath = confPath + "/vhost.conf" - # Create suspension configuration - suspensionConf = """ -# Website Suspension Configuration -errorPage 403{ - url /cyberpanel_suspension_page.html -} - -errorPage 404{ - url /cyberpanel_suspension_page.html -} - -context /{ - accessible 0 -} - -context /cyberpanel_suspension_page.html{ - location /usr/local/CyberCP/static/suspension/suspension.html - accessible 1 - extraHeaders X-Frame-Options: DENY -} -""" - - # Create a temporary file with the suspension configuration - from random import randint - tempFile = "/home/cyberpanel/" + str(randint(100000, 999999)) - - # Read current vhost configuration - command = f"cat {vhostConfPath}" - vhostContent = ProcessUtilities.outputExecutioner(command) - - if "# Website Suspension Configuration" not in vhostContent: - # Add suspension configuration at the beginning - modifiedContent = suspensionConf + "\n" + vhostContent - - # Write to temporary file - with open(tempFile, 'w') as f: - f.write(modifiedContent) - - # Copy temporary file to vhost configuration with proper permissions - command = f"cp {tempFile} {vhostConfPath}" - ProcessUtilities.executioner(command) - - # Set proper ownership - command = f"chown lsadm:lsadm {vhostConfPath}" - ProcessUtilities.executioner(command) - - # Remove temporary file - os.remove(tempFile) - - # Apply same suspension configuration to child domains - childDomains = website.childdomains_set.all() - - for items in childDomains: - childConfPath = virtualHostUtilities.Server_root + "/conf/vhosts/" + items.domain - childVhostConfPath = childConfPath + "/vhconf.conf" - + # Ensure suspension page exists and has proper permissions + suspensionPagePath = "/usr/local/CyberCP/websiteFunctions/suspension.html" + if not os.path.exists(suspensionPagePath): + # Create default suspension page if it doesn't exist + defaultSuspensionHTML = """ + + + + + Website Suspended + + + +
+

Website Suspended

+

This website has been temporarily suspended. This could be due to various reasons including billing issues, policy violations, or administrative actions.

+

If you are the website owner, please contact your hosting provider for more information about why your account was suspended and how to restore service.

+

For support, please contact your system administrator.

+
+ +""" try: - # Read child vhost configuration - command = f"cat {childVhostConfPath}" - childVhostContent = ProcessUtilities.outputExecutioner(command) - - if "# Website Suspension Configuration" not in childVhostContent: - # Create temporary file for child domain - childTempFile = "/home/cyberpanel/" + str(randint(100000, 999999)) - childModifiedContent = suspensionConf + "\n" + childVhostContent - - with open(childTempFile, 'w') as f: - f.write(childModifiedContent) - - # Copy to child vhost configuration - command = f"cp {childTempFile} {childVhostConfPath}" - ProcessUtilities.executioner(command) - - # Set proper ownership - command = f"chown lsadm:lsadm {childVhostConfPath}" - ProcessUtilities.executioner(command) - - # Remove temporary file - os.remove(childTempFile) + with open(suspensionPagePath, 'w') as f: + f.write(defaultSuspensionHTML) except: pass - installUtilities.reStartLiteSpeedSocket() - website.state = 0 - else: - confPath = virtualHostUtilities.Server_root + "/conf/vhosts/" + websiteName - vhostConfPath = confPath + "/vhconf.conf" + # Set proper permissions for suspension page + try: + command = f"chown lsadm:lsadm {suspensionPagePath}" + ProcessUtilities.executioner(command) + command = f"chmod 644 {suspensionPagePath}" + ProcessUtilities.executioner(command) + except: + pass - # Read the current vhost configuration - command = f"cat {vhostConfPath}" - vhostContent = ProcessUtilities.outputExecutioner(command) + # Create suspension configuration with end marker + suspensionConf = """# Website Suspension Configuration +context /{ + location $DOC_ROOT/ + allowBrowse 1 + + rewrite { + enable 1 + autoLoadHtaccess 0 + rules <<