diff --git a/IncBackups/static/IncBackups/IncBackups.js b/IncBackups/static/IncBackups/IncBackups.js index 79b13571e..94f9d5406 100644 --- a/IncBackups/static/IncBackups/IncBackups.js +++ b/IncBackups/static/IncBackups/IncBackups.js @@ -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) { }; -}); \ No newline at end of file +}); + + +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 = ' \n' + + ' ' + snaphots[i].id + '' + + ' \n' + + ' \n' + + ' ' + + ' \n' + + ' \n' + + ' ' + + '' + + ' ' + + ' \n'; + + for (var j = 0; j < snaphots[i].paths.length; j++) { + tml += '\n' + + '\n' + + '\n'; + } + + tml += '
' + snaphots[i].paths[j] + '
\n' + + '\n' + + '\n' + + '\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="+" + + } +} \ No newline at end of file diff --git a/IncBackups/templates/IncBackups/RestoreV2Backup.html b/IncBackups/templates/IncBackups/RestoreV2Backup.html new file mode 100644 index 000000000..9e8ed155c --- /dev/null +++ b/IncBackups/templates/IncBackups/RestoreV2Backup.html @@ -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 %} + + + +
+
+

{% trans "Restore V2 Backup Site" %} - {% trans "Backup Docs" %}

+

{% trans "This page can be used to restore your backup sites" %}

+
+ +
+
+

+ {% trans "Restore V2 Backup Site" %} +

+
+ +
+ + +
+ +
+ +
+
+
+ +
+ +
+
+ +
+ + + +
+ +
+ +
+ + + + + + + + + + + + + +
{% trans "Snapshot ID" %}{% trans "Action" %} >
+
+
+
+ +
+ + +
+ + +{% endblock %} \ No newline at end of file diff --git a/IncBackups/templates/IncBackups/createV2Backup.html b/IncBackups/templates/IncBackups/createV2Backup.html new file mode 100644 index 000000000..6f0e3e28c --- /dev/null +++ b/IncBackups/templates/IncBackups/createV2Backup.html @@ -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 %} + + +
+ +
+
+

+ {% trans "Backup V2" %} +

+
+ + +
+ + +
+ +
+ +
+
+ +
+ + +
+
+
+ + +
+ + +{% endblock %} \ No newline at end of file diff --git a/IncBackups/urls.py b/IncBackups/urls.py index a8862cf04..04bb00ebf 100644 --- a/IncBackups/urls.py +++ b/IncBackups/urls.py @@ -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'), + ] \ No newline at end of file diff --git a/IncBackups/views.py b/IncBackups/views.py index 8f319ac95..81de3ca8d 100644 --- a/IncBackups/views.py +++ b/IncBackups/views.py @@ -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) \ No newline at end of file diff --git a/backup/backupManager.py b/backup/backupManager.py index c42a80d32..e4f2dd4c7 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -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) diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index cdfe3eee8..49984e451 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -715,6 +715,27 @@ + +