Merge branch 'v2.3.4-dev' of github.com:usmannasir/cyberpanel into v2.3.4-dev

This commit is contained in:
usman@cyberpersons.com
2023-03-12 11:26:00 +05:00
8 changed files with 800 additions and 1 deletions

View File

@@ -172,6 +172,63 @@ app.controller('createIncrementalBackups', function ($scope, $http, $timeout) {
};
// $scope.RestoreV2Backup = function () {
//
// // $scope.status = '';
// //
// // $scope.cyberpanelLoading = false;
// //
// //
// // url = "/IncrementalBackups/submitBackupCreation";
//
//
// console.log($scope.websiteToBeBacked)
// console.log($scope.websiteData)
// var websites = document.getElementById('create-backup-select');
// var selected_website = websites.options[websites.selectedIndex].innerHTML;
// console.log(selected_website);
//
// var data = {
// websiteToBeBacked: $scope.websiteToBeBacked,
// backupDestinations: $scope.backupDestinations,
// websiteData: $scope.websiteData,
// websiteEmails: $scope.websiteEmails,
// websiteSSLs: $scope.websiteSSLs,
// websiteDatabases: $scope.websiteDatabases
//
// };
//
// // var config = {
// // headers: {
// // 'X-CSRFToken': getCookie('csrftoken')
// // }
// // };
// //
// //
// // $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
// //
// //
// // function ListInitialDatas(response) {
// //
// // if (response.data.status === 1) {
// // $scope.tempPath = response.data.tempPath;
// // getBackupStatus();
// // } else {
// // $scope.cyberpanelLoading = true;
// // new PNotify({
// // title: 'Operation Failed!',
// // text: response.data.error_message,
// // type: 'error'
// // });
// // }
// //
// // }
// //
// // function cantLoadInitialDatas(response) {
// // }
//
// };
$scope.deleteBackup = function (id) {
@@ -1141,4 +1198,240 @@ app.controller('restoreRemoteBackupsInc', function ($scope, $http, $timeout) {
};
});
});
app.controller('restorev2backupoage', function ($scope, $http, $timeout) {
$scope.backupLoading = true;
$scope.selectwebsite = function () {
document.getElementById('reposelectbox').innerHTML = "";
$scope.backupLoading = false;
var url = "/IncrementalBackups/selectwebsiteRetorev2";
var data = {
Selectedwebsite: $scope.selwebsite,
};
//alert( $scope.selwebsite);
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.backupLoading = true;
if (response.data.status === 1) {
const selectBox = document.getElementById('reposelectbox');
const options = response.data.data;
const option = document.createElement('option');
option.value = 1;
option.text = 'Choose Repooo';
selectBox.appendChild(option);
if (options.length >= 1)
{
for (let i = 0; i < options.length; i++) {
const option = document.createElement('option');
option.value = options[i];
option.text = options[i];
selectBox.appendChild(option);
}
}
else {
new PNotify({
title: 'Error!',
text: 'file empty',
type: 'error'
});
}
} else {
new PNotify({
title: 'Error!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
$scope.backupLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page',
type: 'error'
});
}
}
$scope.selectrepo = function () {
$scope.backupLoading = false;
var url = "/IncrementalBackups/selectreporestorev2";
var data = {
Selectedrepo: $('#reposelectbox').val(),
Selectedwebsite: $scope.selwebsite,
}
//alert( $scope.selwebsite);
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.backupLoading = true;
if (response.data.status === 1) {
var data = response.data.data
console.log(response.data.data)
console.log(response.data.data[0][1])
var snaphots = response.data.data[0][1]
for (var i = 0; i < snaphots.length; i++) {
var tml = ' <tr style="">\n' +
' <td>' + snaphots[i].id + '</td>' +
' <td><button type="button" \n' +
' class="btn btn-danger">Delete</button></td>\n' +
' \n' +
' </tr>' +
'<tr style="border: none!important;"> <td colspan="2" style="display: inherit;max-height: 10px;background-color: transparent; border: none">\n' +
' <button id="' + snaphots[i].id + '" class="my-4 mx-4 btn " style="margin-bottom: 15px;margin-top: -8px;background-color: #161a69; color: white;border-radius: 6px" onclick=listpaths("' + i + '","' + snaphots[i].id + '")>+</button>\n' +
' </td></tr>' +
'<tr style="border: none!important;">' +
' <td colspan="2" style="display: none;border: none" id="' + i + '">' +
' <table id="inside" style="margin: 0 auto;">\n';
for (var j = 0; j < snaphots[i].paths.length; j++) {
tml += '<tr>\n' +
'<td>' + snaphots[i].paths[j] + '</td>\n' +
'</tr>\n';
}
tml += '</table>\n' +
'</td>\n' +
'</tr>\n' +
'</tr>\n';
$('#listsnapshots').append(tml);
}
// $scope.Snaphot_ID
// var table = document.getElementById("snapshotstable");
//
// // Loop through the data and create a new row for each item
// for (var i = 0; i < data.length; i++) {
// // Create a new row element
// var row = table.insertRow();
//
// // Create the first cell and set its value to the current item in the data array
// var idCell = row.insertCell(0);
// idCell.innerHTML = data[i];
//
// // Create the second cell and add a delete button to it
// var deleteCell = row.insertCell(1);
// var deleteButton = document.createElement("button");
// deleteButton.innerHTML = "Delete";
// deleteButton.addEventListener("click", function() {
// // Call your delete function here
// console.log("Deleting item:", data[i]);
// });
// deleteCell.appendChild(deleteButton);
// }
} else {
new PNotify({
title: 'Error!',
text: response.data.error_message,
type: 'error'
});
}
}
function cantLoadInitialDatas(response) {
$scope.backupLoading = true;
new PNotify({
title: 'Operation Failed!',
text: 'Could not connect to server, please refresh this page',
type: 'error'
});
}
}
});
app.controller('createV2Backups', function ($scope, $http, $timeout){
$scope.cyberpanelLoading = true;
$scope.selectbackuptype = function () {
$scope.cyberpanelLoading = false;
var backuptype = $scope.v2backuptype
if (backuptype === 'GDrive')
{
$scope.cyberpanelLoading = true;
$('#GdriveModal').modal('show');
}
}
$scope.setupAccount = function(){
window.open("https://platform.cyberpersons.com/gDrive?name=" + $scope.accountName + '&server=' + window.location.href + 'Setup');
};
});
function listpaths(pathid,button){
console.log("LIST PAYH FUNCTIOB CALLED WITH ID "+ pathid);
var pathlist = document.getElementById(pathid)
if (pathlist.style.display === "none") {
pathlist.style.display = "revert";
document.getElementById(button).innerText="-"
} else {
pathlist.style.display = "none";
document.getElementById(button).innerText="+"
}
}

