From 37d8f5339f8de271c33b60c6073155fca52aca68 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Thu, 16 Jun 2022 21:21:01 +0500 Subject: [PATCH 1/4] some bug fixes in wp manager --- filemanager/views.py | 28 ++-- plogical/IncScheduler.py | 5 +- plogical/acl.py | 26 +++ websiteFunctions/website.py | 319 +++++++++++++++++++++--------------- 4 files changed, 235 insertions(+), 143 deletions(-) diff --git a/filemanager/views.py b/filemanager/views.py index 8eaedcaeb..01d8e0d1e 100755 --- a/filemanager/views.py +++ b/filemanager/views.py @@ -211,21 +211,25 @@ def FileManagerRoot(request): try: - url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission" - data = { - "name": "Filemanager", - "IP": ipAddressLocal - } + from plogical.processUtilities import ProcessUtilities + if ProcessUtilities.decideServer() == ProcessUtilities.OLS: - import requests - response = requests.post(url, data=json.dumps(data)) - Status = response.json()['status'] + url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission" + data = { + "name": "Filemanager", + "IP": ipAddressLocal + } - if(Status == 1): - template = 'baseTemplate/FileManager.html' + import requests + response = requests.post(url, data=json.dumps(data)) + Status = response.json()['status'] + + if(Status == 1): + template = 'baseTemplate/FileManager.html' + else: + return redirect("https://cyberpanel.net/cyberpanel-addons") else: - return redirect("https://cyberpanel.net/cyberpanel-addons") - + template = 'baseTemplate/FileManager.html' except BaseException as msg: template = 'baseTemplate/FileManager.html' diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py index 24a891525..901b57f09 100644 --- a/plogical/IncScheduler.py +++ b/plogical/IncScheduler.py @@ -383,6 +383,8 @@ class IncScheduler(multi.Thread): #logging.writeToFile('job completed') + + url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission" data = { "name": "backups-retention", @@ -393,7 +395,7 @@ class IncScheduler(multi.Thread): response = requests.post(url, data=json.dumps(data)) Status = response.json()['status'] - if (Status == 1): + if (Status == 1) or ProcessUtilities.decideServer() == ProcessUtilities.ent: try: page_token = None @@ -457,7 +459,6 @@ class IncScheduler(multi.Thread): except BaseException as msg: print('An error occurred fetch child: %s' % msg) logging.writeToFile('An error occurred fetch child: %s' % msg) - except BaseException as msg: logging.writeToFile('job not completed [ERROR:]..%s'%msg) diff --git a/plogical/acl.py b/plogical/acl.py index ed4f0c816..baeedf844 100644 --- a/plogical/acl.py +++ b/plogical/acl.py @@ -931,4 +931,30 @@ class ACLManager: return wpsites + @staticmethod + def GetServerIP(): + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + return ipData.split('\n', 1)[0] + + @staticmethod + def CheckForPremFeature(feature): + try: + + if ProcessUtilities.decideServer() == ProcessUtilities.ent: + return 1 + + url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission" + data = { + "name": feature, + "IP": ACLManager.GetServerIP() + } + + import requests + response = requests.post(url, data=json.dumps(data)) + return response.json()['status'] + except: + return 1 + diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index c45dd4e54..55321b991 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -17,7 +17,7 @@ from plogical.virtualHostUtilities import virtualHostUtilities import subprocess import shlex from plogical.installUtilities import installUtilities -from django.shortcuts import HttpResponse, render +from django.shortcuts import HttpResponse, render, redirect from loginSystem.models import Administrator, ACL from packages.models import Package from plogical.mailUtilities import mailUtilities @@ -60,31 +60,44 @@ class WebsiteManager: return proc.render() def WPCreate(self, request=None, userID=None, data=None): - currentACL = ACLManager.loadedACL(userID) - adminNames = ACLManager.loadAllUsers(userID) - packagesName = ACLManager.loadPackages(userID, currentACL) - FinalVersions = [] - userobj = Administrator.objects.get(pk=userID) - counter = 0 - try: - import requests - WPVersions = json.loads(requests.get('https://api.wordpress.org/core/version-check/1.7/').text)['offers'] + url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission" + data = { + "name": "wp-manager", + "IP": ACLManager.GetServerIP() + } - for versions in WPVersions: - if counter == 7: - break - if versions['current'] not in FinalVersions: - FinalVersions.append(versions['current']) - counter = counter + 1 - except: - FinalVersions = ['5.6', '5.5.3', '5.5.2'] + import requests + response = requests.post(url, data=json.dumps(data)) + Status = response.json()['status'] - Plugins = wpplugins.objects.filter(owner=userobj) + if (Status == 1) or ProcessUtilities.decideServer() == ProcessUtilities.ent: + currentACL = ACLManager.loadedACL(userID) + adminNames = ACLManager.loadAllUsers(userID) + packagesName = ACLManager.loadPackages(userID, currentACL) + FinalVersions = [] + userobj = Administrator.objects.get(pk=userID) + counter = 0 + try: + import requests + WPVersions = json.loads(requests.get('https://api.wordpress.org/core/version-check/1.7/').text)['offers'] - Data = {'packageList': packagesName, "owernList": adminNames, 'WPVersions': FinalVersions, 'Plugins': Plugins } - proc = httpProc(request, 'websiteFunctions/WPCreate.html', - Data, 'createWebsite') - return proc.render() + for versions in WPVersions: + if counter == 7: + break + if versions['current'] not in FinalVersions: + FinalVersions.append(versions['current']) + counter = counter + 1 + except: + FinalVersions = ['5.6', '5.5.3', '5.5.2'] + + Plugins = wpplugins.objects.filter(owner=userobj) + + Data = {'packageList': packagesName, "owernList": adminNames, 'WPVersions': FinalVersions, 'Plugins': Plugins } + proc = httpProc(request, 'websiteFunctions/WPCreate.html', + Data, 'createWebsite') + return proc.render() + else: + return redirect("https://cyberpanel.net/cyberpanel-addons") def ListWPSites(self, request=None, userID=None, DeleteID=None): currentACL = ACLManager.loadedACL(userID) @@ -126,89 +139,116 @@ class WebsiteManager: else: return ACLManager.loadError() - Data['wpsite'] = WPobj + url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission" + data = { + "name": "wp-manager", + "IP": ACLManager.GetServerIP() + } - try: - DeleteID = request.GET.get('DeleteID', None) + import requests + response = requests.post(url, data=json.dumps(data)) + Status = response.json()['status'] - if DeleteID != None: - wstagingDelete = WPStaging.objects.get(pk=DeleteID, owner=WPobj) - wstagingDelete.delete() + if (Status == 1) or ProcessUtilities.decideServer() == ProcessUtilities.ent: + Data['wpsite'] = WPobj - except BaseException as msg: - da= str(msg) + try: + DeleteID = request.GET.get('DeleteID', None) - proc = httpProc(request, 'websiteFunctions/WPsiteHome.html', - Data, 'createWebsite') - return proc.render() + if DeleteID != None: + wstagingDelete = WPStaging.objects.get(pk=DeleteID, owner=WPobj) + wstagingDelete.delete() + except BaseException as msg: + da= str(msg) + + proc = httpProc(request, 'websiteFunctions/WPsiteHome.html', + Data, 'createWebsite') + return proc.render() + else: + return redirect("https://cyberpanel.net/cyberpanel-addons") def RestoreHome(self, request=None, userID=None, BackupID=None ): Data = {} currentACL = ACLManager.loadedACL(userID) - Data['backupobj'] = WPSitesBackup.objects.get(pk=BackupID) + if ACLManager.CheckForPremFeature('wp-manager'): - config = json.loads(Data['backupobj'].config) - Data['FileName']= config['name'] - try: - Data['Backuptype']= config['Backuptype'] - except: - Data['Backuptype'] = None - Data['WPsites'] = ACLManager.GetALLWPObjects(currentACL, userID) - proc = httpProc(request, 'websiteFunctions/WPRestoreHome.html', - Data, 'createWebsite') - return proc.render() + Data['backupobj'] = WPSitesBackup.objects.get(pk=BackupID) + + config = json.loads(Data['backupobj'].config) + Data['FileName']= config['name'] + try: + Data['Backuptype']= config['Backuptype'] + except: + Data['Backuptype'] = None + Data['WPsites'] = ACLManager.GetALLWPObjects(currentACL, userID) + proc = httpProc(request, 'websiteFunctions/WPRestoreHome.html', + Data, 'createWebsite') + return proc.render() + else: + return redirect("https://cyberpanel.net/cyberpanel-addons") def RestoreBackups(self, request=None, userID=None, DeleteID=None): Data = {} currentACL = ACLManager.loadedACL(userID) admin = Administrator.objects.get(pk=userID) - backobj = WPSitesBackup.objects.filter(owner=admin).order_by('-id') + url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission" + data = { + "name": "wp-manager", + "IP": ACLManager.GetServerIP() + } - try: - if DeleteID != None: - DeleteIDobj = WPSitesBackup.objects.get(pk=DeleteID, owner=admin) - config = DeleteIDobj.config - conf = json.loads(config) - FileName = conf['name'] - command = "rm -r /home/backup/%s.tar.gz"%FileName - ProcessUtilities.executioner(command) - DeleteIDobj.delete() + import requests + response = requests.post(url, data=json.dumps(data)) + Status = response.json()['status'] - except BaseException as msg: - pass - Data['job'] = [] + if (Status == 1) or ProcessUtilities.decideServer() == ProcessUtilities.ent: - for sub in backobj: - try: - wpsite = WPSites.objects.get(pk=sub.WPSiteID) - web = wpsite.title - except: - web = "Website Not Found" + backobj = WPSitesBackup.objects.filter(owner=admin).order_by('-id') try: - config = sub.config - conf = json.loads(config) - Backuptype = conf['Backuptype'] - except: - Backuptype = "Backup type not exists" + if DeleteID != None: + DeleteIDobj = WPSitesBackup.objects.get(pk=DeleteID, owner=admin) + config = DeleteIDobj.config + conf = json.loads(config) + FileName = conf['name'] + command = "rm -r /home/backup/%s.tar.gz"%FileName + ProcessUtilities.executioner(command) + DeleteIDobj.delete() + + except BaseException as msg: + pass + Data['job'] = [] + + for sub in backobj: + try: + wpsite = WPSites.objects.get(pk=sub.WPSiteID) + web = wpsite.title + except: + web = "Website Not Found" + + try: + config = sub.config + conf = json.loads(config) + Backuptype = conf['Backuptype'] + except: + Backuptype = "Backup type not exists" - Data['job'].append({ - 'id': sub.id, - 'title': web, - 'Backuptype': Backuptype - }) + Data['job'].append({ + 'id': sub.id, + 'title': web, + 'Backuptype': Backuptype + }) - - - - proc = httpProc(request, 'websiteFunctions/RestoreBackups.html', - Data, 'createWebsite') - return proc.render() + proc = httpProc(request, 'websiteFunctions/RestoreBackups.html', + Data, 'createWebsite') + return proc.render() + else: + return redirect("https://cyberpanel.net/cyberpanel-addons") def AutoLogin(self, request=None, userID=None): @@ -225,76 +265,99 @@ class WebsiteManager: #php = VirtualHost.getPHPString(self.data['PHPVersion']) #FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) - ## Get title + url = "https://platform.cyberpersons.com/CyberpanelAdOns/Adonpermission" + data = { + "name": "wp-manager", + "IP": ACLManager.GetServerIP() + } - password = randomPassword.generate_pass(10) + import requests + response = requests.post(url, data=json.dumps(data)) + Status = response.json()['status'] - command = 'sudo -u %s wp user create autologin %s --role=administrator --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (WPobj.owner.externalApp, 'autologin@cloudpages.cloud', password, WPobj.path) - ProcessUtilities.executioner(command) + if (Status == 1) or ProcessUtilities.decideServer() == ProcessUtilities.ent: - command = 'sudo -u %s wp user update autologin --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (WPobj.owner.externalApp, password, WPobj.path) - ProcessUtilities.executioner(command) + ## Get title - data = {} + password = randomPassword.generate_pass(10) - if WPobj.FinalURL.endswith('/'): - FinalURL = WPobj.FinalURL[:-1] + command = 'sudo -u %s wp user create autologin %s --role=administrator --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (WPobj.owner.externalApp, 'autologin@cloudpages.cloud', password, WPobj.path) + ProcessUtilities.executioner(command) + + command = 'sudo -u %s wp user update autologin --user_pass="%s" --path=%s --skip-plugins --skip-themes' % (WPobj.owner.externalApp, password, WPobj.path) + ProcessUtilities.executioner(command) + + data = {} + + if WPobj.FinalURL.endswith('/'): + FinalURL = WPobj.FinalURL[:-1] + else: + FinalURL = WPobj.FinalURL + + data['url'] = 'https://%s' % (FinalURL) + data['userName'] = 'autologin' + data['password'] = password + + proc = httpProc(request, 'websiteFunctions/AutoLogin.html', + data, 'createWebsite') + return proc.render() else: - FinalURL = WPobj.FinalURL - - data['url'] = 'https://%s' % (FinalURL) - data['userName'] = 'autologin' - data['password'] = password - - proc = httpProc(request, 'websiteFunctions/AutoLogin.html', - data, 'createWebsite') - return proc.render() + return redirect("https://cyberpanel.net/cyberpanel-addons") def ConfigurePlugins(self, request=None, userID=None, data=None): - DataPass ={} - currentACL = ACLManager.loadedACL(userID) - userobj = Administrator.objects.get(pk=userID) + if ACLManager.CheckForPremFeature('wp-manager'): + currentACL = ACLManager.loadedACL(userID) + userobj = Administrator.objects.get(pk=userID) - Selectedplugins = wpplugins.objects.filter(owner = userobj) - #data['Selectedplugins'] = wpplugins.objects.filter(ProjectOwner=HostingCompany) + Selectedplugins = wpplugins.objects.filter(owner = userobj) + #data['Selectedplugins'] = wpplugins.objects.filter(ProjectOwner=HostingCompany) - Data = {'Selectedplugins' : Selectedplugins,} - proc = httpProc(request, 'websiteFunctions/WPConfigurePlugins.html', - Data, 'createWebsite') - return proc.render() + Data = {'Selectedplugins' : Selectedplugins,} + proc = httpProc(request, 'websiteFunctions/WPConfigurePlugins.html', + Data, 'createWebsite') + return proc.render() + else: + return redirect("https://cyberpanel.net/cyberpanel-addons") def Addnewplugin(self, request=None, userID=None, data=None): - currentACL = ACLManager.loadedACL(userID) - adminNames = ACLManager.loadAllUsers(userID) - packagesName = ACLManager.loadPackages(userID, currentACL) - phps = PHPManager.findPHPVersions() + if ACLManager.CheckForPremFeature('wp-manager'): + currentACL = ACLManager.loadedACL(userID) + adminNames = ACLManager.loadAllUsers(userID) + packagesName = ACLManager.loadPackages(userID, currentACL) + phps = PHPManager.findPHPVersions() - Data = {'packageList': packagesName, "owernList": adminNames, 'phps': phps} - proc = httpProc(request, 'websiteFunctions/WPAddNewPlugin.html', - Data, 'createWebsite') - return proc.render() + Data = {'packageList': packagesName, "owernList": adminNames, 'phps': phps} + proc = httpProc(request, 'websiteFunctions/WPAddNewPlugin.html', + Data, 'createWebsite') + return proc.render() + return redirect("https://cyberpanel.net/cyberpanel-addons") def SearchOnkeyupPlugin(self, userID=None, data=None): try: - currentACL = ACLManager.loadedACL(userID) + if ACLManager.CheckForPremFeature('wp-manager'): + currentACL = ACLManager.loadedACL(userID) - pluginname = data['pluginname'] - # logging.CyberCPLogFileWriter.writeToFile("Plugin Name ....... %s"%pluginname) + pluginname = data['pluginname'] + # logging.CyberCPLogFileWriter.writeToFile("Plugin Name ....... %s"%pluginname) - url = "http://api.wordpress.org/plugins/info/1.1/?action=query_plugins&request[search]=%s" % str(pluginname) - import requests + url = "http://api.wordpress.org/plugins/info/1.1/?action=query_plugins&request[search]=%s" % str(pluginname) + import requests - res = requests.get(url) - r = res.json() + res = requests.get(url) + r = res.json() - # return proc.ajax(1, 'Done', {'plugins': r}) + # return proc.ajax(1, 'Done', {'plugins': r}) - data_ret = {'status': 1,'plugns': r,} + data_ret = {'status': 1,'plugns': r,} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': 'Premium feature not available.'} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) except BaseException as msg: data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': str(msg)} @@ -715,7 +778,6 @@ class WebsiteManager: json_data = json.dumps(data_ret) return HttpResponse(json_data) - def DeploytoProduction(self, userID=None, data=None): try: @@ -762,7 +824,6 @@ class WebsiteManager: json_data = json.dumps(data_ret) return HttpResponse(json_data) - def WPCreateBackup(self, userID=None, data=None): try: @@ -802,7 +863,6 @@ class WebsiteManager: json_data = json.dumps(data_ret) return HttpResponse(json_data) - def RestoreWPbackupNow(self, userID=None, data=None): try: @@ -812,6 +872,7 @@ class WebsiteManager: backupid = data['backupid'] DesSiteID = data['DesSite'] + Domain = data['Domain'] From 9c0f4927ae12589c9e64fd48f841a15ff7027360 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 17 Jun 2022 12:21:06 +0500 Subject: [PATCH 2/4] add lsws conversion to cli --- cli/cliParser.py | 1 + cli/cyberPanel.py | 12 +++++++++ serverStatus/serverStatusUtil.py | 44 +++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/cli/cliParser.py b/cli/cliParser.py index 00c7cb7d7..5f968afc3 100755 --- a/cli/cliParser.py +++ b/cli/cliParser.py @@ -63,6 +63,7 @@ class cliParser: parser.add_argument('--selectedACL', help='Select ACL while creating user.') parser.add_argument('--securityLevel', help='Set security level while creating user.') parser.add_argument('--state', help='State value used in user suspension.') + parser.add_argument('--licenseKey', help='LSWS License Key') ### WP Install diff --git a/cli/cyberPanel.py b/cli/cyberPanel.py index f17755e51..734136e70 100755 --- a/cli/cyberPanel.py +++ b/cli/cyberPanel.py @@ -1582,6 +1582,18 @@ def main(): wm = WebsiteManager() wm.installJoomla(1, data) + elif args.function == "switchTOLSWS": + + completeCommandExample = 'cyberpanel switchTOLSWS --licenseKey -1: + command = "sudo rm -f " + ServerStatusUtil.lswsInstallStatusPath + ProcessUtilities.popenExecutioner(command) + data_ret = {'status': 1, 'abort': 1, 'requestStatus': output, 'installed': 0} + print(str(data_ret)) + return 0 + elif output.find('[200]') > -1: + command = "sudo rm -f " + ServerStatusUtil.lswsInstallStatusPath + ProcessUtilities.popenExecutioner(command) + data_ret = {'status': 1, 'abort': 1, 'requestStatus': 'Successfully converted.', 'installed': 1} + print(str(data_ret)) + return 1 + else: + data_ret = {'status': 1, 'abort': 0, 'requestStatus': output, 'installed': 0} + #print(output) + time.sleep(2) + + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + + def main(): parser = argparse.ArgumentParser(description='Server Status Util.') From 43ccbe3ef5ec2b5077938f7dfae5002c8c920d30 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 17 Jun 2022 12:47:21 +0500 Subject: [PATCH 3/4] bug fix: lsws converter --- cli/cliParser.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/cliParser.py b/cli/cliParser.py index 1fa1bf2c2..bd7ef4231 100755 --- a/cli/cliParser.py +++ b/cli/cliParser.py @@ -63,7 +63,6 @@ class cliParser: parser.add_argument('--selectedACL', help='Select ACL while creating user.') parser.add_argument('--securityLevel', help='Set security level while creating user.') parser.add_argument('--state', help='State value used in user suspension.') - parser.add_argument('--licenseKey', help='LSWS License Key') ### WP Install From 4076960efbbea9fcf9b765fe721410aa40814951 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 17 Jun 2022 20:01:57 +0500 Subject: [PATCH 4/4] some bug fixing in pp --- cyberpanel_upgrade.sh | 1 + plogical/applicationInstaller.py | 40 +++++------ plogical/vhostConfs.py | 2 +- plogical/virtualHostUtilities.py | 70 +++++++++++++------ .../websiteFunctions/RestoreBackups.html | 2 +- websiteFunctions/website.py | 16 ++++- 6 files changed, 87 insertions(+), 44 deletions(-) diff --git a/cyberpanel_upgrade.sh b/cyberpanel_upgrade.sh index 457d2bc28..cf18ef552 100644 --- a/cyberpanel_upgrade.sh +++ b/cyberpanel_upgrade.sh @@ -401,6 +401,7 @@ EOF #enabled=1 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial #EOF + rm -f /etc/yum.repos.d/CentOS-PowerTools-CyberPanel.repo if [[ "$Server_Country" = "CN" ]] ; then dnf --nogpg install -y https://cyberpanel.sh/mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el8.noarch.rpm diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 8803bb03e..ef4017134 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -2274,7 +2274,6 @@ $parameters = array( WPsitepath = wpsite.path websitedomain = website.domain - php = PHPManager.getPHPString(PhpVersion) FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) @@ -2283,7 +2282,6 @@ $parameters = array( logging.statusWriter(self.tempStatusPath, 'Getting database...,20') command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path={WPsitepath}' - retStatus, stdoutput = ProcessUtilities.outputExecutioner(command, VHuser, None, None, 1) if stdoutput.find('Error:') == -1: @@ -2348,10 +2346,12 @@ $parameters = array( config['Webadmin_id'] = website.admin_id config['name'] = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S") config['Backuptype'] = "Both Website and DataBase" + ###############Create config.Json file #command = "sudo -u %s touch /home/cyberpanel/config.json" % (VHuser) #ProcessUtilities.executioner(command) ###### write into config + json_object = json.dumps(config, indent=4) configPath = "/home/cyberpanel/" + str(randint(1000, 9999)) file = open(configPath, "w") @@ -2361,13 +2361,16 @@ $parameters = array( os.chmod(configPath, 0o600) command = f"cp -R {configPath} {self.tempPath}" - if ProcessUtilities.executioner(command, VHuser) == 0: - raise BaseException('Failed to copy config file to temp path.') + retStatus, stdoutput = ProcessUtilities.outputExecutioner(command, VHuser, None, None, 1) + if retStatus == 0: + raise BaseException(stdoutput) command = f"rm -r {configPath}" - if ProcessUtilities.executioner(command) == 0: - raise BaseException('Failed to remove config.') + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Copying website data.....,50') @@ -2393,7 +2396,6 @@ $parameters = array( logging.statusWriter(self.tempStatusPath, 'Copying database.....,70') - ##### SQLDUMP database into new directory command = "mysqldump %s --result-file %s/%s.sql" % (DataBaseName, self.tempPath, DataBaseName) @@ -2409,8 +2411,6 @@ $parameters = array( ######## Zip backup directory logging.statusWriter(self.tempStatusPath, 'Compressing backup files.....,80') - websitepath = "/home/%s"%websitedomain - command = 'mkdir -p /home/backup/' result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -2424,8 +2424,8 @@ $parameters = array( if retStatus == 0: raise BaseException(result) - if os.path.exists(ProcessUtilities.debugPath): - logging.writeToFile(result) + #if os.path.exists(ProcessUtilities.debugPath): + # logging.writeToFile(result) backupobj = WPSitesBackup(owner=Adminobj, WPSiteID=wpsite.id, WebsiteID=website.id, config=json_object) @@ -2490,6 +2490,7 @@ $parameters = array( config['Webadmin_id'] = website.admin_id config['name'] = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S") config['Backuptype'] = "Website Backup" + ###############Create config.Json file # command = "sudo -u %s touch /home/cyberpanel/config.json" % (VHuser) # ProcessUtilities.executioner(command) @@ -2504,13 +2505,16 @@ $parameters = array( os.chmod(configPath, 0o600) command = f"cp -R {configPath} {self.tempPath}" + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) - if ProcessUtilities.executioner(command) == 0: - raise BaseException('Failed to copy config file to temp path.') + if result == 0: + raise BaseException(stdout) command = f"rm -r {configPath}" - if ProcessUtilities.executioner(command) == 0: - raise BaseException('Failed to remove config temp file.') + result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) + + if result == 0: + raise BaseException(stdout) logging.statusWriter(self.tempStatusPath, 'Copying website data.....,50') @@ -2663,10 +2667,6 @@ $parameters = array( ######## Zip backup directory logging.statusWriter(self.tempStatusPath, 'Compressing backup files.....,80') - websitepath = "/home/%s" % websitedomain - - FinalZipPath = '%s/%s.zip' % (websitepath, RandomPath) - command = 'mkdir -p /home/backup/' result, stdout = ProcessUtilities.outputExecutioner(command, None, None, None, 1) @@ -2710,6 +2710,7 @@ $parameters = array( from managePHP.phpManager import PHPManager from websiteFunctions.website import WebsiteManager from packages.models import Package + if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile("Error Restore WP backup Now ....... start:%s"% self.extraArgs['Domain']) @@ -3991,7 +3992,6 @@ $parameters = array( installUtilities.reStartLiteSpeed() - logging.statusWriter(self.tempStatusPath, 'Completed.[200]') except BaseException as msg: logging.writeToFile("Error RestoreWPbackupNow ....... %s" % str(msg)) diff --git a/plogical/vhostConfs.py b/plogical/vhostConfs.py index 16076f806..02872fa1d 100755 --- a/plogical/vhostConfs.py +++ b/plogical/vhostConfs.py @@ -475,7 +475,7 @@ pm.max_spare_servers = {pmMaxSpareServers} realm {{RealM_Name}} { userDB { - location $SERVER_ROOT/conf/vhosts/$VH_NAME/{{wpid}} + location {{PassFile}} } } diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 9dbb9f453..bf6520cae 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -1246,17 +1246,38 @@ class virtualHostUtilities: return DiskUsage, DiskUsagePercentage, bwInMB, bwUsage @staticmethod - def EnableDisablePP(vhostName, username=None, password=None, path=None, wpid=None): + def EnableDisablePP(vhostName, username=None, password=None, path=None, wpid=None, externalApp = None): try: + vhostPassDir = f'/home/{vhostName}' + + uBuntuPath = '/etc/lsb-release' + + if os.path.exists(uBuntuPath): + group = 'nogroup' + else: + group = 'nobody' + + confPath = f'{virtualHostUtilities.vhostConfPath}/vhosts/{vhostName}/vhost.conf' - htpassword = f'{virtualHostUtilities.vhostConfPath}/vhosts/{vhostName}/{wpid}' + htpassword = f'{vhostPassDir}/{wpid}' + htpasstemp = f'/usr/local/CyberCP/{wpid}' + + command = f'touch {htpasstemp}' + ProcessUtilities.executioner(command) + + command = f'chown {externalApp}:{group} {htpasstemp}' + ProcessUtilities.executioner(command) FindLine = f'PASSWORD PROTECTION CONF STARTS {path}' FindLineEnd = f'PASSWORD PROTECTION CONF ENDS {path}' if ProcessUtilities.decideServer() == ProcessUtilities.OLS: if os.path.exists(htpassword): - os.remove(htpassword) + + command = f'rm -f {htpassword}' + ProcessUtilities.executioner(command, externalApp) + + #os.remove(htpassword) removeCheck = 0 data = open(confPath, 'r').readlines() @@ -1279,6 +1300,7 @@ class virtualHostUtilities: OLSPPConf = OLSPPConf.replace('{{RealM_Name}}', str(randint(1000, 9999))) OLSPPConf = OLSPPConf.replace('{{path}}', path) OLSPPConf = OLSPPConf.replace('{{wpid}}', wpid) + OLSPPConf = OLSPPConf.replace('{{PassFile}}', htpassword) writeToFile.write(OLSPPConf) writeToFile.close() @@ -1288,26 +1310,30 @@ class virtualHostUtilities: password = password.encode() hashed = bcrypt.hashpw(password, bcrypt.gensalt()) UserPass = f'{username}:{hashed.decode()}:{username}' - writeToFile = open(htpassword, 'w') + + writeToFile = open(htpasstemp, 'w') writeToFile.write(UserPass) writeToFile.close() - os.chmod(htpassword, 0o644) + command = f'cp {htpasstemp} {htpassword}' + ProcessUtilities.executioner(command, externalApp) - uBuntuPath = '/etc/lsb-release' + os.remove(htpasstemp) - if os.path.exists(uBuntuPath): - group = 'nogroup' - else: - group = 'nobody' + command = f'chmod 640 {htpassword}' + ProcessUtilities.executioner(command, externalApp, True) - command = f'chown lsadm:{group} {htpassword}' + command = f'sudo -u {externalApp} -g {group} chown {externalApp}:{group} {htpassword}' ProcessUtilities.executioner(command) else: RealmName = str(randint(1000, 9999)) htaccesspath = f'{path}/.htaccess' if os.path.exists(htpassword): - os.remove(htpassword) + + command = f'rm -f {htpassword}' + ProcessUtilities.executioner(command, externalApp) + + #os.remove(htpassword) removeCheck = 0 if os.path.exists(htaccesspath): @@ -1340,20 +1366,22 @@ class virtualHostUtilities: password = password.encode() hashed = bcrypt.hashpw(password, bcrypt.gensalt()) UserPass = f'{username}:{hashed.decode()}:{username}' - writeToFile = open(htpassword, 'w') + + + writeToFile = open(htpasstemp, 'w') writeToFile.write(UserPass) writeToFile.close() - os.chmod(htpassword, 0o644) + command = f'cp {htpasstemp} {htpassword}' + ProcessUtilities.executioner(command, externalApp) - uBuntuPath = '/etc/lsb-release' + os.remove(htpasstemp) - if os.path.exists(uBuntuPath): - group = 'nogroup' - else: - group = 'nobody' + command = f'chmod 640 {htpassword}' + ProcessUtilities.executioner(command, externalApp, True) - command = f'chown lsadm:{group} {htpassword}' + + command = f'sudo -u {externalApp} -g {group} chown {externalApp}:{group} {htpassword}' ProcessUtilities.executioner(command) installUtilities.installUtilities.reStartLiteSpeed() @@ -1534,7 +1562,7 @@ def main(): elif args.function == 'switchServer': virtualHostUtilities.switchServer(args.virtualHostName, args.phpVersion, int(args.server), args.tempStatusPath) elif args.function == 'EnableDisablePP': - virtualHostUtilities.EnableDisablePP(args.virtualHostName, args.username, args.password, args.path, args.wpid) + virtualHostUtilities.EnableDisablePP(args.virtualHostName, args.username, args.password, args.path, args.wpid, args.virtualHostUser) if __name__ == "__main__": diff --git a/websiteFunctions/templates/websiteFunctions/RestoreBackups.html b/websiteFunctions/templates/websiteFunctions/RestoreBackups.html index c90bd0e86..e5f18e4c1 100644 --- a/websiteFunctions/templates/websiteFunctions/RestoreBackups.html +++ b/websiteFunctions/templates/websiteFunctions/RestoreBackups.html @@ -101,7 +101,7 @@ Website - BackUp Tpye + Type Action diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 55321b991..fadfeeb3c 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -872,6 +872,19 @@ class WebsiteManager: backupid = data['backupid'] DesSiteID = data['DesSite'] + # bwp = WPSites.objects.get(pk=int(backupid)) + # dwp = WPSites.objects.get(pk=int(DesSiteID)) + # + # if ACLManager.checkOwnership(bwp.owner.domain, admin, currentACL) == 1: + # pass + # else: + # return ACLManager.loadError() + # + # if ACLManager.checkOwnership(dwp.owner.domain, admin, currentACL) == 1: + # pass + # else: + # return ACLManager.loadError() + Domain = data['Domain'] @@ -1347,7 +1360,8 @@ class WebsiteManager: 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}' --virtualHostName {Webobj.domain} --path {path} --wpid {str(wpsite.id)}" + execPath = f"{execPath} EnableDisablePP --username '{PPUsername}' --password '{PPPassword}' " \ + f"--virtualHostName {Webobj.domain} --path {path} --wpid {str(wpsite.id)} --virtualHostUser {Webobj.externalApp}" ProcessUtilities.executioner(execPath)