mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-08 06:16:08 +01:00
fix dkim: Shouldn’t be different for domain and subdomain (causes issue while sending mail)
This commit is contained in:
@@ -652,6 +652,12 @@ class MailServerManager:
|
||||
return ACLManager.loadError()
|
||||
|
||||
try:
|
||||
|
||||
import tldextract
|
||||
|
||||
extractDomain = tldextract.extract(domainName)
|
||||
domainName = extractDomain.domain + '.' + extractDomain.suffix
|
||||
|
||||
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
|
||||
command = "sudo cat " + path
|
||||
output = ProcessUtilities.outputExecutioner(command, 'opendkim')
|
||||
|
||||
@@ -121,7 +121,6 @@ class DNS:
|
||||
subDomain = extractDomain.subdomain
|
||||
|
||||
if len(subDomain) == 0:
|
||||
|
||||
if Domains.objects.filter(name=topLevelDomain).count() == 0:
|
||||
try:
|
||||
pdns = PDNSStatus.objects.get(pk=1)
|
||||
@@ -440,12 +439,66 @@ class DNS:
|
||||
|
||||
DNS.createDNSRecord(zone, actualSubDomain, "A", ipAddress, 0, 3600)
|
||||
|
||||
## Mail Record
|
||||
|
||||
DNS.createDNSRecord(zone, 'mail.' + actualSubDomain, "A", ipAddress, 0, 3600)
|
||||
|
||||
# CNAME Records.
|
||||
|
||||
cNameValue = "www." + actualSubDomain
|
||||
|
||||
DNS.createDNSRecord(zone, cNameValue, "CNAME", actualSubDomain, 0, 3600)
|
||||
|
||||
## MX Records
|
||||
|
||||
mxValue = "mail." + actualSubDomain
|
||||
|
||||
record = Records(domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=actualSubDomain,
|
||||
type="MX",
|
||||
content=mxValue,
|
||||
ttl=3600,
|
||||
prio="10",
|
||||
disabled=0,
|
||||
auth=1)
|
||||
record.save()
|
||||
|
||||
## TXT Records
|
||||
|
||||
record = Records(domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name=actualSubDomain,
|
||||
type="TXT",
|
||||
content="v=spf1 a mx ip4:" + ipAddress + " ~all",
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1)
|
||||
record.save()
|
||||
|
||||
record = Records(domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name="_dmarc." + actualSubDomain,
|
||||
type="TXT",
|
||||
content="v=DMARC1; p=none",
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1)
|
||||
record.save()
|
||||
|
||||
record = Records(domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name="_domainkey." + actualSubDomain,
|
||||
type="TXT",
|
||||
content="t=y; o=~;",
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1)
|
||||
record.save()
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
|
||||
command = 'sudo systemctl restart pdns'
|
||||
ProcessUtilities.executioner(command)
|
||||
@@ -465,6 +518,7 @@ class DNS:
|
||||
|
||||
extractDomain = tldextract.extract(domain)
|
||||
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
|
||||
subDomain = extractDomain.subdomain
|
||||
|
||||
zone = Domains.objects.get(name=topLevelDomain)
|
||||
|
||||
@@ -487,9 +541,18 @@ class DNS:
|
||||
auth=1)
|
||||
record.save()
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
|
||||
command = ' systemctl restart pdns'
|
||||
ProcessUtilities.executioner(command)
|
||||
if len(subDomain) > 0:
|
||||
if Records.objects.filter(domainOwner=zone, name="default._domainkey." + domain).count() == 0:
|
||||
record = Records(domainOwner=zone,
|
||||
domain_id=zone.id,
|
||||
name="default._domainkey." + domain,
|
||||
type="TXT",
|
||||
content=output[leftIndex:rightIndex],
|
||||
ttl=3600,
|
||||
prio=0,
|
||||
disabled=0,
|
||||
auth=1)
|
||||
record.save()
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
|
||||
command = ' systemctl restart pdns'
|
||||
|
||||
@@ -214,41 +214,39 @@ class mailUtilities:
|
||||
|
||||
import tldextract
|
||||
|
||||
#extractDomain = tldextract.extract(virtualHostName)
|
||||
#virtualHostName = extractDomain.domain + '.' + extractDomain.suffix
|
||||
actualDomain = virtualHostName
|
||||
extractDomain = tldextract.extract(virtualHostName)
|
||||
virtualHostName = extractDomain.domain + '.' + extractDomain.suffix
|
||||
|
||||
if os.path.exists("/etc/opendkim/keys/" + virtualHostName + "/default.txt"):
|
||||
return 1, "None"
|
||||
if not os.path.exists("/etc/opendkim/keys/" + virtualHostName + "/default.txt"):
|
||||
path = '/etc/opendkim/keys/%s' % (virtualHostName)
|
||||
command = 'mkdir %s' % (path)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
## Generate keys
|
||||
|
||||
path = '/etc/opendkim/keys/%s' % (virtualHostName)
|
||||
command = 'mkdir %s' % (path)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
|
||||
command = "/usr/sbin/opendkim-genkey -D /etc/opendkim/keys/%s -d %s -s default" % (virtualHostName, virtualHostName)
|
||||
else:
|
||||
command = "opendkim-genkey -D /etc/opendkim/keys/%s -d %s -s default" % (
|
||||
virtualHostName, virtualHostName)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
## Fix permissions
|
||||
|
||||
## Generate keys
|
||||
command = "chown -R root:opendkim /etc/opendkim/keys/" + virtualHostName
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
if ProcessUtilities.decideDistro() == ProcessUtilities.centos:
|
||||
command = "/usr/sbin/opendkim-genkey -D /etc/opendkim/keys/%s -d %s -s default" % (virtualHostName, virtualHostName)
|
||||
else:
|
||||
command = "opendkim-genkey -D /etc/opendkim/keys/%s -d %s -s default" % (
|
||||
virtualHostName, virtualHostName)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
## Fix permissions
|
||||
command = "chmod 640 /etc/opendkim/keys/" + virtualHostName + "/default.private"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
command = "chown -R root:opendkim /etc/opendkim/keys/" + virtualHostName
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
command = "chmod 640 /etc/opendkim/keys/" + virtualHostName + "/default.private"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
command = "chmod 644 /etc/opendkim/keys/" + virtualHostName + "/default.txt"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
command = "chmod 644 /etc/opendkim/keys/" + virtualHostName + "/default.txt"
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
## Edit key file
|
||||
|
||||
|
||||
keyTable = "/etc/opendkim/KeyTable"
|
||||
configToWrite = "default._domainkey." + virtualHostName + " " + virtualHostName + ":default:/etc/opendkim/keys/" + virtualHostName + "/default.private\n"
|
||||
configToWrite = "default._domainkey." + actualDomain + " " + actualDomain + ":default:/etc/opendkim/keys/" + virtualHostName + "/default.private\n"
|
||||
|
||||
writeToFile = open(keyTable, 'a')
|
||||
writeToFile.write(configToWrite)
|
||||
@@ -257,7 +255,7 @@ class mailUtilities:
|
||||
## Edit signing table
|
||||
|
||||
signingTable = "/etc/opendkim/SigningTable"
|
||||
configToWrite = "*@" + virtualHostName + " default._domainkey." + virtualHostName + "\n"
|
||||
configToWrite = "*@" + actualDomain + " default._domainkey." + actualDomain + "\n"
|
||||
|
||||
writeToFile = open(signingTable, 'a')
|
||||
writeToFile.write(configToWrite)
|
||||
@@ -266,7 +264,7 @@ class mailUtilities:
|
||||
## Trusted hosts
|
||||
|
||||
trustedHosts = "/etc/opendkim/TrustedHosts"
|
||||
configToWrite = virtualHostName + "\n"
|
||||
configToWrite = actualDomain + "\n"
|
||||
|
||||
writeToFile = open(trustedHosts, 'a')
|
||||
writeToFile.write(configToWrite)
|
||||
|
||||
Reference in New Issue
Block a user