View File

@@ -0,0 +1,82 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Backup Website" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<style>
</style>
<div class="container">
<div id="page-title">
<h2>{% trans "Restore V2 Backup Site" %} - <a target="_blank" href="http://go.cyberpanel.net/backup" style="height: 23px;line-height: 21px;" class="btn btn-border btn-alt border-red btn-link font-red" title=""><span>{% trans "Backup Docs" %}</span></a></h2>
<p>{% trans "This page can be used to restore your backup sites" %}</p>
</div>
<div ng-controller="restorev2backupoage" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Restore V2 Backup Site" %} <img ng-hide="backupLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<form action="/IncBackups/static" class="form-horizontal bordered-row">
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Select Website" %} </label>
<div class="col-sm-6">
<select id="create-backup-select" ng-change="selectwebsite()" ng-model="selwebsite" class="form-control">
{% for items in websiteList %}
<option value="{{ items }}">{{ items }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Select Repo" %} </label>
<div class="col-sm-6">
<select id="reposelectbox" ng-change="selectrepo()" ng-model="testhabbi" class="form-control">
</select>
</div>
</div>
</form>
</div>
<div ng-hide="runningSnapshot" class="form-group">
<div class="col-sm-12">
<table id="snapshotstable" class="table">
<thead>
<tr style="border-bottom: #cccccc solid 1px!important;" >
<th style="border: none">{% trans "Snapshot ID" %}</th>
<th style="border: none">{% trans "Action" %} ></th>
</tr>
</thead>
<tbody id="listsnapshots">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,84 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Create V2 Backup" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div ng-controller="createV2Backups" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Backup V2" %} <img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<form action="/" class="form-horizontal bordered-row">
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Select Backup Type" %} </label>
<div class="col-sm-6">
<select ng-change="selectbackuptype()" ng-model="v2backuptype" class="form-control">
<option >SFTP</option>
<option >GDrive</option>
</select>
</div>
</div>
</form>
<div id="GdriveModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;
</button>
<h4 class="modal-title">{% trans "Set up account" %}</h4>
</div>
<div class="modal-body">
<form name="containerSettingsForm" action="/" class="form-horizontal">
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Account Name" %}</label>
<div class="col-sm-6">
<input name="accountName" type="text" class="form-control"
ng-model="accountName">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary"
ng-click="setupAccount()">Save <img
ng-hide="cyberPanelLoading"
src="{% static 'images/loading.gif' %}">
</button>
<button type="button" ng-disabled="savingSettings"
class="btn btn-default" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -22,4 +22,11 @@ urlpatterns = [
url(r'^saveChanges$', views.save_changes, name='saveChanges'),
url(r'^removeSite$', views.remove_site, name='removeSite'),
url(r'^addWebsite$', views.add_website, name='addWebsite'),
### V2 Backups URls
url(r'^createV2Backup$', views.createV2Backup, name='createV2Backup'),
url(r'^createV2BackupSetup$', views.createV2BackupSetup, name='createV2BackupSetup'),
url(r'^RestoreV2backupSite$', views.RestoreV2backupSite, name='RestoreV2backupSite'),
url(r'^selectwebsiteRetorev2$', views.selectwebsiteRetorev2, name='selectwebsiteRetorev2'),
url(r'^selectreporestorev2$', views.selectreporestorev2, name='selectreporestorev2'),
]

View File

@@ -6,8 +6,11 @@ from pathlib import Path
from random import randint
from django.shortcuts import HttpResponse, redirect
from backup.backupManager import BackupManager
from loginSystem.models import Administrator
from loginSystem.views import loadLoginPage
from plogical.Backupsv2 import CPBackupsV2
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
from plogical.acl import ACLManager
from plogical.httpProc import httpProc
@@ -48,6 +51,8 @@ def _get_user_acl(request):
return user_id, current_acl
def create_backup(request):
try:
@@ -704,3 +709,286 @@ def add_website(request):
except BaseException as msg:
final_json = json.dumps({'status': 0, 'error_message': str(msg)})
return HttpResponse(final_json)
def createV2Backup(request):
try:
user_id, current_acl = _get_user_acl(request)
if ACLManager.currentContextPermission(current_acl, 'createBackup') == 0:
return ACLManager.loadError()
# websites = ACLManager.findAllSites(current_acl, user_id)
#
# destinations = _get_destinations(local=True)
proc = httpProc(request, 'IncBackups/createV2Backup.html')
return proc.render()
except BaseException as msg:
logging.writeToFile(str(msg))
return redirect(loadLoginPage)
def createV2BackupSetup(request):
try:
userID = request.session['userID']
req_data={}
req_data['token'] = request.GET.get('t')
req_data['refresh_token'] = request.GET.get('r')
req_data['token_uri'] = request.GET.get('to')
req_data['scopes'] = request.GET.get('s')
req_data['accountname'] = request.GET.get('n')
cpbuv2 = CPBackupsV2(
{'domain': 'cyberpanel.net', 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1,
'BackupEmails': 1, 'BackendName': 'testremote'})
# RcloneData = {"name": 'testremote', "host": "staging.cyberpanel.net", "user": "abcds2751", "port": "22",
# "password": "hosting", }
cpbuv2.SetupRcloneBackend(CPBackupsV2.GDrive, req_data)
cpbuv2.InitiateBackup()
# wm = BackupManager()
# return wm.gDriveSetup(userID, request)
final_dic = {'status': 1}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except KeyError:
return redirect(loadLoginPage)
def RestoreV2backupSite(request):
try:
userID = request.session['userID']
bm = BackupManager()
return bm.RestoreV2backupSite(request, userID)
except KeyError:
return redirect(loadLoginPage)
def selectwebsiteRetorev2(request):
import re
try:
userID = request.session['userID']
data = json.loads(request.body)
Selectedwebsite = data['Selectedwebsite']
admin = Administrator.objects.get(pk=userID)
obj = Websites.objects.get(domain = str(Selectedwebsite), admin = admin)
#/home/cyberpanel.net/.config/rclone/rclone.conf
path = '/home/%s/.config/rclone/rclone.conf' %(obj.domain)
command = 'cat %s'%(path)
result = pu.outputExecutioner(command)
if result.find('host') > -1:
pattern = r'\[(.*?)\]'
matches = re.findall(pattern, result)
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": matches})
return HttpResponse(final_json)
else:
final_json = json.dumps({'status': 0, 'fetchStatus': 0, 'error_message': 'Could not Find repo'})
return HttpResponse(final_json)
# final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": 1})
# return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def selectreporestorev2(request):
try:
userID = request.session['userID']
data = json.loads(request.body)
Selectedrepo = data['Selectedrepo']
Selectedwebsite= data['Selectedwebsite']
admin = Administrator.objects.get(pk=userID)
# f'rustic -r testremote snapshots --password "" --json 2>/dev/null'
# final_json = json.dumps({'status': 0, 'fetchStatus': 1, 'error_message': Selectedrepo })
# return HttpResponse(final_json)
vm = CPBackupsV2({'domain': Selectedwebsite, 'BackendName': Selectedrepo, })
status, data = vm.FetchSnapShots()
# ac=[
# [
# {
# "hostname": "ip-172-31-15-45.eu-central-1.compute.internal",
# "label": "",
# "paths": [
# "/home/backup/cyberpanel.net/config.json",
# "/home/cyberpanel.net",
# "MxS2hpJkGLVhZW.sql",
# "cybe_usman.sql",
# "cybe_usmans.sql",
# "qf4fza8IocVVqU.sql",
# "yKtbkp1THRlmBk.sql"
# ]
# },
# [
# {
# "time": "2023-03-10T09:32:14.116381993+00:00",
# "program_version": "rustic v0.4.4-38-g81650ff",
# "tree": "b398a0c342dbba4073f24ee72fe4b25123c76db1cbc59e99d014bf545726e93b",
# "paths": [
# "/home/backup/cyberpanel.net/config.json",
# "/home/cyberpanel.net",
# "MxS2hpJkGLVhZW.sql",
# "cybe_usman.sql",
# "cybe_usmans.sql",
# "qf4fza8IocVVqU.sql",
# "yKtbkp1THRlmBk.sql"
# ],
# "hostname": "ip-172-31-15-45.eu-central-1.compute.internal",
# "username": "",
# "uid": 0,
# "gid": 0,
# "tags": [],
# "original": "2f1003db93946aeea1dd02bea3648794fc547c61863423bfb002667079baa1e0",
# "summary": {
# "files_new": 0,
# "files_changed": 0,
# "files_unmodified": 3469,
# "dirs_new": 0,
# "dirs_changed": 2,
# "dirs_unmodified": 659,
# "data_blobs": 0,
# "tree_blobs": 2,
# "data_added": 1007,
# "data_added_packed": 618,
# "data_added_files": 0,
# "data_added_files_packed": 0,
# "data_added_trees": 1007,
# "data_added_trees_packed": 618,
# "total_files_processed": 3469,
# "total_dirs_processed": 661,
# "total_bytes_processed": 95956649,
# "total_dirsize_processed": 1612281,
# "total_duration": 0.105304887,
# "command": "rustic -r rclone:testremote:cyberpanel.net merge 22fa1914edaf884d722e8ad761863aab34e5d626602911602af4051efd73c587 e305fbceddc516972d18972830e340c24b436a17c8d8df25c5ef726ca1ce462d 12366c9ed1f4b31d288e9419d91236cebf0623ac05845605193977efae1a2880 e2dcdb6e3a96ff235a813c0b60ce2c34eddb5aa0abd15a2aec9bd6dcc2bb26bb b6a4bae0ff82d6bf4863c6b1860db239c8b91f7f980217fb3296749833ee4281 4799a31682522a17286f45689205991ce2cee238f556a51c71ac823c186ea332 aa9324a2807accc30b91b6578c62a5ca752a67e3caef5f9de6a684041554db7a --password --json",
# "backup_start": "2023-03-10T09:32:14.127752385+00:00",
# "backup_end": "2023-03-10T09:32:14.221686880+00:00",
# "backup_duration": 0.093934495
# },
# "id": "2f1003db93946aeea1dd02bea3648794fc547c61863423bfb002667079baa1e0"
# },
# {
# "time": "2023-03-10T09:32:27.903095150+00:00",
# "program_version": "rustic v0.4.4-38-g81650ff",
# "tree": "397ebf2e96308728763b6ed6a5415852e5b1312d4eafcdf93909521d35933a49",
# "paths": [
# "/home/backup/cyberpanel.net/config.json",
# "/home/cyberpanel.net",
# "MxS2hpJkGLVhZW.sql",
# "cybe_usman.sql",
# "cybe_usmans.sql",
# "qf4fza8IocVVqU.sql",
# "yKtbkp1THRlmBk.sql"
# ],
# "hostname": "ip-172-31-15-45.eu-central-1.compute.internal",
# "username": "",
# "uid": 0,
# "gid": 0,
# "tags": [],
# "original": "2c899e20ad27d25a9b731c03a33e0b98d7d040eda47b6a34c97f4a3c9cbf2fc7",
# "summary": {
# "files_new": 0,
# "files_changed": 0,
# "files_unmodified": 3476,
# "dirs_new": 0,
# "dirs_changed": 2,
# "dirs_unmodified": 673,
# "data_blobs": 0,
# "tree_blobs": 2,
# "data_added": 1007,
# "data_added_packed": 619,
# "data_added_files": 0,
# "data_added_files_packed": 0,
# "data_added_trees": 1007,
# "data_added_trees_packed": 619,
# "total_files_processed": 3476,
# "total_dirs_processed": 675,
# "total_bytes_processed": 96567760,
# "total_dirsize_processed": 1620704,
# "total_duration": 0.101950563,
# "command": "rustic -r rclone:testremote:cyberpanel.net merge 6340ecbae01618a1f5def5e2620d778b6dcd9fc36074edcf9b8f0e52509798ed 1de78d7916fb6391bc7445b4a77967b6bf99ad9d0ed09d473ccb80c0be412fe0 2a31010ab415940d2c7d203ecabdd85d0dcc03f74351607808bc16137ec17b29 4a8e1bc5fbf6f228f1af619d97e1864e62b7e57c62840c0ecc68d255fed06e45 a510f06887c3d8535232ccec3a99a055c33e1a0d5671929b440a1f7a3e0fb396 f1d53a4d7d706a110d945d34f69f8fbffb4ec77787ec6fd36771572ef8f91a64 dd4a7eef8c8836624f11b0f5bff25303371886aaa5de30cf8035104529f193e3 --password --json",
# "backup_start": "2023-03-10T09:32:27.913203884+00:00",
# "backup_end": "2023-03-10T09:32:28.005045713+00:00",
# "backup_duration": 0.091841829
# },
# "id": "2c899e20ad27d25a9b731c03a33e0b98d7d040eda47b6a34c97f4a3c9cbf2fc7"
# },
# {
# "time": "2023-03-10T09:34:44.180484566+00:00",
# "program_version": "rustic v0.4.4-38-g81650ff",
# "tree": "0e44a3eeca24698340f4c5a852570c2c7ae35f7c881c2208478516b576caa1e9",
# "paths": [
# "/home/backup/cyberpanel.net/config.json",
# "/home/cyberpanel.net",
# "MxS2hpJkGLVhZW.sql",
# "cybe_usman.sql",
# "cybe_usmans.sql",
# "qf4fza8IocVVqU.sql",
# "yKtbkp1THRlmBk.sql"
# ],
# "hostname": "ip-172-31-15-45.eu-central-1.compute.internal",
# "username": "",
# "uid": 0,
# "gid": 0,
# "tags": [],
# "original": "b2e3c5f38343531305538e53192c7499d81989ba98ec2356f8b578c4d8f758e6",
# "summary": {
# "files_new": 0,
# "files_changed": 0,
# "files_unmodified": 3483,
# "dirs_new": 0,
# "dirs_changed": 2,
# "dirs_unmodified": 686,
# "data_blobs": 0,
# "tree_blobs": 2,
# "data_added": 1007,
# "data_added_packed": 617,
# "data_added_files": 0,
# "data_added_files_packed": 0,
# "data_added_trees": 1007,
# "data_added_trees_packed": 617,
# "total_files_processed": 3483,
# "total_dirs_processed": 688,
# "total_bytes_processed": 96583806,
# "total_dirsize_processed": 1628726,
# "total_duration": 0.105863471,
# "command": "rustic -r rclone:testremote:cyberpanel.net merge da3e8ac0d680095d7317393b5403e8745638c385e9131ad82e69c7274acfea39 6b5b6a5471c91bfafc0cdc362c2bb231cad9b349407e6ff9641159c396862d6d 34e6356574fd57f61af52806b6190c4e0b765ca6e46e2c2fbb9dc597cabeeaa3 eec2b9a55d7e6c23a5c80f9804504efd838b51881d3181372d77d47abd45ffa2 cfa880f8d28aca6ecfab0a36681146cbabece413fbea91317e7255af14feb73a ef6fe3f125710a4d7a6b1026ecc14345f68cfdea4994399d4ae5af44cc97f966 a1c1e536f51dbf7fbf1565875b233e5ea2a72953ab22df9d8ba95d1b7d29185c --password --json",
# "backup_start": "2023-03-10T09:34:44.191031543+00:00",
# "backup_end": "2023-03-10T09:34:44.286348037+00:00",
# "backup_duration": 0.095316494
# },
# "id": "b2e3c5f38343531305538e53192c7499d81989ba98ec2356f8b578c4d8f758e6"
# }
# ]
# ]
# ]
# id = []
# for item in ac[0][1]:
# id.append(item['id'])
if status == 1:
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": data})
return HttpResponse(final_json)
else:
# final_json = json.dumps({'status': 0, 'fetchStatus': 1, 'error_message': ac,})
final_json = json.dumps({'status': 0, 'fetchStatus': 1, 'error_message': 'Cannot Find!',})
return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)

