fix the problem where cyberpanel keep rdns in cache and does not update

This commit is contained in:
usmannasir
2024-10-08 11:33:18 +05:00
parent 7420d188c4
commit 768cab7df0
2 changed files with 51 additions and 12 deletions

View File

@@ -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):

View File

@@ -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)