|
|
@ -24,10 +24,9 @@ __date__ = "$Date$"
|
|
|
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
|
|
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
|
|
|
__license__ = "GPL"
|
|
|
|
__license__ = "GPL"
|
|
|
|
|
|
|
|
|
|
|
|
import logging, smtplib
|
|
|
|
import logging, smtplib, email.Utils
|
|
|
|
|
|
|
|
|
|
|
|
from utils.strings import replaceTag
|
|
|
|
from utils.strings import replaceTag
|
|
|
|
from time import strftime, gmtime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Gets the instance of the logger.
|
|
|
|
# Gets the instance of the logger.
|
|
|
|
logSys = logging.getLogger("fail2ban")
|
|
|
|
logSys = logging.getLogger("fail2ban")
|
|
|
@ -39,6 +38,7 @@ class Mail:
|
|
|
|
def __init__(self, host, port = 25):
|
|
|
|
def __init__(self, host, port = 25):
|
|
|
|
self.host = host
|
|
|
|
self.host = host
|
|
|
|
self.port = port
|
|
|
|
self.port = port
|
|
|
|
|
|
|
|
self.localTimeFlag = False
|
|
|
|
|
|
|
|
|
|
|
|
def setFromAddr(self, fromAddr):
|
|
|
|
def setFromAddr(self, fromAddr):
|
|
|
|
""" Set from: address
|
|
|
|
""" Set from: address
|
|
|
@ -50,6 +50,11 @@ class Mail:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
self.toAddr = toAddr.split()
|
|
|
|
self.toAddr = toAddr.split()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setLocalTimeFlag(self, localTimeFlag):
|
|
|
|
|
|
|
|
""" Set to: address
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.localTimeFlag = localTimeFlag
|
|
|
|
|
|
|
|
|
|
|
|
def sendmail(self, subject, message, aInfo):
|
|
|
|
def sendmail(self, subject, message, aInfo):
|
|
|
|
""" Send an email using smtplib
|
|
|
|
""" 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" %
|
|
|
|
mail = ("From: %s\r\nTo: %s\r\nDate: %s\r\nSubject: %s\r\n\r\n" %
|
|
|
|
(self.fromAddr, ", ".join(self.toAddr),
|
|
|
|
(self.fromAddr, ", ".join(self.toAddr),
|
|
|
|
strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()),
|
|
|
|
email.Utils.formatdate(localtime = self.localTimeFlag),
|
|
|
|
subj)) + msg
|
|
|
|
subj)) + msg
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -71,4 +76,4 @@ class Mail:
|
|
|
|
logSys.error("Unable to send mail to " + self.host + ":" +
|
|
|
|
logSys.error("Unable to send mail to " + self.host + ":" +
|
|
|
|
`self.port` + " from " + self.fromAddr + " to " +
|
|
|
|
`self.port` + " from " + self.fromAddr + " to " +
|
|
|
|
`self.toAddr` + ": " + `e` + ": " + `e.args`)
|
|
|
|
`self.toAddr` + ": " + `e` + ": " + `e.args`)
|
|
|
|
|
|
|
|
|
|
|
|