View File

@@ -52,6 +52,12 @@ class BackupManager:
proc = httpProc(request, 'backup/backup.html', {'websiteList': websitesName}, 'createBackup')
return proc.render()
def RestoreV2backupSite(self, request=None, userID=None, data=None):
currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID)
proc = httpProc(request, 'IncBackups/RestoreV2Backup.html', {'websiteList': websitesName}, 'createBackup')
return proc.render()
def gDrive(self, request=None, userID=None, data=None):
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)

View File

@@ -715,6 +715,27 @@
</div><!-- .sidebar-submenu -->
</li>
<li id="sidebar-menu-item-backupV2">
<a href="{% url 'loadBackupHome' %}" title="{% trans 'BackupV2' %}">
<i class="glyph-icon tooltip-button icon-copy" title=".icon-folder"></i>
<span>{% trans "Backup V2" %}</span>
</a>
<div class="sidebar-submenu">
<ul>
<li><a href="{% url 'createV2Backup' %}"
title="{% trans "Create V2 Backup" %}"><span>{% trans "Create V2 Backup" %}</span></a>
</li>
<li><a href="{% url 'RestoreV2backupSite' %}"
title="{% trans "Restore V2 Backup" %}"><span>{% trans "Restore V2 Backup" %}</span></a>
</li>
</ul>
</div><!-- .sidebar-submenu -->
</li>
<li id="sidebar-menu-item-incremental-backup">
<a href="{% url 'loadBackupHome' %}" title="{% trans 'Incremental Backup - Beta' %}">

