- Added an option to report local time (including timezone) or GMT in mail notification. Thanks to Yaroslav Halchenko

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_5@213 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.5
Cyril Jaquier 19 years ago
parent e12db53bf7
commit 4559dbf09f

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

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

@ -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:

Loading…
Cancel
Save