backupv2 setup and remotewpbackup bug fix

This commit is contained in:
unknown
2023-03-19 15:03:34 +05:00
parent a41e52bef6
commit 8d78715c86
10 changed files with 457 additions and 41 deletions

View File

@@ -1438,12 +1438,17 @@ app.controller('CreateV2Backup', 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/selectwebsiteRetorev2";
var url = "/IncrementalBackups/selectwebsiteCreatev2";
var data = {
Selectedwebsite: $scope.selwebsite,
@@ -1465,7 +1470,6 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
$scope.backupLoading = true;
if (response.data.status === 1) {
const selectBox = document.getElementById('reposelectbox');
@@ -1519,9 +1523,7 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
}
}
var Domain;
$scope.CreateV2BackupButton = function () {
$scope.backupLoading = false;
@@ -1533,7 +1535,6 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
Selectedrepo: $('#reposelectbox').val(),
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
@@ -1548,11 +1549,17 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
$scope.backupLoading = true;
if (response.data.status === 1) {
alert("....................."+response.data.status);
Domain = $scope.selwebsite;
getCreationStatus();
}
else {
alert('fail..........'+response.data.status);
$scope.goBackDisable = false;
new PNotify({
title: 'Operation Failed!',
text: response.data.error_message,
type: 'error'
});
}
}
@@ -1568,6 +1575,87 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
}
function getCreationStatus() {
url = "/IncrementalBackups/CreateV2BackupStatus";
var data = {
domain: Domain
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if (response.data.abort === 1) {
if (response.data.installStatus === 1) {
$scope.webSiteCreationLoading = true;
$scope.installationDetailsForm = true;
$scope.installationProgress = false;
$scope.errorMessageBox = true;
$scope.success = false;
$scope.couldNotConnect = true;
$scope.goBackDisable = false;
$("#installProgress").css("width", "100%");
$scope.installPercentage = "100";
$scope.currentStatus = response.data.currentStatus;
$timeout.cancel();
} else {
$scope.webSiteCreationLoading = 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;
$("#installProgress").css("width", "0%");
$scope.installPercentage = "0";
$scope.goBackDisable = false;
}
} else {
$scope.webSiteCreationLoading = false;
$("#installProgress").css("width", response.data.installationProgress + "%");
$scope.installPercentage = response.data.installationProgress;
$scope.currentStatus = response.data.currentStatus;
$timeout(getCreationStatus, 1000);
}
}
function cantLoadInitialDatas(response) {
$scope.webSiteCreationLoading = true;
$scope.installationDetailsForm = true;
$scope.installationProgress = false;
$scope.errorMessageBox = true;
$scope.success = true;
$scope.couldNotConnect = false;
$scope.goBackDisable = false;
}
}
});
app.controller('ConfigureV2Backup', function ($scope, $http, $timeout){
@@ -1582,12 +1670,65 @@ app.controller('ConfigureV2Backup', function ($scope, $http, $timeout){
$scope.cyberpanelLoading = true;
$('#GdriveModal').modal('show');
}
else if(backuptype === 'SFTP')
{
$scope.cyberpanelLoading = true;
$('#SFTPModal').modal('show');
}
}
$scope.setupAccount = function(){
window.open("https://platform.cyberpersons.com/gDrive?name=" + $scope.accountName + '&server=' + window.location.href + 'Setup');
window.open("https://platform.cyberpersons.com/gDrive?name=" + $scope.accountName + '&server=' + window.location.href + 'Setup&domain=' + $scope.selwebsite);
};
$scope.ConfigerSFTP = function (){
$scope.cyberpanelLoading = false;
var url = "/IncrementalBackups/ConfigureSftpV2Backup";
var data = {
Selectedwebsite: $scope.selwebsite,
sfptpasswd: $scope.sfptpasswd,
hostName: $scope.hostName,
};
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) {
location.reload()
}
else {
$scope.goBackDisable = false;
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'
});
}
}
});
function listpaths(pathid, button) {

View File

@@ -21,6 +21,17 @@
<form action="/" 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="selwebsite" 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 Backup Type" %} </label>
@@ -73,6 +84,55 @@
</div>
</div>
</div>
<div id="SFTPModal" 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 "Host Name" %}</label>
<div class="col-sm-6">
<input name="accountName" type="text" class="form-control"
ng-model="hostName">
</div>
</div>
<div ng-hide="installationDetailsForm" class="form-group">
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
<div class="col-sm-6">
<input name="accountName" type="text" class="form-control"
ng-model="sfptpasswd">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary"
ng-click="ConfigerSFTP()">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>