View File

@@ -28,6 +28,7 @@ class CPBackupsV2:
### RCLONE BACKEND TYPES
SFTP = 1
LOCAL = 2
GDrive = 3
RUSTIC_PATH = '/usr/bin/rustic'
RCLONE_CONFIG = '/root/.config/rclone/rclone.conf'
@@ -55,6 +56,7 @@ class CPBackupsV2:
def FetchSnapShots(self):
try:
command = f'rustic -r {self.repo} snapshots --password "" --json 2>/dev/null'
# SLSkjoSCczb6wxTMCBPmBMGq/UDSpp28-u cyber5986 rustic -r rclone:None:cyberpanel.net snapshots --password "" --json 2>/dev/null
result = json.loads(
ProcessUtilities.outputExecutioner(command, self.website.externalApp, True).rstrip('\n'))
return 1, result
@@ -83,6 +85,22 @@ pass = {ObsecurePassword}
command = f"echo '{content}' > {self.ConfigFilePath}"
#ProcessUtilities.executioner(command, self.website.externalApp, True)
command = f"chmod 600 {self.ConfigFilePath}"
ProcessUtilities.executioner(command, self.website.externalApp)
elif type == CPBackupsV2.GDrive:
## config = {"name":, "host":, "user":, "port":, "path":, "password":,}
command = f'rclone obscure {config["password"]}'
ObsecurePassword = ProcessUtilities.outputExecutioner(command).rstrip('\n')
content = f'''[{config["name"]}]
type = sftp
host = {config["host"]}
user = {config["user"]}
pass = {ObsecurePassword}
'''
command = f"echo '{content}' > {self.ConfigFilePath}"
ProcessUtilities.executioner(command, self.website.externalApp, True)
command = f"chmod 600 {self.ConfigFilePath}"
ProcessUtilities.executioner(command, self.website.externalApp)