mirror of https://github.com/fail2ban/fail2ban
ENH: introduced usa of Ticket.__matches throughout
parent
b52d420575
commit
de8786dd1d
|
@ -161,6 +161,7 @@ class Actions(JailThread):
|
|||
aInfo["ip"] = bTicket.getIP()
|
||||
aInfo["failures"] = bTicket.getAttempt()
|
||||
aInfo["time"] = bTicket.getTime()
|
||||
aInfo["matches"] = bTicket.getMatches()
|
||||
if self.__banManager.addBanTicket(bTicket):
|
||||
logSys.warn("[%s] Ban %s" % (self.jail.getName(), aInfo["ip"]))
|
||||
for action in self.__actions:
|
||||
|
@ -201,6 +202,7 @@ class Actions(JailThread):
|
|||
aInfo["ip"] = ticket.getIP()
|
||||
aInfo["failures"] = ticket.getAttempt()
|
||||
aInfo["time"] = ticket.getTime()
|
||||
aInfo["matches"] = ticket.getMatches()
|
||||
logSys.warn("[%s] Unban %s" % (self.jail.getName(), aInfo["ip"]))
|
||||
for action in self.__actions:
|
||||
action.execActionUnban(aInfo)
|
||||
|
|
|
@ -133,7 +133,7 @@ class BanManager:
|
|||
ip = ticket.getIP()
|
||||
#lastTime = ticket.getTime()
|
||||
lastTime = MyTime.time()
|
||||
banTicket = BanTicket(ip, lastTime)
|
||||
banTicket = BanTicket(ip, lastTime, ticket.getMatches())
|
||||
banTicket.setAttempt(ticket.getAttempt())
|
||||
return banTicket
|
||||
createBanTicket = staticmethod(createBanTicket)
|
||||
|
|
|
@ -38,16 +38,24 @@ class FailData:
|
|||
self.__retry = 0
|
||||
self.__lastTime = 0
|
||||
self.__lastReset = 0
|
||||
|
||||
self.__matches = []
|
||||
|
||||
def setRetry(self, value):
|
||||
self.__retry = value
|
||||
|
||||
# keep only the last matches or reset entirely
|
||||
self.__matches = self.__matches[-min(len(self.__matches, value)):] \
|
||||
if value else []
|
||||
|
||||
def getRetry(self):
|
||||
return self.__retry
|
||||
|
||||
def inc(self):
|
||||
|
||||
def getMatches(self):
|
||||
return self.__matches
|
||||
|
||||
def inc(self, matches=None):
|
||||
self.__retry += 1
|
||||
|
||||
self.__matches += matches or []
|
||||
|
||||
def setLastTime(self, value):
|
||||
if value > self.__lastTime:
|
||||
self.__lastTime = value
|
||||
|
|
|
@ -91,16 +91,17 @@ class FailManager:
|
|||
self.__lock.acquire()
|
||||
ip = ticket.getIP()
|
||||
unixTime = ticket.getTime()
|
||||
matches = ticket.getMatches()
|
||||
if self.__failList.has_key(ip):
|
||||
fData = self.__failList[ip]
|
||||
if fData.getLastReset() < unixTime - self.__maxTime:
|
||||
fData.setLastReset(unixTime)
|
||||
fData.setRetry(0)
|
||||
fData.inc()
|
||||
fData.inc(matches)
|
||||
fData.setLastTime(unixTime)
|
||||
else:
|
||||
fData = FailData()
|
||||
fData.inc()
|
||||
fData.inc(matches)
|
||||
fData.setLastReset(unixTime)
|
||||
fData.setLastTime(unixTime)
|
||||
self.__failList[ip] = fData
|
||||
|
@ -139,7 +140,7 @@ class FailManager:
|
|||
if data.getRetry() >= self.__maxRetry:
|
||||
self.__delFailure(ip)
|
||||
# Create a FailTicket from BanData
|
||||
failTicket = FailTicket(ip, data.getLastTime())
|
||||
failTicket = FailTicket(ip, data.getLastTime(), data.getMatches())
|
||||
failTicket.setAttempt(data.getRetry())
|
||||
return failTicket
|
||||
raise FailManagerEmpty
|
||||
|
|
|
@ -281,7 +281,7 @@ class Filter(JailThread):
|
|||
logSys.debug("Ignore %s" % ip)
|
||||
continue
|
||||
logSys.debug("Found %s" % ip)
|
||||
self.failManager.addFailure(FailTicket(ip, unixTime))
|
||||
self.failManager.addFailure(FailTicket(ip, unixTime, [line]))
|
||||
|
||||
##
|
||||
# Returns true if the line should be ignored.
|
||||
|
|
Loading…
Reference in New Issue