@@ -1955,21 +1955,43 @@ def CreateStagingNow(self, userID=None, data=None):
19551955 return HttpResponse (json_data )
19561956
19571957 def UpdateWPSettings (self , userID = None , data = None ):
1958+ # Map old setting names to new ones
1959+ setting_map = {
1960+ 'PasswordProtection' : 'password-protection' ,
1961+ 'searchIndex' : 'search-indexing' ,
1962+ 'debugging' : 'debugging' ,
1963+ 'maintenanceMode' : 'maintenance-mode' ,
1964+ 'lscache' : 'lscache' ,
1965+ 'Wpcron' : 'wpcron' ,
1966+ # Add more mappings as needed
1967+ }
1968+
1969+ siteId = data .get ('siteId' ) or data .get ('WPid' )
1970+ if not siteId :
1971+ resp = {'status' : 0 , 'error_message' : 'Missing siteId or WPid' }
1972+ return JsonResponse (resp )
1973+
1974+ # Accept both new and old setting names
1975+ setting = data .get ('setting' )
1976+ if not setting :
1977+ for old_key in setting_map :
1978+ if old_key in data :
1979+ setting = old_key
1980+ data ['settingValue' ] = data [old_key ]
1981+ break
1982+
1983+ # Map to new setting name if needed
1984+ setting = setting_map .get (setting , setting )
1985+ value = data .get ('value' ) or data .get ('settingValue' )
1986+
19581987 try :
19591988 currentACL = ACLManager .loadedACL (userID )
19601989 admin = Administrator .objects .get (pk = userID )
1961-
1962- siteId = data .get ('siteId' ) or data .get ('WPid' )
1963- if not siteId :
1964- return JsonResponse ({'status' : 0 , 'error_message' : 'Missing siteId or WPid' })
1965- setting = data ['setting' ]
1966- value = data ['value' ]
1967-
19681990 wpsite = WPSites .objects .get (pk = siteId )
1969-
1991+
19701992 if ACLManager .checkOwnership (wpsite .owner .domain , admin , currentACL ) != 1 :
19711993 return ACLManager .loadError ()
1972-
1994+
19731995 # Get PHP version and path
19741996 Webobj = Websites .objects .get (pk = wpsite .owner_id )
19751997 Vhuser = Webobj .externalApp
@@ -1979,10 +2001,8 @@ def UpdateWPSettings(self, userID=None, data=None):
19792001
19802002 # Update the appropriate setting based on the setting type
19812003 if setting == 'search-indexing' :
1982- # Update search engine indexing
19832004 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 } '
19842005 elif setting == 'debugging' :
1985- # Update debugging in wp-config.php
19862006 if value :
19872007 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 } '
19882008 else :
@@ -1992,76 +2012,84 @@ def UpdateWPSettings(self, userID=None, data=None):
19922012 vhostPassDir = f'/home/{ vhostName } '
19932013 path = f'{ vhostPassDir } /{ siteId } '
19942014 if value :
1995- # Enable password protection
19962015 tempPath = f'/home/cyberpanel/{ str (randint (1000 , 9999 ))} '
19972016 os .makedirs (tempPath )
1998-
1999- # Create temporary .htpasswd file
20002017 htpasswd = f'{ tempPath } /.htpasswd'
20012018 htaccess = f'{ tempPath } /.htaccess'
20022019 password = randomPassword .generate_pass (12 )
2003-
2004- # Create .htpasswd file
20052020 command = f"htpasswd -cb { htpasswd } admin { password } "
20062021 ProcessUtilities .executioner (command )
2007-
2008- # Create .htaccess file content
20092022 htaccess_content = f"""
20102023AuthType Basic
20112024AuthName "Restricted Access"
20122025AuthUserFile { path } /.htpasswd
20132026Require valid-user
20142027"""
2015-
20162028 with open (htaccess , 'w' ) as f :
20172029 f .write (htaccess_content )
2018-
2019- # Create final directory and move files
20202030 command = f"mkdir -p { path } "
20212031 ProcessUtilities .executioner (command , wpsite .owner .externalApp )
2022-
2023- # Move files to final location
20242032 command = f"mv { htpasswd } { path } /.htpasswd"
20252033 ProcessUtilities .executioner (command , wpsite .owner .externalApp )
2026-
2027- command = f"mv { htaccess } { wpsite .path } /.htaccess"
2034+ command = f"mv { htaccess } { wpsite .path } /.htaccess"
20282035 ProcessUtilities .executioner (command , wpsite .owner .externalApp )
2029-
2030- # Cleanup temp directory
20312036 command = f"rm -rf { tempPath } "
20322037 ProcessUtilities .executioner (command )
2033-
20342038 else :
2035- # Disable password protection
20362039 if os .path .exists (path ):
20372040 command = f"rm -rf { path } "
20382041 ProcessUtilities .executioner (command , wpsite .owner .externalApp )
2039-
20402042 htaccess = f'{ wpsite .path } /.htaccess'
20412043 if os .path .exists (htaccess ):
20422044 command = f"rm -f { htaccess } "
20432045 ProcessUtilities .executioner (command , wpsite .owner .externalApp )
2044-
2045- return JsonResponse ({'status' : 1 , 'error_message' : 'None' })
2046+ resp = {'status' : 1 , 'error_message' : 'None' }
2047+ if data .get ('legacy_response' ):
2048+ import json
2049+ return HttpResponse (json .dumps (resp ))
2050+ else :
2051+ return JsonResponse (resp )
20462052 elif setting == 'maintenance-mode' :
20472053 if value :
20482054 command = f'sudo -u { Vhuser } { FinalPHPPath } -d error_reporting=0 /usr/bin/wp maintenance-mode activate --skip-plugins --skip-themes --path={ wpsite .path } '
20492055 else :
20502056 command = f'sudo -u { Vhuser } { FinalPHPPath } -d error_reporting=0 /usr/bin/wp maintenance-mode deactivate --skip-plugins --skip-themes --path={ wpsite .path } '
2057+ elif setting == 'lscache' :
2058+ if value :
2059+ command = f'sudo -u { Vhuser } { FinalPHPPath } -d error_reporting=0 /usr/bin/wp plugin activate litespeed-cache --skip-plugins --skip-themes --path={ wpsite .path } '
2060+ else :
2061+ command = f'sudo -u { Vhuser } { FinalPHPPath } -d error_reporting=0 /usr/bin/wp plugin deactivate litespeed-cache --skip-plugins --skip-themes --path={ wpsite .path } '
20512062 else :
2052- return JsonResponse ({'status' : 0 , 'error_message' : 'Invalid setting type' })
2053-
2063+ resp = {'status' : 0 , 'error_message' : 'Invalid setting type' }
2064+ if data .get ('legacy_response' ):
2065+ import json
2066+ return HttpResponse (json .dumps (resp ))
2067+ else :
2068+ return JsonResponse (resp )
2069+
20542070 result = ProcessUtilities .outputExecutioner (command )
20552071 if result .find ('Error:' ) > - 1 :
2056- return JsonResponse ({'status' : 0 , 'error_message' : result })
2057-
2058- return JsonResponse ({'status' : 1 , 'error_message' : 'None' })
2059-
2060- except BaseException as msg :
2061- return JsonResponse ({'status' : 0 , 'error_message' : str (msg )})
2062-
2072+ resp = {'status' : 0 , 'error_message' : result }
2073+ if data .get ('legacy_response' ):
2074+ import json
2075+ return HttpResponse (json .dumps (resp ))
2076+ else :
2077+ return JsonResponse (resp )
20632078
2079+ resp = {'status' : 1 , 'error_message' : 'None' }
2080+ if data .get ('legacy_response' ):
2081+ import json
2082+ return HttpResponse (json .dumps (resp ))
2083+ else :
2084+ return JsonResponse (resp )
20642085
2086+ except BaseException as msg :
2087+ resp = {'status' : 0 , 'error_message' : str (msg )}
2088+ if data and data .get ('legacy_response' ):
2089+ import json
2090+ return HttpResponse (json .dumps (resp ))
2091+ else :
2092+ return JsonResponse (resp )
20652093
20662094 def submitWorpressCreation (self , userID = None , data = None ):
20672095 try :
@@ -4789,7 +4817,6 @@ def switchServer(self, userID=None, data=None):
47894817 return ACLManager .loadErrorJson ()
47904818
47914819 tempStatusPath = "/home/cyberpanel/" + str (randint (1000 , 9999 ))
4792-
47934820 execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities .cyberPanel + "/plogical/virtualHostUtilities.py"
47944821 execPath = execPath + " switchServer --phpVersion '" + phpVersion + "' --server " + str (
47954822 server ) + " --virtualHostName " + domainName + " --tempStatusPath " + tempStatusPath
@@ -7231,5 +7258,4 @@ def fetchWPSitesForDomain(self, userID=None, data=None):
72317258 except BaseException as msg :
72327259 data_ret = {'status' : 0 , 'fetchStatus' : 0 , 'error_message' : str (msg )}
72337260 json_data = json .dumps (data_ret )
7234- return HttpResponse (json_data )
7235-
7261+ return HttpResponse (json_data )
0 commit comments