mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-16 18:26:12 +01:00
some design changes
This commit is contained in:
@@ -656,31 +656,31 @@
|
|||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<li id="sidebar-menu-item-backupV2">
|
{# <li id="sidebar-menu-item-backupV2">#}
|
||||||
<a href="{% url 'loadBackupHome' %}" title="{% trans 'BackupV2' %}">
|
{# <a href="{% url 'loadBackupHome' %}" title="{% trans 'BackupV2' %}">#}
|
||||||
<i class="glyph-icon tooltip-button icon-copy" title=".icon-folder"></i>
|
{# <i class="glyph-icon tooltip-button icon-copy" title=".icon-folder"></i>#}
|
||||||
<span>{% trans "Backup V2" %}</span>
|
{# <span>{% trans "Backup V2" %}</span>#}
|
||||||
</a>
|
{# </a>#}
|
||||||
<div class="sidebar-submenu">
|
{# <div class="sidebar-submenu">#}
|
||||||
|
{##}
|
||||||
<ul>
|
{# <ul>#}
|
||||||
<li><a href="{% url 'CreateV2Backup' %}"
|
{# <li><a href="{% url 'CreateV2Backup' %}"#}
|
||||||
title="{% trans "Create V2 Backup" %}"><span>{% trans "Create/Restore V2 Backup" %}</span></a>
|
{# title="{% trans "Create V2 Backup" %}"><span>{% trans "Create/Restore V2 Backup" %}</span></a>#}
|
||||||
</li>
|
{# </li>#}
|
||||||
<li><a href="{% url 'ConfigureV2Backup' %}"
|
{# <li><a href="{% url 'ConfigureV2Backup' %}"#}
|
||||||
title="{% trans "Configure Backends" %}"><span>{% trans "Configure Backends" %}</span></a>
|
{# title="{% trans "Configure Backends" %}"><span>{% trans "Configure Backends" %}</span></a>#}
|
||||||
</li>
|
{# </li>#}
|
||||||
<li><a href="{% url 'schedulev2Backups' %}"
|
{# <li><a href="{% url 'schedulev2Backups' %}"#}
|
||||||
title="{% trans "Schedule V2 Backup" %}"><span>{% trans "Schedule V2 Backup" %}</span></a>
|
{# title="{% trans "Schedule V2 Backup" %}"><span>{% trans "Schedule V2 Backup" %}</span></a>#}
|
||||||
</li>
|
{# </li>#}
|
||||||
<li><a href="{% url 'DeleteRepoV2' %}"
|
{# <li><a href="{% url 'DeleteRepoV2' %}"#}
|
||||||
title="{% trans "Delete V2 Backup Repo" %}"><span>{% trans "Delete V2 Backup Repo" %}</span></a>
|
{# title="{% trans "Delete V2 Backup Repo" %}"><span>{% trans "Delete V2 Backup Repo" %}</span></a>#}
|
||||||
</li>
|
{# </li>#}
|
||||||
|
{##}
|
||||||
</ul>
|
{# </ul>#}
|
||||||
|
{##}
|
||||||
</div><!-- .sidebar-submenu -->
|
{# </div><!-- .sidebar-submenu -->#}
|
||||||
</li>
|
{# </li>#}
|
||||||
|
|
||||||
<li id="sidebar-menu-item-backup">
|
<li id="sidebar-menu-item-backup">
|
||||||
<a href="{% url 'loadBackupHome' %}" title="{% trans 'Backup' %}">
|
<a href="{% url 'loadBackupHome' %}" title="{% trans 'Backup' %}">
|
||||||
@@ -690,7 +690,7 @@
|
|||||||
<div class="sidebar-submenu">
|
<div class="sidebar-submenu">
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% if admin or createBackup %}
|
{% if admin or createBackup %}
|
||||||
<li><a href="{% url 'OneClickBackups' %}"
|
<li><a href="{% url 'OneClickBackups' %}"
|
||||||
title="{% trans 'One-Click Backups' %}"><span>{% trans "One-Click Backups" %}</span></a>
|
title="{% trans 'One-Click Backups' %}"><span>{% trans "One-Click Backups" %}</span></a>
|
||||||
</li>
|
</li>
|
||||||
@@ -731,33 +731,72 @@
|
|||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li id="sidebar-menu-item-incremental-backup">
|
<li id="sidebar-menu-item-incremental-backup">
|
||||||
<a href="{% url 'loadBackupHome' %}" title="{% trans 'Incremental Backup - Beta' %}">
|
<a href="{% url 'loadBackupHome' %}" title="{% trans 'Incremental Backups' %}">
|
||||||
<i class="glyph-icon tooltip-button icon-save" title="Incremental Backup"></i>
|
<i class="glyph-icon tooltip-button icon-save" title="Incremental Backup"></i>
|
||||||
<span>{% trans "Incremental Backup" %}</span>
|
<span>{% trans "Incremental Backup" %}</span>
|
||||||
</a>
|
</a>
|
||||||
<div class="sidebar-submenu">
|
<div class="sidebar-submenu">
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% if admin or createBackup %}
|
{% if admin or createBackup %}
|
||||||
<li><a href="{% url 'createBackupInc' %}"
|
|
||||||
title="{% trans 'Create Backup' %}"><span>{% trans "Create/Restore Backup" %}</span></a>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
{% if admin or restoreBackup %}
|
|
||||||
<li><a href="{% url 'backupDestinationsInc' %}"
|
<li><a href="{% url 'backupDestinationsInc' %}"
|
||||||
title="{% trans 'Restore Backup' %}"><span>{% trans "Add/Remove Destinations" %}</span></a>
|
title="{% trans 'Restore Backup' %}"><span>{% trans "Backups v2" %}</span></a>
|
||||||
</li>
|
|
||||||
{% endif %}
|
<div class="sidebar-submenu">
|
||||||
{% if admin or restoreBackup %}
|
|
||||||
<li><a href="{% url 'scheduleBackupsInc' %}"
|
<ul>
|
||||||
title="{% trans 'Schedule Backups' %}"><span>{% trans "Schedule Backups" %}</span></a>
|
<li><a href="{% url 'CreateV2Backup' %}"
|
||||||
</li>
|
title="{% trans "Create V2 Backup" %}"><span>{% trans "Create/Restore V2 Backup" %}</span></a>
|
||||||
{% endif %}
|
</li>
|
||||||
{% if admin or remoteBackups %}
|
<li><a href="{% url 'ConfigureV2Backup' %}"
|
||||||
<li><a href="{% url 'restoreRemoteBackupsInc' %}"
|
title="{% trans "Configure Backends" %}"><span>{% trans "Configure Backends" %}</span></a>
|
||||||
title="{% trans 'Restore from Remote Server' %}"><span>{% trans "Restore from Remote" %}</span></a>
|
</li>
|
||||||
|
<li><a href="{% url 'schedulev2Backups' %}"
|
||||||
|
title="{% trans "Schedule V2 Backup" %}"><span>{% trans "Schedule V2 Backup" %}</span></a>
|
||||||
|
</li>
|
||||||
|
<li><a href="{% url 'DeleteRepoV2' %}"
|
||||||
|
title="{% trans "Delete V2 Backup Repo" %}"><span>{% trans "Delete V2 Backup Repo" %}</span></a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div><!-- .sidebar-submenu -->
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li><a href="{% url 'createBackupInc' %}"
|
||||||
|
title="{% trans 'Create Backup' %}"><span>{% trans "v1 (Deprecated)" %}</span></a>
|
||||||
|
|
||||||
|
<div class="sidebar-submenu">
|
||||||
|
<ul>
|
||||||
|
{% if admin or createBackup %}
|
||||||
|
<li><a href="{% url 'createBackupInc' %}"
|
||||||
|
title="{% trans 'Create Backup' %}"><span>{% trans "Create/Restore Backup" %}</span></a>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% if admin or restoreBackup %}
|
||||||
|
<li><a href="{% url 'backupDestinationsInc' %}"
|
||||||
|
title="{% trans 'Restore Backup' %}"><span>{% trans "Add/Remove Destinations" %}</span></a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% if admin or restoreBackup %}
|
||||||
|
<li><a href="{% url 'scheduleBackupsInc' %}"
|
||||||
|
title="{% trans 'Schedule Backups' %}"><span>{% trans "Schedule Backups" %}</span></a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% if admin or remoteBackups %}
|
||||||
|
<li><a href="{% url 'restoreRemoteBackupsInc' %}"
|
||||||
|
title="{% trans 'Restore from Remote Server' %}"><span>{% trans "Restore from Remote" %}</span></a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3069,19 +3069,9 @@ class ApplicationInstaller(multi.Thread):
|
|||||||
ssh_keygen_command = "ssh-keygen -t rsa -b 2048 -f ~/.ssh/cyberpanelbackup -q -N ''"
|
ssh_keygen_command = "ssh-keygen -t rsa -b 2048 -f ~/.ssh/cyberpanelbackup -q -N ''"
|
||||||
stdin, stdout, stderr = ssh.exec_command(ssh_keygen_command)
|
stdin, stdout, stderr = ssh.exec_command(ssh_keygen_command)
|
||||||
|
|
||||||
# # Check for errors in SSH key generation
|
|
||||||
# error = stderr.read().decode()
|
|
||||||
# if error:
|
|
||||||
# if os.path.exists(ProcessUtilities.debugPath):
|
|
||||||
# logging.writeToFile(f"Error generating SSH key: {error}")
|
|
||||||
# else:
|
|
||||||
# if os.path.exists(ProcessUtilities.debugPath):
|
|
||||||
# logging.writeToFile("SSH key 'cyberpanelbackup' generated successfully.")
|
|
||||||
|
|
||||||
if os.path.exists(ProcessUtilities.debugPath):
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
logging.writeToFile(f"SSH key generated..")
|
logging.writeToFile(f"SSH key generated..")
|
||||||
|
|
||||||
|
|
||||||
# 2. Download the SSH keys from the remote server to the local server
|
# 2. Download the SSH keys from the remote server to the local server
|
||||||
|
|
||||||
### put generated key in local server
|
### put generated key in local server
|
||||||
@@ -3123,7 +3113,7 @@ class ApplicationInstaller(multi.Thread):
|
|||||||
from WebTerminal.CPWebSocket import SSHServer
|
from WebTerminal.CPWebSocket import SSHServer
|
||||||
SSHServer.findSSHPort()
|
SSHServer.findSSHPort()
|
||||||
|
|
||||||
command = f"sudo scp -o StrictHostKeyChecking=no -i {remote_private_key} -P {str(SSHServer.DEFAULT_PORT)} {remotepath} root@{ACLManager.fetchIP()}:{loaclpath}"
|
command = f"scp -o StrictHostKeyChecking=no -i {remote_private_key} -P {str(SSHServer.DEFAULT_PORT)} {remotepath} root@{ACLManager.fetchIP()}:{loaclpath}"
|
||||||
|
|
||||||
stdin, stdout, stderr = ssh.exec_command(command)
|
stdin, stdout, stderr = ssh.exec_command(command)
|
||||||
|
|
||||||
@@ -6573,7 +6563,9 @@ class ApplicationInstaller(multi.Thread):
|
|||||||
nbd = NormalBackupDests.objects.get(name=ocb.sftpUser)
|
nbd = NormalBackupDests.objects.get(name=ocb.sftpUser)
|
||||||
ip = json.loads(nbd.config)['ip']
|
ip = json.loads(nbd.config)['ip']
|
||||||
|
|
||||||
# Connect to the remote server using the private key
|
|
||||||
|
#######################
|
||||||
|
|
||||||
ssh = paramiko.SSHClient()
|
ssh = paramiko.SSHClient()
|
||||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
# Read the private key content
|
# Read the private key content
|
||||||
@@ -6585,9 +6577,104 @@ class ApplicationInstaller(multi.Thread):
|
|||||||
key = paramiko.RSAKey.from_private_key(key_file)
|
key = paramiko.RSAKey.from_private_key(key_file)
|
||||||
# Connect to the server using the private key
|
# Connect to the server using the private key
|
||||||
ssh.connect(ip, username=ocb.sftpUser, pkey=key)
|
ssh.connect(ip, username=ocb.sftpUser, pkey=key)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.writeToFile(f"SFTP Connected successfully..")
|
||||||
|
|
||||||
|
# 1. Generate SSH keys on the remote server with the name 'cyberpanelbackup'
|
||||||
|
ssh_keygen_command = "ssh-keygen -t rsa -b 2048 -f ~/.ssh/cyberpanelbackup -q -N ''"
|
||||||
|
stdin, stdout, stderr = ssh.exec_command(ssh_keygen_command)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.writeToFile(f"SSH key generated..")
|
||||||
|
|
||||||
|
# 2. Download the SSH keys from the remote server to the local server
|
||||||
|
|
||||||
|
### put generated key in local server
|
||||||
|
|
||||||
|
remote_private_key = "~/.ssh/cyberpanelbackup"
|
||||||
|
remote_public_key = "~/.ssh/cyberpanelbackup.pub"
|
||||||
|
|
||||||
|
ssh_keygen_command = f"cat {remote_public_key}"
|
||||||
|
stdin, stdout, stderr = ssh.exec_command(ssh_keygen_command)
|
||||||
|
|
||||||
|
# Read the output (stdout) into a variable
|
||||||
|
public_key_content = stdout.read().decode().strip()
|
||||||
|
|
||||||
|
if len(public_key_content) < 10:
|
||||||
|
statusFile = open(tempStatusPath, 'w')
|
||||||
|
statusFile.writelines(f"Failed to get content of public key. [404]")
|
||||||
|
statusFile.close()
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.writeToFile(f'Key from remote server {public_key_content}')
|
||||||
|
|
||||||
|
command = f'echo "{public_key_content}" >> ~/.ssh/authorized_keys'
|
||||||
|
ProcessUtilities.executioner(command, 'root', True)
|
||||||
|
|
||||||
|
command = f"awk '!seen[$0]++' ~/.ssh/authorized_keys > temp && mv temp ~/.ssh/authorized_keys"
|
||||||
|
ProcessUtilities.executioner(command, 'root', True)
|
||||||
|
|
||||||
|
command = f'cat ~/.ssh/authorized_keys'
|
||||||
|
updatedAuth = ProcessUtilities.outputExecutioner(command, 'root', True)
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.writeToFile(f'Updated content of authorized key file {updatedAuth}')
|
||||||
|
|
||||||
|
####
|
||||||
|
|
||||||
sftp = ssh.open_sftp()
|
sftp = ssh.open_sftp()
|
||||||
|
|
||||||
sftp.get(f'cpbackups/{folder}/{backupfile}', f'/home/cyberpanel/{backupfile}', callback=self.UpdateDownloadStatus)
|
logging.statusWriter(self.tempStatusPath, 'Downloading Backups...,15')
|
||||||
|
loaclpath = f'/home/cyberpanel/{backupfile}'
|
||||||
|
remotepath = f'cpbackups/{folder}/{backupfile}'
|
||||||
|
logging.writeToFile("Downloading start")
|
||||||
|
|
||||||
|
from WebTerminal.CPWebSocket import SSHServer
|
||||||
|
SSHServer.findSSHPort()
|
||||||
|
|
||||||
|
command = f"scp -o StrictHostKeyChecking=no -i {remote_private_key} -P {str(SSHServer.DEFAULT_PORT)} {remotepath} root@{ACLManager.fetchIP()}:{loaclpath}"
|
||||||
|
|
||||||
|
stdin, stdout, stderr = ssh.exec_command(command)
|
||||||
|
|
||||||
|
# Read the output (stdout) into a variable
|
||||||
|
successRet = stdout.read().decode().strip()
|
||||||
|
errorRet = stderr.read().decode().strip()
|
||||||
|
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.writeToFile(f"Command used to retrieve backup {command}")
|
||||||
|
if errorRet:
|
||||||
|
logging.writeToFile(f"Error in scp command to retrieve backup {errorRet}")
|
||||||
|
statusFile = open(tempStatusPath, 'w')
|
||||||
|
statusFile.writelines(f"Error in scp command to retrieve backup {errorRet} [404]")
|
||||||
|
statusFile.close()
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
logging.writeToFile(f"Success in scp command to retrieve backup {successRet}")
|
||||||
|
|
||||||
|
if sftp:
|
||||||
|
sftp.close() # Close the SFTP session
|
||||||
|
if ssh:
|
||||||
|
ssh.close() # Close the SSH connection
|
||||||
|
|
||||||
|
#######################
|
||||||
|
|
||||||
|
# # Connect to the remote server using the private key
|
||||||
|
# ssh = paramiko.SSHClient()
|
||||||
|
# ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
# # Read the private key content
|
||||||
|
# private_key_path = '/root/.ssh/cyberpanel'
|
||||||
|
# key_content = ProcessUtilities.outputExecutioner(f'cat {private_key_path}').rstrip('\n')
|
||||||
|
#
|
||||||
|
# # Load the private key from the content
|
||||||
|
# key_file = StringIO(key_content)
|
||||||
|
# key = paramiko.RSAKey.from_private_key(key_file)
|
||||||
|
# # Connect to the server using the private key
|
||||||
|
# ssh.connect(ip, username=ocb.sftpUser, pkey=key)
|
||||||
|
# sftp = ssh.open_sftp()
|
||||||
|
#
|
||||||
|
# sftp.get(f'cpbackups/{folder}/{backupfile}', f'/home/cyberpanel/{backupfile}', callback=self.UpdateDownloadStatus)
|
||||||
|
|
||||||
if not os.path.exists('/home/backup'):
|
if not os.path.exists('/home/backup'):
|
||||||
command = 'mkdir /home/backup'
|
command = 'mkdir /home/backup'
|
||||||
|
|||||||
Reference in New Issue
Block a user