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()
|
return ACLManager.loadError()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
import tldextract
|
||||||
|
|
||||||
|
extractDomain = tldextract.extract(domainName)
|
||||||
|
domainName = extractDomain.domain + '.' + extractDomain.suffix
|
||||||
|
|
||||||
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
|
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
|
||||||
command = "sudo cat " + path
|
command = "sudo cat " + path
|
||||||
output = ProcessUtilities.outputExecutioner(command, 'opendkim')
|
output = ProcessUtilities.outputExecutioner(command, 'opendkim')
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ class DNS:
|
|||||||
subDomain = extractDomain.subdomain
|
subDomain = extractDomain.subdomain
|
||||||
|
|
||||||
if len(subDomain) == 0:
|
if len(subDomain) == 0:
|
||||||
|
|
||||||
if Domains.objects.filter(name=topLevelDomain).count() == 0:
|
if Domains.objects.filter(name=topLevelDomain).count() == 0:
|
||||||
try:
|
try:
|
||||||
pdns = PDNSStatus.objects.get(pk=1)
|
pdns = PDNSStatus.objects.get(pk=1)
|
||||||
@@ -440,12 +439,66 @@ class DNS:
|
|||||||
|
|
||||||
DNS.createDNSRecord(zone, actualSubDomain, "A", ipAddress, 0, 3600)
|
DNS.createDNSRecord(zone, actualSubDomain, "A", ipAddress, 0, 3600)
|
||||||
|
|
||||||
|
## Mail Record
|
||||||
|
|
||||||
|
DNS.createDNSRecord(zone, 'mail.' + actualSubDomain, "A", ipAddress, 0, 3600)
|
||||||
|
|
||||||
# CNAME Records.
|
# CNAME Records.
|
||||||
|
|
||||||
cNameValue = "www." + actualSubDomain
|
cNameValue = "www." + actualSubDomain
|
||||||
|
|
||||||
DNS.createDNSRecord(zone, cNameValue, "CNAME", actualSubDomain, 0, 3600)
|
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:
|
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
|
||||||
command = 'sudo systemctl restart pdns'
|
command = 'sudo systemctl restart pdns'
|
||||||
ProcessUtilities.executioner(command)
|
ProcessUtilities.executioner(command)
|
||||||
@@ -465,6 +518,7 @@ class DNS:
|
|||||||
|
|
||||||
extractDomain = tldextract.extract(domain)
|
extractDomain = tldextract.extract(domain)
|
||||||
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
|
topLevelDomain = extractDomain.domain + '.' + extractDomain.suffix
|
||||||
|
subDomain = extractDomain.subdomain
|
||||||
|
|
||||||
zone = Domains.objects.get(name=topLevelDomain)
|
zone = Domains.objects.get(name=topLevelDomain)
|
||||||
|
|
||||||
@@ -487,9 +541,18 @@ class DNS:
|
|||||||
auth=1)
|
auth=1)
|
||||||
record.save()
|
record.save()
|
||||||
|
|
||||||
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
|
if len(subDomain) > 0:
|
||||||
command = ' systemctl restart pdns'
|
if Records.objects.filter(domainOwner=zone, name="default._domainkey." + domain).count() == 0:
|
||||||
ProcessUtilities.executioner(command)
|
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:
|
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
|
||||||
command = ' systemctl restart pdns'
|
command = ' systemctl restart pdns'
|
||||||
|
|||||||
@@ -214,13 +214,11 @@ class mailUtilities:
|
|||||||
|
|
||||||
import tldextract
|
import tldextract
|
||||||
|
|
||||||
#extractDomain = tldextract.extract(virtualHostName)
|
actualDomain = virtualHostName
|
||||||
#virtualHostName = extractDomain.domain + '.' + extractDomain.suffix
|
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)
|
path = '/etc/opendkim/keys/%s' % (virtualHostName)
|
||||||
command = 'mkdir %s' % (path)
|
command = 'mkdir %s' % (path)
|
||||||
ProcessUtilities.normalExecutioner(command)
|
ProcessUtilities.normalExecutioner(command)
|
||||||
@@ -248,7 +246,7 @@ class mailUtilities:
|
|||||||
|
|
||||||
|
|
||||||
keyTable = "/etc/opendkim/KeyTable"
|
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 = open(keyTable, 'a')
|
||||||
writeToFile.write(configToWrite)
|
writeToFile.write(configToWrite)
|
||||||
@@ -257,7 +255,7 @@ class mailUtilities:
|
|||||||
## Edit signing table
|
## Edit signing table
|
||||||
|
|
||||||
signingTable = "/etc/opendkim/SigningTable"
|
signingTable = "/etc/opendkim/SigningTable"
|
||||||
configToWrite = "*@" + virtualHostName + " default._domainkey." + virtualHostName + "\n"
|
configToWrite = "*@" + actualDomain + " default._domainkey." + actualDomain + "\n"
|
||||||
|
|
||||||
writeToFile = open(signingTable, 'a')
|
writeToFile = open(signingTable, 'a')
|
||||||
writeToFile.write(configToWrite)
|
writeToFile.write(configToWrite)
|
||||||
@@ -266,7 +264,7 @@ class mailUtilities:
|
|||||||
## Trusted hosts
|
## Trusted hosts
|
||||||
|
|
||||||
trustedHosts = "/etc/opendkim/TrustedHosts"
|
trustedHosts = "/etc/opendkim/TrustedHosts"
|
||||||
configToWrite = virtualHostName + "\n"
|
configToWrite = actualDomain + "\n"
|
||||||
|
|
||||||
writeToFile = open(trustedHosts, 'a')
|
writeToFile = open(trustedHosts, 'a')
|
||||||
writeToFile.write(configToWrite)
|
writeToFile.write(configToWrite)
|
||||||
|
|||||||
Reference in New Issue
Block a user