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']
|
ipAddress = data['ipAddress']
|
||||||
accountsToTransfer = data['accountsToTransfer']
|
accountsToTransfer = data['accountsToTransfer']
|
||||||
|
port = data['port']
|
||||||
|
logging.writeToFile('port on server B-------------- %s' % str(port))
|
||||||
if hashPassword.check_password(admin.password, password):
|
if hashPassword.check_password(admin.password, password):
|
||||||
dir = str(randint(1000, 9999))
|
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()
|
mailUtilities.checkHome()
|
||||||
path = "/home/cyberpanel/accounts-" + str(randint(1000, 9999))
|
path = "/home/cyberpanel/accounts-" + str(randint(1000, 9999))
|
||||||
@@ -532,6 +538,7 @@ def FetchRemoteTransferStatus(request):
|
|||||||
command = f"cat {dir}"
|
command = f"cat {dir}"
|
||||||
status = ProcessUtilities.outputExecutioner(command)
|
status = ProcessUtilities.outputExecutioner(command)
|
||||||
|
|
||||||
|
|
||||||
if hashPassword.check_password(admin.password, password):
|
if hashPassword.check_password(admin.password, password):
|
||||||
|
|
||||||
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "status": status})
|
final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "status": status})
|
||||||
|
|||||||
@@ -1189,12 +1189,27 @@ class BackupManager:
|
|||||||
|
|
||||||
try:
|
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")
|
ipFile = os.path.join("/etc", "cyberpanel", "machineIP")
|
||||||
f = open(ipFile)
|
f = open(ipFile)
|
||||||
ownIP = f.read()
|
ownIP = f.read()
|
||||||
|
|
||||||
finalData = json.dumps({'username': "admin", "password": password, "ipAddress": ownIP,
|
finalData = json.dumps({'username': "admin", "password": password, "ipAddress": ownIP,
|
||||||
"accountsToTransfer": accountsToTransfer})
|
"accountsToTransfer": accountsToTransfer, 'port': port})
|
||||||
|
|
||||||
url = "https://" + ipAddress + ":8090/api/remoteTransfer"
|
url = "https://" + ipAddress + ":8090/api/remoteTransfer"
|
||||||
|
|
||||||
@@ -1341,12 +1356,20 @@ class BackupManager:
|
|||||||
command = "sudo cat " + backupLogPath
|
command = "sudo cat " + backupLogPath
|
||||||
status = ProcessUtilities.outputExecutioner(command)
|
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:
|
if status.find("completed[success]") > -1:
|
||||||
command = "rm -rf " + removalPath
|
command = "rm -rf " + removalPath
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 1}
|
data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 1}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
elif status.find("[5010]") > -1:
|
elif status.find("[5010]") > -1:
|
||||||
command = "sudo rm -rf " + removalPath
|
command = "sudo rm -rf " + removalPath
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
@@ -1354,6 +1377,7 @@ class BackupManager:
|
|||||||
"status": "None", "complete": 0}
|
"status": "None", "complete": 0}
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
return HttpResponse(json_data)
|
return HttpResponse(json_data)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 0}
|
data_ret = {'remoteTransferStatus': 1, 'error_message': "None", "status": status, "complete": 0}
|
||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
|
|||||||
@@ -181,6 +181,9 @@ class remoteTransferUtilities:
|
|||||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [remoteTransferUtilities.backupProcess:173]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [remoteTransferUtilities.backupProcess:173]")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
portpath = "/home/cyberpanel/remote_port"
|
||||||
|
os.remove(portpath)
|
||||||
|
|
||||||
writeToFile = open(backupLogPath, "a")
|
writeToFile = open(backupLogPath, "a")
|
||||||
writeToFile.writelines("[" + time.strftime(
|
writeToFile.writelines("[" + time.strftime(
|
||||||
"%m.%d.%Y_%H-%M-%S") + "]" + " Backups are successfully generated and received on: " + ipAddress + "\n")
|
"%m.%d.%Y_%H-%M-%S") + "]" + " Backups are successfully generated and received on: " + ipAddress + "\n")
|
||||||
@@ -191,15 +194,31 @@ class remoteTransferUtilities:
|
|||||||
# rmtree(dir)
|
# rmtree(dir)
|
||||||
|
|
||||||
except BaseException as msg:
|
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]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [backupProcess]")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def sendBackup(completedPathToSend, IPAddress, folderNumber,writeToFile):
|
def sendBackup(completedPathToSend, IPAddress, folderNumber,writeToFile):
|
||||||
try:
|
try:
|
||||||
## complete path is a path to the file need to send
|
## 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):
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
logging.CyberCPLogFileWriter.writeToFile(command)
|
logging.CyberCPLogFileWriter.writeToFile(command)
|
||||||
@@ -333,6 +352,10 @@ class remoteTransferUtilities:
|
|||||||
writeToFile.writelines("completed[success]")
|
writeToFile.writelines("completed[success]")
|
||||||
|
|
||||||
except BaseException as msg:
|
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]")
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [remoteTransferUtilities.startRestore]")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user