added localtime config option to MAIL

debian-releases/etch
Yaroslav Halchenko 2005-10-31 22:04:11 +00:00
parent 1e0cb0326e
commit 909f05351e
4 changed files with 29 additions and 3 deletions

View File

@ -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: <section> active section (eg ssh, apache, etc)

12
debian/changelog vendored
View File

@ -1,3 +1,15 @@
fail2ban (0.5.4-9) UNRELEASED; urgency=low
* NOT RELEASED YET
-- Yaroslav Halchenko <debian@onerussian.com> 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 <debian@onerussian.com> 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

View File

@ -384,6 +384,7 @@ def main():
["int", "port", "25"],
["str", "from", "root"],
["str", "to", "root"],
["bool", "localtime", False],
["str", "subject", "[Fail2Ban] Banned <ip>"],
["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

View File

@ -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`)