"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "fail2ban/server/failmanager.py" between
fail2ban-0.10.5.tar.gz and fail2ban-0.11.1.tar.gz

About:

failmanager.py  (fail2ban-0.10.5):failmanager.py  (fail2ban-0.11.1)
skipping to change at line 30 skipping to change at line 30
# Author: Cyril Jaquier # Author: Cyril Jaquier
# #
__author__ = "Cyril Jaquier" __author__ = "Cyril Jaquier"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL" __license__ = "GPL"
from threading import Lock from threading import Lock
import logging import logging
from .ticket import FailTicket from .ticket import FailTicket, BanTicket
from ..helpers import getLogger, BgService from ..helpers import getLogger, BgService
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = getLogger(__name__) logSys = getLogger(__name__)
logLevel = logging.DEBUG logLevel = logging.DEBUG
class FailManager: class FailManager:
def __init__(self): def __init__(self):
self.__lock = Lock() self.__lock = Lock()
skipping to change at line 77 skipping to change at line 77
def getMaxRetry(self): def getMaxRetry(self):
return self.__maxRetry return self.__maxRetry
def setMaxTime(self, value): def setMaxTime(self, value):
self.__maxTime = value self.__maxTime = value
def getMaxTime(self): def getMaxTime(self):
return self.__maxTime return self.__maxTime
def addFailure(self, ticket, count=1): def addFailure(self, ticket, count=1, observed=False):
attempts = 1 attempts = 1
with self.__lock: with self.__lock:
fid = ticket.getID() fid = ticket.getID()
try: try:
fData = self.__failList[fid] fData = self.__failList[fid]
# if the same object - the same matches but +1 at tempt: # if the same object - the same matches but +1 at tempt:
if fData is ticket: if fData is ticket:
matches = None matches = None
attempt = 1 attempt = 1
else: else:
skipping to change at line 107 skipping to change at line 107
fData.setRetry(0) fData.setRetry(0)
fData.inc(matches, attempt, count) fData.inc(matches, attempt, count)
# truncate to maxMatches: # truncate to maxMatches:
if self.maxMatches: if self.maxMatches:
matches = fData.getMatches() matches = fData.getMatches()
if len(matches) > self.maxMatches: if len(matches) > self.maxMatches:
fData.setMatches(matches[-self.ma xMatches:]) fData.setMatches(matches[-self.ma xMatches:])
else: else:
fData.setMatches(None) fData.setMatches(None)
except KeyError: except KeyError:
# not found - already banned - prevent to add fai
lure if comes from observer:
if observed or isinstance(ticket, BanTicket):
return ticket.getRetry()
# if already FailTicket - add it direct, otherwis e create (using copy all ticket data): # if already FailTicket - add it direct, otherwis e create (using copy all ticket data):
if isinstance(ticket, FailTicket): if isinstance(ticket, FailTicket):
fData = ticket; fData = ticket;
else: else:
fData = FailTicket(ticket=ticket) fData = FailTicket.wrap(ticket)
if count > ticket.getAttempt(): if count > ticket.getAttempt():
fData.setRetry(count) fData.setRetry(count)
self.__failList[fid] = fData self.__failList[fid] = fData
attempts = fData.getRetry() attempts = fData.getRetry()
self.__failTotal += 1 self.__failTotal += 1
if logSys.getEffectiveLevel() <= logLevel: if logSys.getEffectiveLevel() <= logLevel:
# yoh: Since composing this list might be somewha t time consuming # yoh: Since composing this list might be somewha t time consuming
# in case of having many active failures, it shou ld be ran only # in case of having many active failures, it shou ld be ran only
 End of changes. 4 change blocks. 
3 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)