From 768cab7df0d03de66c99604ee4bc9f1ac6fff620 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Tue, 8 Oct 2024 11:33:18 +0500 Subject: [PATCH] fix the problem where cyberpanel keep rdns in cache and does not update --- plogical/mailUtilities.py | 49 ++++++++++++++++++++++++++++---- plogical/virtualHostUtilities.py | 14 ++++----- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index 38eb44965..055c1119c 100755 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -1590,12 +1590,51 @@ LogFile /var/log/clamav/clamav.log @staticmethod def reverse_dns_lookup(ip_address): try: - import socket - host_name, _, _ = socket.gethostbyaddr(ip_address) - return host_name - except socket.herror as e: + import requests + + fetchURLs = requests.get('https://cyberpanel.net/dnsServers.txt') + + if fetchURLs.status_code == 200: + + urls = fetchURLs.json()['urls'] + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'DNS urls {urls}.') + + results = [] + + ### + + for url in urls: + try: + response = requests.get(f'{url}/index.php?ip={ip_address}', timeout=5) + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'url to call {ip_address} is {url}') + + if response.status_code == 200: + data = response.json() + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'response from dns system {str(data)}') + + if data['status'] == 1: + results.append(data['results']['8.8.8.8']) + results.append(data['results']['1.1.1.1']) + results.append(data['results']['9.9.9.9']) + except: + pass + + if os.path.exists(ProcessUtilities.debugPath): + logging.CyberCPLogFileWriter.writeToFile(f'rDNS result of {ip_address} is {str(results)}') + + ### + + return results + except BaseException as e: + logging.CyberCPLogFileWriter.writeToFile(f'Error in fetch rDNS {str(msg)}') # Handle errors, e.g., if reverse DNS lookup fails - return None + return [] @staticmethod def SaveEmailLimitsNew(tempPath): diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index cd8fff680..7a4f0e997 100644 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -94,20 +94,20 @@ class virtualHostUtilities: ### if skipRDNSCheck == 1, it means we need to skip checking for rDNS if skipRDNSCheck: ### so if skipRDNSCheck is 1 means we need to skip checking for rDNS so lets set current as rDNS because no checking is required - rDNS = CurrentHostName + rDNS = [CurrentHostName] else: rDNS = mailUtilities.reverse_dns_lookup(serverIP) time.sleep(3) if os.path.exists(ProcessUtilities.debugPath): - print(f'Postfix Hostname: {PostFixHostname}. Server IP {serverIP}. rDNS: {rDNS}') - logging.CyberCPLogFileWriter.writeToFile(f'Postfix Hostname: {PostFixHostname}. Server IP {serverIP}. rDNS: {rDNS}, rDNS check {skipRDNSCheck}') + print(f'Postfix Hostname: {PostFixHostname}. Server IP {serverIP}. rDNS: {str(rDNS)}') + logging.CyberCPLogFileWriter.writeToFile(f'Postfix Hostname: {PostFixHostname}. Server IP {serverIP}. rDNS: {str(rDNS)}, rDNS check {skipRDNSCheck}') ### Case 1 if hostname already exists check if same hostname in postfix and rdns filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (PostFixHostname) - if (CurrentHostName == PostFixHostname and CurrentHostName == rDNS) and os.path.exists(filePath): + if (CurrentHostName == PostFixHostname and CurrentHostName in rDNS) and os.path.exists(filePath): # expireData = x509.get_notAfter().decode('ascii') # finalDate = datetime.strptime(expireData, '%Y%m%d%H%M%SZ') @@ -222,16 +222,16 @@ class virtualHostUtilities: ### if skipRDNSCheck == 1, it means we need to skip checking for rDNS if skipRDNSCheck: ### so if skipRDNSCheck is 1 means we need to skip checking for rDNS so lets set current domain as rDNS because no checking is required - rDNS = Domain + rDNS = [Domain] if os.path.exists(ProcessUtilities.debugPath): logging.CyberCPLogFileWriter.writeToFile( - f'Second if: Postfix Hostname: {PostFixHostname}. Server IP {serverIP}. rDNS: {rDNS}, rDNS check {skipRDNSCheck}') + f'Second if: Postfix Hostname: {PostFixHostname}. Server IP {serverIP}. rDNS: {str(rDNS)}, rDNS check {skipRDNSCheck}') #first check if hostname is already configured as rDNS, if not return error - if Domain != rDNS: + if Domain not in rDNS: message = 'Domain that you have provided is not configured as rDNS for your server IP. [404]' print(message) logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, message)