backup v2 delete repo page

This commit is contained in:
unknown
2023-08-14 16:34:00 +05:00
parent 4ddc6859e2
commit c3a6fa7f6e
8 changed files with 383 additions and 10 deletions

View File

@@ -1918,10 +1918,10 @@ app.controller('ScheduleV2Backup', function ($scope, $http, $timeout, $compile)
if (response.data.status === 1) {
$scope.selectwebsite();
new PNotify({
title: 'Success!',
text: 'Successfully deleted.',
type: 'success'
});
title: 'Success!',
text: 'Successfully deleted.',
type: 'success'
});
} else {
new PNotify({
@@ -2054,10 +2054,10 @@ app.controller('ScheduleV2Backup', function ($scope, $http, $timeout, $compile)
if (response.data.status === 1) {
$scope.selectwebsite();
new PNotify({
title: 'Success!',
text: 'Successfully created.',
type: 'success'
});
title: 'Success!',
text: 'Successfully created.',
type: 'success'
});
} else {
new PNotify({
@@ -2242,3 +2242,162 @@ app.controller('ScheduleV2Backup', function ($scope, $http, $timeout, $compile)
});
app.controller('DeleteBackuprepo', function ($scope, $http, $timeout, $compile) {
$scope.backupLoading = true;
$scope.installationProgress = true;
$scope.errorMessageBox = true;
$scope.success = true;
$scope.couldNotConnect = true;
$scope.goBackDisable = true;
$scope.selectwebsite = function () {
document.getElementById('reposelectbox').innerHTML = "";
$scope.backupLoading = false;
// document.getElementById('CreateV2BackupButton').style.display = "block";
var url = "/IncrementalBackups/selectwebsiteCreatev2";
var data = {
Selectedwebsite: $scope.selwebsite,
Selectedrepo: $('#reposelectbox').val(),
};
//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 Repo';
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.DeleteV2BackupButton = function () {
$scope.backupLoading = false;
$scope.installationDetailsForm = true;
$scope.installationProgress = false;
$scope.errorMessageBox = true;
$scope.success = true;
$scope.couldNotConnect = true;
$scope.goBackDisable = true;
var url = "/IncrementalBackups/DeleteV2BackupButton";
data = {
Selectedwebsite: $scope.selwebsite,
Selectedrepo: $('#reposelectbox').val(),
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
//alert('Done..........')
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if (response.data.status === 1) {
$scope.backupLoading = true;
$scope.installationDetailsForm = true;
$scope.installationProgress = true;
$scope.errorMessageBox = true;
$scope.success = false;
$scope.couldNotConnect = true;
$scope.goBackDisable = true;
new PNotify({
title: 'Operation Done!',
text: 'Delete Successfully',
type: 'sucess'
});
} else {
$scope.backupLoading = 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;
new PNotify({
title: 'Operation Failed!',
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'
});
}
}
});

View File

@@ -27,7 +27,6 @@
- <a href="{% url 'RestoreV2backupSite' %}">Restore Backups</a>
</h3>
<div class="example-box-wrapper">
<p align="center" style="margin-top: 2%; margin-bottom: 2%">
<iframe width="788.54" height="443" src="https://www.youtube.com/embed/7dI1013xvUc"
title="YouTube video player" frameborder="0"
@@ -58,7 +57,7 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Backup Content" %}</label>
<label class="col-sm-3 control-label">{% trans "Backup Contents" %}</label>
<div class="col-sm-9">
<div class="checkbox">
<label>

View File

@@ -0,0 +1,121 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Delete v2 Backup" %}{% 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 "Delete V2 Repo" %} - <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 delete your backup repo" %}</p>
</div>
<div ng-controller="DeleteBackuprepo" class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Create v2 Backup" %} <img ng-hide="backupLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="example-box-wrapper">
<form 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>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans " " %} </label>
<div class="col-sm-6">
<button class="btn" id="DeleteV2BackupButton" ng-click="DeleteV2BackupButton()"
style="border-radius: 6px;background-color: #3447b7;color: white !important;">
Delete Backup repo
</button>
</div>
</div>
<div ng-hide="installationProgress" class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-7">
<div class="alert alert-success text-center">
<h2>{$ currentStatus $}</h2>
</div>
<div class="progress">
<div id="installProgress" class="progress-bar" role="progressbar" aria-valuenow="70"
aria-valuemin="0" aria-valuemax="100" style="width:0%">
<span class="sr-only">70% Complete</span>
</div>
</div>
<div ng-hide="errorMessageBox" class="alert alert-danger">
<p>{% trans "Error message:" %} {$ errorMessage $}</p>
</div>
<div ng-hide="success" class="alert alert-success">
<p>{% trans "Backup succesfully." %}</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect to server. Please refresh this page." %}</p>
</div>
</div>
</div>
<div ng-hide="installationProgress" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-disabled="goBackDisable" ng-click="goBack()"
class="btn btn-primary btn-lg">{% trans "Go Back" %}</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -38,5 +38,7 @@ urlpatterns = [
url(r'^schedulev2Backups$', views.schedulev2Backups, name='schedulev2Backups'),
url(r'^DeleteScheduleV2$', views.DeleteScheduleV2, name='DeleteScheduleV2'),
url(r'^CreateScheduleV2$', views.CreateScheduleV2, name='CreateScheduleV2'),
url(r'^DeleteRepoV2$', views.DeleteRepoV2, name='DeleteRepoV2'),
url(r'^DeleteV2BackupButton$', views.DeleteV2BackupButton, name='DeleteV2BackupButton'),
]

View File

@@ -780,6 +780,15 @@ def CreateV2Backup(request):
except KeyError:
return redirect(loadLoginPage)
def DeleteRepoV2(request):
try:
userID = request.session['userID']
bm = BackupManager()
return bm.DeleteRepoV2(request, userID)
except KeyError:
return redirect(loadLoginPage)
def CreateV2BackupButton(request):
try:
userID = request.session['userID']
@@ -1155,6 +1164,47 @@ def CreateScheduleV2(request):
# 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 DeleteV2BackupButton(request):
try:
userID = request.session['userID']
data = json.loads(request.body)
Selectedwebsite = data['Selectedwebsite']
repo = data['Selectedrepo']
currentACL = ACLManager.loadedACL(userID)
admin = Administrator.objects.get(pk=userID)
if ACLManager.checkOwnership(str(Selectedwebsite), admin, currentACL) == 1:
pass
else:
return ACLManager.loadError()
obj = Websites.objects.get(domain=Selectedwebsite)
usr= obj.externalApp
status, message = CPBackupsV2.DeleteRepoScheduleV2(Selectedwebsite, repo, usr)
if status == 1:
final_dic = {'status': 1, 'error_message': message}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
final_dic = {'status': 0, 'error_message': message}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
# final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": None})
# return HttpResponse(final_json)
except BaseException as msg:
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)

View File

@@ -71,6 +71,11 @@ class BackupManager:
websitesName = ACLManager.findAllSites(currentACL, userID)
proc = httpProc(request, 'IncBackups/CreateV2Backup.html', {'websiteList': websitesName}, 'createBackup')
return proc.render()
def DeleteRepoV2(self, request=None, userID=None, data=None):
currentACL = ACLManager.loadedACL(userID)
websitesName = ACLManager.findAllSites(currentACL, userID)
proc = httpProc(request, 'IncBackups/DeleteV2repo.html', {'websiteList': websitesName}, 'createBackup')
return proc.render()
def schedulev2Backups(self, request=None, userID=None, data=None):

View File

@@ -690,6 +690,9 @@
<li><a href="{% url 'schedulev2Backups' %}"
title="{% trans "Schedule V2 Backup" %}"><span>{% trans "Schedule V2 Backup" %}</span></a>
</li>
<li><a href="{% url 'DeleteRepoV2' %}"
title="{% trans "Delete V2 Backup Repo" %}"><span>{% trans "Delete V2 Backup Repo" %}</span></a>
</li>
</ul>

View File

@@ -1137,6 +1137,40 @@ team_drive =
except BaseException as msg:
return 0, str(msg)
@staticmethod
def DeleteRepoScheduleV2(website, repo, eu):
import shutil
try:
finalConfigPath = f'/home/{website}/.config/rclone/rclone.conf'
if os.path.exists(finalConfigPath):
command = f'cat {finalConfigPath}'
result = ProcessUtilities.outputExecutioner(command, eu)
new_lines = []
skip_section = False
for line in result.split('\n'):
if line.strip().startswith('[') and line.strip().endswith(']'):
if line.strip() == f'[{repo}]':
skip_section = True
else:
skip_section = False
if not skip_section:
new_lines.append(line)
cmd = f'echo "{new_lines}" > {finalConfigPath}'
result = ProcessUtilities.outputExecutioner(cmd, eu, True)
return 1, 'Done'
else:
return 0, "Repo not found!"
except BaseException as msg:
return 0, str(msg)
# def BackupEmails(self):
#
# ### This function will backup emails of the website, also need to take care of emails that we need to exclude