diff --git a/config/fail2ban.conf.default b/config/fail2ban.conf.default index 1bf63358..d2a5d8e9 100644 --- a/config/fail2ban.conf.default +++ b/config/fail2ban.conf.default @@ -144,6 +144,12 @@ from = fail2ban@localhost # to = root@localhost +# 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/debian/changelog b/debian/changelog index 150aa86f..7fbddcd0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,15 @@ +fail2ban (0.5.4-9) UNRELEASED; urgency=low + + * NOT RELEASED YET + + -- Yaroslav Halchenko Mon, 31 Oct 2005 16:58:51 -0500 + +fail2ban (0.5.4-8) unstable; urgency=low + + * Added config option MAIL.localtime (closes: #336449) + + -- Yaroslav Halchenko Mon, 31 Oct 2005 16:53:19 -0500 + fail2ban (0.5.4-7) unstable; urgency=low * Adjusted init.d script so it is resistant to delayed shutdowns of diff --git a/fail2ban.py b/fail2ban.py index 6f82781d..aa680749 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -384,6 +384,7 @@ def main(): ["int", "port", "25"], ["str", "from", "root"], ["str", "to", "root"], + ["bool", "localtime", False], ["str", "subject", "[Fail2Ban] Banned "], ["str", "message", "Fail2Ban notification"]) @@ -396,6 +397,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 73b8bd92..1b2990be 100644 --- a/utils/mail.py +++ b/utils/mail.py @@ -27,7 +27,7 @@ __license__ = "GPL" import logging, smtplib from utils.strings import replaceTag -from time import strftime, gmtime +import email.Utils # Gets the instance of the logger. logSys = logging.getLogger("fail2ban") @@ -39,6 +39,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 +51,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 +64,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 +77,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 +