From e28e6ee6980231c3d2c0b9b21d827c06c1120931 Mon Sep 17 00:00:00 2001 From: Tim Brugman Date: Tue, 1 Mar 2022 02:51:37 +0100 Subject: [PATCH 001/178] bug fix: Duplicate file --- install/cyberpanel.repo | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 install/cyberpanel.repo diff --git a/install/cyberpanel.repo b/install/cyberpanel.repo deleted file mode 100644 index 4dc23d316..000000000 --- a/install/cyberpanel.repo +++ /dev/null @@ -1,5 +0,0 @@ -[CyberPanel] -name=CyberPanel -baseurl=https://rep.cyberpanel.net/ -gpgkey=https://rep.cyberpanel.net/RPM-GPG-KEY-cyberpanel -gpgcheck=1 \ No newline at end of file From bf36a4eaec635bf1604b8bc114a74800cb231b1f Mon Sep 17 00:00:00 2001 From: Tim Brugman Date: Tue, 1 Mar 2022 03:00:04 +0100 Subject: [PATCH 002/178] add ids to menu items --- .../templates/baseTemplate/index.html | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 18c90e470..997472f8d 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -297,31 +297,31 @@
@@ -362,6 +362,55 @@
+
+

Create Backup Now

+
+ +
+
+ +
+ +
+

{$ currentStatus $}

+
+ +
+
+ 70% Complete +
+
+ +
+

{% trans "Error message:" %} {$ errorMessage $}

+
+ +
+

{% trans "Backup succesfully created." %}

+
+ + +
+

{% trans "Could not connect to server. Please refresh this page." %}

