From da00ef7d280160dd670fdb3fb8329ccfeab3c9f6 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Tue, 1 Apr 2025 14:17:01 +0500 Subject: [PATCH] additional setting for improved wp page --- .../websiteFunctions/WPsitesList.html | 8 +- websiteFunctions/views.py | 17 +- websiteFunctions/website.py | 210 ++++++------------ 3 files changed, 72 insertions(+), 163 deletions(-) diff --git a/websiteFunctions/templates/websiteFunctions/WPsitesList.html b/websiteFunctions/templates/websiteFunctions/WPsitesList.html index ff5a18100..8c63b0a4b 100644 --- a/websiteFunctions/templates/websiteFunctions/WPsitesList.html +++ b/websiteFunctions/templates/websiteFunctions/WPsitesList.html @@ -247,7 +247,7 @@ Manage - @@ -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}`; + } + } {% endblock %} diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 5904d23d0..bcefc8a77 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -622,21 +622,10 @@ def GetCurrentThemes(request): def UpdateWPSettings(request): try: userID = request.session['userID'] - - result = pluginManager.preWebsiteCreation(request) - - if result != 200: - return result - + data = json.loads(request.body) + wm = WebsiteManager() - coreResult = wm.UpdateWPSettings(userID, json.loads(request.body)) - - result = pluginManager.postWebsiteCreation(request, coreResult) - if result != 200: - return result - - return coreResult - + return wm.UpdateWPSettings(userID, data) except KeyError: return redirect(loadLoginPage) diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 0822a03db..933b65517 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -42,6 +42,7 @@ from plogical.vhostConfs import vhostConfs from plogical.cronUtil import CronUtil from .StagingSetup import StagingSetup import validators +from django.http import JsonResponse class WebsiteManager: @@ -1925,170 +1926,83 @@ class WebsiteManager: def UpdateWPSettings(self, userID=None, data=None): try: - currentACL = ACLManager.loadedACL(userID) admin = Administrator.objects.get(pk=userID) - - WPManagerID = data['WPid'] + + siteId = data['siteId'] setting = data['setting'] - - if setting == 'PasswordProtection': - 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: - pass - else: + value = data['value'] + + wpsite = WPSites.objects.get(pk=siteId) + + if ACLManager.checkOwnership(wpsite.owner.domain, admin, currentACL) != 1: return ACLManager.loadError() - - path = wpsite.path - + + # Get PHP version and path Webobj = Websites.objects.get(pk=wpsite.owner_id) - Vhuser = Webobj.externalApp PHPVersion = Webobj.phpSelection php = ACLManager.getPHPString(PHPVersion) FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) - if setting == 'lscache': - if settingValue: - - command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp plugin install litespeed-cache --path=%s --skip-plugins --skip-themes" % ( - 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) + # 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': - - 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 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)) - - + # 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: - command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp config set WP_DEBUG false --path=%s --skip-plugins --skip-themes" % ( - Vhuser, FinalPHPPath, path) - 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)) - elif setting == 'searchIndex': - - 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 option update blog_public 1 --path=%s --skip-plugins --skip-themes" % ( - Vhuser, FinalPHPPath, path) - stdoutput = ProcessUtilities.outputExecutioner(command) - - + 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}' + elif setting == 'password-protection': + vhostName = wpsite.owner.domain + vhostPassDir = f'/home/{vhostName}' + path = f'{vhostPassDir}/{siteId}' + if value: + # Enable password protection + if not os.path.exists(path): + os.makedirs(path) + htpasswd = f'{path}/.htpasswd' + htaccess = f'{wpsite.path}/.htaccess' + password = randomPassword.generate_pass(12) + + # 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: - command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp option update blog_public 0 --path=%s --skip-plugins --skip-themes" % ( - Vhuser, FinalPHPPath, path) - stdoutput = ProcessUtilities.outputExecutioner(command) - elif setting == 'maintenanceMode': - - 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 maintenance-mode activate --path=%s --skip-plugins --skip-themes" % ( - Vhuser, FinalPHPPath, path) - stdoutput = ProcessUtilities.outputExecutioner(command) - - + # Disable password protection + if os.path.exists(path): + import shutil + shutil.rmtree(path) + htaccess = f'{wpsite.path}/.htaccess' + if os.path.exists(htaccess): + os.remove(htaccess) + return JsonResponse({'status': 1, 'error_message': 'None'}) + 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 = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp maintenance-mode deactivate --path=%s --skip-plugins --skip-themes" % ( - 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: - - command = "sudo -u %s %s -d error_reporting=0 /usr/bin/wp config set DISABLE_WP_CRON false --path=%s --skip-plugins --skip-themes" % ( - Vhuser, FinalPHPPath, path) - - 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) - + command = f'sudo -u {Vhuser} {FinalPHPPath} -d error_reporting=0 /usr/bin/wp maintenance-mode deactivate --skip-plugins --skip-themes --path={wpsite.path}' + else: + return JsonResponse({'status': 0, 'error_message': 'Invalid setting type'}) + + result = ProcessUtilities.outputExecutioner(command) + if result.find('Error:') > -1: + return JsonResponse({'status': 0, 'error_message': result}) + + return JsonResponse({'status': 1, 'error_message': 'None'}) except BaseException as msg: - data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) + return JsonResponse({'status': 0, 'error_message': str(msg)}) def submitWorpressCreation(self, userID=None, data=None): try: