This commit is contained in:
usmannasir
2025-05-18 13:30:29 +05:00
27 changed files with 4622 additions and 1649 deletions

View File

@@ -1955,19 +1955,43 @@ class WebsiteManager:
return HttpResponse(json_data)
def UpdateWPSettings(self, userID=None, data=None):
# Map old setting names to new ones
setting_map = {
'PasswordProtection': 'password-protection',
'searchIndex': 'search-indexing',
'debugging': 'debugging',
'maintenanceMode': 'maintenance-mode',
'lscache': 'lscache',
'Wpcron': 'wpcron',
# Add more mappings as needed
}
siteId = data.get('siteId') or data.get('WPid')
if not siteId:
resp = {'status': 0, 'error_message': 'Missing siteId or WPid'}
return JsonResponse(resp)
# Accept both new and old setting names
setting = data.get('setting')
if not setting:
for old_key in setting_map:
if old_key in data:
setting = old_key
data['settingValue'] = data[old_key]
break
# Map to new setting name if needed
setting = setting_map.get(setting, setting)
value = data.get('value') or data.get('settingValue')
try:
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
siteId = data['siteId']
setting = data['setting']
value = data['value']
wpsite = WPSites.objects.get(pk=siteId)
if ACLManager.checkOwnership(wpsite.owner.domain, admin, currentACL) != 1:
return ACLManager.loadError()
# Get PHP version and path
Webobj = Websites.objects.get(pk=wpsite.owner_id)
Vhuser = Webobj.externalApp
@@ -1977,10 +2001,8 @@ class WebsiteManager:
# Update the appropriate setting based on the setting type
if setting == 'search-indexing':
# Update search engine indexing
command = f'sudo -u {Vhuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp option update blog_public {value} --skip-plugins --skip-themes --path={wpsite.path}'
elif setting == 'debugging':
# Update debugging in wp-config.php
if value:
command = f'sudo -u {Vhuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp config set WP_DEBUG true --raw --skip-plugins --skip-themes --path={wpsite.path}'
else:
@@ -1990,76 +2012,84 @@ class WebsiteManager:
vhostPassDir = f'/home/{vhostName}'
path = f'{vhostPassDir}/{siteId}'
if value:
# Enable password protection
tempPath = f'/home/cyberpanel/{str(randint(1000, 9999))}'
os.makedirs(tempPath)
# Create temporary .htpasswd file
htpasswd = f'{tempPath}/.htpasswd'
htaccess = f'{tempPath}/.htaccess'
password = randomPassword.generate_pass(12)
# Create .htpasswd file
command = f"htpasswd -cb {htpasswd} admin {password}"
ProcessUtilities.executioner(command)
# Create .htaccess file content
htaccess_content = f"""
AuthType Basic
AuthName "Restricted Access"
AuthUserFile {path}/.htpasswd
Require valid-user
"""
with open(htaccess, 'w') as f:
f.write(htaccess_content)
# Create final directory and move files
command = f"mkdir -p {path}"
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
# Move files to final location
command = f"mv {htpasswd} {path}/.htpasswd"
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
command = f"mv {htaccess} {wpsite.path}/.htaccess"
command = f"mv {htaccess} {wpsite.path}/.htaccess"
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
# Cleanup temp directory
command = f"rm -rf {tempPath}"
ProcessUtilities.executioner(command)
else:
# Disable password protection
if os.path.exists(path):
command = f"rm -rf {path}"
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
htaccess = f'{wpsite.path}/.htaccess'
if os.path.exists(htaccess):
command = f"rm -f {htaccess}"
ProcessUtilities.executioner(command, wpsite.owner.externalApp)
return JsonResponse({'status': 1, 'error_message': 'None'})
resp = {'status': 1, 'error_message': 'None'}
if data.get('legacy_response'):
import json
return HttpResponse(json.dumps(resp))
else:
return JsonResponse(resp)
elif setting == 'maintenance-mode':
if value:
command = f'sudo -u {Vhuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp maintenance-mode activate --skip-plugins --skip-themes --path={wpsite.path}'
else:
command = f'sudo -u {Vhuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp maintenance-mode deactivate --skip-plugins --skip-themes --path={wpsite.path}'
elif setting == 'lscache':
if value:
command = f'sudo -u {Vhuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp plugin activate litespeed-cache --skip-plugins --skip-themes --path={wpsite.path}'
else:
command = f'sudo -u {Vhuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp plugin deactivate litespeed-cache --skip-plugins --skip-themes --path={wpsite.path}'
else:
return JsonResponse({'status': 0, 'error_message': 'Invalid setting type'})
resp = {'status': 0, 'error_message': 'Invalid setting type'}
if data.get('legacy_response'):
import json
return HttpResponse(json.dumps(resp))
else:
return JsonResponse(resp)
result = ProcessUtilities.outputExecutioner(command)
if result.find('Error:') > -1:
return JsonResponse({'status': 0, 'error_message': result})
return JsonResponse({'status': 1, 'error_message': 'None'})
resp = {'status': 0, 'error_message': result}
if data.get('legacy_response'):
import json
return HttpResponse(json.dumps(resp))
else:
return JsonResponse(resp)
resp = {'status': 1, 'error_message': 'None'}
if data.get('legacy_response'):
import json
return HttpResponse(json.dumps(resp))
else:
return JsonResponse(resp)
except BaseException as msg:
return JsonResponse({'status': 0, 'error_message': str(msg)})
resp = {'status': 0, 'error_message': str(msg)}
if data and data.get('legacy_response'):
import json
return HttpResponse(json.dumps(resp))
else:
return JsonResponse(resp)
def submitWorpressCreation(self, userID=None, data=None):
try:
@@ -4572,8 +4602,7 @@ StrictHostKeyChecking no
websites = ACLManager.searchWebsiteObjects(currentlACL, userID, searchTerm)
json_data = "["
checker = 0
json_data = []
try:
ipFile = "/etc/cyberpanel/machineIP"
@@ -4604,19 +4633,34 @@ StrictHostKeyChecking no
PHPVersionActual = 'PHP 8.1'
diskUsed = "%sMB" % str(DiskUsage)
dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress,
'admin': items.admin.userName, 'package': items.package.packageName, 'state': state,
'diskUsed': diskUsed, 'phpVersion': PHPVersionActual}
if checker == 0:
json_data = json_data + json.dumps(dic)
checker = 1
else:
json_data = json_data + ',' + json.dumps(dic)
# Get WordPress sites for this website
wp_sites = []
try:
wp_sites = WPSites.objects.filter(owner=items)
wp_sites = [{
'id': wp.id,
'title': wp.title,
'url': wp.FinalURL,
'version': wp.version if hasattr(wp, 'version') else 'Unknown',
'phpVersion': wp.phpVersion if hasattr(wp, 'phpVersion') else 'Unknown'
} for wp in wp_sites]
except:
pass
json_data = json_data + ']'
json_data.append({
'domain': items.domain,
'adminEmail': items.adminEmail,
'ipAddress': ipAddress,
'admin': items.admin.userName,
'package': items.package.packageName,
'state': state,
'diskUsed': diskUsed,
'phpVersion': PHPVersionActual,
'wp_sites': wp_sites
})
return json_data
return json.dumps(json_data)
def findWebsitesJson(self, currentACL, userID, pageNumber):
finalPageNumber = ((pageNumber * 10)) - 10
@@ -4779,7 +4823,6 @@ StrictHostKeyChecking no
return ACLManager.loadErrorJson()
tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999))
execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py"
execPath = execPath + " switchServer --phpVersion '" + phpVersion + "' --server " + str(
server) + " --virtualHostName " + domainName + " --tempStatusPath " + tempStatusPath
@@ -7221,5 +7264,4 @@ StrictHostKeyChecking no
except BaseException as msg:
data_ret = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
return HttpResponse(json_data)