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 c960024e1..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,12 +2262,12 @@ $parameters = array( try: from managePHP.phpManager import PHPManager import json - tempStatusPath = self.extraArgs['tempStatusPath'] - statusFile = open(tempStatusPath, 'w') - statusFile.writelines('Creating BackUp...,10') - statusFile.close() + logging.writeToFile("WPCreateBackup ....... start" ) + self.tempStatusPath = self.extraArgs['tempStatusPath'] + logging.statusWriter(self.tempStatusPath, 'Creating BackUp...,10') 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 @@ -2278,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) @@ -2307,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) @@ -2354,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) @@ -2371,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 @@ -2384,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 @@ -2395,24 +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)) - statusFile = open(self.tempStatusPath, 'w') - statusFile.writelines(str(msg) + " [404]") - statusFile.close() + command = f'rm -rf {self.tempPath}' + ProcessUtilities.executioner(command) + logging.statusWriter(self.tempStatusPath, str(msg)) return 0 diff --git a/websiteFunctions/static/websiteFunctions/websiteFunctions.js b/websiteFunctions/static/websiteFunctions/websiteFunctions.js index 24ca0e52a..44f523a92 100755 --- a/websiteFunctions/static/websiteFunctions/websiteFunctions.js +++ b/websiteFunctions/static/websiteFunctions/websiteFunctions.js @@ -1154,11 +1154,16 @@ 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"; $scope.currentStatus = response.data.currentStatus; $timeout.cancel(); + + + } else { $scope.wordpresshomeloading = true; @@ -1172,17 +1177,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/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/templates/websiteFunctions/WPsiteHome.html b/websiteFunctions/templates/websiteFunctions/WPsiteHome.html index 3e7b2336f..07315d50e 100644 --- a/websiteFunctions/templates/websiteFunctions/WPsiteHome.html +++ b/websiteFunctions/templates/websiteFunctions/WPsiteHome.html @@ -378,7 +378,7 @@
    -
    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 803f5e283..2e62f4fe3 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,42 @@ 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') @@ -717,7 +753,6 @@ class WebsiteManager: extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999)) - background = ApplicationInstaller('WPCreateBackup', extraArgs) background.start()