diff --git a/config/fail2ban.conf.default b/config/fail2ban.conf.default index e2c29567..d841bd7a 100644 --- a/config/fail2ban.conf.default +++ b/config/fail2ban.conf.default @@ -132,6 +132,12 @@ from = fail2ban # to = root +# Option: localtime +# Notes.: report local time (including timezone) or GMT +# Values: [true | false] Default: false +# +localtime = true + # Option: subject # Notes.: subject of the e-mail. # Tags:
active section (eg ssh, apache, etc) diff --git a/fail2ban.py b/fail2ban.py index 5a630be8..d2e88b3e 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -358,6 +358,7 @@ def main(): ["int", "port", "25"], ["str", "from", "root"], ["str", "to", "root"], + ["bool", "localtime", False], ["str", "subject", "[Fail2Ban] Banned "], ["str", "message", "Fail2Ban notification"]) @@ -370,6 +371,7 @@ def main(): mail = Mail(mailConf["host"], mailConf["port"]) mail.setFromAddr(mailConf["from"]) mail.setToAddr(mailConf["to"]) + mail.setLocalTimeFlag(mailConf["localtime"]) logSys.debug("to: " + mailConf["to"] + " from: " + mailConf["from"]) # Options diff --git a/utils/mail.py b/utils/mail.py index 23270335..8a244d4f 100644 --- a/utils/mail.py +++ b/utils/mail.py @@ -24,10 +24,9 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -import logging, smtplib +import logging, smtplib, email.Utils from utils.strings import replaceTag -from time import strftime, gmtime # Gets the instance of the logger. logSys = logging.getLogger("fail2ban") @@ -39,6 +38,7 @@ class Mail: def __init__(self, host, port = 25): self.host = host self.port = port + self.localTimeFlag = False def setFromAddr(self, fromAddr): """ Set from: address @@ -50,6 +50,11 @@ class Mail: """ self.toAddr = toAddr.split() + def setLocalTimeFlag(self, localTimeFlag): + """ Set to: address + """ + self.localTimeFlag = localTimeFlag + def sendmail(self, subject, message, aInfo): """ Send an email using smtplib """ @@ -58,7 +63,7 @@ class Mail: mail = ("From: %s\r\nTo: %s\r\nDate: %s\r\nSubject: %s\r\n\r\n" % (self.fromAddr, ", ".join(self.toAddr), - strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()), + email.Utils.formatdate(localtime = self.localTimeFlag), subj)) + msg try: @@ -71,4 +76,4 @@ class Mail: logSys.error("Unable to send mail to " + self.host + ":" + `self.port` + " from " + self.fromAddr + " to " + `self.toAddr` + ": " + `e` + ": " + `e.args`) - \ No newline at end of file +