mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
backupv2 setup and remotewpbackup bug fix
This commit is contained in:
@@ -1438,12 +1438,17 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
|
|||||||
|
|
||||||
|
|
||||||
$scope.backupLoading = true;
|
$scope.backupLoading = true;
|
||||||
|
$scope.installationProgress = true;
|
||||||
|
$scope.errorMessageBox = true;
|
||||||
|
$scope.success = true;
|
||||||
|
$scope.couldNotConnect = true;
|
||||||
|
$scope.goBackDisable = true;
|
||||||
|
|
||||||
$scope.selectwebsite = function () {
|
$scope.selectwebsite = function () {
|
||||||
document.getElementById('reposelectbox').innerHTML = "";
|
document.getElementById('reposelectbox').innerHTML = "";
|
||||||
$scope.backupLoading = false;
|
$scope.backupLoading = false;
|
||||||
// document.getElementById('CreateV2BackupButton').style.display = "block";
|
// document.getElementById('CreateV2BackupButton').style.display = "block";
|
||||||
var url = "/IncrementalBackups/selectwebsiteRetorev2";
|
var url = "/IncrementalBackups/selectwebsiteCreatev2";
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
Selectedwebsite: $scope.selwebsite,
|
Selectedwebsite: $scope.selwebsite,
|
||||||
@@ -1465,7 +1470,6 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
|
|||||||
$scope.backupLoading = true;
|
$scope.backupLoading = true;
|
||||||
if (response.data.status === 1) {
|
if (response.data.status === 1) {
|
||||||
|
|
||||||
|
|
||||||
const selectBox = document.getElementById('reposelectbox');
|
const selectBox = document.getElementById('reposelectbox');
|
||||||
|
|
||||||
|
|
||||||
@@ -1519,9 +1523,7 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Domain;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$scope.CreateV2BackupButton = function () {
|
$scope.CreateV2BackupButton = function () {
|
||||||
$scope.backupLoading = false;
|
$scope.backupLoading = false;
|
||||||
@@ -1533,7 +1535,6 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
|
|||||||
Selectedrepo: $('#reposelectbox').val(),
|
Selectedrepo: $('#reposelectbox').val(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
headers: {
|
headers: {
|
||||||
'X-CSRFToken': getCookie('csrftoken')
|
'X-CSRFToken': getCookie('csrftoken')
|
||||||
@@ -1548,11 +1549,17 @@ app.controller('CreateV2Backup', function ($scope, $http, $timeout, $compile) {
|
|||||||
$scope.backupLoading = true;
|
$scope.backupLoading = true;
|
||||||
if (response.data.status === 1) {
|
if (response.data.status === 1) {
|
||||||
|
|
||||||
alert("....................."+response.data.status);
|
Domain = $scope.selwebsite;
|
||||||
|
getCreationStatus();
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
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){
|
app.controller('ConfigureV2Backup', function ($scope, $http, $timeout){
|
||||||
@@ -1582,12 +1670,65 @@ app.controller('ConfigureV2Backup', function ($scope, $http, $timeout){
|
|||||||
$scope.cyberpanelLoading = true;
|
$scope.cyberpanelLoading = true;
|
||||||
$('#GdriveModal').modal('show');
|
$('#GdriveModal').modal('show');
|
||||||
}
|
}
|
||||||
|
else if(backuptype === 'SFTP')
|
||||||
|
{
|
||||||
|
$scope.cyberpanelLoading = true;
|
||||||
|
$('#SFTPModal').modal('show');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$scope.setupAccount = function(){
|
$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) {
|
function listpaths(pathid, button) {
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,17 @@
|
|||||||
|
|
||||||
<form action="/" class="form-horizontal bordered-row">
|
<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">
|
<div class="form-group">
|
||||||
<label class="col-sm-3 control-label">{% trans "Select Backup Type" %} </label>
|
<label class="col-sm-3 control-label">{% trans "Select Backup Type" %} </label>
|
||||||
@@ -73,6 +84,55 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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">×
|
||||||
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -52,6 +52,47 @@
|
|||||||
</div>
|
</div>
|
||||||
</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>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
|
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
|
|||||||
@@ -32,5 +32,8 @@ urlpatterns = [
|
|||||||
url(r'^selectreporestorev2$', views.selectreporestorev2, name='selectreporestorev2'),
|
url(r'^selectreporestorev2$', views.selectreporestorev2, name='selectreporestorev2'),
|
||||||
url(r'^RestorePathV2$', views.RestorePathV2, name='RestorePathV2'),
|
url(r'^RestorePathV2$', views.RestorePathV2, name='RestorePathV2'),
|
||||||
url(r'^CreateV2BackupButton$', views.CreateV2BackupButton, name='CreateV2BackupButton'),
|
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'),
|
||||||
|
|
||||||
]
|
]
|
||||||
@@ -721,10 +721,10 @@ def ConfigureV2Backup(request):
|
|||||||
return ACLManager.loadError()
|
return ACLManager.loadError()
|
||||||
|
|
||||||
|
|
||||||
# websites = ACLManager.findAllSites(current_acl, user_id)
|
websites = ACLManager.findAllSites(current_acl, user_id)
|
||||||
#
|
#
|
||||||
# destinations = _get_destinations(local=True)
|
# destinations = _get_destinations(local=True)
|
||||||
proc = httpProc(request, 'IncBackups/ConfigureV2Backup.html')
|
proc = httpProc(request, 'IncBackups/ConfigureV2Backup.html', {'websiteList': websites})
|
||||||
return proc.render()
|
return proc.render()
|
||||||
|
|
||||||
|
|
||||||
@@ -752,23 +752,17 @@ def createV2BackupSetup(request):
|
|||||||
req_data['token_uri'] = request.GET.get('to')
|
req_data['token_uri'] = request.GET.get('to')
|
||||||
req_data['scopes'] = request.GET.get('s')
|
req_data['scopes'] = request.GET.get('s')
|
||||||
req_data['accountname'] = request.GET.get('n')
|
req_data['accountname'] = request.GET.get('n')
|
||||||
|
website = request.GET.get('d')
|
||||||
|
# logging.writeToFile('domainname is ====%s'%(request.GET.get))
|
||||||
|
|
||||||
cpbuv2 = CPBackupsV2(
|
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'})
|
'BackupEmails': 1, 'BackendName': 'testremote'})
|
||||||
|
|
||||||
# RcloneData = {"name": 'testremote', "host": "staging.cyberpanel.net", "user": "abcds2751", "port": "22",
|
|
||||||
# "password": "hosting", }
|
|
||||||
cpbuv2.SetupRcloneBackend(CPBackupsV2.GDrive, req_data)
|
cpbuv2.SetupRcloneBackend(CPBackupsV2.GDrive, req_data)
|
||||||
|
|
||||||
return ConfigureV2Backup(request)
|
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:
|
except KeyError:
|
||||||
return redirect(loadLoginPage)
|
return redirect(loadLoginPage)
|
||||||
|
|
||||||
@@ -781,14 +775,37 @@ def CreateV2BackupButton(request):
|
|||||||
Selectedwebsite = data['Selectedwebsite']
|
Selectedwebsite = data['Selectedwebsite']
|
||||||
Selectedrepo = data['Selectedrepo']
|
Selectedrepo = data['Selectedrepo']
|
||||||
|
|
||||||
final_dic = {'status': 1, 'data': None}
|
extraArgs = {}
|
||||||
final_json = json.dumps(final_dic)
|
|
||||||
return HttpResponse(final_json)
|
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:
|
except BaseException as msg:
|
||||||
final_dic = {'status': 0, 'error_message': str(msg)}
|
data_ret = {'status': 0, 'installStatus': 0, 'error_message': str(msg)}
|
||||||
final_json = json.dumps(final_dic)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(final_json)
|
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):
|
def RestoreV2backupSite(request):
|
||||||
try:
|
try:
|
||||||
@@ -830,7 +847,7 @@ def selectwebsiteRetorev2(request):
|
|||||||
command = 'cat %s'%(path)
|
command = 'cat %s'%(path)
|
||||||
result = pu.outputExecutioner(command)
|
result = pu.outputExecutioner(command)
|
||||||
|
|
||||||
if result.find('host') > -1:
|
if result.find('type') > -1:
|
||||||
pattern = r'\[(.*?)\]'
|
pattern = r'\[(.*?)\]'
|
||||||
matches = re.findall(pattern, result)
|
matches = re.findall(pattern, result)
|
||||||
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": matches})
|
final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": matches})
|
||||||
@@ -848,6 +865,109 @@ def selectwebsiteRetorev2(request):
|
|||||||
return HttpResponse(final_json)
|
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):
|
def selectreporestorev2(request):
|
||||||
try:
|
try:
|
||||||
userID = request.session['userID']
|
userID = request.session['userID']
|
||||||
|
|||||||
@@ -1795,3 +1795,52 @@ class BackupManager:
|
|||||||
data_ret = {'status': 0, 'error_message': str(msg)}
|
data_ret = {'status': 0, 'error_message': str(msg)}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
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)
|
||||||
@@ -4,6 +4,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
sys.path.append('/usr/local/CyberCP')
|
sys.path.append('/usr/local/CyberCP')
|
||||||
import django
|
import django
|
||||||
@@ -112,12 +113,14 @@ pass = {ObsecurePassword}
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
command = f"echo '{content}' > {self.ConfigFilePath}"
|
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}"
|
command = f"chmod 600 {self.ConfigFilePath}"
|
||||||
ProcessUtilities.executioner(command, self.website.externalApp)
|
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:
|
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"])
|
token = """{"access_token":"%s","token_type":"Bearer","refresh_token":"%s"}""" %(config["token"], config["refresh_token"])
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ except:
|
|||||||
pass
|
pass
|
||||||
import threading as multi
|
import threading as multi
|
||||||
|
|
||||||
|
|
||||||
class IncScheduler(multi.Thread):
|
class IncScheduler(multi.Thread):
|
||||||
logPath = '/home/cyberpanel/incbackuplogs'
|
logPath = '/home/cyberpanel/incbackuplogs'
|
||||||
gitFolder = '/home/cyberpanel/git'
|
gitFolder = '/home/cyberpanel/git'
|
||||||
@@ -122,7 +121,7 @@ class IncScheduler(multi.Thread):
|
|||||||
break
|
break
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.writeToFile(str(msg))
|
logging.writeToFile( "%s [startBackup]"%str(msg))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def git(type):
|
def git(type):
|
||||||
@@ -964,29 +963,35 @@ Automatic backup failed for %s on %s.
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def RemoteBackup(function):
|
def RemoteBackup(function):
|
||||||
try:
|
try:
|
||||||
|
# print("....start remote backup...............")
|
||||||
from websiteFunctions.models import RemoteBackupSchedule, RemoteBackupsites, WPSites
|
from websiteFunctions.models import RemoteBackupSchedule, RemoteBackupsites, WPSites
|
||||||
from loginSystem.models import Administrator
|
from loginSystem.models import Administrator
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from plogical.applicationInstaller import ApplicationInstaller
|
from plogical.applicationInstaller import ApplicationInstaller
|
||||||
for config in RemoteBackupSchedule.objects.all():
|
for config in RemoteBackupSchedule.objects.all():
|
||||||
|
# print("....start remote backup........site.......%s"%config.Name)
|
||||||
try:
|
try:
|
||||||
configbakup = json.loads(config.config)
|
configbakup = json.loads(config.config)
|
||||||
backuptype = configbakup['BackupType']
|
backuptype = configbakup['BackupType']
|
||||||
|
# print("....start remote backup........site.......%s.. and bakuptype...%s" % (config.Name, backuptype))
|
||||||
if backuptype == 'Only DataBase':
|
if backuptype == 'Only DataBase':
|
||||||
Backuptype = "3"
|
Backuptype = "3"
|
||||||
elif backuptype == 'Only Website':
|
elif backuptype == 'Only Website':
|
||||||
Backuptype = "2"
|
Backuptype = "2"
|
||||||
else:
|
else:
|
||||||
Backuptype = "1"
|
Backuptype = "1"
|
||||||
except:
|
except BaseException as msg:
|
||||||
|
print("....backup config type Error.%s" % str(msg))
|
||||||
continue
|
continue
|
||||||
try:
|
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:
|
for i in allRemoteBackupsiteobj:
|
||||||
try:
|
try:
|
||||||
backupsiteID = i.WPsites
|
backupsiteID = i.WPsites
|
||||||
wpsite = WPSites.objects.get(pk=backupsiteID)
|
wpsite = WPSites.objects.get(pk=backupsiteID)
|
||||||
|
# print("site name.....%s"%wpsite.title)
|
||||||
AdminID = wpsite.owner.admin_id
|
AdminID = wpsite.owner.admin_id
|
||||||
Admin = Administrator.objects.get(pk=AdminID)
|
Admin = Administrator.objects.get(pk=AdminID)
|
||||||
|
|
||||||
@@ -1375,7 +1380,7 @@ def main():
|
|||||||
IncScheduler.CalculateAndUpdateDiskUsage()
|
IncScheduler.CalculateAndUpdateDiskUsage()
|
||||||
return 0
|
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)
|
IncScheduler.RemoteBackup(args.function)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
@@ -1326,7 +1326,7 @@ class WebsiteManager:
|
|||||||
'BucketName': BucketName
|
'BucketName': BucketName
|
||||||
}
|
}
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
config = {}
|
config = {'BackupType': BackupType}
|
||||||
pass
|
pass
|
||||||
|
|
||||||
svobj = RemoteBackupSchedule(RemoteBackupConfig=RemoteBackupConfigobj, Name=ScheduleName,
|
svobj = RemoteBackupSchedule(RemoteBackupConfig=RemoteBackupConfigobj, Name=ScheduleName,
|
||||||
|
|||||||
Reference in New Issue
Block a user