+
+ + +
+
+
+
+ +
+
+
+
@@ -396,11 +445,7 @@ Autoupdate Configurations -
- -
+ - - - + + {% endblock %} diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index 2c3f730d1..bd217c996 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -56,6 +56,7 @@ def WPHome(request): return wm.WPHome(request, userID, WPid, DeleteID) except KeyError: return redirect(loadLoginPage) + def AutoLogin(request): try: userID = request.session['userID'] @@ -305,19 +306,19 @@ def DeploytoProduction(request): try: userID = request.session['userID'] - result = pluginManager.preWebsiteCreation(request) + #result = pluginManager.preWebsiteCreation(request) - if result != 200: - return result + #if result != 200: + # return result wm = WebsiteManager() - coreResult = wm.DeploytoProduction(userID, json.loads(request.body)) + return wm.DeploytoProduction(userID, json.loads(request.body)) - result = pluginManager.postWebsiteCreation(request, coreResult) - if result != 200: - return result + #result = pluginManager.postWebsiteCreation(request, coreResult) + #if result != 200: + # return result - return coreResult + #return coreResult except KeyError: return redirect(loadLoginPage) diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 7669f9f6f..81e42fc0a 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -659,20 +659,27 @@ class WebsiteManager: wpsite = WPSites.objects.get(pk=WPManagerID) StagingObj = WPSites.objects.get(pk=statgingID) + ### + if ACLManager.checkOwnership(wpsite.owner.domain, admin, currentACL) == 1: pass else: return ACLManager.loadError() + if ACLManager.checkOwnership(StagingObj.owner.domain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadError() + + ### + extraArgs = {} extraArgs['adminID'] = admin.pk - extraArgs['StagingDomain'] = StagingObj.FinalURL - extraArgs['StagingName'] = StagingObj.title + extraArgs['statgingID'] = statgingID extraArgs['WPid'] = WPManagerID extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) - - background = ApplicationInstaller('CreateStagingNow', extraArgs) + background = ApplicationInstaller('DeploytoProduction', extraArgs) background.start() time.sleep(2) From fe50a30a79f15f4ae78e8a3182fc0a8ba4ccf06c Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Tue, 7 Jun 2022 13:50:32 +0500 Subject: [PATCH 097/178] resolve conflic --- plogical/applicationInstaller.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index b073d6b7e..c960024e1 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -2246,7 +2246,7 @@ $parameters = array( command = f'rm -rf {self.tempPath}' - #ProcessUtilities.executioner(command) + ProcessUtilities.executioner(command) logging.statusWriter(self.tempStatusPath, 'Completed.[200]') @@ -2258,7 +2258,6 @@ $parameters = array( mesg = '%s. [404]' % (str(msg)) logging.statusWriter(self.tempStatusPath, mesg) - def WPCreateBackup(self): try: from managePHP.phpManager import PHPManager From f2bb90649e8e90e7a63a24afa0d208cff6c6e412 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Tue, 7 Jun 2022 13:59:06 +0500 Subject: [PATCH 098/178] backups table --- plogical/upgrade.py | 10 ++++++++++ websiteFunctions/models.py | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 7cccd7b32..2f2709862 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -905,6 +905,16 @@ autocreate_system_folders = On except: pass + try: + cursor.execute("CREATE TABLE `websiteFunctions_wpsitesbackup` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `WPSiteID` integer NOT NULL, `WebsiteID` integer NOT NULL, `config` longtext NOT NULL, `owner_id` integer NOT NULL); ") + except: + pass + + try: + cursor.execute("ALTER TABLE `websiteFunctions_wpsitesbackup` ADD CONSTRAINT `websiteFunctions_wps_owner_id_8a8dd0c5_fk_loginSyst` FOREIGN KEY (`owner_id`) REFERENCES `loginSystem_administrator` (`id`); ") + except: + pass + try: connection.close() except: diff --git a/websiteFunctions/models.py b/websiteFunctions/models.py index c799a29bd..34647f3e1 100755 --- a/websiteFunctions/models.py +++ b/websiteFunctions/models.py @@ -122,3 +122,9 @@ class WPSites(models.Model): class WPStaging(models.Model): owner = models.ForeignKey(WPSites, on_delete=models.CASCADE) wpsite = models.ForeignKey(WPSites, on_delete=models.CASCADE, related_name='actual_wpsite') + +class WPSitesBackup(models.Model): + owner = models.ForeignKey(Administrator, on_delete=models.CASCADE) + WPSiteID = models.IntegerField(default=-1) + WebsiteID = models.IntegerField(default=-1) + config = models.TextField() From 698c0385c535aa527d774296d462a1e1fa33ea4f Mon Sep 17 00:00:00 2001 From: Hassan Hashmi <75794688+habbi-hb@users.noreply.github.com> Date: Tue, 7 Jun 2022 13:59:42 +0500 Subject: [PATCH 099/178] backupdoneini --- plogical/applicationInstaller.py | 7 +++++-- .../static/websiteFunctions/websiteFunctions.js | 9 +++++++++ .../templates/websiteFunctions/WPsiteHome.html | 2 +- websiteFunctions/website.py | 1 - 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index e76a518d9..527f04581 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -2147,10 +2147,11 @@ $parameters = array( from managePHP.phpManager import PHPManager import json tempStatusPath = self.extraArgs['tempStatusPath'] + self.tempStatusPath = tempStatusPath + statusFile = open(tempStatusPath, 'w') statusFile.writelines('Creating BackUp...,10') statusFile.close() - wpsite = WPSites.objects.get(pk=self.extraArgs['WPid']) website =Websites.objects.get(pk=wpsite.owner_id) @@ -2282,10 +2283,10 @@ $parameters = array( if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(result) + command = f'rm -rf {tempPath}' ProcessUtilities.executioner(command) - statusFile = open(tempStatusPath, 'w') statusFile.writelines("Successfully Created. [200]") statusFile.close() @@ -2293,6 +2294,8 @@ $parameters = array( except BaseException as msg: + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) logging.writeToFile("Error WPCreateBackup ....... %s" % str(msg)) statusFile = open(self.tempStatusPath, 'w') statusFile.writelines(str(msg) + " [404]") diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index c8f8eb2b3..7f7eb881d 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -1149,10 +1149,14 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo $scope.goBackDisable = false; $("#installProgress").css("width", "100%"); + $("#installProgressbackup").css("width", "100%"); $scope.installPercentage = "100"; $scope.currentStatus = response.data.currentStatus; $timeout.cancel(); + + + } else { $scope.wordpresshomeloading = true; @@ -1166,17 +1170,22 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo $scope.errorMessage = response.data.error_message; $("#installProgress").css("width", "0%"); + $("#installProgressbackup").css("width", "0%"); $scope.installPercentage = "0"; $scope.goBackDisable = false; + + } } else { $("#installProgress").css("width", response.data.installationProgress + "%"); + $("#installProgressbackup").css("width", response.data.installationProgress + "%"); $scope.installPercentage = response.data.installationProgress; $scope.currentStatus = response.data.currentStatus; $timeout(getCreationStatus, 1000); + } } diff --git a/websiteFunctions/templates/websiteFunctions/WPsiteHome.html b/websiteFunctions/templates/websiteFunctions/WPsiteHome.html index 3d6b21343..fdd0c619a 100644 --- a/websiteFunctions/templates/websiteFunctions/WPsiteHome.html +++ b/websiteFunctions/templates/websiteFunctions/WPsiteHome.html @@ -378,7 +378,7 @@
-
diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 421c9fee2..89cab4e21 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -710,7 +710,6 @@ class WebsiteManager: extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) - background = ApplicationInstaller('WPCreateBackup', extraArgs) background.start() From 9589380af9c72a6d612c11880efc31debc46fb44 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Tue, 7 Jun 2022 15:14:03 +0500 Subject: [PATCH 100/178] convert to lsws ent via cli --- cli/cliParser.py | 5 +++++ cli/cyberPanel.py | 12 ++++++++++++ serverStatus/serverStatusUtil.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/cli/cliParser.py b/cli/cliParser.py index 00c7cb7d7..bd7ef4231 100755 --- a/cli/cliParser.py +++ b/cli/cliParser.py @@ -70,4 +70,9 @@ class cliParser: parser.add_argument('--siteTitle', help='Site Title for application installers.') parser.add_argument('--path', help='Path for application installers.') + ### Convert to LSWS Ent via cli + + parser.add_argument('--licenseKey', help='LiteSpeed Enterprise License key') + + return parser.parse_args() 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) + + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + def main(): parser = argparse.ArgumentParser(description='Server Status Util.') From 4e0c8c2ac973ce8cba57d82926d07e3d83bc1da8 Mon Sep 17 00:00:00 2001 From: Hassan Hashmi <75794688+habbi-hb@users.noreply.github.com> Date: Wed, 8 Jun 2022 15:55:36 +0500 Subject: [PATCH 101/178] backuplistanddelete --- .../templates/baseTemplate/index.html | 3 + plogical/applicationInstaller.py | 56 +++--- .../websiteFunctions/websiteFunctions.js | 1 + .../websiteFunctions/RestoreBackups.html | 179 ++++++++++++++++++ websiteFunctions/urls.py | 1 + websiteFunctions/views.py | 9 + websiteFunctions/website.py | 41 +++- 7 files changed, 259 insertions(+), 31 deletions(-) create mode 100644 websiteFunctions/templates/websiteFunctions/RestoreBackups.html diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 7e60963b5..3516383a2 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -415,6 +415,9 @@
  • {% trans "Configure Plugins" %}
  • +
  • {% trans "Restore Backups" %} +
  • diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index f7a8c16f6..be6445751 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -16,7 +16,7 @@ django.setup() import threading as multi from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging import subprocess -from websiteFunctions.models import ChildDomains, Websites, WPSites, WPStaging, wpplugins +from websiteFunctions.models import ChildDomains, Websites, WPSites, WPStaging, wpplugins, WPSitesBackup from plogical import randomPassword from plogical.mysqlUtilities import mysqlUtilities from databases.models import Databases @@ -2262,13 +2262,12 @@ $parameters = array( try: from managePHP.phpManager import PHPManager import json - tempStatusPath = self.extraArgs['tempStatusPath'] - self.tempStatusPath = tempStatusPath + logging.writeToFile("WPCreateBackup ....... start" ) + self.tempStatusPath = self.extraArgs['tempStatusPath'] + logging.statusWriter(self.tempStatusPath, 'Creating BackUp...,10') - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Creating BackUp...,10') - statusFile.close() wpsite = WPSites.objects.get(pk=self.extraArgs['WPid']) + Adminobj = Administrator.objects.get(pk=self.extraArgs['adminID']) website =Websites.objects.get(pk=wpsite.owner_id) PhpVersion = website.phpSelection @@ -2279,9 +2278,9 @@ $parameters = array( php = PHPManager.getPHPString(PhpVersion) FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Getting DataBase...,20') - statusFile.close() + + + logging.statusWriter(self.tempStatusPath, 'Getting DataBase...,20') command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % (VHuser, FinalPHPPath, WPsitepath) stdoutput = ProcessUtilities.outputExecutioner(command) @@ -2308,9 +2307,7 @@ $parameters = array( ProcessUtilities.executioner(command) ### Make directory for backup - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Creating Backup Directory...,40') - statusFile.close() + logging.statusWriter(self.tempStatusPath, 'Creating Backup Directory...,40') command = "sudo -u %s mkdir -p %s/public_html" % (VHuser, tempPath) ProcessUtilities.executioner(command) @@ -2355,9 +2352,8 @@ $parameters = array( command = "rm -r /home/cyberpanel/config.json" ProcessUtilities.executioner(command) - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Copying website data.....,50') - statusFile.close() + logging.statusWriter(self.tempStatusPath, 'Copying website data.....,50') + ############## Copy Public_htnl to backup command = "sudo -u %s cp -R %s* %s/public_html" % (VHuser, WPsitepath, tempPath) @@ -2372,9 +2368,9 @@ $parameters = array( if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(result) - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Copying DataBase.....,70') - statusFile.close() + logging.statusWriter(self.tempStatusPath, 'Copying DataBase.....,70') + + ##### SQLDUMP database into new directory @@ -2385,10 +2381,10 @@ $parameters = array( if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(result) + + ######## Zip backup directory - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Compressing backup files.....,90') - statusFile.close() + logging.statusWriter(self.tempStatusPath, 'Compressing backup files.....,80') websitepath = "/home/%s"%websitedomain @@ -2396,26 +2392,26 @@ $parameters = array( command = "sudo -u %s tar -czvf %s -P %s" % (VHuser, FinalZipPath, tempPath) result = ProcessUtilities.outputExecutioner(command) + + + backupobj = WPSitesBackup(owner=Adminobj, WPSiteID=wpsite.id, WebsiteID=website.id, config=json_object) + backupobj.save() if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(result) - - command = f'rm -rf {tempPath}' ProcessUtilities.executioner(command) - statusFile = open(tempStatusPath, 'w') - statusFile.writelines("Successfully Created. [200]") - statusFile.close() + + + logging.statusWriter(self.tempStatusPath, 'Completed.[200]') return 0 except BaseException as msg: + logging.writeToFile("Error WPCreateBackup ....... %s" % str(msg)) command = f'rm -rf {self.tempPath}' ProcessUtilities.executioner(command) - logging.writeToFile("Error WPCreateBackup ....... %s" % str(msg)) - statusFile = open(self.tempStatusPath, 'w') - statusFile.writelines(str(msg) + " [404]") - statusFile.close() + logging.statusWriter(self.tempStatusPath, str(msg)) return 0 diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index bbfd4fcce..44f523a92 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -1154,6 +1154,7 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo $scope.couldNotConnect = true; $scope.goBackDisable = false; + $("#installProgress").css("width", "100%"); $("#installProgressbackup").css("width", "100%"); $scope.installPercentage = "100"; diff --git a/websiteFunctions/templates/websiteFunctions/RestoreBackups.html b/websiteFunctions/templates/websiteFunctions/RestoreBackups.html new file mode 100644 index 000000000..adc067a74 --- /dev/null +++ b/websiteFunctions/templates/websiteFunctions/RestoreBackups.html @@ -0,0 +1,179 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "Restore Backpus - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + + + + + + +
    + +
    +

    {% trans "List Backups " %} +

    + +

    {% trans "On this page you can Restore, list, modify and delete Backups Wordpress Sites from your server." %}

    +
    + + + + + + + + + + + + + + {% for sub in job %} + + + + + + + + + + {% endfor %} + + + + +
    ID + Website + Action +
    + +

    {{ sub.id }}

    +
    +
    + {{ sub.title }} + + + + + + +
    + + +
    + +{% endblock %} diff --git a/websiteFunctions/urls.py b/websiteFunctions/urls.py index 2115cd4e3..d5f37e100 100755 --- a/websiteFunctions/urls.py +++ b/websiteFunctions/urls.py @@ -20,6 +20,7 @@ urlpatterns = [ url(r'^createWordpress$', views.WPCreate, name='createWordpress'), url(r'^ListWPSites$', views.ListWPSites, name='ListWPSites'), url(r'^WPHome$', views.WPHome, name='WPHome'), + url(r'^RestoreBackups$', views.RestoreBackups, name='RestoreBackups'), url(r'^AutoLogin$', views.AutoLogin, name='AutoLogin'), diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py index c55f3075c..8cc6dc5ed 100755 --- a/websiteFunctions/views.py +++ b/websiteFunctions/views.py @@ -56,6 +56,15 @@ def WPHome(request): return wm.WPHome(request, userID, WPid, DeleteID) except KeyError: return redirect(loadLoginPage) +def RestoreBackups(request): + try: + userID = request.session['userID'] + + DeleteID = request.GET.get('DeleteID') + wm = WebsiteManager() + return wm.RestoreBackups(request, userID, DeleteID) + except KeyError: + return redirect(loadLoginPage) def AutoLogin(request): try: diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 3e424f0e8..dac489109 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -12,7 +12,7 @@ django.setup() import json from plogical.acl import ACLManager import plogical.CyberCPLogFileWriter as logging -from websiteFunctions.models import Websites, ChildDomains, GitLogs, wpplugins, WPSites, WPStaging +from websiteFunctions.models import Websites, ChildDomains, GitLogs, wpplugins, WPSites, WPStaging, WPSitesBackup from plogical.virtualHostUtilities import virtualHostUtilities import subprocess import shlex @@ -142,6 +142,45 @@ class WebsiteManager: Data, 'createWebsite') return proc.render() + 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) + + try: + if DeleteID != None: + DeleteIDobj = WPSitesBackup.objects.get(pk=DeleteID) + 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" + + Data['job'].append({ + 'id': sub.id, + 'title': web, + }) + + + + + + proc = httpProc(request, 'websiteFunctions/RestoreBackups.html', + Data, 'createWebsite') + return proc.render() + def AutoLogin(self, request=None, userID=None): WPid = request.GET.get('id') From d4795c3e74b62aab0ec2b7e6cb3528c13c8fc1e3 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Wed, 8 Jun 2022 19:37:55 +0500 Subject: [PATCH 102/178] resolve alma issue, ref https://github.com/usmannasir/cyberpanel/issues/891 --- install/installCyberPanel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/installCyberPanel.py b/install/installCyberPanel.py index f0a5a7f1c..60c10cd9c 100755 --- a/install/installCyberPanel.py +++ b/install/installCyberPanel.py @@ -248,7 +248,7 @@ class InstallCyberPanel: subprocess.call(command, shell=True) if self.distro == cent8: - command = 'dnf install lsphp71* lsphp72* lsphp73* lsphp74* lsphp80* --exclude lsphp73-pecl-zip -y' + command = 'dnf install lsphp71* lsphp72* lsphp73* lsphp74* lsphp80* --exclude lsphp73-pecl-zip --exclude *imagick* -y' subprocess.call(command, shell=True) def installMySQL(self, mysql): From 9b636e6c1a589317cbee6475d718b164ed36f65e Mon Sep 17 00:00:00 2001 From: Hassan Hashmi <75794688+habbi-hb@users.noreply.github.com> Date: Wed, 8 Jun 2022 19:46:00 +0500 Subject: [PATCH 103/178] backuplistanddelete1 --- websiteFunctions/website.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index dac489109..2e62f4fe3 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -147,9 +147,6 @@ class WebsiteManager: currentACL = ACLManager.loadedACL(userID) admin = Administrator.objects.get(pk=userID) - - - backobj = WPSitesBackup.objects.filter(owner=admin) try: From f6f6a5a23fb291817490ba4b229a5ead48340e2c Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Wed, 8 Jun 2022 20:19:20 +0500 Subject: [PATCH 104/178] bug fix: wp backups --- plogical/applicationInstaller.py | 66 +++++++++++++++----------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index be6445751..142596383 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -2269,7 +2269,7 @@ $parameters = array( wpsite = WPSites.objects.get(pk=self.extraArgs['WPid']) Adminobj = Administrator.objects.get(pk=self.extraArgs['adminID']) - website =Websites.objects.get(pk=wpsite.owner_id) + website = wpsite.owner PhpVersion = website.phpSelection VHuser = website.externalApp WPsitepath = wpsite.path @@ -2280,37 +2280,35 @@ $parameters = array( FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) - logging.statusWriter(self.tempStatusPath, 'Getting DataBase...,20') + logging.statusWriter(self.tempStatusPath, 'Getting database...,20') - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % (VHuser, FinalPHPPath, WPsitepath) - stdoutput = ProcessUtilities.outputExecutioner(command) + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path={WPsitepath}' + stdoutput = ProcessUtilities.outputExecutioner(command, VHuser) DataBaseName = stdoutput.rstrip("\n") - command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( - VHuser, FinalPHPPath, WPsitepath) - stdoutput = ProcessUtilities.outputExecutioner(command) + command = f'{FinalPHPPath} -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path={WPsitepath}' + stdoutput = ProcessUtilities.outputExecutioner(command,VHuser) DataBaseUser = stdoutput.rstrip("\n") - ### Create secure folder + ACLManager.CreateSecureDir() RandomPath = str(randint(1000, 9999)) - tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) - self.tempPath = tempPath + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) - command = f'mkdir -p {tempPath}' + command = f'mkdir -p {self.tempPath}' ProcessUtilities.executioner(command) - command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {tempPath}' + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' ProcessUtilities.executioner(command) ### Make directory for backup logging.statusWriter(self.tempStatusPath, 'Creating Backup Directory...,40') - command = "sudo -u %s mkdir -p %s/public_html" % (VHuser, tempPath) - ProcessUtilities.executioner(command) + command = f"mkdir -p {self.tempPath}/public_html" + ProcessUtilities.executioner(command, VHuser) config = {} config['WPtitle']=wpsite.title @@ -2331,38 +2329,36 @@ $parameters = array( config['WebVHuser'] = website.externalApp config['Webpackage_id'] = website.package_id config['Webadmin_id'] = website.admin_id + config['name'] = 'backup-' + websitedomain + "-" + time.strftime("%m.%d.%Y_%H-%M-%S") ###############Create config.Json file - - - command = "sudo -u %s touch /home/cyberpanel/config.json" % (VHuser) - ProcessUtilities.executioner(command) + #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/config.json" + configPath = "/home/cyberpanel/" + str(randint(1000, 9999)) file = open(configPath, "w") file.write(json_object) file.close() os.chmod(configPath, 0o600) - command ="sudo -u %s cp -R /home/cyberpanel/config.json %s"%(VHuser, tempPath) - ProcessUtilities.executioner(command) + command = f"cp -R {configPath} {self.tempPath}" + ProcessUtilities.executioner(command, VHuser) - command = "rm -r /home/cyberpanel/config.json" + command = f"rm -r {configPath}" ProcessUtilities.executioner(command) logging.statusWriter(self.tempStatusPath, 'Copying website data.....,50') - ############## Copy Public_htnl to backup - command = "sudo -u %s cp -R %s* %s/public_html" % (VHuser, WPsitepath, tempPath) + command = "sudo -u %s cp -R %s* %s/public_html" % (VHuser, WPsitepath, self.tempPath) result = ProcessUtilities.outputExecutioner(command) if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(result) - command = "sudo -u %s cp -R %s.[^.]* %s/public_html/" % (VHuser, WPsitepath, tempPath) + command = "sudo -u %s cp -R %s.[^.]* %s/public_html/" % (VHuser, WPsitepath, self.tempPath) result = ProcessUtilities.outputExecutioner(command) if os.path.exists(ProcessUtilities.debugPath): @@ -2372,10 +2368,9 @@ $parameters = array( - ##### SQLDUMP database into new directory - command = "mysqldump %s --result-file %s/%s.sql" % (DataBaseName, tempPath, DataBaseName) + command = "mysqldump %s --result-file %s/%s.sql" % (DataBaseName, self.tempPath, DataBaseName) result = ProcessUtilities.outputExecutioner(command) if os.path.exists(ProcessUtilities.debugPath): @@ -2389,30 +2384,31 @@ $parameters = array( websitepath = "/home/%s"%websitedomain FinalZipPath = '%s/%s.zip' % (websitepath, RandomPath) - command = "sudo -u %s tar -czvf %s -P %s" % (VHuser, FinalZipPath, tempPath) - result = ProcessUtilities.outputExecutioner(command) + command = 'mkdir -p /home/backup/' + ProcessUtilities.executioner(command) + + command = f"tar -czvf /home/backup/{config['name']}.tar.gz -P {self.tempPath}" + result = ProcessUtilities.outputExecutioner(command) backupobj = WPSitesBackup(owner=Adminobj, WPSiteID=wpsite.id, WebsiteID=website.id, config=json_object) backupobj.save() if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(result) - command = f'rm -rf {tempPath}' + + command = f'rm -rf {self.tempPath}' ProcessUtilities.executioner(command) - - logging.statusWriter(self.tempStatusPath, 'Completed.[200]') - return 0 - + return 1, f"/home/backup/{config['name']}.tar.gz" except BaseException as msg: logging.writeToFile("Error WPCreateBackup ....... %s" % str(msg)) command = f'rm -rf {self.tempPath}' ProcessUtilities.executioner(command) logging.statusWriter(self.tempStatusPath, str(msg)) - return 0 + return 0, str(msg) From 4529d1c7097f2929d83c395ad165dd5626f3b958 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 10 Jun 2022 12:25:25 +0500 Subject: [PATCH 105/178] bug fix in sub domain creation --- install/install.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/install/install.py b/install/install.py index b58d33a65..f1de1601d 100755 --- a/install/install.py +++ b/install/install.py @@ -2051,6 +2051,27 @@ milter_default_action = accept logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableEmail]") return 0 + @staticmethod + def fixSudoers(): + try: + distroPath = '/etc/lsb-release' + + if not os.path.exists(distroPath): + fileName = '/etc/sudoers' + data = open(fileName, 'r').readlines() + + writeDataToFile = open(fileName, 'w') + for line in data: + if line.find("root") > -1 and line.find("ALL=(ALL)") > -1 and line[0] != '#': + writeDataToFile.writelines('root ALL=(ALL:ALL) ALL\n') + else: + writeDataToFile.write(line) + writeDataToFile.close() + + + except IOError as err: + pass + @staticmethod def setUpFirstAccount(): try: From 5c26218e38de39ecfa76d3399524a9fe6e272d9f Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 10 Jun 2022 12:29:33 +0500 Subject: [PATCH 106/178] bug fix: subdomain creation on cent/alma --- install/install.py | 20 ++++++++++++++++++++ plogical/upgrade.py | 3 +++ 2 files changed, 23 insertions(+) diff --git a/install/install.py b/install/install.py index 48d6c197d..e109267a8 100755 --- a/install/install.py +++ b/install/install.py @@ -2031,6 +2031,25 @@ milter_default_action = accept logging.InstallLog.writeToFile('[ERROR] ' + str(msg) + " [enableDisableEmail]") return 0 + @staticmethod + def fixSudoers(): + try: + distroPath = '/etc/lsb-release' + + if not os.path.exists(distroPath): + fileName = '/etc/sudoers' + data = open(fileName, 'r').readlines() + + writeDataToFile = open(fileName, 'w') + for line in data: + if line.find("root") > -1 and line.find("ALL=(ALL)") > -1 and line[0] != '#': + writeDataToFile.writelines('root ALL=(ALL:ALL) ALL\n') + else: + writeDataToFile.write(line) + writeDataToFile.close() + except IOError as err: + pass + @staticmethod def setUpFirstAccount(): try: @@ -2279,6 +2298,7 @@ def main(): checks.setupPHPAndComposer() checks.fix_selinux_issue() checks.install_psmisc() + checks.fixSudoers() if args.postfix is None: checks.install_postfix_dovecot() diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 581f2a61d..63e9e09ba 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -248,6 +248,9 @@ class Upgrade: else: writeToFile.writelines(items) + if items.find("root") > -1 and items.find("ALL=(ALL)") > -1 and items[0] != '#': + writeToFile.writelines('root ALL=(ALL:ALL) ALL\n') + writeToFile.close() except: pass From 9cbd29df9c90b33067aa4162f8c415dab66a931c Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 10 Jun 2022 12:37:21 +0500 Subject: [PATCH 107/178] bug fix: subdomain creation on cent/alma --- plogical/upgrade.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 63e9e09ba..8cefa941f 100755 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -245,12 +245,11 @@ class Upgrade: for items in data: if items.find("wheel") > -1 and items.find("ALL=(ALL)"): continue + elif items.find("root") > -1 and items.find("ALL=(ALL)") > -1 and items[0] != '#': + writeToFile.writelines('root ALL=(ALL:ALL) ALL\n') else: writeToFile.writelines(items) - if items.find("root") > -1 and items.find("ALL=(ALL)") > -1 and items[0] != '#': - writeToFile.writelines('root ALL=(ALL:ALL) ALL\n') - writeToFile.close() except: pass From 292e1c1c4cf9fd68a95a3f16b272c1f5852fdb01 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Fri, 10 Jun 2022 14:41:33 +0500 Subject: [PATCH 108/178] bug fix: resolve https://github.com/usmannasir/cyberpanel/issues/855 --- plogical/vhostConfs.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/plogical/vhostConfs.py b/plogical/vhostConfs.py index 30b121484..1a1eb705d 100755 --- a/plogical/vhostConfs.py +++ b/plogical/vhostConfs.py @@ -36,18 +36,6 @@ accesslog $VH_ROOT/logs/$VH_NAME.access_log { compressArchive 1 } -errorpage 403 { - url 403.html -} - -errorpage 404 { - url 404.html -} - -errorpage 500 { - url 500.html -} - scripthandler { add lsapi:{virtualHostUser} php } @@ -145,18 +133,6 @@ module cache { storagePath /usr/local/lsws/cachedata/$VH_NAME } -errorpage 403 { - url 403.html -} - -errorpage 404 { - url 404.html -} - -errorpage 500 { - url 500.html -} - scripthandler { add lsapi:{externalApp} php } From 2003317a2fbc6d3a3ff3df5d4e6210350bb0a718 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sat, 11 Jun 2022 13:16:28 +0500 Subject: [PATCH 109/178] bug fix: ssl obtain for childdomain on lsws ent --- plogical/vhostConfs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plogical/vhostConfs.py b/plogical/vhostConfs.py index 1a1eb705d..244ddf225 100755 --- a/plogical/vhostConfs.py +++ b/plogical/vhostConfs.py @@ -204,6 +204,7 @@ context /.well-known/acme-challenge { ServerAdmin {administratorEmail} SuexecUserGroup {externalApp} {externalApp} DocumentRoot {path} + Alias /.well-known/acme-challenge /usr/local/lsws/Example/html/.well-known/acme-challenge CustomLog /home/{masterDomain}/logs/{masterDomain}.access_log combined AddHandler application/x-httpd-php{php} .php .php7 .phtml From 84a1ba66ea9ab135e3e77d0eff596968bd070dc8 Mon Sep 17 00:00:00 2001 From: Hassan Hashmi <75794688+habbi-hb@users.noreply.github.com> Date: Sat, 11 Jun 2022 13:39:48 +0500 Subject: [PATCH 110/178] backuprestore --- plogical/applicationInstaller.py | 305 +++++++++++++++++- .../websiteFunctions/websiteFunctions.js | 219 ++++++++++++- .../websiteFunctions/RestoreBackups.html | 7 + .../websiteFunctions/WPRestoreHome.html | 112 +++++++ websiteFunctions/urls.py | 2 + websiteFunctions/views.py | 32 ++ websiteFunctions/website.py | 50 +++ 7 files changed, 718 insertions(+), 9 deletions(-) create mode 100644 websiteFunctions/templates/websiteFunctions/WPRestoreHome.html diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 142596383..2f12cab4c 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -80,6 +80,8 @@ class ApplicationInstaller(multi.Thread): self.DeploytoProduction() elif self.installApp == 'WPCreateBackup': self.WPCreateBackup() + elif self.installApp == 'RestoreWPbackupNow': + self.RestoreWPbackupNow() except BaseException as msg: logging.writeToFile(str(msg) + ' [ApplicationInstaller.run]') @@ -738,9 +740,6 @@ $parameters = array( ############## Install Save Plugin Buckets try: - logging.writeToFile("plugin bucket list start") - logging.writeToFile("plugin bucket list: %s" % str(self.extraArgs['AllPluginsList'])) - logging.writeToFile("plugin bucket saved: %s" % str(self.extraArgs['SavedPlugins'])) if self.extraArgs['SavedPlugins'] == True: AllPluginList= self.extraArgs['AllPluginsList'] for i in range(len(AllPluginList)): @@ -1683,6 +1682,7 @@ $parameters = array( DataToPass = {} currentTemp = self.extraArgs['tempStatusPath'] + DataToPass['domainName'] = self.data['domainName'] DataToPass['adminEmail'] = self.data['adminEmail'] DataToPass['phpSelection'] = "PHP 7.4" @@ -1745,11 +1745,9 @@ $parameters = array( for i in range(len(pluginlistt)): AllPluginsList.append(pluginlistt[i]) except BaseException as msg: - logging.writeToFile("Error in Get save plugin ....... %s" % str(msg)) pass - logging.writeToFile("AllPluginsList 1 ....... %s" % str(AllPluginsList)) - logging.writeToFile("SavedPlugins 1 ....... %s" % str(SavedPlugins)) + currentTemp = self.extraArgs['tempStatusPath'] self.extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) @@ -2410,6 +2408,301 @@ $parameters = array( logging.statusWriter(self.tempStatusPath, str(msg)) return 0, str(msg) + def RestoreWPbackupNow(self): + try: + import json + from managePHP.phpManager import PHPManager + from websiteFunctions.website import WebsiteManager + from packages.models import Package + self.tempStatusPath = self.extraArgs['tempStatusPath'] + logging.statusWriter(self.tempStatusPath, 'Restoring BackUp...,10') + DesSiteID = self.extraArgs['DesSiteID'] + backupid = self.extraArgs['backupid'] + DomainName = self.extraArgs['Domain'] + userID = self.extraArgs['adminID'] + + + + #### First get BAckup file from backupobj + + backupobj = WPSitesBackup.objects.get(pk=backupid) + config = json.loads(backupobj.config) + BackUpFileName = config['name'] + oldtemppath = config['RandomPath'] + DatabaseNameold = config['DatabaseName'] + DumpFileName = DatabaseNameold+".sql" + oldurl = config['WPFinalURL'] + packgobj = Package.objects.get(pk=config['Webpackage_id']) + packegs = packgobj.packageName + WebOwnerobj = Administrator.objects.get(pk=config['Webadmin_id']) + WebOwner = WebOwnerobj.userName + + + + + #### Methode of Restoring + ############## Existing site + if (DomainName == "" and int(self.extraArgs['DesSiteID']) != -1): + wpsite = WPSites.objects.get(pk=DesSiteID) + VHuser = wpsite.owner.externalApp + PhpVersion = wpsite.owner.phpSelection + newWPpath = wpsite.path + newurl = wpsite.FinalURL + + + + ### get WPsite Database name and usr + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % (VHuser, FinalPHPPath, newWPpath) + stdout = ProcessUtilities.outputExecutioner(command) + Finaldbname = stdout.rstrip("\n") + + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % (VHuser, FinalPHPPath, newWPpath) + stdout = ProcessUtilities.outputExecutioner(command) + Finaldbuser = stdout.rstrip("\n") + + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % (VHuser, FinalPHPPath, newWPpath) + stdout = ProcessUtilities.outputExecutioner(command) + Finaldbpasswd = stdout.rstrip("\n") + + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + ProcessUtilities.executioner(command) + + command = f'chown -R {wpsite.owner.externalApp}:{wpsite.owner.externalApp} {self.tempPath}' + ProcessUtilities.executioner(command) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,30') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + ProcessUtilities.executioner(command) + + #### Make temp dir ab for unzip + command ="sudo -u %s mkdir %s/ab"%(VHuser,self.tempPath) + ProcessUtilities.executioner(command) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % (VHuser, self.tempPath, BackUpFileName, self.tempPath) + ProcessUtilities.outputExecutioner(command) + + + ###first empty the Existing site phblichtml folder + command = "sudo -u %s rm -r %s/*"%(VHuser, newWPpath) + result = ProcessUtilities.outputExecutioner(command) + + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,50') + ###Copy backup content to newsite + unzippath ="%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/"%(self.tempPath, oldtemppath) + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result = ProcessUtilities.outputExecutioner(command) + + + #dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + ProcessUtilities.outputExecutioner(command) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,70') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % (VHuser, FinalPHPPath, Finaldbname, newWPpath) + ProcessUtilities.outputExecutioner(command) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % (VHuser, FinalPHPPath, Finaldbuser, newWPpath) + ProcessUtilities.outputExecutioner(command) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % (VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) + ProcessUtilities.outputExecutioner(command) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % (VHuser, newWPpath, oldurl, newurl) + ProcessUtilities.outputExecutioner(command) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % (VHuser, newWPpath, newurl, newurl) + ProcessUtilities.outputExecutioner(command) + + ##Remove temppath + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + + + ############## New Site + elif(DomainName != "" and int(self.extraArgs['DesSiteID']) == -1): + ###############Create New WordPressSite First + # logging.writeToFile("New Website Domain ....... %s" % str(DomainName)) + DataToPass = {} + + DataToPass['title'] = config['WPtitle'] + DataToPass['domain'] = DomainName + DataToPass['WPVersion'] = "6.0" + DataToPass['adminUser'] = config['WebVHuser'] + DataToPass['Email'] = config['WebadminEmail'] + DataToPass['PasswordByPass'] = config['DatabaseUser'] + DataToPass['AutomaticUpdates'] = config['WPAutoUpdates'] + DataToPass['Plugins'] = config['WPPluginUpdates'] + DataToPass['Themes'] = config['WPThemeUpdates'] + DataToPass['websiteOwner'] = WebOwner + DataToPass['package'] = packegs + + try: + website = Websites.objects.get(domain=DomainName) + logging.statusWriter(self.tempStatusPath, 'Web Site Already Exist.[404]') + except: + ab = WebsiteManager() + coreResult = ab.submitWorpressCreation(userID, DataToPass) + coreResult1 = json.loads((coreResult).content) + logging.writeToFile("WP Creating website result....%s" % coreResult1) + reutrntempath = coreResult1['tempStatusPath'] + while (1): + lastLine = open(reutrntempath, 'r').read() + logging.writeToFile("Error WP creating lastline ....... %s" % lastLine) + if lastLine.find('[200]') > -1: + break + elif lastLine.find('[404]') > -1: + logging.statusWriter(self.tempStatusPath, 'Failed to WordPress: error: %s. [404]'% lastLine) + return 0 + else: + logging.statusWriter(self.tempStatusPath, 'Creating WordPress....,20') + time.sleep(2) + + logging.statusWriter(self.tempStatusPath, 'Restoring site ....,30') + NewWPsite =WPSites.objects.get(FinalURL=DomainName) + VHuser = NewWPsite.owner.externalApp + PhpVersion = NewWPsite.owner.phpSelection + newWPpath = NewWPsite.path + newurl = NewWPsite.FinalURL + + + ###### Same code already used in Existing site + + ### get WPsite Database name and usr + php = PHPManager.getPHPString(PhpVersion) + FinalPHPPath = '/usr/local/lsws/lsphp%s/bin/php' % (php) + + ######Get DBname + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_NAME --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + stdout = ProcessUtilities.outputExecutioner(command) + Finaldbname = stdout.rstrip("\n") + + ######Get DBuser + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_USER --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + stdout = ProcessUtilities.outputExecutioner(command) + Finaldbuser = stdout.rstrip("\n") + + #####Get DBpsswd + command = 'sudo -u %s %s -d error_reporting=0 /usr/bin/wp config get DB_PASSWORD --skip-plugins --skip-themes --path=%s' % ( + VHuser, FinalPHPPath, newWPpath) + stdout = ProcessUtilities.outputExecutioner(command) + Finaldbpasswd = stdout.rstrip("\n") + + ### Create secure folder + + ACLManager.CreateSecureDir() + RandomPath = str(randint(1000, 9999)) + self.tempPath = '%s/%s' % ('/usr/local/CyberCP/tmp', RandomPath) + + command = f'mkdir -p {self.tempPath}' + ProcessUtilities.executioner(command) + + command = f'chown -R {NewWPsite.owner.externalApp}:{NewWPsite.owner.externalApp} {self.tempPath}' + ProcessUtilities.executioner(command) + + logging.statusWriter(self.tempStatusPath, 'Extracting Backup File...,40') + + ###First copy backup file to temp and then Unzip + command = "sudo -u %s cp -R /home/backup/%s* %s" % (VHuser, BackUpFileName, self.tempPath) + ProcessUtilities.executioner(command) + + #### Make temp dir ab for unzip + command = "sudo -u %s mkdir %s/ab" % (VHuser, self.tempPath) + ProcessUtilities.executioner(command) + + command = "sudo -u %s tar -xvf %s/%s.tar.gz -C %s/ab" % ( + VHuser, self.tempPath, BackUpFileName, self.tempPath) + ProcessUtilities.outputExecutioner(command) + + ###first empty the Existing site phblichtml folder + command = "sudo -u %s rm -r %s/*" % (VHuser, newWPpath) + result = ProcessUtilities.outputExecutioner(command) + + logging.statusWriter(self.tempStatusPath, 'Copying Data File...,60') + ###Copy backup content to newsite + unzippath = "%s/ab/usr/local/CyberCP/tmp/%s/public_html/public_html/" % (self.tempPath, oldtemppath) + command = "sudo -u %s cp -R %s* %s" % (VHuser, unzippath, newWPpath) + result = ProcessUtilities.outputExecutioner(command) + + # dump Mysql file in unzippath path + unzippath2 = "%s/ab/usr/local/CyberCP/tmp/%s/%s" % (self.tempPath, oldtemppath, DumpFileName) + command = "mysql -u root %s < %s" % (Finaldbname, unzippath2) + ProcessUtilities.outputExecutioner(command) + + logging.statusWriter(self.tempStatusPath, 'Restoreing Data Base...,80') + #####SetUp DataBase Settings + ##set DBName + command = "sudo -u %s %s /usr/bin/wp config set DB_NAME %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbname, newWPpath) + ProcessUtilities.outputExecutioner(command) + + ##set DBuser + command = "sudo -u %s %s /usr/bin/wp config set DB_USER %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbuser, newWPpath) + ProcessUtilities.outputExecutioner(command) + + ##set DBpasswd + command = "sudo -u %s %s /usr/bin/wp config set DB_PASSWORD %s --skip-plugins --skip-themes --path=%s" % ( + VHuser, FinalPHPPath, Finaldbpasswd, newWPpath) + ProcessUtilities.outputExecutioner(command) + + logging.statusWriter(self.tempStatusPath, 'Replacing URLs...,90') + ########Now Replace URL's + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --path=%s "%s" "%s"' % ( + VHuser, newWPpath, oldurl, newurl) + ProcessUtilities.outputExecutioner(command) + + command = 'sudo -u %s /usr/local/lsws/lsphp74/bin/php -d error_reporting=0 /usr/bin/wp search-replace --skip-plugins --skip-themes --allow-root --path=%s "https://www.%s" "http://%s"' % ( + VHuser, newWPpath, newurl, newurl) + ProcessUtilities.outputExecutioner(command) + + ##Remove temppath + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) + + ###Restart Server + + from plogical.installUtilities import installUtilities + installUtilities.reStartLiteSpeed() + + + + logging.statusWriter(self.tempStatusPath, 'Completed.[200]') + except BaseException as msg: + logging.writeToFile("Error RestoreWPbackupNow ....... %s" % str(msg)) + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) + logging.statusWriter(self.tempStatusPath, str(msg)) + return 0, str(msg) def main(): diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 44f523a92..208f20400 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -1162,8 +1162,6 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo $timeout.cancel(); - - } else { $scope.wordpresshomeloading = true; @@ -1182,7 +1180,6 @@ app.controller('WPsiteHome', function ($scope, $http, $timeout, $compile, $windo $scope.goBackDisable = false; - } } else { @@ -1503,6 +1500,222 @@ function AppendToTable(table, markup) { } +//..................Restore Backup Home + + +app.controller('RestoreWPBackup', function ($scope, $http, $timeout, $window) { + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + + + $scope.checkmethode = function () { + var val = $('#RestoreMethode').children("option:selected").val(); + if (val == 1) { + $('#Newsitediv').show(); + $('#exinstingsitediv').hide(); + } else if (val == 0) { + $('#exinstingsitediv').show(); + $('#Newsitediv').hide(); + } else { + + } + }; + + + $scope.RestoreWPbackupNow = function () { + $('#wordpresshomeloading').show(); + $scope.wordpresshomeloading = false; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $scope.currentStatus = "Start Restoring WordPress.."; + + var url = "/websites/RestoreWPbackupNow"; + + + + var data = { + backupid: $('#backupid').html(), + DesSite: $('#DesSite').children("option:selected").val(), + Domain: $("input[name=Newdomain]").val() + } + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + // console.log(data) + + var d = $('#DesSite').children("option:selected").val(); + var c = $("input[name=Newdomain]").val(); + if( d == -1 && c == "") + { + alert("Please Select Method of Backup Restore"); + } + else { + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + } + + + + + + function ListInitialDatas(response) { + wordpresshomeloading = true; + $('#wordpresshomeloading').hide(); + + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Restoring process starts!.', + type: 'success' + }); + statusFile = response.data.tempStatusPath; + getCreationStatus(); + + } else { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.installationDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = false; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + + new PNotify({ + title: 'Operation Failed!', + text: response.data.error_message, + type: 'error' + }); + + + } + } + + function getCreationStatus() { + $('#wordpresshomeloading').show(); + + url = "/websites/installWordpressStatus"; + + var data = { + statusFile: statusFile + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $('#wordpresshomeloading').hide(); + + if (response.data.abort === 1) { + + if (response.data.installStatus === 1) { + + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = false; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + + $("#installProgress").css("width", "100%"); + $("#installProgressbackup").css("width", "100%"); + $scope.installPercentage = "100"; + $scope.currentStatus = response.data.currentStatus; + $timeout.cancel(); + + + } else { + + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = false; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = false; + + $scope.errorMessage = response.data.error_message; + + $("#installProgress").css("width", "0%"); + $("#installProgressbackup").css("width", "0%"); + $scope.installPercentage = "0"; + $scope.goBackDisable = false; + + + } + + } else { + + $("#installProgress").css("width", response.data.installationProgress + "%"); + $("#installProgressbackup").css("width", response.data.installationProgress + "%"); + $scope.installPercentage = response.data.installationProgress; + $scope.currentStatus = response.data.currentStatus; + $timeout(getCreationStatus, 1000); + + } + + } + + function cantLoadInitialDatas(response) { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = true; + $scope.installationProgress = false; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = false; + $scope.goBackDisable = false; + + } + + + } + + $scope.goBack = function () { + $('#wordpresshomeloading').hide(); + $scope.wordpresshomeloading = true; + $scope.stagingDetailsForm = false; + $scope.installationProgress = true; + $scope.errorMessageBox = true; + $scope.success = true; + $scope.couldNotConnect = true; + $scope.goBackDisable = true; + $("#installProgress").css("width", "0%"); + }; +}); + + /* Java script code to create account */ app.controller('createWebsite', function ($scope, $http, $timeout, $window) { diff --git a/websiteFunctions/templates/websiteFunctions/RestoreBackups.html b/websiteFunctions/templates/websiteFunctions/RestoreBackups.html index adc067a74..03516ab1d 100644 --- a/websiteFunctions/templates/websiteFunctions/RestoreBackups.html +++ b/websiteFunctions/templates/websiteFunctions/RestoreBackups.html @@ -121,6 +121,12 @@ + + Restore + +