Minor bug fixes to Backups.

This commit is contained in:
usmannasir
2018-02-21 20:10:39 +05:00
parent 4371cc9caf
commit 851fac636c
5 changed files with 79 additions and 55 deletions

View File

@@ -364,18 +364,22 @@ def fetchSSHkey(request):
if hashPassword.check_password(admin.password, password): if hashPassword.check_password(admin.password, password):
keyPath = os.path.join("/root",".ssh") pubKey = os.path.join("/root",".ssh",'cyberpanel.pub')
pubKey = keyPath + "/cyberpanel.pub"
execPath = "sudo cat " + pubKey execPath = "sudo cat " + pubKey
data = subprocess.check_output(shlex.split(execPath)) data = subprocess.check_output(shlex.split(execPath))
data_ret = {'pubKeyStatus': 1, 'error_message': "None", "pubKey":data} data_ret = {
'pubKeyStatus': 1,
'error_message': "None",
'pubKey':data
}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
else: else:
data_ret = {'pubKeyStatus': 0, 'error_message': "Invalid Credentials"} data_ret = {
'pubKeyStatus': 0,
'error_message': "Could not authorize access to API."
}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
@@ -546,7 +550,6 @@ def cancelRemoteTransfer(request):
json_data = json.dumps(data) json_data = json.dumps(data)
return HttpResponse(json_data) return HttpResponse(json_data)
def cyberPanelVersion(request): def cyberPanelVersion(request):
try: try:
if request.method == 'POST': if request.method == 'POST':
@@ -563,22 +566,28 @@ def cyberPanelVersion(request):
Version = version.objects.get(pk=1) Version = version.objects.get(pk=1)
data_ret = {"getVersion": 1, data_ret = {
'error_message': "Could not authorize access to API", "getVersion": 1,
'error_message': "none",
'currentVersion':Version.currentVersion, 'currentVersion':Version.currentVersion,
'build':Version.build} 'build':Version.build
}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
else: else:
data_ret = {"getVersion": 0, data_ret = {
'error_message': "Could not authorize access to API"} "getVersion": 0,
'error_message': "Could not authorize access to API."
}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)
return HttpResponse(json_data) return HttpResponse(json_data)
except BaseException, msg: except BaseException, msg:
data_ret = {"getVersion": 0, data_ret = {
'error_message': "Could not authorize access to API"} "getVersion": 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)

View File

