additional setting for improved wp page

This commit is contained in:
usmannasir
2025-04-01 14:17:01 +05:00
parent 04d6ac1694
commit da00ef7d28
3 changed files with 72 additions and 163 deletions

View File

@@ -247,7 +247,7 @@
<a href="{% url 'WPHome' %}?ID={{ site.id }}" class="btn-tool"> <a href="{% url 'WPHome' %}?ID={{ site.id }}" class="btn-tool">
<i class="fas fa-cog"></i> Manage <i class="fas fa-cog"></i> Manage
</a> </a>
<button onclick="DeleteWPNow('{% url 'ListWPSites' %}?DeleteID={{ site.id }}')" class="btn-tool"> <button onclick="DeleteWPNow('{% url 'ListWPSites' %}', '{{ site.id }}')" class="btn-tool">
<i class="fas fa-trash"></i> Delete <i class="fas fa-trash"></i> Delete
</button> </button>
</div> </div>
@@ -365,6 +365,12 @@
}); });
}); });
}); });
function DeleteWPNow(url, siteId) {
if (confirm('Are you sure you want to delete this WordPress site?')) {
window.location.href = `${url}?DeleteID=${siteId}`;
}
}
</script> </script>
{% endblock %} {% endblock %}

View File

@@ -622,21 +622,10 @@ def GetCurrentThemes(request):
def UpdateWPSettings(request): def UpdateWPSettings(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']
data = json.loads(request.body)
result = pluginManager.preWebsiteCreation(request)
if result != 200:
return result
wm = WebsiteManager() wm = WebsiteManager()
coreResult = wm.UpdateWPSettings(userID, json.loads(request.body)) return wm.UpdateWPSettings(userID, data)
result = pluginManager.postWebsiteCreation(request, coreResult)
if result != 200:
return result
return coreResult
except KeyError: except KeyError:
return redirect(loadLoginPage) return redirect(loadLoginPage)

View File

@@ -42,6 +42,7 @@ from plogical.vhostConfs import vhostConfs
from plogical.cronUtil import CronUtil from plogical.cronUtil import CronUtil
from .StagingSetup import StagingSetup from .StagingSetup import StagingSetup
import validators import validators
from django.http import JsonResponse
class WebsiteManager: class WebsiteManager:
@@ -1925,170 +1926,83 @@ class WebsiteManager:
def UpdateWPSettings(self, userID=None, data=None): def UpdateWPSettings(self, userID=None, data=None):
try: try:
currentACL = ACLManager.loadedACL(userID) currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID) admin = Administrator.objects.get(pk=userID)
WPManagerID = data['WPid'] siteId = data['siteId']
setting = data['setting'] setting = data['setting']
value = data['value']
if setting == 'PasswordProtection': wpsite = WPSites.objects.get(pk=siteId)
PPUsername = data['PPUsername']
PPPassword = data['PPPassword']
else:
settingValue = data['settingValue']
wpsite = WPSites.objects.get(pk=WPManagerID) if ACLManager.checkOwnership(wpsite.owner.domain, admin, currentACL) != 1:
if ACLManager.checkOwnership(wpsite.owner.domain, admin, currentACL) == 1:
pass
else:
return ACLManager.loadError() return ACLManager.loadError()
path = wpsite.path # Get PHP version and path
Webobj = Websites.objects.get(pk=wpsite.owner_id) Webobj = Websites.objects.get(pk=wpsite.owner_id)
Vhuser = Webobj.externalApp Vhuser = Webobj.externalApp
PHPVersion = Webobj.phpSelection PHPVersion = Webobj.phpSelection
php = ACLManager.getPHPString(PHPVersion) php = ACLManager.getPHPString(PHPVersion)
FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php)
if setting == 'lscache': # Update the appropriate setting based on the setting type
if settingValue: if setting == 'search-indexing':
# Update search engine indexing
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp plugin install litespeed-cache --path=%s --skip-plugins --skip-themes" % ( 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}'
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp plugin activate litespeed-cache --path=%s --skip-plugins --skip-themes" % (
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
else:
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp plugin deactivate litespeed-cache --path=%s --skip-plugins --skip-themes' % (
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
elif setting == 'debugging': elif setting == 'debugging':
# Update debugging in wp-config.php
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp litespeed-purge all --path=%s --skip-plugins --skip-themes" % ( if value:
Vhuser, FinalPHPPath, path) 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}'
stdoutput = ProcessUtilities.outputExecutioner(command)
if settingValue:
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp config set WP_DEBUG true --path=%s --skip-plugins --skip-themes" % (
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
logging.CyberCPLogFileWriter.writeToFile("Debugging mk true 1 output:" + str(stdoutput))
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config list --skip-plugins --skip-themes --path=%s' % (
Vhuser, FinalPHPPath, path)
stdout = ProcessUtilities.outputExecutioner(command)
logging.CyberCPLogFileWriter.writeToFile("Debugging output:" + str(stdout))
else: else:
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp config set WP_DEBUG false --path=%s --skip-plugins --skip-themes" % ( command = f'sudo -u {Vhuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp config set WP_DEBUG false --raw --skip-plugins --skip-themes --path={wpsite.path}'
Vhuser, FinalPHPPath, path) elif setting == 'password-protection':
stdoutput = ProcessUtilities.outputExecutioner(command) vhostName = wpsite.owner.domain
logging.CyberCPLogFileWriter.writeToFile("Debugging mk false 0 output:" + str(stdoutput)) vhostPassDir = f'/home/{vhostName}'
path = f'{vhostPassDir}/{siteId}'
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config list --skip-plugins --skip-themes --path=%s' % ( if value:
Vhuser, FinalPHPPath, path) # Enable password protection
stdout = ProcessUtilities.outputExecutioner(command) if not os.path.exists(path):
logging.CyberCPLogFileWriter.writeToFile("Debugging output:" + str(stdout)) os.makedirs(path)
elif setting == 'searchIndex': htpasswd = f'{path}/.htpasswd'
htaccess = f'{wpsite.path}/.htaccess'
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp litespeed-purge all --path=%s --skip-plugins --skip-themes" % ( password = randomPassword.generate_pass(12)
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
if settingValue:
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp option update blog_public 1 --path=%s --skip-plugins --skip-themes" % (
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
# Create .htpasswd file
command = f"htpasswd -cb {htpasswd} admin {password}"
ProcessUtilities.executioner(command)
# Create .htaccess file
htaccess_content = f"""AuthType Basic
AuthName "Restricted Access"
AuthUserFile {htpasswd}
Require valid-user"""
with open(htaccess, 'w') as f:
f.write(htaccess_content)
else: else:
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp option update blog_public 0 --path=%s --skip-plugins --skip-themes" % ( # Disable password protection
Vhuser, FinalPHPPath, path) if os.path.exists(path):
stdoutput = ProcessUtilities.outputExecutioner(command) import shutil
elif setting == 'maintenanceMode': shutil.rmtree(path)
htaccess = f'{wpsite.path}/.htaccess'
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp litespeed-purge all --path=%s --skip-plugins --skip-themes" % ( if os.path.exists(htaccess):
Vhuser, FinalPHPPath, path) os.remove(htaccess)
stdoutput = ProcessUtilities.outputExecutioner(command) return JsonResponse({'status': 1, 'error_message': 'None'})
elif setting == 'maintenance-mode':
if settingValue: 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}'
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp maintenance-mode activate --path=%s --skip-plugins --skip-themes" % (
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
else: else:
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp maintenance-mode deactivate --path=%s --skip-plugins --skip-themes" % ( command = f'sudo -u {Vhuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp maintenance-mode deactivate --skip-plugins --skip-themes --path={wpsite.path}'
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
elif setting == 'PasswordProtection':
execPath = f"/usr/local/CyberCP/bin/python {virtualHostUtilities.cyberPanel}/plogical/virtualHostUtilities.py"
execPath = f"{execPath} EnableDisablePP --username '{PPUsername}' --password '{PPPassword}' " \
f"--virtualHostName {Webobj.domain} --path {path} --wpid {str(wpsite.id)} --virtualHostUser {Webobj.externalApp}"
ProcessUtilities.executioner(execPath)
elif setting == 'Wpcron':
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp litespeed-purge all --path=%s --skip-plugins --skip-themes" % (
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
if settingValue:
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp config set DISABLE_WP_CRON true --path=%s --skip-plugins --skip-themes" % (
Vhuser, FinalPHPPath, path)
stdoutput = ProcessUtilities.outputExecutioner(command)
logging.CyberCPLogFileWriter.writeToFile("Debugging mk true 1 output:" + str(stdoutput))
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config list --skip-plugins --skip-themes --path=%s' % (
Vhuser, FinalPHPPath, path)
stdout = ProcessUtilities.outputExecutioner(command)
logging.CyberCPLogFileWriter.writeToFile("Debugging output:" + str(stdout))
else: else:
return JsonResponse({'status': 0, 'error_message': 'Invalid setting type'})
command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp config set DISABLE_WP_CRON false --path=%s --skip-plugins --skip-themes" % ( result = ProcessUtilities.outputExecutioner(command)
Vhuser, FinalPHPPath, path) if result.find('Error:') > -1:
return JsonResponse({'status': 0, 'error_message': result})
stdoutput = ProcessUtilities.outputExecutioner(command)
logging.CyberCPLogFileWriter.writeToFile("Debugging mk false 0 output:" + str(stdoutput))
command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config list --skip-plugins --skip-themes --path=%s' % (
Vhuser, FinalPHPPath, path)
stdout = ProcessUtilities.outputExecutioner(command)
logging.CyberCPLogFileWriter.writeToFile("Debugging output:" + str(stdout))
data_ret = {'status': 1, 'error_message': 'None'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
return JsonResponse({'status': 1, 'error_message': 'None'})
except BaseException as msg: except BaseException as msg:
data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)} return JsonResponse({'status': 0, 'error_message': str(msg)})
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def submitWorpressCreation(self, userID=None, data=None): def submitWorpressCreation(self, userID=None, data=None):
try: try: