mirror of https://github.com/fail2ban/fail2ban
ENH: added 'matches' to the Ticket(s) and deprecated "custom" constructors for derived *Tickets
parent
ed6daa70bf
commit
b52d420575
|
@ -34,15 +34,24 @@ logSys = logging.getLogger("fail2ban")
|
||||||
|
|
||||||
class Ticket:
|
class Ticket:
|
||||||
|
|
||||||
def __init__(self, ip, time):
|
def __init__(self, ip, time, matches=None):
|
||||||
|
"""Ticket constructor
|
||||||
|
|
||||||
|
@param ip the IP address
|
||||||
|
@param time the ban time
|
||||||
|
@param matches (log) lines caused the ticket
|
||||||
|
"""
|
||||||
|
|
||||||
self.__ip = ip
|
self.__ip = ip
|
||||||
self.__time = time
|
self.__time = time
|
||||||
self.__attempt = 0
|
self.__attempt = 0
|
||||||
|
self.__matches = matches or []
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s: ip=%s time=%s #attempts=%d" % \
|
return "%s: ip=%s time=%s #attempts=%d" % \
|
||||||
(self.__class__, self.__ip, self.__time, self.__attempt)
|
(self.__class__, self.__ip, self.__time, self.__attempt)
|
||||||
|
|
||||||
|
|
||||||
def setIP(self, value):
|
def setIP(self, value):
|
||||||
self.__ip = value
|
self.__ip = value
|
||||||
|
|
||||||
|
@ -61,11 +70,12 @@ class Ticket:
|
||||||
def getAttempt(self):
|
def getAttempt(self):
|
||||||
return self.__attempt
|
return self.__attempt
|
||||||
|
|
||||||
|
def getMatches(self):
|
||||||
|
return self.__matches
|
||||||
|
|
||||||
|
|
||||||
class FailTicket(Ticket):
|
class FailTicket(Ticket):
|
||||||
|
pass
|
||||||
def __init__(self, ip, time):
|
|
||||||
Ticket.__init__(self, ip, time)
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -74,14 +84,4 @@ class FailTicket(Ticket):
|
||||||
# This class extends the Ticket class. It is mainly used by the BanManager.
|
# This class extends the Ticket class. It is mainly used by the BanManager.
|
||||||
|
|
||||||
class BanTicket(Ticket):
|
class BanTicket(Ticket):
|
||||||
|
pass
|
||||||
##
|
|
||||||
# Constructor.
|
|
||||||
#
|
|
||||||
# Call the Ticket (parent) constructor and initialize default
|
|
||||||
# values.
|
|
||||||
# @param ip the IP address
|
|
||||||
# @param time the ban time
|
|
||||||
|
|
||||||
def __init__(self, ip, time):
|
|
||||||
Ticket.__init__(self, ip, time)
|
|
||||||
|
|
Loading…
Reference in New Issue