From bf0445b76ca90749375e8f6e09dd7e6d362e009d 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 1/3] 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 c37104f687edf972af94eb14e7602e2e67c45363 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 2/3] 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." %}
+
+
+
+
+
+
+ | ID
+ |
+ Website
+ |
+ Action
+ |
+
+
+
+
+
+ {% for sub in job %}
+
+
+ |
+
+ {{ sub.id }}
+
+ |
+
+ {{ sub.title }}
+ |
+
+
+
+
+
+
+
+ |
+
+
+
+ {% endfor %}
+
+
+
+
+
+
+
+
+
+{% 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 b9dea6f73d28069d2ef6292f8a0fd89adf3652f8 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 3/3] 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: