From d1151684dcd217f9994c14f3e827303d6cff6464 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Mon, 22 Jan 2024 10:29:19 +0500 Subject: [PATCH] bug fix: fix opendkim port on email settings reset; ref: https://app.clickup.com/t/86enggytc --- plogical/mailUtilities.py | 40 ++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index 0f3886451..a2fbff4ce 100755 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -356,27 +356,39 @@ def setupDKIM(virtualHostName): keyTable = "/etc/opendkim/KeyTable" configToWrite = "default._domainkey." + actualDomain + " " + actualDomain + ":default:/etc/opendkim/keys/" + virtualHostName + "/default.private\n" - writeToFile = open(keyTable, 'a') - writeToFile.write(configToWrite) - writeToFile.close() + data = open(keyTable, 'r').read() + + if data.find("default._domainkey." + actualDomain) == -1: + + writeToFile = open(keyTable, 'a') + writeToFile.write(configToWrite) + writeToFile.close() ## Edit signing table signingTable = "/etc/opendkim/SigningTable" configToWrite = "*@" + actualDomain + " default._domainkey." + actualDomain + "\n" - writeToFile = open(signingTable, 'a') - writeToFile.write(configToWrite) - writeToFile.close() + data = open(signingTable, 'r').read() + + if data.find("default._domainkey." + actualDomain) == -1: + + writeToFile = open(signingTable, 'a') + writeToFile.write(configToWrite) + writeToFile.close() ## Trusted hosts trustedHosts = "/etc/opendkim/TrustedHosts" configToWrite = actualDomain + "\n" - writeToFile = open(trustedHosts, 'a') - writeToFile.write(configToWrite) - writeToFile.close() + data = open(trustedHosts, 'r').read() + + if data.find(actualDomain) == -1: + + writeToFile = open(trustedHosts, 'a') + writeToFile.write(configToWrite) + writeToFile.close() ## Restart Postfix and OpenDKIM @@ -2149,6 +2161,14 @@ def installOpenDKIMNew(self): return 1 + def SetupDKIMFromResetMail(self): + + for website in Websites.objects.all(): + mailUtilities.setupDKIM(website.domain) + + for website in ChildDomains.objects.all(): + mailUtilities.setupDKIM(website.domain) + def ResetEmailConfigurations(self): try: ### Check if remote or local mysql @@ -2221,6 +2241,8 @@ def ResetEmailConfigurations(self): 'configureOpenDKIM failed. [404].') return 0 + self.SetupDKIMFromResetMail() + if self.MailSSL: logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], 'Setting up Mail Server SSL if any..,75')