usmannasir
2025-07-20 19:43:34 +05:00
parent 1e494b685a
commit 973763541d

View File

@@ -2764,11 +2764,7 @@ Require valid-user
confPath = virtualHostUtilities.Server_root + "/conf/vhosts/" + websiteName
vhostConfPath = confPath + "/vhconf.conf"
# Read the current vhost configuration
with open(vhostConfPath, 'r') as f:
vhostContent = f.read()
# Add suspension error document configuration
# Create suspension configuration
suspensionConf = """
# Website Suspension Configuration
errorPage 403{
@@ -2790,14 +2786,32 @@ context /cyberpanel_suspension_page.html{
}
"""
# Check if suspension configuration already exists
if "# Website Suspension Configuration" not in vhostContent:
# Add suspension configuration at the beginning of the file
modifiedContent = suspensionConf + "\n" + vhostContent
# 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}"
result = ProcessUtilities.outputExecutioner(command)
if result[0] == 1 and "# Website Suspension Configuration" not in result[1]:
# Add suspension configuration at the beginning
modifiedContent = suspensionConf + "\n" + result[1]
# Write the modified configuration
with open(vhostConfPath, 'w') as f:
# 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()
@@ -2807,14 +2821,28 @@ context /cyberpanel_suspension_page.html{
childVhostConfPath = childConfPath + "/vhconf.conf"
try:
with open(childVhostConfPath, 'r') as f:
childVhostContent = f.read()
# Read child vhost configuration
command = f"cat {childVhostConfPath}"
result = ProcessUtilities.outputExecutioner(command)
if "# Website Suspension Configuration" not in childVhostContent:
childModifiedContent = suspensionConf + "\n" + childVhostContent
if result[0] == 1 and "# Website Suspension Configuration" not in result[1]:
# Create temporary file for child domain
childTempFile = "/home/cyberpanel/" + str(randint(100000, 999999))
childModifiedContent = suspensionConf + "\n" + result[1]
with open(childVhostConfPath, 'w') as f:
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)
except:
pass
@@ -2825,15 +2853,16 @@ context /cyberpanel_suspension_page.html{
vhostConfPath = confPath + "/vhconf.conf"
# Read the current vhost configuration
try:
with open(vhostConfPath, 'r') as f:
vhostContent = f.read()
command = f"cat {vhostConfPath}"
result = ProcessUtilities.outputExecutioner(command)
if result[0] == 1:
vhostContent = result[1]
# Remove suspension configuration
if "# Website Suspension Configuration" in vhostContent:
# Find the start and end of suspension configuration
start_marker = "# Website Suspension Configuration"
end_marker = "}\n" # End of last context block
start_index = vhostContent.find(start_marker)
if start_index != -1:
@@ -2856,11 +2885,23 @@ context /cyberpanel_suspension_page.html{
# Remove the suspension configuration
modifiedContent = vhostContent[:start_index] + vhostContent[end_index:]
# Write the cleaned configuration
with open(vhostConfPath, 'w') as f:
# Create temporary file and write cleaned configuration
from random import randint
tempFile = "/home/cyberpanel/" + str(randint(100000, 999999))
with open(tempFile, 'w') as f:
f.write(modifiedContent)
except:
pass
# Copy back 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)
# Remove suspension configuration from child domains
childDomains = website.childdomains_set.all()
@@ -2870,31 +2911,49 @@ context /cyberpanel_suspension_page.html{
childVhostConfPath = childConfPath + "/vhconf.conf"
try:
with open(childVhostConfPath, 'r') as f:
childVhostContent = f.read()
# Read child vhost configuration
command = f"cat {childVhostConfPath}"
result = ProcessUtilities.outputExecutioner(command)
if "# Website Suspension Configuration" in childVhostContent:
# Find and remove suspension configuration
start_marker = "# Website Suspension Configuration"
start_index = childVhostContent.find(start_marker)
if start_index != -1:
temp_content = childVhostContent[start_index:]
brace_count = 0
end_index = start_index
for i, char in enumerate(temp_content):
if char == '}':
brace_count += 1
if brace_count == 4:
end_index = start_index + i + 1
while end_index < len(childVhostContent) and childVhostContent[end_index] == '\n':
end_index += 1
break
childModifiedContent = childVhostContent[:start_index] + childVhostContent[end_index:]
with open(childVhostConfPath, 'w') as f:
f.write(childModifiedContent)
if result[0] == 1:
childVhostContent = result[1]
if "# Website Suspension Configuration" in childVhostContent:
# Find and remove suspension configuration
start_marker = "# Website Suspension Configuration"
start_index = childVhostContent.find(start_marker)
if start_index != -1:
temp_content = childVhostContent[start_index:]
brace_count = 0
end_index = start_index
for i, char in enumerate(temp_content):
if char == '}':
brace_count += 1
if brace_count == 4:
end_index = start_index + i + 1
while end_index < len(childVhostContent) and childVhostContent[end_index] == '\n':
end_index += 1
break
childModifiedContent = childVhostContent[:start_index] + childVhostContent[end_index:]
# Create temporary file for child domain
childTempFile = "/home/cyberpanel/" + str(randint(100000, 999999))
with open(childTempFile, 'w') as f:
f.write(childModifiedContent)
# Copy back with proper permissions
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)
except:
pass