View File

@@ -52,6 +52,47 @@
</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 "Website succesfully created." %}</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>

View File

@@ -1,6 +0,0 @@
# -*- coding: utf-8 -*-
from django.test import TestCase
# Create your tests here.

View File

@@ -32,5 +32,8 @@ urlpatterns = [
url(r'^selectreporestorev2$', views.selectreporestorev2, name='selectreporestorev2'),
url(r'^RestorePathV2$', views.RestorePathV2, name='RestorePathV2'),
url(r'^CreateV2BackupButton$', views.CreateV2BackupButton, name='CreateV2BackupButton'),
url(r'^selectwebsiteCreatev2$', views.selectwebsiteCreatev2, name='selectwebsiteCreatev2'),
url(r'^CreateV2BackupStatus$', views.CreateV2BackupStatus, name='CreateV2BackupStatus'),
url(r'^ConfigureSftpV2Backup$', views.ConfigureSftpV2Backup, name='ConfigureSftpV2Backup'),
]

View File

@@ -721,10 +721,10 @@ def ConfigureV2Backup(request):
return ACLManager.loadError()
# websites = ACLManager.findAllSites(current_acl, user_id)
websites = ACLManager.findAllSites(current_acl, user_id)
#
# destinations = _get_destinations(local=True)
proc = httpProc(request, 'IncBackups/ConfigureV2Backup.html')
proc = httpProc(request, 'IncBackups/ConfigureV2Backup.html', {'websiteList': websites})
return proc.render()
@@ -752,23 +752,17 @@ def createV2BackupSetup(request):
req_data['token_uri'] = request.GET.get('to')
req_data['scopes'] = request.GET.get('s')
req_data['accountname'] = request.GET.get('n')
website = request.GET.get('d')
# logging.writeToFile('domainname is ====%s'%(request.GET.get))
cpbuv2 = CPBackupsV2(
{'domain': 'cyberpanel.net', 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1,
{'domain': website, '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)
return ConfigureV2Backup(request)
# wm = BackupManager()
# return wm.gDriveSetup(userID, request)
# currentACL = ACLManager.loadedACL(userID)
# websitesName = ACLManager.findAllSites(currentACL, userID)
# proc = httpProc(request, 'IncBackups/RestoreV2Backup.html', {'websiteList': websitesName}, 'createBackup')
# return proc.render()
except KeyError:
return redirect(loadLoginPage)
@@ -781,14 +775,37 @@ def CreateV2BackupButton(request):
Selectedwebsite = data['Selectedwebsite']
Selectedrepo = data['Selectedrepo']
final_dic = {'status': 1, 'data': None}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
extraArgs = {}
extraArgs['function'] = 'InitiateBackup'
extraArgs['BackendName'] = Selectedrepo
extraArgs['domain'] = Selectedwebsite
extraArgs['BasePath']= '/home/backup'
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + str(randint(1000, 9999))
background = CPBackupsV2(extraArgs)
background.start()
time.sleep(2)
data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None',
'tempStatusPath': extraArgs['tempStatusPath']}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
final_dic = {'status': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def CreateV2BackupStatus(request):
try:
userID = request.session['userID']
bm = BackupManager()
return bm.CreateV2BackupStatus(userID, json.loads(request.body))
except KeyError:
return redirect(loadLoginPage)
def RestoreV2backupSite(request):
try:
@@ -830,7 +847,7 @@ def selectwebsiteRetorev2(request):
command = 'cat %s'%(path)
result = pu.outputExecutioner(command)
if result.find('host') > -1:
if result.find('type') > -1:
pattern = r'\[(.*?)\]'
matches = re.findall(pattern, result)
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": matches})
@@ -848,6 +865,109 @@ def selectwebsiteRetorev2(request):
return HttpResponse(final_json)
def ConfigureSftpV2Backup(request):
try:
userID = request.session['userID']
data = json.loads(request.body)
Selectedwebsite = data['Selectedwebsite']
sfptpasswd = data['sfptpasswd']
hostName = data['hostName']
admin = Administrator.objects.get(pk=userID)
req_data = {}
req_data['name'] = 'SFTP'
req_data['host'] = Selectedwebsite
req_data['user'] = hostName
req_data['password'] = sfptpasswd
cpbuv2 = CPBackupsV2(
{'domain': Selectedwebsite, 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1,
'BackupEmails': 1, 'BackendName': 'SFTP', 'function': None})
cpbuv2.SetupRcloneBackend(CPBackupsV2.SFTP, req_data)
return ConfigureV2Backup(request)
# 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)
return HttpResponse(final_json)
def selectwebsiteCreatev2(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)
CurrentContent = pu.outputExecutioner(command)
if CurrentContent.find('No such file or directory') > -1:
LocalRclonePath = f'/home/{obj.domain}/.config/rclone'
command = f'mkdir -p {LocalRclonePath}'
pu.executioner(command, obj.externalApp)
content = '''
[local]
type = local
'''
command = f"echo '{content}' > {path}"
pu.executioner(command, obj.externalApp, True)
command = 'cat %s' % (path)
result = pu.outputExecutioner(command)
if result.find('type') > -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)
else:
command = 'cat %s' % (path)
result = pu.outputExecutioner(command)
if result.find('type') > -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)
# logging.writeToFile(str(CurrentContent))
# 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)
return HttpResponse(final_json)
def selectreporestorev2(request):
try:
userID = request.session['userID']

View File

@@ -1795,3 +1795,52 @@ class BackupManager:
data_ret = {'status': 0, 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def CreateV2BackupStatus(self, userID=None, data=None):
try:
domain = data['domain']
statusFile = f'/home/cyberpanel/{domain}_rustic_backup_log'
if ACLManager.CheckStatusFilleLoc(statusFile):
pass
else:
data_ret = {'abort': 1, 'installStatus': 0, 'installationProgress': "100",
'currentStatus': 'Invalid status file.'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
#currentStatus:"cat: /home/cyberpanel/9219: No such file or directory"
statusData = ProcessUtilities.outputExecutioner("cat " + statusFile).splitlines()
lastLine = statusData[-1]
if lastLine.find('[200]') > -1:
command = 'rm -f ' + statusFile
subprocess.call(shlex.split(command))
data_ret = {'abort': 1, 'installStatus': 1, 'installationProgress': "100",
'currentStatus': 'Successfully Installed.'}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
elif lastLine.find('[404]') > -1:
data_ret = {'abort': 1, 'installStatus': 0, 'installationProgress': "0",
'error_message': ProcessUtilities.outputExecutioner("cat " + statusFile).splitlines()}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
progress = lastLine.split(',')
currentStatus = progress[0]
try:
installationProgress = progress[1]
except:
installationProgress = 0
data_ret = {'abort': 0, 'installStatus': 0, 'installationProgress': installationProgress,
'currentStatus': currentStatus}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException as msg:
data_ret = {'abort': 0, 'installStatus': 0, 'installationProgress': "0", 'error_message': str(msg)}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

View File

@@ -4,6 +4,7 @@ import os
import sys
import time
import requests
from django.http import HttpResponse
sys.path.append('/usr/local/CyberCP')
import django
@@ -112,12 +113,14 @@ pass = {ObsecurePassword}
'''
command = f"echo '{content}' > {self.ConfigFilePath}"
#ProcessUtilities.executioner(command, self.website.externalApp, True)
ProcessUtilities.executioner(command, self.website.externalApp, True)
command = f"chmod 600 {self.ConfigFilePath}"
ProcessUtilities.executioner(command, self.website.externalApp)
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": None})
return HttpResponse(final_json)
elif type == CPBackupsV2.GDrive:
logging.CyberCPLogFileWriter.writeToFile('tes 2,...gdive..........in')
token = """{"access_token":"%s","token_type":"Bearer","refresh_token":"%s"}""" %(config["token"], config["refresh_token"])

View File

@@ -34,7 +34,6 @@ except:
pass
import threading as multi
class IncScheduler(multi.Thread):
logPath = '/home/cyberpanel/incbackuplogs'
gitFolder = '/home/cyberpanel/git'
@@ -122,7 +121,7 @@ class IncScheduler(multi.Thread):
break
except BaseException as msg:
logging.writeToFile(str(msg))
logging.writeToFile( "%s [startBackup]"%str(msg))
@staticmethod
def git(type):
@@ -964,29 +963,35 @@ Automatic backup failed for %s on %s.
@staticmethod
def RemoteBackup(function):
try:
# print("....start remote backup...............")
from websiteFunctions.models import RemoteBackupSchedule, RemoteBackupsites, WPSites
from loginSystem.models import Administrator
import json
import time
from plogical.applicationInstaller import ApplicationInstaller
for config in RemoteBackupSchedule.objects.all():
# print("....start remote backup........site.......%s"%config.Name)
try:
configbakup = json.loads(config.config)
backuptype = configbakup['BackupType']
# print("....start remote backup........site.......%s.. and bakuptype...%s" % (config.Name, backuptype))
if backuptype == 'Only DataBase':
Backuptype = "3"
elif backuptype == 'Only Website':
Backuptype = "2"
else:
Backuptype = "1"
except:
except BaseException as msg:
print("....backup config type Error.%s" % str(msg))
continue
try:
allRemoteBackupsiteobj = RemoteBackupsites.objects.filter(owner=config.pk)
allRemoteBackupsiteobj = RemoteBackupsites.objects.filter(owner=config)
# print("store site id.....%s"%str(allRemoteBackupsiteobj))
for i in allRemoteBackupsiteobj:
try:
backupsiteID = i.WPsites
wpsite = WPSites.objects.get(pk=backupsiteID)
# print("site name.....%s"%wpsite.title)
AdminID = wpsite.owner.admin_id
Admin = Administrator.objects.get(pk=AdminID)
@@ -1375,7 +1380,7 @@ def main():
IncScheduler.CalculateAndUpdateDiskUsage()
return 0
if args.function == '30 Minutes' or args.function == '30 Minutes' or args.function == '1 Hour' or args.function == '6 Hours' or args.function == '12 Hours' or args.function == '1 Day' or args.function == '3 Days' or args.function == '1 Week':
if args.function == '30 Minutes' or args.function == '30 Minutes'or args.function == 'Daily' or args.function == '1 Hour' or args.function == '6 Hours' or args.function == '12 Hours' or args.function == '1 Day' or args.function == '3 Days' or args.function == '1 Week':
IncScheduler.RemoteBackup(args.function)
return 0

View File

@@ -1326,7 +1326,7 @@ class WebsiteManager:
'BucketName': BucketName
}
except BaseException as msg:
config = {}
config = {'BackupType': BackupType}
pass
svobj = RemoteBackupSchedule(RemoteBackupConfig=RemoteBackupConfigobj, Name=ScheduleName,