mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
remote backup error reporting fixed
This commit is contained in:
11
api/views.py
11
api/views.py
@@ -422,11 +422,17 @@ def remoteTransfer(request):
|
||||
|
||||
ipAddress = data['ipAddress']
|
||||
accountsToTransfer = data['accountsToTransfer']
|
||||
|
||||
port = data['port']
|
||||
logging.writeToFile('port on server B-------------- %s' % str(port))
|
||||
if hashPassword.check_password(admin.password, password):
|
||||
dir = str(randint(1000, 9999))
|
||||
|
||||
##
|
||||
##save this port into file
|
||||
portpath = "/home/cyberpanel/remote_port"
|
||||
writeToFile = open(portpath, 'w')
|
||||
writeToFile.writelines(port)
|
||||
writeToFile.close()
|
||||
|
||||
|
||||
mailUtilities.checkHome()
|
||||
path = "/home/cyberpanel/accounts-" + str(randint(1000, 9999))
|
||||
@@ -532,6 +538,7 @@ def FetchRemoteTransferStatus(request):
|
||||
command = f"cat {dir}"
|
||||
status = ProcessUtilities.outputExecutioner(command)
|
||||
|
||||
|
||||
if hashPassword.check_password(admin.password, password):
|
||||
|
||||
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "status": status})
|
||||
|
||||
@@ -1189,12 +1189,27 @@ class BackupManager:
|
||||
|
||||
try:
|
||||
|
||||
#this command is for enable permit root login over SSH:
|
||||
command = "sudo sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config && sudo service ssh restart"
|
||||
ProcessUtilities.executioner(command, None, True)
|
||||
|
||||
|
||||
# this command is for enable permit root login over SSH:
|
||||
command = "sudo sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && sudo systemctl restart sshd"
|
||||
ProcessUtilities.executioner(command, None, True)
|
||||
|
||||
# this command is for get port of SSH:
|
||||
command = """grep -oP '^Port \K\d+' /etc/ssh/sshd_config | head -n 1"""
|
||||
output = ProcessUtilities.outputExecutioner(command)
|
||||
port = output.strip('\n')
|
||||
|
||||
|
||||
ipFile = os.path.join("/etc", "cyberpanel", "machineIP")
|
||||
f = open(ipFile)
|
||||
ownIP = f.read()
|
||||
|
||||
finalData = json.dumps({'username': "admin", "password": password, "ipAddress": ownIP,
|
||||
"accountsToTransfer": accountsToTransfer})
|
||||
"accountsToTransfer": accountsToTransfer, 'port': port})
|
||||
|
||||
url = "https://" + ipAddress + ":8090/api/remoteTransfer"
|
||||
|
||||
@@ -1341,12 +1356,20 @@ class BackupManager:
|
||||
command = "sudo cat " + backupLogPath
|
||||
status = ProcessUtilities.outputExecutioner(command)
|
||||
|
||||
|
||||
if status.find("Error") > -1:
|
||||
Error_find = "There was an error during the backup process. Please review the log for more information."
|
||||
status = status + Error_find
|
||||
|
||||
|
||||
|
||||
if status.find("completed[success]") > -1:
|
||||
command = "rm -rf " + removalPath
|
||||
ProcessUtilities.executioner(command)
|
||||
data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 1}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
elif status.find("[5010]") > -1:
|
||||
command = "sudo rm -rf " + removalPath
|
||||
ProcessUtilities.executioner(command)
|
||||
@@ -1354,6 +1377,7 @@ class BackupManager:
|
||||
"status": "None", "complete": 0}
|
||||
json_data = json.dumps(data)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
else:
|
||||
data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 0}
|
||||
json_data = json.dumps(data_ret)
|
||||
|
||||
@@ -181,6 +181,9 @@ class remoteTransferUtilities:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [remoteTransferUtilities.backupProcess:173]")
|
||||
pass
|
||||
|
||||
portpath = "/home/cyberpanel/remote_port"
|
||||
os.remove(portpath)
|
||||
|
||||
writeToFile = open(backupLogPath, "a")
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%m.%d.%Y_%H-%M-%S") + "]" + " Backups are successfully generated and received on: " + ipAddress + "\n")
|
||||
@@ -191,15 +194,31 @@ class remoteTransferUtilities:
|
||||
# rmtree(dir)
|
||||
|
||||
except BaseException as msg:
|
||||
writeToFile = open(backupLogPath, "a")
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%m.%d.%Y_%H-%M-%S") + "]" + " Backups are not generated " "\n")
|
||||
writeToFile.close()
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [backupProcess]")
|
||||
|
||||
@staticmethod
|
||||
def sendBackup(completedPathToSend, IPAddress, folderNumber,writeToFile):
|
||||
try:
|
||||
## complete path is a path to the file need to send
|
||||
portpath = "/home/cyberpanel/remote_port"
|
||||
|
||||
logging.CyberCPLogFileWriter.writeToFile("habbi--------open file:%s"%portpath)
|
||||
|
||||
# Read the contents of the file
|
||||
with open(portpath, 'r') as file:
|
||||
sshPort = file.readline().strip()
|
||||
|
||||
command = "sudo scp -o StrictHostKeyChecking=no -i /root/.ssh/cyberpanel -P "+ sshPort + " " + completedPathToSend + " root@" + IPAddress + ":/home/backup/transfer-" + folderNumber + "/"
|
||||
return_Code = subprocess.call(shlex.split(command), stdout=writeToFile)
|
||||
if return_Code == 0:
|
||||
logging.CyberCPLogFileWriter.writeToFile("This backup file is run")
|
||||
else:
|
||||
logging.CyberCPLogFileWriter.writeToFile("This back file is not run")
|
||||
|
||||
command = "sudo scp -o StrictHostKeyChecking=no -i /root/.ssh/cyberpanel " + completedPathToSend + " root@" + IPAddress + ":/home/backup/transfer-" + folderNumber + "/"
|
||||
subprocess.call(shlex.split(command), stdout=writeToFile)
|
||||
|
||||
if os.path.exists(ProcessUtilities.debugPath):
|
||||
logging.CyberCPLogFileWriter.writeToFile(command)
|
||||
@@ -333,6 +352,10 @@ class remoteTransferUtilities:
|
||||
writeToFile.writelines("completed[success]")
|
||||
|
||||
except BaseException as msg:
|
||||
writeToFile = open(backupLogPath, "a")
|
||||
writeToFile.writelines("[" + time.strftime(
|
||||
"%m.%d.%Y_%H-%M-%S") + "]" + " Backup Restore Failed\n")
|
||||
writeToFile.writelines("Error[Failed]")
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [remoteTransferUtilities.startRestore]")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user