Simplify and change some filter line buffer

Include change variable names to `fail2ban` style
pull/108/head
Steven Hiscocks 2013-01-23 18:26:49 +00:00
parent aec709f4c1
commit 5c7e3841e0
1 changed files with 9 additions and 13 deletions

View File

@ -36,7 +36,6 @@ from mytime import MyTime
from failregex import FailRegex, Regex, RegexException from failregex import FailRegex, Regex, RegexException
import logging, re, os, fcntl, time import logging, re, os, fcntl, time
from collections import deque
# Gets the instance of the logger. # Gets the instance of the logger.
logSys = logging.getLogger("fail2ban.filter") logSys = logging.getLogger("fail2ban.filter")
@ -73,9 +72,9 @@ class Filter(JailThread):
## The ignore IP list. ## The ignore IP list.
self.__ignoreIpList = [] self.__ignoreIpList = []
## Size of line buffer ## Size of line buffer
self.__line_buffer_size = 1 self.__lineBufferSize = 1
## Line buffer ## Line buffer
self.__line_buffer = deque() self.__lineBuffer = []
self.dateDetector = DateDetector() self.dateDetector = DateDetector()
self.dateDetector.addDefaultTemplate() self.dateDetector.addDefaultTemplate()
@ -215,10 +214,8 @@ class Filter(JailThread):
# @param value the line buffer size # @param value the line buffer size
def setMaxLines(self, value): def setMaxLines(self, value):
if value < 1: self.__lineBufferSize = max(1, value)
value = 1 logSys.info("Set maxLines = %i" % self.__lineBufferSize)
self.__line_buffer_size = value
logSys.info("Set maxLines = %s" % value)
## ##
# Get the maximum line buffer size. # Get the maximum line buffer size.
@ -226,7 +223,7 @@ class Filter(JailThread):
# @return the line buffer size # @return the line buffer size
def getMaxLines(self): def getMaxLines(self):
return self.__line_buffer_size return self.__lineBufferSize
## ##
# Main loop. # Main loop.
@ -329,10 +326,9 @@ class Filter(JailThread):
else: else:
timeLine = l timeLine = l
logLine = l logLine = l
self.__line_buffer.append(logLine) self.__lineBuffer = ((self.__lineBuffer +
while len(self.__line_buffer) > self.__line_buffer_size: [logLine])[-self.__lineBufferSize:])
self.__line_buffer.popleft() return self.findFailure(timeLine, "".join(self.__lineBuffer))
return self.findFailure(timeLine, "".join(self.__line_buffer))
def processLineAndAdd(self, line): def processLineAndAdd(self, line):
"""Processes the line for failures and populates failManager """Processes the line for failures and populates failManager
@ -392,7 +388,7 @@ class Filter(JailThread):
"in order to get support for this format." "in order to get support for this format."
% (logLine, timeLine)) % (logLine, timeLine))
else: else:
self.__line_buffer.clear() self.__lineBuffer = []
try: try:
host = failRegex.getHost() host = failRegex.getHost()
ipMatch = DNSUtils.textToIp(host, self.__useDns) ipMatch = DNSUtils.textToIp(host, self.__useDns)