ssl bug fix for backups

This commit is contained in:
usmannasir
2019-03-13 23:05:22 +05:00
parent e40c7d8912
commit bb6f7f0111
5 changed files with 2133 additions and 785 deletions

1326
backup/backupManager.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -63,7 +63,6 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -106,7 +105,9 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
}
}
function cantLoadInitialDatas(response) {}
function cantLoadInitialDatas(response) {
}
};
@@ -133,7 +134,6 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -146,19 +146,19 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
}
function cantLoadInitialDatas(response) {}
function cantLoadInitialDatas(response) {
}
};
$scope.createBackup = function () {
var websiteToBeBacked = $scope.websiteToBeBacked;
$scope.backupLoading = false;
url = "/backup/submitBackupCreation";
var data = {
@@ -172,7 +172,6 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -184,7 +183,9 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
}
}
function cantLoadInitialDatas(response) {}
function cantLoadInitialDatas(response) {
}
};
@@ -205,7 +206,6 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -223,24 +223,21 @@ app.controller('backupWebsiteControl', function($scope,$http,$timeout) {
}
}
function cantLoadInitialDatas(response) {
}
};
});
///** Backup site ends **///
///** Restore site ***//
@@ -282,7 +279,6 @@ app.controller('restoreWebsiteControl', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -314,6 +310,7 @@ app.controller('restoreWebsiteControl', function($scope,$http,$timeout) {
}
}
function cantLoadInitialDatas(response) {
$scope.couldNotConnect = false;
@@ -340,7 +337,6 @@ app.controller('restoreWebsiteControl', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -361,6 +357,7 @@ app.controller('restoreWebsiteControl', function($scope,$http,$timeout) {
}
}
function cantLoadInitialDatas(response) {
$scope.couldNotConnect = false;
@@ -407,25 +404,21 @@ app.controller('restoreWebsiteControl', function($scope,$http,$timeout) {
}
function cantLoadInitialDatas(response) {
$scope.couldNotConnect = false;
}
};
});
//*** Resotre site ends here ***///
///** Backup Destination ***//
@@ -465,7 +458,6 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -495,6 +487,7 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$scope.destinationLoading = true;
$scope.connectionFailed = true;
@@ -529,7 +522,6 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -560,6 +552,7 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
$scope.IPAddress = ip;
}
}
function cantLoadInitialDatas(response) {
$scope.destinationLoading = true;
$scope.connectionFailed = true;
@@ -594,7 +587,6 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -626,6 +618,7 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
$scope.IPAddress = ip;
}
}
function cantLoadInitialDatas(response) {
$scope.destinationLoading = true;
$scope.connectionFailed = true;
@@ -638,13 +631,11 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
};
function populateCurrentRecords() {
url = "/backup/getCurrentBackupDestinations";
var data = {
};
var data = {};
var config = {
headers: {
@@ -653,7 +644,6 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -666,6 +656,7 @@ app.controller('backupDestinations', function($scope,$http,$timeout) {
}
}
function cantLoadInitialDatas(response) {
$scope.couldNotConnect = false;
}
@@ -722,7 +713,6 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
$scope.scheduleBtn = false;
url = "/backup/submitBackupSchedule";
@@ -738,7 +728,6 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -755,7 +744,6 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
$scope.scheduleBtn = true;
populateCurrentRecords();
}
@@ -771,6 +759,7 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$scope.scheduleBackupLoading = true;
@@ -807,7 +796,6 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -838,6 +826,7 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
$scope.IPAddress = ip;
}
}
function cantLoadInitialDatas(response) {
$scope.destinationLoading = true;
$scope.connectionFailed = true;
@@ -874,7 +863,6 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -906,6 +894,7 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
$scope.errorMessage = response.data.error_message;
}
}
function cantLoadInitialDatas(response) {
$scope.scheduleBackupLoading = true;
@@ -919,13 +908,11 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
};
function populateCurrentRecords() {
url = "/backup/getCurrentBackupSchedules";
var data = {
};
var data = {};
var config = {
headers: {
@@ -934,7 +921,6 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
};
$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);
@@ -947,6 +933,7 @@ app.controller('scheduleBackup', function($scope,$http,$timeout) {
}
}
function cantLoadInitialDatas(response) {
$scope.couldNotConnect = false;
}
@@ -999,8 +986,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
$scope.addRemoveWebsite = function (website, websiteStatus) {
if(websiteStatus === true)
{
if (websiteStatus === true) {
var check = 1;
for (var j = 0; j < websitesToBeBacked.length; j++) {
if (websitesToBeBacked[j] == website) {
@@ -1138,7 +1124,6 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
$scope.backupCancelled = true;
if (websitesToBeBacked.length === 0) {
alert("No websites selected for transfer.");
return;
@@ -1337,7 +1322,6 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
function localRestoreStatus(password) {
url = "/backup/localRestoreStatus";
var data = {
@@ -1525,7 +1509,6 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
$scope.backupCancelled = true;
}
}

View File

@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import redirect
# Create your views here.
import json
from loginSystem.views import loadLoginPage
from plogical.backupManager import BackupManager
from django.shortcuts import redirect
from backup.backupManager import BackupManager
from backup.pluginManager import pluginManager
from loginSystem.views import loadLoginPage
def loadBackupHome(request):

View File

@@ -1,30 +1,33 @@
from loginSystem.models import Administrator
from django.shortcuts import HttpResponse
import json
from plogical.website import WebsiteManager
from plogical.acl import ACLManager
from plogical.virtualHostUtilities import virtualHostUtilities
from websiteFunctions.models import Websites
import subprocess, shlex
import os
import shlex
import subprocess
from random import randint
from django.shortcuts import HttpResponse
import userManagment.views as um
from backup.backupManager import BackupManager
from databases.databaseManager import DatabaseManager
from dns.dnsManager import DNSManager
from mailServer.mailserverManager import MailServerManager
from ftp.ftpManager import FTPManager
from manageSSL.views import issueSSL, obtainHostNameSSL, obtainMailServerSSL
from plogical.backupManager import BackupManager
import userManagment.views as um
from packages.packagesManager import PackagesManager
from plogical.processUtilities import ProcessUtilities
from firewall.firewallManager import FirewallManager
from serverLogs.views import getLogsFromFile
from random import randint
from ftp.ftpManager import FTPManager
from highAvailability.haManager import HAManager
from loginSystem.models import Administrator
from mailServer.mailserverManager import MailServerManager
from manageSSL.views import issueSSL, obtainHostNameSSL, obtainMailServerSSL
from packages.packagesManager import PackagesManager
from plogical.acl import ACLManager
from plogical.httpProc import httpProc
from s3Backups.s3Backups import S3Backups
import os
from serverStatus.views import topProcessesStatus, killProcess
from plogical.mysqlUtilities import mysqlUtilities
from plogical.CyberCPLogFileWriter import CyberCPLogFileWriter as logging
from plogical.processUtilities import ProcessUtilities
from plogical.virtualHostUtilities import virtualHostUtilities
from plogical.website import WebsiteManager
from s3Backups.s3Backups import S3Backups
from serverLogs.views import getLogsFromFile
from serverStatus.views import topProcessesStatus, killProcess
from websiteFunctions.models import Websites
class CloudManager:
def __init__(self, data=None, admin = None):

View File

@@ -230,6 +230,7 @@ class backupUtilities:
## Saving original vhost conf file
completPathToConf = virtualHostUtilities.Server_root + '/conf/vhosts/' + domainName + '/vhost.conf'
if os.path.exists(backupUtilities.licenseKey):
copy(completPathToConf, tempStoragePath + '/vhost.conf')
@@ -243,7 +244,12 @@ class backupUtilities:
sslStoragePath = '/etc/letsencrypt/live/' + domainName
if os.path.exists(sslStoragePath):
make_archive(os.path.join(tempStoragePath, "sslData-" + domainName), 'gztar', sslStoragePath)
try:
copy(os.path.join(sslStoragePath, "cert.pem"), os.path.join(tempStoragePath, domainName + ".cert.pem"))
copy(os.path.join(sslStoragePath, "fullchain.pem"), os.path.join(tempStoragePath, domainName + ".fullchain.pem"))
copy(os.path.join(sslStoragePath, "privkey.pem"), os.path.join(tempStoragePath, domainName + ".privkey.pem"))
except:
pass
## backup email accounts
@@ -281,10 +287,23 @@ class backupUtilities:
completPathToConf = virtualHostUtilities.Server_root + '/conf/vhosts/' + actualChildDomain + '/vhost.conf'
copy(completPathToConf, tempStoragePath + '/' + actualChildDomain + '.vhost.conf')
### Storing SSL for child domainsa
sslStoragePath = '/etc/letsencrypt/live/' + actualChildDomain
if os.path.exists(sslStoragePath):
make_archive(os.path.join(tempStoragePath, "sslData-" + actualChildDomain), 'gztar', sslStoragePath)
try:
copy(os.path.join(sslStoragePath, "cert.pem"),
os.path.join(tempStoragePath, actualChildDomain + ".cert.pem"))
copy(os.path.join(sslStoragePath, "fullchain.pem"),
os.path.join(tempStoragePath, actualChildDomain + ".fullchain.pem"))
copy(os.path.join(sslStoragePath, "privkey.pem"),
os.path.join(tempStoragePath, actualChildDomain + ".privkey.pem"))
make_archive(os.path.join(tempStoragePath, "sslData-" + domainName), 'gztar',
sslStoragePath)
except:
pass
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [startBackup]")
@@ -295,10 +314,8 @@ class backupUtilities:
make_archive(os.path.join(backupPath,backupName), 'gztar', tempStoragePath)
rmtree(tempStoragePath)
logging.CyberCPLogFileWriter.statusWriter(status, "Completed\n")
except BaseException,msg:
try:
os.remove(os.path.join(backupPath,backupName+".tar.gz"))
@@ -464,14 +481,22 @@ class backupUtilities:
if result[0] == 1:
## Let us try to restore SSL.
sslStoragePath = completPath + "/sslData-" + masterDomain + '.tar.gz'
sslStoragePath = completPath + "/" + masterDomain + ".cert.pem"
if os.path.exists(sslStoragePath):
sslHome = '/etc/letsencrypt/live/' + masterDomain
tar = tarfile.open(sslStoragePath)
tar.extractall(sslHome)
tar.close()
try:
if not os.path.exists(sslHome):
os.mkdir(sslHome)
copy(completPath + "/" + masterDomain + ".cert.pem", sslHome + "/cert.pem")
copy(completPath + "/" + masterDomain + ".privkey.pem", sslHome + "/privkey.pem")
copy(completPath + "/" + masterDomain + ".fullchain.pem", sslHome + "/fullchain.pem")
sslUtilities.installSSLForDomain(masterDomain)
except:
pass
else:
logging.CyberCPLogFileWriter.statusWriter(status, "Error Message: " + result[1] + ". Not able to create Account, Databases and DNS Records, aborting. [5009]")
@@ -512,14 +537,23 @@ class backupUtilities:
completPathToConf = virtualHostUtilities.Server_root + '/conf/vhosts/' + domain + '/vhost.conf'
copy(completPath + '/' + domain + '.vhost.conf', completPathToConf)
sslStoragePath = completPath + "/sslData-" + domain + '.tar.gz'
sslStoragePath = completPath + "/" + domain + ".cert.pem"
if os.path.exists(sslStoragePath):
sslHome = '/etc/letsencrypt/live/' + domain
tar = tarfile.open(sslStoragePath)
tar.extractall(sslHome)
tar.close()
try:
if not os.path.exists(sslHome):
os.mkdir(sslHome)
copy(completPath + "/" + domain + ".cert.pem", sslHome + "/cert.pem")
copy(completPath + "/" + domain + ".privkey.pem", sslHome + "/privkey.pem")
copy(completPath + "/" + domain + ".fullchain.pem",
sslHome + "/fullchain.pem")
sslUtilities.installSSLForDomain(domain)
except:
pass
except:
logging.CyberCPLogFileWriter.writeToFile('While restoring backup we had minor issues for rebuilding vhost conf for: ' + domain + '. However this will be auto healed.')