Updates to Remote Backup Transfer

This commit is contained in:
usmannasir
2017-10-26 23:50:59 +05:00
parent 66b9c55b35
commit f41b420071
14 changed files with 1674 additions and 851 deletions

View File

@@ -15,4 +15,8 @@ urlpatterns = [
url(r'^fetchSSHkey', views.fetchSSHkey, name='fetchSSHkey'),
url(r'^remoteTransfer', views.remoteTransfer, name='remoteTransfer'),
url(r'^fetchAccountsFromRemoteServer', views.fetchAccountsFromRemoteServer, name='fetchAccountsFromRemoteServer'),
url(r'^FetchRemoteTransferStatus', views.FetchRemoteTransferStatus, name='FetchRemoteTransferStatus'),
url(r'^cancelRemoteTransfer', views.cancelRemoteTransfer, name='cancelRemoteTransfer'),
]

View File

@@ -16,6 +16,10 @@ from baseTemplate.views import renderBase
from random import randint
import plogical.remoteBackup as rBackup
from websiteFunctions.models import Websites
import os
import signal
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
from shutil import rmtree
# Create your views here.
@@ -422,6 +426,80 @@ def fetchAccountsFromRemoteServer(request):
return HttpResponse(json_data)
except BaseException, msg:
data = {'transferStatus': 0,'error_message': str(msg)}
data = {'fetchStatus': 0,'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)
def FetchRemoteTransferStatus(request):
try:
if request.method == "POST":
data = json.loads(request.body)
username = data['username']
password = data['password']
dir = "/home/backup/transfer-"+str(data['dir'])+"/backup_log"
statusFile = open(dir,'r')
status = statusFile.read()
statusFile.close()
admin = Administrator.objects.get(userName=username)
if hashPassword.check_password(admin.password, password):
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "status": status})
return HttpResponse(final_json)
else:
data_ret = {'fetchStatus': 0, 'error_message': "Invalid Credentials"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException, msg:
data = {'fetchStatus': 0,'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)
def cancelRemoteTransfer(request):
try:
if request.method == "POST":
data = json.loads(request.body)
username = data['username']
password = data['password']
dir = "/home/backup/transfer-"+str(data['dir'])
admin = Administrator.objects.get(userName=username)
if hashPassword.check_password(admin.password, password):
if os.path.exists(dir):
path = dir+"/pid"
pid = open(path, "r").readlines()[0]
try:
os.kill(int(pid), signal.SIGKILL)
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [cancelRemoteTransfer]")
rmtree(dir)
data = {'cancelStatus': 1, 'error_message': "None"}
json_data = json.dumps(data)
return HttpResponse(json_data)
else:
data = {'cancelStatus': 1, 'error_message': "None"}
json_data = json.dumps(data)
return HttpResponse(json_data)
else:
data_ret = {'cancelStatus': 0, 'error_message': "Invalid Credentials"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException, msg:
data = {'cancelStatus': 1, 'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)

View File

@@ -396,7 +396,6 @@ app.controller('restoreWebsiteControl', function($scope,$http,$timeout) {
};
$scope.restoreBackup = function(){
var backupFile = $scope.backupFile;
@@ -1033,21 +1032,97 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
//*** Remote Backup site ****//
app.controller('remoteBackupControl', function($scope, $http, $timeout) {
$scope.backupButton = true;
$scope.status_success = true;
$scope.status_danger = true;
$scope.status_info = true;
$scope.backupLoading = true;
$scope.request = true;
$scope.requestData = "";
$scope.submitDisable = false;
$scope.startRestore = true;
$scope.accountsInRemoteServerTable = true;
$scope.transferBoxBtn = true;
$scope.stopTransferbtn = true;
$scope.fetchAccountsBtn = false;
// notifications boxes
$scope.notificationsBox = true;
$scope.errorMessage = true;
$scope.couldNotConnect = true;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
// status box
$scope.backupStatus = true;
var websitesToBeBacked = [];
var websitesToBeBackedTemp = [];
var index = 0;
var tempTransferDir = "";
$scope.passwordEnter = function() {
$scope.backupButton = false;
};
$scope.addRemoveWebsite = function (website,websiteStatus) {
if(websiteStatus==true)
{
var check = 1;
for(var j = 0; j < websitesToBeBacked.length; j++){
if (websitesToBeBacked[j] == website){
check = 0;
break;
}
}
if(check == 1) {
websitesToBeBacked.push(website);
}
}
else{
var tempArray = [];
for(var j = 0; j < websitesToBeBacked.length; j++){
if (websitesToBeBacked[j] != website){
tempArray.push(websitesToBeBacked[j]);
}
}
websitesToBeBacked = tempArray;
}
};
$scope.allChecked = function (webSiteStatus) {
if(webSiteStatus==true) {
websitesToBeBacked = websitesToBeBackedTemp;
$scope.webSiteStatus = true;
}
else{
websitesToBeBacked = [];
$scope.webSiteStatus = false;
}
};
$scope.fetchAccountsFromRemoteServer = function () {
$scope.backupLoading = false;
// notifications boxes
$scope.notificationsBox = true;
$scope.errorMessage = true;
$scope.couldNotConnect = true;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
var IPAddress = $scope.IPAddress;
var password = $scope.password;
@@ -1071,112 +1146,87 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
if (response.data.status == 1) {
$scope.records = JSON.parse(response.data.data);
var parsed = JSON.parse(response.data.data);
for(var j = 0; j < parsed.length; j++){
websitesToBeBackedTemp.push(parsed[j].website);
}
$scope.accountsInRemoteServerTable = false;
$scope.backupLoading = true;
// enable the transfer/cancel btn
$scope.transferBoxBtn = false;
// notifications boxes
$scope.notificationsBox = false;
$scope.errorMessage = true;
$scope.couldNotConnect = true;
$scope.accountsFetched = false;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
}
else {
$scope.error_message = response.data.error_message;
$scope.backupLoading = true;
// notifications boxes
$scope.notificationsBox = false;
$scope.errorMessage = false;
$scope.couldNotConnect = true;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
}
}
function cantLoadInitialDatas(response) {
// notifications boxes
$scope.notificationsBox = false;
$scope.errorMessage = true;
$scope.couldNotConnect = false;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
}
};
$scope.passwordEnter = function() {
$scope.backupButton = false;
};
$scope.startTransfer = function () {
var seek = 0;
var backupDir;
var username = "admin";
// notifications boxes
$scope.notificationsBox = true;
$scope.errorMessage = true;
$scope.couldNotConnect = true;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
function getBackupStatus(password) {
url = "/backup/getRemoteTransferStatus";
var data = {
ipAddress: $scope.IPAddress,
seek: seek,
backupDir: backupDir,
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
console.log("Initiating Status with seek: " + seek)
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
console.log(response.data)
if (response.data.remoteTransferStatus == 1) {
seek = response.data.where;
if (response.data.complete == 1) {
$scope.submitDisable = false;
$scope.backupLoading = true;
$scope.status_danger = true;
$scope.status_info = true;
$scope.status_success = false;
$scope.startRestore = true;
$scope.statusBox = "Backup Files Transferred! Require Permission to restore backups";
$scope.requestData = $scope.requestData + response.data.logs
seek = 0;
$scope.startRestore = false;
} else {
$scope.requestData = $scope.requestData + response.data.logs
$timeout(getBackupStatus(password), 5000);
}
} else {
if (response.data.error_message == "list index out of range") {
$timeout(getBackupStatus(password), 5000);
} else {
$scope.submitDisable = false;
$scope.status_danger = false;
$scope.status_info = true;
$scope.status_success = true;
$scope.statusBox = "Unable to Transfer File: " + response.data.error_message;
}
}
if(websitesToBeBacked.length === 0){
alert("No websites selected for transfer.")
return;
}
function cantLoadInitialDatas(response) {
$scope.status_danger = false;
$scope.status_info = true;
$scope.status_success = true;
$scope.statusBox = "Unable to connect"
}
};
$scope.submitRemoteBackup = function() {
$scope.requestData = "";
$scope.status_success = true;
$scope.status_danger = true;
$scope.status_info = true;
$scope.fetchAccountsBtn = true;
$scope.backupLoading = false;
$scope.submitDisable = true;
var IPAddress = $scope.IPAddress;
var password = $scope.password;
url = "/backup/submitRemoteBackups";
url = "/backup/starRemoteTransfer";
var data = {
ipAddress: IPAddress,
username: username,
password: password,
};
@@ -1187,48 +1237,82 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
console.log(response.data)
if (response.data.status == 1) {
$scope.request = false;
console.log("Backup generated!!")
backupDir = response.data.dir;
getBackupStatus(password);
} else {
$scope.submitDisable = false;
if (response.data.remoteTransferStatus == 1) {
tempTransferDir = response.data.dir;
$scope.accountsInRemoteServerTable = true;
// notifications boxes
$scope.notificationsBox = false;
$scope.errorMessage = true;
$scope.couldNotConnect = true;
$scope.accountsFetched = true;
$scope.backupProcessStarted = false;
$scope.backupCancelled = true;
// disable transfer button
$scope.startTransferbtn = true;
// enable cancel button
$scope.stopTransferbtn = false;
getBackupStatus();
}
else {
$scope.error_message = response.data.error_message;
$scope.backupLoading = true;
$scope.status_danger = false;
$scope.status_info = true;
$scope.status_success = true;
$scope.statusBox = "Unable to Transfer File: " + response.data.error_message;
// Notifications box settings
// notifications boxes
$scope.notificationsBox = false;
$scope.errorMessage = false;
$scope.couldNotConnect = true;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
}
}
function cantLoadInitialDatas(response) {
$scope.status_danger = false;
$scope.status_info = true;
$scope.status_success = true;
$scope.statusBox = "Unable to connect"
// Notifications box settings
// notifications boxes
$scope.notificationsBox = false;
$scope.errorMessage = true;
$scope.couldNotConnect = false;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
}
};
function getRestStatus() {
url = "/backup/remoteRestoreStatus";
function getBackupStatus(password) {
url = "/backup/getRemoteTransferStatus";
var data = {
seek: seek,
backupDir: backupDir,
password : $scope.password,
ipAddress: $scope.IPAddress,
dir: tempTransferDir,
};
console.log(data)
var config = {
headers: {
@@ -1237,69 +1321,58 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
};
console.log("Initiating Status with seek: " + seek)
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
console.log(response.data)
if (response.data.remoteRestoreStatus == 1) {
seek = response.data.where;
console.log(seek);
if (response.data.complete == 1) {
$scope.submitDisable = false;
if (response.data.remoteTransferStatus == 1) {
if(response.data.backupsSent == 0){
$scope.backupStatus = false;
$scope.requestData = response.data.status;
$timeout(getBackupStatus, 2000);
}
else{
$scope.requestData = response.data.status;
$timeout.cancel();
$scope.backupLoading = true;
$scope.status_danger = true;
$scope.status_info = true;
$scope.status_success = false;
$scope.statusBox = "Backup Files Restored!";
$scope.requestData = $scope.requestData + response.data.logs
$scope.startRestore = false;
} else {
$scope.requestData = $scope.requestData + response.data.logs
$timeout(getRestStatus(), 5000);
}
} else {
if (response.data.error_message == "list index out of range") {
$timeout(getRestStatus(), 5000);
} else {
$scope.submitDisable = false;
$scope.status_danger = false;
$scope.status_info = true;
$scope.status_success = true;
$scope.statusBox = "Unable to Restore File: " + response.data.error_message;
remoteBackupRestore();
}
}
else{
$scope.error_message = response.data.error_message;
$scope.backupLoading = true;
$scope.couldNotConnect = true;
// Notifications box settings
$scope.couldNotConnect = true;
$scope.errorMessage = false;
$scope.accountsFetched = true;
$scope.notificationsBox = false;
$timeout.cancel();
}
}
function cantLoadInitialDatas(response) {
$scope.status_danger = false;
$scope.status_info = true;
$scope.status_success = true;
$scope.statusBox = "Unable to connect"
// Notifications box settings
$scope.couldNotConnect = false;
$scope.errorMessage = true;
$scope.accountsFetched = true;
$scope.notificationsBox = false;
}
};
$scope.submitBackupRestore = function() {
$scope.status_success = true;
$scope.status_danger = true;
$scope.status_info = false;
$scope.statusBox = "Restoring Backup";
$scope.backupLoading = false;
$scope.submitDisable = true;
function remoteBackupRestore(){
url = "/backup/remoteBackupRestore";
var data = {
backupDir: backupDir
backupDir: tempTransferDir,
};
console.log(data)
var config = {
headers: {
@@ -1307,42 +1380,241 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
}
};
seek = 0
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
console.log(response.data)
if (response.data.remoteRestoreStatus == 1) {
$scope.request = false;
$scope.backupLoading = false;
localRestoreStatus();
}
}
$scope.status_danger = true;
$scope.status_info = true;
$scope.status_success = false;
$scope.statusBox = "Restore in Progress, fetching details"
getRestStatus();
} else {
$scope.submitDisable = false;
function cantLoadInitialDatas(response) {
// Notifications box settings
$scope.couldNotConnect = false;
$scope.errorMessage = true;
$scope.accountsFetched = true;
$scope.notificationsBox = false;
}
///////////////
};
function localRestoreStatus(password) {
url = "/backup/localRestoreStatus";
var data = {
backupDir: tempTransferDir,
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if (response.data.remoteTransferStatus == 1) {
if(response.data.complete == 0){
$scope.backupStatus = false;
$scope.requestData = response.data.status;
$timeout(localRestoreStatus, 2000);
}
else{
$scope.requestData = response.data.status;
$timeout.cancel();
$scope.backupLoading = true;
$scope.startTransferbtn = false;
}
}
else{
$scope.error_message = response.data.error_message;
$scope.backupLoading = true;
$scope.status_danger = false;
$scope.status_info = true;
$scope.status_success = true;
$scope.statusBox = "Unable to Restore Backups: " + response.data.error_message;
$scope.couldNotConnect = true;
// Notifications box settings
$scope.couldNotConnect = true;
$scope.errorMessage = false;
$scope.accountsFetched = true;
$scope.notificationsBox = false;
}
}
function cantLoadInitialDatas(response) {
$scope.status_danger = false;
$scope.status_info = true;
$scope.status_success = true;
$scope.statusBox = "Unable to connect";
// Notifications box settings
$scope.couldNotConnect = false;
$scope.errorMessage = true;
$scope.accountsFetched = true;
$scope.notificationsBox = false;
}
};
function restoreAccounts() {
url = "/backup/getRemoteTransferStatus";
var data = {
password : $scope.password,
ipAddress: $scope.IPAddress,
dir: tempTransferDir,
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if (response.data.remoteTransferStatus == 1) {
if(response.data.backupsSent == 0){
$scope.backupStatus = false;
$scope.requestData = response.data.status;
$timeout(getBackupStatus, 2000);
}
else{
$timeout.cancel();
}
}
}
function cantLoadInitialDatas(response) {
// Notifications box settings
$scope.couldNotConnect = false;
$scope.errorMessage = true;
$scope.accountsFetched = true;
$scope.notificationsBox = false;
}
};
$scope.cancelRemoteBackup = function () {
$scope.backupLoading = false;
// notifications boxes
$scope.notificationsBox = true;
$scope.errorMessage = true;
$scope.couldNotConnect = true;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
var IPAddress = $scope.IPAddress;
var password = $scope.password;
url = "/backup/cancelRemoteBackup";
var data = {
ipAddress: IPAddress,
password: password,
dir:tempTransferDir,
};
var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if (response.data.cancelStatus == 1) {
$scope.backupLoading = true;
// notifications boxes
$scope.notificationsBox = false;
$scope.errorMessage = true;
$scope.couldNotConnect = true;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = false;
// enable transfer button
$scope.startTransferbtn = false;
//disable cancel button
$scope.stopTransferbtn = true;
// hide status box
$scope.backupStatus = true;
// bring back websites table
$scope.accountsInRemoteServerTable = false;
// enable fetch button
$scope.fetchAccountsBtn = false;
}
else {
$scope.error_message = response.data.error_message;
$scope.backupLoading = true;
// notifications boxes
$scope.notificationsBox = false;
$scope.errorMessage = false;
$scope.couldNotConnect = true;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
}
}
function cantLoadInitialDatas(response) {
// notifications boxes
$scope.notificationsBox = false;
$scope.errorMessage = true;
$scope.couldNotConnect = false;
$scope.accountsFetched = true;
$scope.backupProcessStarted = true;
$scope.backupCancelled = true;
}
};
});
///** Backup site ends **///

View File

@@ -41,13 +41,60 @@
<div ng-hide="backupButton" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-disabled="submitDisable" ng-click="fetchAccountsFromRemoteServer()" class="btn btn-primary btn-lg btn-block">Fetch Accounts</button>
<button type="button" ng-disabled="fetchAccountsBtn" ng-click="fetchAccountsFromRemoteServer()" class="btn btn-primary btn-lg btn-block">Fetch Accounts</button>
</div>
</div>
</div>
<div ng-hide="transferBoxBtn" class="form-group">
<label class="col-sm-1 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-disabled="startTransferbtn" ng-click="startTransfer()" class="btn btn-primary btn-lg btn-block">Start Transfer</button>
</div>
<div class="col-sm-4">
<button type="button" ng-disabled="stopTransferbtn" ng-click="cancelRemoteBackup()" class="btn btn-primary btn-lg btn-block">Cancel</button>
</div>
</div>
<div ng-hide="notificationsBox" class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<div ng-hide="errorMessage" class="alert alert-danger">
<p>{$ error_message $}</p>
</div>
<div ng-hide="couldNotConnect" class="alert alert-danger">
<p>Could not connect, please refresh this page.</p>
</div>
<div ng-hide="accountsFetched" class="alert alert-success">
<p>Accounts Successfully Fetched from remote server.</p>
</div>
<div ng-hide="backupProcessStarted" class="alert alert-success">
<p>Backup Process successfully started.</p>
</div>
<div ng-hide="backupCancelled" class="alert alert-success">
<p>Backup successfully cancelled.</p>
</div>
</div>
</div>
<!------ List of Accounts in remote server --------------->
<div ng-hide="accountsInRemoteServerTable" class="form-group">
<div class="col-sm-12">
<input type="text" ng-model="accountsSearch" placeholder="{% trans 'Search Accounts..' %}" class="form-control autocomplete-input">
</div>
</div>
<div ng-hide="accountsInRemoteServerTable" class="form-group">
<div class="col-sm-12">
@@ -59,16 +106,16 @@
<th>{% trans "PHP" %}</th>
<th>{% trans "Package" %}</th>
<th>{% trans "Email" %}</th>
<th>{% trans "Transfer" %}</th>
<th><input ng-model="webSiteStatus" ng-change="allChecked(webSiteStatus)" type="checkbox" value=""></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="record in records track by $index">
<tr ng-repeat="record in records | filter:accountsSearch">
<td ng-bind="record.website"></td>
<td ng-bind="record.php"></td>
<td ng-bind="record.package"></td>
<td ng-bind="record.email"></td>
<td ng-click=""><input ng-model="sslCheck" type="checkbox" value=""></td>
<td ng-click=""><input ng-model="webSiteStatus" ng-change="addRemoveWebsite(record.website,webSiteStatus)" type="checkbox" value=""></td>
</tr>
</tbody>
</table>
@@ -78,17 +125,12 @@
<!------ List of Accounts in remote server --------------->
</form>
<div ng-hide="status_danger" class="alert alert-danger">
<p>{$ error_message $}</p>
</div>
<div ng-hide="status_info" class="alert alert-info">
<p>{$ statusBox $}</p>
</div>
<div ng-hide="request" class="form-group">
<div ng-hide="backupStatus" class="form-group">
<div class="col-sm-12">
<button ng-disabled="startRestore" style="margin-bottom: 1%" type="button" ng-click="submitBackupRestore()" class="btn ra-100 btn-blue-alt">Start Restore</button>
<textarea ng-model="requestData" rows="15" class="form-control" readonly>{{ requestData }}</textarea>
<textarea ng-model="requestData" rows="15" class="form-control"></textarea>
</div>
</div>

View File

@@ -39,11 +39,12 @@ urlpatterns = [
url(r'^remoteBackups', views.remoteBackups, name='remoteBackups'),
url(r'^submitRemoteBackups', views.submitRemoteBackups, name='submitRemoteBackups'),
url(r'^remoteTransferStatus', views.remoteTransferStatus, name='remoteTransferStatus'),
url(r'^getRemoteTransferStatus', views.getRemoteTransferStatus, name='getRemoteTransferStatus'),
url(r'^remoteBackupRestore', views.remoteBackupRestore, name='remoteBackupRestore'),
url(r'^remoteRestoreStatus', views.remoteRestoreStatus, name='remoteRestoreStatus'),
url(r'^starRemoteTransfer', views.starRemoteTransfer, name='starRemoteTransfer'),
url(r'^localRestoreStatus', views.localRestoreStatus, name='localRestoreStatus'),
url(r'^cancelRemoteBackup', views.cancelRemoteBackup, name='cancelRemoteBackup'),

View File

@@ -160,61 +160,55 @@ def getCurrentBackups(request):
def submitBackupCreation(request):
try:
try:
if request.method == 'POST':
if request.method == 'POST':
data = json.loads(request.body)
backupDomain = data['websiteToBeBacked']
data = json.loads(request.body)
backupDomain = data['websiteToBeBacked']
website = Websites.objects.get(domain=backupDomain)
website = Websites.objects.get(domain=backupDomain)
backupPath = "/home/"+backupDomain+"/backup/"
backupPath = "/home/" + backupDomain + "/backup/"
if not os.path.exists(backupPath):
os.mkdir(backupPath)
if not os.path.exists(backupPath):
os.mkdir(backupPath)
domainUser = backupDomain.split('.')
domainUser = backupDomain.split('.')
backupName = 'backup-'+domainUser[0]+"-"+time.strftime("%I-%M-%S-%a-%b-%Y")
backupName = 'backup-' + domainUser[0] + "-" + time.strftime("%I-%M-%S-%a-%b-%Y")
tempStoragePath = backupPath+backupName
tempStoragePath = backupPath + backupName
if not os.path.exists(tempStoragePath):
os.mkdir(tempStoragePath)
if not os.path.exists(tempStoragePath):
os.mkdir(tempStoragePath)
## Generating meta
## Generating meta
meta = tempStoragePath+"/meta"
meta = tempStoragePath + "/meta"
metaFile = open(meta,'w')
metaFile = open(meta, 'w')
metaFile.write(backupDomain+"\n")
metaFile.write(backupDomain + "\n")
databases = website.databases_set.all()
databases = website.databases_set.all()
for items in databases:
dbuser = DBUsers.objects.get(user=items.dbUser)
metaFile.write(items.dbName + "-" + items.dbUser + "-"+dbuser.password + "\n")
metaFile.close()
for items in databases:
dbuser = DBUsers.objects.get(user=items.dbUser)
metaFile.write(items.dbName + "-" + items.dbUser + "-" + dbuser.password + "\n")
metaFile.close()
backupUtil.backupUtilities.initiateBackup(tempStoragePath,backupName,backupPath)
backupUtil.backupUtilities.initiateBackup(tempStoragePath, backupName, backupPath)
newBackup = Backups(website=website,fileName=backupName,date=time.strftime("%I-%M-%S-%a-%b-%Y"),
size=0,status=0)
newBackup.save()
final_json = json.dumps({'metaStatus': 1, 'error_message': "None",'tempStorage':tempStoragePath})
return HttpResponse(final_json)
except BaseException,msg:
final_dic = {'metaStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
newBackup = Backups(website=website, fileName=backupName, date=time.strftime("%I-%M-%S-%a-%b-%Y"),
size=0, status=0)
newBackup.save()
final_json = json.dumps({'metaStatus': 1, 'error_message': "None", 'tempStorage': tempStoragePath})
return HttpResponse(final_json)
except KeyError:
final_dic = {'metaStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
except BaseException, msg:
final_dic = {'metaStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def backupStatus(request):
@@ -397,79 +391,78 @@ def deleteBackup(request):
def submitRestore(request):
try:
val = request.session['userID']
try:
if request.method == 'POST':
if request.method == 'POST':
data = json.loads(request.body)
backupFile = data['backupFile']
data = json.loads(request.body)
backupFile = data['backupFile']
originalFile = "/home/backup/" + backupFile
backupUtil.backupUtilities.initiateRestore(backupFile)
if not os.path.exists(originalFile):
dir = data['dir']
else:
dir = None
final_dic = {'restoreStatus': 1, 'error_message': "None"}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
backupUtil.backupUtilities.initiateRestore(backupFile, dir)
except BaseException,msg:
final_dic = {'restoreStatus': 0, 'error_message': str(msg)}
final_dic = {'restoreStatus': 1, 'error_message': "None"}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except KeyError:
final_dic = {'restoreStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
except BaseException, msg:
final_dic = {'restoreStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
def restoreStatus(request):
try:
val = request.session['userID']
try:
if request.method == 'POST':
if request.method == 'POST':
data = json.loads(request.body)
backupFile = data['backupFile'].strip(".tar.gz")
data = json.loads(request.body)
backupFile = data['backupFile'].strip(".tar.gz")
path = "/home/backup/" + backupFile
path = "/home/backup/"+backupFile
if os.path.exists(path):
pass
else:
dir = data['dir']
path = "/home/backup/transfer-" + str(dir) + "/" + backupFile
if os.path.exists(path):
try:
status = open(path + '/status', 'r').readlines()[0]
except:
status = "Just Started"
if os.path.exists(path):
try:
status = open(path+'/status','r').readlines()[0]
except:
status = "Just Started"
if status == "Done":
rmtree(path)
final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": "Done"})
return HttpResponse(final_json)
if status == "Website already exists":
rmtree(path)
final_json = json.dumps({'restoreStatus': 1, 'error_message': "Website already exists", "status": "Website already exists"})
return HttpResponse(final_json)
if status.find("Not able to create Account and databases") > -1:
rmtree(path)
final_json = json.dumps({'restoreStatus': 1, 'error_message': "Not able to create Account and databases, aborting.",
"status": "Not able to create Account and databases, aborting."})
return HttpResponse(final_json)
final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": status})
return HttpResponse(final_json)
else:
final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": 0})
if status == "Done":
rmtree(path)
final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": "Done"})
return HttpResponse(final_json)
if status == "Website already exists":
rmtree(path)
final_json = json.dumps({'restoreStatus': 1, 'error_message': "Website already exists",
"status": "Website already exists"})
return HttpResponse(final_json)
except BaseException,msg:
final_dic = {'restoreStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except KeyError:
final_dic = {'restoreStatus': 0, 'error_message': "Not Logged In, please refresh the page or login again."}
if status.find("Not able to create Account and databases") > -1:
rmtree(path)
final_json = json.dumps(
{'restoreStatus': 1, 'error_message': "Not able to create Account and databases, aborting.",
"status": "Not able to create Account and databases, aborting."})
return HttpResponse(final_json)
final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": status})
return HttpResponse(final_json)
else:
final_json = json.dumps({'restoreStatus': 1, 'error_message': "None", "status": 0})
return HttpResponse(final_json)
except BaseException, msg:
final_dic = {'restoreStatus': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
@@ -1063,10 +1056,6 @@ def submitRemoteBackups(request):
pathToSSH = "/root/.ssh/authorized_keys"
sshFile = open(pathToSSH, 'a')
sshFile.writelines("#Added by CyberPanel\n")
sshFile.close()
presenseCheck = 0
@@ -1078,6 +1067,7 @@ def submitRemoteBackups(request):
if presenseCheck == 0:
writeToFile = open(pathToSSH, 'a')
writeToFile.writelines("#Added by CyberPanel\n")
writeToFile.writelines("\n")
writeToFile.writelines(sshkey)
writeToFile.writelines("\n")
@@ -1091,8 +1081,6 @@ def submitRemoteBackups(request):
r = requests.post(url, data=finalData, verify=False)
logging.CyberCPLogFileWriter.writeToFile(r.text)
data = json.loads(r.text)
@@ -1127,73 +1115,92 @@ def submitRemoteBackups(request):
final_json = json.dumps({'status': 0, 'type':'exception', 'error_message': str(msg)})
return HttpResponse(final_json)
def remoteTransferStatus(request):
def starRemoteTransfer(request):
try:
if request.method == "POST":
data = json.loads(request.body)
backupDir = data['backupDir']
seek = data['seek']
val = request.session['userID']
try:
if request.method == 'POST':
data = json.loads(request.body)
#admin = Administrator.objects.get(userName=username)
if 1==1:
backupLogPath = "/home/backup/transfer-"+ backupDir +"/" + "backup_log"
print backupLogPath
ipAddress = data['ipAddress']
password = data['password']
if os.path.isfile(backupLogPath):
pass
ownIP = requests.get('https://api.ipify.org').text
finalData = json.dumps({'username': "admin", "password": password,"ipAddress": ownIP})
url = "https://" + ipAddress + ":8090/api/remoteTransfer"
r = requests.post(url, data=finalData, verify=False)
data = json.loads(r.text)
localStoragePath = "/home/backup/transfer-"+str(data['dir'])
if not os.path.exists(localStoragePath):
os.makedirs(localStoragePath)
if data['transferStatus'] == 1:
final_json = json.dumps({'remoteTransferStatus': 1, 'error_message': "None","dir":data['dir']})
return HttpResponse(final_json)
else:
data_ret = {'remoteTransferStatus': 0, 'error_message': "No such log found"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
final_json = json.dumps({'remoteTransferStatus': 0, 'error_message': data['error_message']})
return HttpResponse(final_json)
last_line = ""
with open(backupLogPath, 'r') as logfile:
last_line = logfile.readlines()[-1]
logfile.seek(seek)
data = logfile.read()
where = logfile.tell()
if 'success' in last_line:
data_ret = {'remoteTransferStatus': 1, "complete":1, 'error_message': "None","logs":data,"where":where}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
data_ret = {'remoteTransferStatus': 1, "complete":0, 'error_message': "Backup In Progress","logs":data,"where":where}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
data_ret = {'remoteTransferStatus': 0, "complete":0, 'error_message': "Invalid Credentials"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException, msg:
data = {'remoteTransferStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)
except BaseException,msg:
final_json = json.dumps({'remoteTransferStatus': 0, 'error_message': str(msg)})
return HttpResponse(final_json)
except KeyError:
final_json = json.dumps({'remoteTransferStatus': 0, 'error_message': str(msg)})
return HttpResponse(final_json)
def getRemoteTransferStatus(request):
try:
if request.method == "POST":
data = json.loads(request.body)
ipAddress = data['ipAddress']
backupDir = data['backupDir']
seek = data['seek']
password = data['password']
dir = data['dir']
username = "admin"
finalData = json.dumps({'backupDir': backupDir, "seek":seek})
r = requests.post("https://"+ipAddress+":8090/backup/remoteTransferStatus", data=finalData)
finalData = json.dumps({'dir': dir, "username":username,"password":password})
r = requests.post("https://"+ipAddress+":8090/api/FetchRemoteTransferStatus", data=finalData)
data = json.loads(r.text)
if data['fetchStatus'] == 1:
if data['status'].find("Backups are successfully generated and received on") > -1:
#try:
#finalData = json.dumps({"backupDir": dir})
#r = requests.post("http://localhost:5003/backup/remoteBackupRestore", data=finalData)
#logging.CyberCPLogFileWriter.writeToFile(r.text)
#except BaseException,msg:
# logging.CyberCPLogFileWriter.writeToFile("Something happened here:" +str(msg))
data = {'remoteTransferStatus': 1, 'error_message': "None", "status": data['status'],'backupsSent': 1}
json_data = json.dumps(data)
return HttpResponse(json_data)
else:
data = {'remoteTransferStatus': 1, 'error_message': "None", "status": data['status'],
'backupsSent': 0}
json_data = json.dumps(data)
return HttpResponse(json_data)
else:
data = {'remoteTransferStatus': 0, 'error_message': data['error_message'],
'backupsSent': 0}
json_data = json.dumps(data)
return HttpResponse(json_data)
return HttpResponse(r.text)
except BaseException, msg:
data = {'remoteTransferStatus': 0, 'error_message': str(msg)}
data = {'remoteTransferStatus': 0, 'error_message': str(msg),'backupsSent': 0}
json_data = json.dumps(data)
return HttpResponse(json_data)
def remoteBackupRestore(request):
try:
val = request.session['userID']
@@ -1202,11 +1209,10 @@ def remoteBackupRestore(request):
data = json.loads(request.body)
backupDir = data['backupDir']
backupDir = "/home/backup/transfer-"+str(backupDir)
admin = Administrator.objects.get(pk=val)
backupDirComplete = "/home/backup/transfer-"+str(backupDir)
#adminEmail = admin.email
restoreRequest = rBackup.remoteBackup.remoteRestore(backupDir, admin)
restoreRequest = rBackup.remoteBackup.remoteRestore(backupDirComplete,str(backupDir))
if restoreRequest[0] == 1:
data = {'remoteRestoreStatus': 1, 'error_message': 'None'}
@@ -1227,50 +1233,93 @@ def remoteBackupRestore(request):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
def remoteRestoreStatus(request):
def localRestoreStatus(request):
try:
if request.method == "POST":
data = json.loads(request.body)
backupDir = data['backupDir']
seek = data['seek']
#admin = Administrator.objects.get(userName=username)
if 1==1:
backupLogPath = "/home/backup/transfer-"+ backupDir +"/" + "backup_log"
backupLogPath = "/home/backup/transfer-"+ backupDir +"/" + "backup_log"
if os.path.isfile(backupLogPath):
pass
else:
data_ret = {'remoteRestoreStatus': 0, 'error_message': "No such log found"}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
removalPath = "/home/backup/transfer-"+ str(backupDir)
last_line = ""
with open(backupLogPath, 'r') as logfile:
last_line = logfile.readlines()[-1]
logfile.seek(seek)
data = logfile.read()
where = logfile.tell()
if os.path.isfile(backupLogPath):
if 'success' in last_line:
data_ret = {'remoteRestoreStatus': 1, "complete":1, 'error_message': "None","logs":data,"where":where}
statusFile = open(backupLogPath,"r")
status = statusFile.read()
statusFile.close()
if status.find("completed[success]")>-1:
rmtree(removalPath)
data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 1}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
data_ret = {'remoteRestoreStatus': 1, "complete":0, 'error_message': "Backup In Progress","logs":data,"where":where}
data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
else:
data_ret = {'remoteRestoreStatus': 0, "complete":0, 'error_message': "Invalid Credentials"}
data_ret = {'remoteTransferStatus': 0, 'error_message': "No such log found","status":"None","complete":0}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
except BaseException, msg:
data = {'remoteRestoreStatus': 0, "complete":0, 'error_message': str(msg)}
data = {'remoteTransferStatus': 0,'error_message': str(msg),"status":"None","complete":0}
json_data = json.dumps(data)
return HttpResponse(json_data)
def cancelRemoteBackup(request):
try:
if request.method == "POST":
data = json.loads(request.body)
ipAddress = data['ipAddress']
password = data['password']
dir = data['dir']
username = "admin"
finalData = json.dumps({'dir': dir, "username":username,"password":password})
r = requests.post("https://"+ipAddress+":8090/api/cancelRemoteTransfer", data=finalData)
data = json.loads(r.text)
if data['cancelStatus'] == 1:
pass
else:
logging.CyberCPLogFileWriter.writeToFile("Some error cancelling at remote server, see the log file for remote server.")
path = "/home/backup/transfer-" + str(dir)
if os.path.exists(path):
try:
pathpid = path + "/pid"
pid = open(pathpid, "r").readlines()[0]
try:
os.kill(int(pid), signal.SIGKILL)
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [cancelRemoteBackup]")
rmtree(path)
except:
rmtree(path)
data = {'cancelStatus': 1, 'error_message': "None"}
json_data = json.dumps(data)
return HttpResponse(json_data)
else:
data = {'cancelStatus': 1, 'error_message': "None"}
json_data = json.dumps(data)
return HttpResponse(json_data)
except BaseException, msg:
data = {'cancelStatus': 0, 'error_message': str(msg)}
json_data = json.dumps(data)
return HttpResponse(json_data)

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -127,6 +127,9 @@ def issueSSL(request):
website.ssl = 1
website.save()
sslUtilities.installSSLForDomain(virtualHost)
installUtilities.reStartLiteSpeed()
data_ret = {"SSL": 1,
'error_message': "None"}
json_data = json.dumps(data_ret)

View File

@@ -1,6 +0,0 @@
from django.utils.translation import LANGUAGE_SESSION_KEY
class SetLanguage(object):
def setUserLanguage(self,request,exception):
request.session[LANGUAGE_SESSION_KEY] = "pt-pt"
return "Hello"

View File

@@ -76,18 +76,24 @@ class backupUtilities:
p.start()
pid = open(backupPath + 'pid', "w")
pid.write(str(p.pid))
pid.close()
except BaseException,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateBackup]")
@staticmethod
def startRestore(backupName, backupNames):
def startRestore(backupName, dir):
try:
backupFileName = backupName.strip(".tar.gz")
completPath = "/home/backup/" + backupFileName
originalFile = "/home/backup/" + backupName
if dir == None:
backupFileName = backupName.strip(".tar.gz")
completPath = "/home/backup/" + backupFileName ## without extension
originalFile = "/home/backup/" + backupName ## with extension
else:
backupFileName = backupName.strip(".tar.gz")
completPath = "/home/backup/transfer-"+str(dir)+"/"+backupFileName ## without extension
originalFile = "/home/backup/transfer-"+str(dir)+"/"+backupName ## with extension
pathToCompressedHome = completPath + "/public_html.tar.gz"
@@ -115,7 +121,7 @@ class backupUtilities:
## creating website and its dabases
try:
finalData = json.dumps({'backupFile': backupName})
finalData = json.dumps({'backupFile': backupName,"dir":dir})
r = requests.post("http://localhost:5003/websites/CreateWebsiteFromBackup", data=finalData)
data = json.loads(r.text)
@@ -183,9 +189,9 @@ class backupUtilities:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
@staticmethod
def initiateRestore(backupName):
def initiateRestore(backupName,dir):
try:
p = Process(target=backupUtilities.startRestore, args=(backupName, backupName,))
p = Process(target=backupUtilities.startRestore, args=(backupName, dir,))
p.start()
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]")
@@ -379,17 +385,16 @@ class backupUtilities:
verifyHostKey.sendline("yes")
except pexpect.TIMEOUT, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [verifyHostKey]")
logging.CyberCPLogFileWriter.writeToFile("Timeout [verifyHostKey]")
return 0
except pexpect.EOF, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [verifyHostKey]")
logging.CyberCPLogFileWriter.writeToFile("EOF [verifyHostKey]")
return 0
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [verifyHostKey]")
return 0
@staticmethod
def createBackupDir(IPAddress,IPAddressA):

View File

@@ -15,6 +15,8 @@ from websiteFunctions.models import Websites
from plogical.virtualHostUtilities import virtualHostUtilities
from plogical.installUtilities import installUtilities
from plogical.mysqlUtilities import mysqlUtilities
from multiprocessing import Process
from shutil import move,rmtree
class remoteBackup:
@@ -37,7 +39,7 @@ class remoteBackup:
return [0, msg]
@staticmethod
def startRestore(backupName, backupDir, admin, backupLogPath):
def startRestoreTemp(backupName, backupDir, admin, backupLogPath):
try:
adminEmail = admin.email
@@ -189,13 +191,95 @@ class remoteBackup:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startRestore]")
@staticmethod
def initiateRestore(backupDir, admin, backupLogPath):
def startRestore(backupDir,backupLogPath,dir):
try:
ext = ".tar.gz"
for backup in os.listdir(backupDir):
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("\n")
writeToFile.writelines("\n")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Starting restore for: "+backup+".\n")
writeToFile.close()
if backup.endswith(ext):
remoteBackup.startRestore(backup, backupDir, admin, backupLogPath)
installUtilities.reStartLiteSpeed()
finalData = json.dumps({'backupFile': backup,"dir":dir})
r = requests.post("http://localhost:5003/backup/submitRestore", data=finalData)
data = json.loads(r.text)
logging.CyberCPLogFileWriter.writeToFile(r.text)
if data['restoreStatus'] == 1:
while (1):
finalData = json.dumps({'backupFile': backup, "dir": dir})
r = requests.post("http://localhost:5003/backup/restoreStatus", data=finalData)
data = json.loads(r.text)
logging.CyberCPLogFileWriter.writeToFile(r.text)
if data['status'] == "Done":
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("\n")
writeToFile.writelines("\n")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Restore Completed.\n")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " #########################################\n")
writeToFile.close()
break
elif data['status'] == "Website already exists":
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("\n")
writeToFile.writelines("\n")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Website associated with this backup already exists.\n")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " #########################################\n")
writeToFile.close()
logging.CyberCPLogFileWriter.writeToFile(
"Website associated with this backup already exists")
break
elif data['status'] == 0:
time.sleep(2)
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("\n")
writeToFile.writelines("\n")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Waiting for restore to complete.\n")
writeToFile.close()
pass
elif data['status'] == "Not able to create Account and databases, aborting.":
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("\n")
writeToFile.writelines("\n")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Not able to create Account and databases, aborting.\n")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " #########################################\n")
writeToFile.close()
logging.CyberCPLogFileWriter.writeToFile(
"Not able to create Account and databases, aborting.")
break
else:
time.sleep(3)
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("\n")
writeToFile.writelines("\n")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Waiting for restore to complete.\n")
writeToFile.close()
pass
else:
logging.CyberCPLogFileWriter.writeToFile("Could not start restore process for: "+backup)
writeToFile = open(backupLogPath, "a")
@@ -210,8 +294,12 @@ class remoteBackup:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]")
@staticmethod
def remoteRestore(backupDir, admin):
def remoteRestore(backupDir, dir):
try:
## dir is transfer-###
# backupDir is /home/backup/transfer-###
backupLogPath = backupDir + "/backup_log"
writeToFile = open(backupLogPath, "a+")
@@ -224,6 +312,7 @@ class remoteBackup:
writeToFile.writelines("############################\n")
writeToFile.writelines("\n")
writeToFile.writelines("\n")
writeToFile.close()
if os.path.exists(backupDir):
pass
@@ -231,12 +320,17 @@ class remoteBackup:
return [0, 'No such directory found']
thread.start_new_thread(remoteBackup.initiateRestore, (backupDir, admin, backupLogPath))
p = Process(target=remoteBackup.startRestore, args=(backupDir, backupLogPath,dir,))
p.start()
return [1, 'Started']
pid = open(destination + '/pid', "w")
pid.write(str(p.pid))
pid.close()
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [getKey]")
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [remoteRestore]")
return [0, msg]
@staticmethod
@@ -306,27 +400,98 @@ class remoteBackup:
@staticmethod
def sendBackup(backupPath, IPAddress, writeToFile, dir):
def sendBackup(completedPathToSend, IPAddress, folderNumber,writeToFile):
try:
command = 'rsync -avz -e "ssh -i /root/.ssh/cyberpanel" ' + backupPath + ' root@' + IPAddress + ':' + dir + "/"
## complete path is a path to the file need to send
command = 'rsync -avz -e "ssh -i /root/.ssh/cyberpanel" ' + completedPathToSend + ' root@' + IPAddress + ':/home/backup/transfer-'+folderNumber
subprocess.call(shlex.split(command), stdout=writeToFile)
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
@staticmethod
def backupProcess(ipAddress, dir, backupLogPath):
def backupProcess(ipAddress, dir, backupLogPath,folderNumber):
try:
## dir is without forward slash
writeToFile = open(backupLogPath, "a")
for virtualHost in os.listdir("/home"):
remoteBackup.createBackup(virtualHost, ipAddress, writeToFile, dir)
try:
if virtualHost == "vmail" or virtualHost == "backup":
pass
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Currently generating local backups for: " + virtualHost + "\n")
writeToFile.close()
finalData = json.dumps({'websiteToBeBacked': virtualHost})
r = requests.post("http://localhost:5003/backup/submitBackupCreation", data=finalData)
data = json.loads(r.text)
fileName = data['tempStorage']+".tar.gz"
completePathToBackupFile = fileName
while (1):
r = requests.post("http://localhost:5003/backup/backupStatus", data= finalData)
time.sleep(2)
data = json.loads(r.text)
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Waiting for backup to complete.. " + "\n")
writeToFile.close()
if data['status'] == 0:
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Local Backup Completed for: " +virtualHost + "\n")
## move the generated backup file to specified destination
if os.path.exists(completePathToBackupFile):
move(completePathToBackupFile,dir)
completedPathToSend = dir +"/" + completePathToBackupFile.split("/")[-1]
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Sending " + completedPathToSend +" to "+ipAddress +".\n")
remoteBackup.sendBackup(completedPathToSend,ipAddress,str(folderNumber),writeToFile)
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " #############################################" + "\n")
writeToFile.close()
break
except:
pass
writeToFile = open(backupLogPath, "a")
writeToFile.writelines("[" + time.strftime(
"%I-%M-%S-%a-%b-%Y") + "]" + " Remote Backup Complete" + "\n")
writeToFile.writelines("completed[success]\n")
"%I-%M-%S-%a-%b-%Y") + "]" + " Backups are successfully generated and received on: " + ipAddress + "\n")
writeToFile.close()
## removing local directory where backups were generated
time.sleep(5)
rmtree(dir)
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [backupProcess]")
@@ -350,6 +515,8 @@ class remoteBackup:
writeToFile.writelines("\n")
writeToFile.writelines("\n")
writeToFile.close()
## fix yes/no
backupUtil.backupUtilities.verifyHostKey(ipAddress)
@@ -368,7 +535,12 @@ class remoteBackup:
return [0, "Host is down"]
thread.start_new_thread(remoteBackup.backupProcess, (ipAddress, destination, backupLogPath))
p = Process(target=remoteBackup.backupProcess, args=(ipAddress, destination, backupLogPath,dir,))
p.start()
pid = open(destination + '/pid', "w")
pid.write(str(p.pid))
pid.close()
return [1, None]

View File

@@ -55,6 +55,7 @@ class sslUtilities:
data = open("/usr/local/lsws/conf/httpd_config.conf").readlines()
writeDataToFile = open("/usr/local/lsws/conf/httpd_config.conf", 'w')
sslCheck = 0
for items in data:
if (items.find("listener SSL")>-1):
sslCheck = 1

View File

@@ -1268,6 +1268,14 @@ def CreateWebsiteFromBackup(request):
data = json.loads(request.body)
backupFile = data['backupFile'].strip(".tar.gz")
originalFile = "/home/backup/" + data['backupFile']
if not os.path.exists(originalFile):
dir = data['dir']
path = "/home/backup/transfer-"+str(dir)+"/"+backupFile
else:
path = "/home/backup/" + backupFile
admin = Administrator.objects.get(pk=1)
websiteOwner = admin.userName
@@ -1276,7 +1284,6 @@ def CreateWebsiteFromBackup(request):
## open meta file to read data
path = "/home/backup/" + backupFile
data = open(path + "/meta", 'r').readlines()
domain = data[0].strip('\n')