From 245bc48fe14dee848ec0feab7e716b3462e8a249 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Mon, 5 Feb 2024 11:33:24 +0500 Subject: [PATCH] feature: add port option for backup v2 https://community.cyberpanel.net/t/backup-v2-need-to-change-port-of-sftp-backend/52106 --- IncBackups/static/IncBackups/IncBackups.js | 1 + .../IncBackups/ConfigureV2Backup.html | 8 + IncBackups/views.py | 6 + plogical/Backupsv2.py | 1 + plogical/test.py | 221 ++++++++++-------- 5 files changed, 146 insertions(+), 91 deletions(-) diff --git a/IncBackups/static/IncBackups/IncBackups.js b/IncBackups/static/IncBackups/IncBackups.js index 37ee906ff..77782fe8e 100644 --- a/IncBackups/static/IncBackups/IncBackups.js +++ b/IncBackups/static/IncBackups/IncBackups.js @@ -1877,6 +1877,7 @@ app.controller('ConfigureV2Backup', function ($scope, $http, $timeout) { hostName: $scope.hostName, UserName: $scope.UserName, Repo_Name: $scope.reponame, + sshPort: $scope.sshPort }; var config = { diff --git a/IncBackups/templates/IncBackups/ConfigureV2Backup.html b/IncBackups/templates/IncBackups/ConfigureV2Backup.html index a273d7f28..06db25c44 100644 --- a/IncBackups/templates/IncBackups/ConfigureV2Backup.html +++ b/IncBackups/templates/IncBackups/ConfigureV2Backup.html @@ -134,6 +134,14 @@ +
+ +
+ +
+
+ diff --git a/IncBackups/views.py b/IncBackups/views.py index 6e5455e75..9e747eeb6 100644 --- a/IncBackups/views.py +++ b/IncBackups/views.py @@ -986,6 +986,7 @@ def ConfigureSftpV2Backup(request): hostName = data['hostName'] UserName = data['UserName'] Repo_Name = data['Repo_Name'] + sshPort = data['sshPort'] currentACL = ACLManager.loadedACL(userID) admin = Administrator.objects.get(pk=userID) @@ -1001,6 +1002,11 @@ def ConfigureSftpV2Backup(request): req_data['password'] = sfptpasswd req_data['Repo_Name'] = Repo_Name + try: + req_data['sshPort'] = sshPort + except: + req_data['sshPort'] = '22' + cpbuv2 = CPBackupsV2( {'domain': Selectedwebsite, 'BasePath': '/home/backup', 'BackupDatabase': 1, 'BackupData': 1, diff --git a/plogical/Backupsv2.py b/plogical/Backupsv2.py index b0166be79..0924f1454 100644 --- a/plogical/Backupsv2.py +++ b/plogical/Backupsv2.py @@ -186,6 +186,7 @@ type = sftp host = {config["host"]} user = {config["user"]} pass = {ObsecurePassword} +port = {config["sshPort"]} ''' command = f"echo '{content}' >> {self.ConfigFilePath}" diff --git a/plogical/test.py b/plogical/test.py index 6837d9794..2ebc2a9f4 100644 --- a/plogical/test.py +++ b/plogical/test.py @@ -1,93 +1,132 @@ -# -# import imaplib -# import getpass -# from email import message_from_string -# import socket -# -# import dns.resolver as dnspython -# -# def get_mx_records(domain): -# try: -# # Query MX records for the domain -# mx_records = dns.resolver.resolve(domain, 'MX') -# # Extract and return the MX record data -# return [(mx.exchange.to_text(), mx.preference) for mx in mx_records] -# except dns.resolver.NoAnswer: -# print(f"No MX records found for {domain}") -# return [] -# except dns.resolver.NXDOMAIN: -# print(f"Domain {domain} not found") -# return [] -# except Exception as e: -# print(f"Error: {str(e)}") -# return [] -# -# -# # IMAP server settings -# imap_server = '' -# imap_port = 993 -# -# # User credentials -# email_address = '' -# password = '' -# -# # Connect to the IMAP server -# mail = imaplib.IMAP4_SSL(imap_server, imap_port) -# -# # Log in to the mailbox -# mail.login(email_address, password) -# -# # Select the INBOX -# mail.select("inbox") -# -# # Search for all emails in the INBOX -# result, data = mail.search(None, "ALL") -# email_ids = data[0].split() -# -# # Fetch and print header information for each email -# for email_id in email_ids: -# result, message_data = mail.fetch(email_id, "(BODY[HEADER.FIELDS (FROM TO SUBJECT DATE)])") -# raw_email = message_data[0][1].decode('utf-8') -# msg = message_from_string(raw_email) -# FromDomain = msg['From'].split('@')[1].rstrip('>') -# MailServer = get_mx_records(FromDomain) -# print(f'From Domain {FromDomain}') -# print(f'MX Records of the domains {MailServer}') -# print(f'Mail Server From Domain {MailServer}') -# print(f"Email ID: {email_id}") -# print(f"From: {msg['From']}") -# print(f"To: {msg['To']}") -# print(f"Subject: {msg['Subject']}") -# print(f"Date: {msg['Date']}") -# print("-" * 30) -# print(message_data) -# -# # Logout -# mail.logout() # # -# # # from cryptography import x509 -# # # from cryptography.hazmat.backends import default_backend +# # import imaplib +# # import getpass +# # from email import message_from_string +# # import socket +# # +# # import dns.resolver as dnspython +# # +# # def get_mx_records(domain): +# # try: +# # # Query MX records for the domain +# # mx_records = dns.resolver.resolve(domain, 'MX') +# # # Extract and return the MX record data +# # return [(mx.exchange.to_text(), mx.preference) for mx in mx_records] +# # except dns.resolver.NoAnswer: +# # print(f"No MX records found for {domain}") +# # return [] +# # except dns.resolver.NXDOMAIN: +# # print(f"Domain {domain} not found") +# # return [] +# # except Exception as e: +# # print(f"Error: {str(e)}") +# # return [] +# # +# # +# # # IMAP server settings +# # imap_server = '' +# # imap_port = 993 +# # +# # # User credentials +# # email_address = '' +# # password = '' +# # +# # # Connect to the IMAP server +# # mail = imaplib.IMAP4_SSL(imap_server, imap_port) +# # +# # # Log in to the mailbox +# # mail.login(email_address, password) +# # +# # # Select the INBOX +# # mail.select("inbox") +# # +# # # Search for all emails in the INBOX +# # result, data = mail.search(None, "ALL") +# # email_ids = data[0].split() +# # +# # # Fetch and print header information for each email +# # for email_id in email_ids: +# # result, message_data = mail.fetch(email_id, "(BODY[HEADER.FIELDS (FROM TO SUBJECT DATE)])") +# # raw_email = message_data[0][1].decode('utf-8') +# # msg = message_from_string(raw_email) +# # FromDomain = msg['From'].split('@')[1].rstrip('>') +# # MailServer = get_mx_records(FromDomain) +# # print(f'From Domain {FromDomain}') +# # print(f'MX Records of the domains {MailServer}') +# # print(f'Mail Server From Domain {MailServer}') +# # print(f"Email ID: {email_id}") +# # print(f"From: {msg['From']}") +# # print(f"To: {msg['To']}") +# # print(f"Subject: {msg['Subject']}") +# # print(f"Date: {msg['Date']}") +# # print("-" * 30) +# # print(message_data) +# # +# # # Logout +# # mail.logout() # # # -# # # def get_domains_covered(cert_path): -# # # with open(cert_path, 'rb') as cert_file: -# # # cert_data = cert_file.read() -# # # cert = x509.load_pem_x509_certificate(cert_data, default_backend()) -# # # -# # # # Check for the Subject Alternative Name (SAN) extension -# # # san_extension = cert.extensions.get_extension_for_class(x509.SubjectAlternativeName) -# # # -# # # if san_extension: -# # # # Extract and print the domains from SAN -# # # san_domains = san_extension.value.get_values_for_type(x509.DNSName) -# # # return san_domains -# # # else: -# # # # If SAN is not present, return the Common Name as a fallback -# # # return [cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value] -# # # -# # # # Example usage -# # # cert_path = '/etc/letsencrypt/live/cyberplanner.io/fullchain.pem' -# # # domains_covered = get_domains_covered(cert_path) -# # # -# # # print("Domains covered by the certificate:") -# # # for domain in domains_covered: -# # # print(domain) +# # # # from cryptography import x509 +# # # # from cryptography.hazmat.backends import default_backend +# # # # +# # # # def get_domains_covered(cert_path): +# # # # with open(cert_path, 'rb') as cert_file: +# # # # cert_data = cert_file.read() +# # # # cert = x509.load_pem_x509_certificate(cert_data, default_backend()) +# # # # +# # # # # Check for the Subject Alternative Name (SAN) extension +# # # # san_extension = cert.extensions.get_extension_for_class(x509.SubjectAlternativeName) +# # # # +# # # # if san_extension: +# # # # # Extract and print the domains from SAN +# # # # san_domains = san_extension.value.get_values_for_type(x509.DNSName) +# # # # return san_domains +# # # # else: +# # # # # If SAN is not present, return the Common Name as a fallback +# # # # return [cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value] +# # # # +# # # # # Example usage +# # # # cert_path = '/etc/letsencrypt/live/cyberplanner.io/fullchain.pem' +# # # # domains_covered = get_domains_covered(cert_path) +# # # # +# # # # print("Domains covered by the certificate:") +# # # # for domain in domains_covered: +# # # # print(domain) +# +# import dns.resolver +# +# +# def query_sbl(ip): +# try: +# # Construct the reverse DNS lookup domain +# reversed_ip = '.'.join(reversed(ip.split('.'))) +# sbl_domain = reversed_ip + '.zen.spamhaus.org' +# +# # Query the SBL DNS server +# result = dns.resolver.resolve(sbl_domain, 'A') +# +# # If the query returns a result, it means the IP is listed in SBL +# return True +# except dns.resolver.NXDOMAIN: +# # If the domain does not exist, the IP is not listed in SBL +# return False +# except dns.resolver.Timeout: +# # Handle DNS query timeout +# print("DNS query timed out") +# return None +# except dns.resolver.NoAnswer: +# # Handle no DNS answer +# print("No DNS answer") +# +# return None +# +# +# # Example usage +# ip_to_check = '209.85.166.5' +# result = query_sbl(ip_to_check) +# if result is True: +# print(f"The IP {ip_to_check} is listed in Spamhaus Block List (SBL)") +# elif result is False: +# print(f"The IP {ip_to_check} is not listed in Spamhaus Block List (SBL)") +# else: +# print("Unable to determine SBL status for the given IP") +#