@@ -1074,7 +1074,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
function ListInitialDatas(response) { function ListInitialDatas(response) {
if (response.data.status == 1) { if (response.data.status === 1) {
$scope.records = JSON.parse(response.data.data); $scope.records = JSON.parse(response.data.data);
var parsed = JSON.parse(response.data.data); var parsed = JSON.parse(response.data.data);
@@ -1268,7 +1268,10 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
else{ else{
$scope.requestData = response.data.status; $scope.requestData = response.data.status;
$timeout.cancel(); $timeout.cancel();
$scope.backupLoading = true;
// Start the restore of remote backups that are transferred to local server
remoteBackupRestore(); remoteBackupRestore();
} }
} }
@@ -1318,7 +1321,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
function ListInitialDatas(response) { function ListInitialDatas(response) {
if (response.data.remoteRestoreStatus == 1) { if (response.data.remoteRestoreStatus === 1) {
localRestoreStatus(); localRestoreStatus();
} }
} }
@@ -1330,6 +1333,7 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
$scope.errorMessage = true; $scope.errorMessage = true;
$scope.accountsFetched = true; $scope.accountsFetched = true;
$scope.notificationsBox = false; $scope.notificationsBox = false;
$scope.backupLoading = true;
} }
/////////////// ///////////////
@@ -1357,9 +1361,9 @@ app.controller('remoteBackupControl', function($scope, $http, $timeout) {
function ListInitialDatas(response) { function ListInitialDatas(response) {
if (response.data.remoteTransferStatus == 1) { if (response.data.remoteTransferStatus === 1) {
if(response.data.complete == 0){ if(response.data.complete === 0){
$scope.backupStatus = false; $scope.backupStatus = false;
$scope.restoreData = response.data.status; $scope.restoreData = response.data.status;
$timeout(localRestoreStatus, 2000); $timeout(localRestoreStatus, 2000);

View File

@@ -1189,7 +1189,6 @@ def scheduleDelete(request):
final_json = json.dumps({'delStatus': 0, 'error_message': str(msg)}) final_json = json.dumps({'delStatus': 0, 'error_message': str(msg)})
return HttpResponse(final_json) return HttpResponse(final_json)
def remoteBackups(request): def remoteBackups(request):
try: try:
userID = request.session['userID'] userID = request.session['userID']
@@ -1211,10 +1210,10 @@ def submitRemoteBackups(request):
ipAddress = data['ipAddress'] ipAddress = data['ipAddress']
password = data['password'] password = data['password']
## ask for remote version ## Ask for Remote version of CyberPanel
try: try:
finalData = json.dumps({'username': "admin","password": password}) finalData = json.dumps({'username': "admin", "password": password})
url = "https://" + ipAddress + ":8090/api/cyberPanelVersion" url = "https://" + ipAddress + ":8090/api/cyberPanelVersion"
@@ -1222,7 +1221,6 @@ def submitRemoteBackups(request):
data = json.loads(r.text) data = json.loads(r.text)
if data['getVersion'] == 1: if data['getVersion'] == 1:
Version = version.objects.get(pk=1) Version = version.objects.get(pk=1)
@@ -1230,28 +1228,31 @@ def submitRemoteBackups(request):
if data['currentVersion'] == Version.currentVersion and data['build'] == Version.build: if data['currentVersion'] == Version.currentVersion and data['build'] == Version.build:
pass pass
else: else:
data_ret = {'status': 0, 'error_message': "Your version does not match with version of remote server.", data_ret = {'status': 0,
"dir": "Null" } 'error_message': "Your version does not match with version of remote server.",
"dir": "Null"}
data_ret = json.dumps(data_ret) data_ret = json.dumps(data_ret)
return HttpResponse(data_ret) return HttpResponse(data_ret)
else: else:
data_ret = {'status': 0, 'error_message': "Not able to fetch version of remote server. Error Message: "+data['error_message'], "dir": "Null"} data_ret = {'status': 0,
'error_message': "Not able to fetch version of remote server. Error Message: " + data[
'error_message'], "dir": "Null"}
data_ret = json.dumps(data_ret) data_ret = json.dumps(data_ret)
return HttpResponse(data_ret) return HttpResponse(data_ret)
except BaseException,msg:
except BaseException, msg:
data_ret = {'status': 0, data_ret = {'status': 0,
'error_message': "Not able to fetch version of remote server. Error Message: " + str(msg), "dir": "Null"} 'error_message': "Not able to fetch version of remote server. Error Message: " + str(msg),
"dir": "Null"}
data_ret = json.dumps(data_ret) data_ret = json.dumps(data_ret)
return HttpResponse(data_ret) return HttpResponse(data_ret)
## setup ssh key ## Fetch public key of remote server!
finalData = json.dumps({'username': "admin", "password": password}) finalData = json.dumps({'username': "admin", "password": password})
url = "https://" + ipAddress + ":8090/api/fetchSSHkey" url = "https://" + ipAddress + ":8090/api/fetchSSHkey"
r = requests.post(url, data=finalData, verify=False) r = requests.post(url, data=finalData, verify=False)
data = json.loads(r.text) data = json.loads(r.text)
@@ -1259,25 +1260,23 @@ def submitRemoteBackups(request):
if data['pubKeyStatus'] == 1: if data['pubKeyStatus'] == 1:
pubKey = data["pubKey"].strip("\n") pubKey = data["pubKey"].strip("\n")
else: else:
final_json = json.dumps({'status': 0, 'error_message': "I am sorry, I could not fetch key from remote server. Error Message: "+data['error_message']}) final_json = json.dumps({'status': 0,
'error_message': "I am sorry, I could not fetch key from remote server. Error Message: " +data['error_message']
})
return HttpResponse(final_json) return HttpResponse(final_json)
## write key ## write key
## ## Writing key to a temporary location, to be read later by backup process.
pathToKey = "/home/cyberpanel/" + str(randint(1000, 9999)) pathToKey = "/home/cyberpanel/" + str(randint(1000, 9999))
vhost = open(pathToKey, "w") vhost = open(pathToKey, "w")
vhost.write(pubKey) vhost.write(pubKey)
vhost.close() vhost.close()
## ##
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py" execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/remoteTransferUtilities.py"
execPath = execPath + " writeAuthKey --pathToKey " + pathToKey execPath = execPath + " writeAuthKey --pathToKey " + pathToKey
output = subprocess.check_output(shlex.split(execPath)) output = subprocess.check_output(shlex.split(execPath))
@@ -1285,13 +1284,13 @@ def submitRemoteBackups(request):
if output.find("1,None") > -1: if output.find("1,None") > -1:
pass pass
else: else:
final_json = json.dumps({'status': 0, 'type': 'exception', 'error_message': output}) final_json = json.dumps({'status': 0, 'error_message': output})
return HttpResponse(final_json) return HttpResponse(final_json)
## ##
try: try:
finalData = json.dumps({'username': "admin","password": password}) finalData = json.dumps({'username': "admin", "password": password})
url = "https://" + ipAddress + ":8090/api/fetchAccountsFromRemoteServer" url = "https://" + ipAddress + ":8090/api/fetchAccountsFromRemoteServer"
@@ -1299,28 +1298,30 @@ def submitRemoteBackups(request):
data = json.loads(r.text) data = json.loads(r.text)
if data['fetchStatus'] == 1: if data['fetchStatus'] == 1:
json_data = data['data'] json_data = data['data']
data_ret = {'status': 1, 'error_message': "None", data_ret = {'status': 1, 'error_message': "None",
"dir": "Null",'data':json_data} "dir": "Null", 'data': json_data}
data_ret = json.dumps(data_ret) data_ret = json.dumps(data_ret)
return HttpResponse(data_ret) return HttpResponse(data_ret)
else: else:
data_ret = {'status': 0, 'error_message': "Not able to fetch accounts from remote server. Error Message: "+data['error_message'], "dir": "Null"} data_ret = {'status': 0,
'error_message': "Not able to fetch accounts from remote server. Error Message: " +
data['error_message'], "dir": "Null"}
data_ret = json.dumps(data_ret) data_ret = json.dumps(data_ret)
return HttpResponse(data_ret) return HttpResponse(data_ret)
except BaseException,msg: except BaseException, msg:
data_ret = {'status': 0, data_ret = {'status': 0,
'error_message': "Not able to fetch accounts from remote server. Error Message: " + str(msg), "dir": "Null"} 'error_message': "Not able to fetch accounts from remote server. Error Message: " + str(
msg), "dir": "Null"}
data_ret = json.dumps(data_ret) data_ret = json.dumps(data_ret)
return HttpResponse(data_ret) return HttpResponse(data_ret)
else: else:
return HttpResponse("This URL only accepts POST requests") return HttpResponse("This URL only accepts POST requests")
except BaseException, msg: except BaseException, msg:
final_json = json.dumps({'status': 0, 'type':'exception', 'error_message': str(msg)}) final_json = json.dumps({'status': 0, 'type': 'exception', 'error_message': str(msg)})
return HttpResponse(final_json) return HttpResponse(final_json)
def starRemoteTransfer(request): def starRemoteTransfer(request):
try: try:

View File

@@ -64,7 +64,10 @@ class backupUtilities:
status.write("Backing up email accounts!\n") status.write("Backing up email accounts!\n")
status.close() status.close()
make_archive(os.path.join(tempStoragePath,domainName),'gztar',os.path.join("/home","vmail",domainName)) try:
make_archive(os.path.join(tempStoragePath,domainName),'gztar',os.path.join("/home","vmail",domainName))
except:
pass
## Backing up databases ## Backing up databases
databases = backupMetaData.findall('Databases/database') databases = backupMetaData.findall('Databases/database')
@@ -303,12 +306,16 @@ class backupUtilities:
status.write("Extracting email accounts!") status.write("Extracting email accounts!")
status.close() status.close()
pathToCompressedEmails = os.path.join(completPath, masterDomain + ".tar.gz") try:
emailHome = os.path.join("/home","vmail",masterDomain)
tar = tarfile.open(pathToCompressedEmails) pathToCompressedEmails = os.path.join(completPath, masterDomain + ".tar.gz")
tar.extractall(emailHome) emailHome = os.path.join("/home","vmail",masterDomain)
tar.close()
tar = tarfile.open(pathToCompressedEmails)
tar.extractall(emailHome)
tar.close()
except:
pass
## emails extracted ## emails extracted

View File

@@ -6,7 +6,10 @@ try:
mydoc = ElementTree.parse('domain.xml') mydoc = ElementTree.parse('domain.xml')
print mydoc.find('masterDomain').text len = 0
if len == 0:
raise BaseException("Error occurred!")
domains = mydoc.findall('ChildDomains/domain') domains = mydoc.findall('ChildDomains/domain')
@@ -32,4 +35,4 @@ try:
print os.path.join("/home", "cyberpanel", str(randint(1000, 9999)) + ".xml/", "test") print os.path.join("/home", "cyberpanel", str(randint(1000, 9999)) + ".xml/", "test")
except BaseException,msg: except BaseException,msg:
print "hello" print str(msg)