From d4e5c174e2d3e9da5d2de8647badd30217dd9a84 Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Wed, 8 May 2013 21:57:23 +0100 Subject: [PATCH] BF: Multiline regex now works with log line strip of "\r\n" --- fail2ban/server/failregex.py | 8 ++++---- fail2ban/server/filter.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fail2ban/server/failregex.py b/fail2ban/server/failregex.py index 3d05ad55..98b4f87b 100644 --- a/fail2ban/server/failregex.py +++ b/fail2ban/server/failregex.py @@ -117,7 +117,7 @@ class Regex: n += 1 except IndexError: break - return skippedLines.splitlines(True) + return skippedLines.splitlines(False) ## # Returns unmatched lines. @@ -129,9 +129,9 @@ class Regex: if not self.hasMatched(): return [] unmatchedLines = ( - self._matchCache.string[:self._matchLineStart].splitlines(True) + self._matchCache.string[:self._matchLineStart].splitlines(False) + self.getSkippedLines() - + self._matchCache.string[self._matchLineEnd:].splitlines(True)) + + self._matchCache.string[self._matchLineEnd:].splitlines(False)) return unmatchedLines ## @@ -145,7 +145,7 @@ class Regex: if not self.hasMatched(): return [] matchedLines = self._matchCache.string[ - self._matchLineStart:self._matchLineEnd].splitlines(True) + self._matchLineStart:self._matchLineEnd].splitlines(False) return [line for line in matchedLines if line not in self.getSkippedLines()] diff --git a/fail2ban/server/filter.py b/fail2ban/server/filter.py index 838fd890..c4c4bc22 100644 --- a/fail2ban/server/filter.py +++ b/fail2ban/server/filter.py @@ -325,7 +325,7 @@ class Filter(JailThread): logLine = line self.__lineBuffer = ((self.__lineBuffer + [logLine])[-self.__lineBufferSize:]) - return self.findFailure(timeLine, "".join(self.__lineBuffer)) + return self.findFailure(timeLine, "\n".join(self.__lineBuffer) + "\n") def processLineAndAdd(self, line): """Processes the line for failures and populates failManager @@ -373,7 +373,8 @@ class Filter(JailThread): failRegex.search(logLine) if failRegex.hasMatched(): # Checks if we must ignore this match. - if self.ignoreLine("".join(failRegex.getMatchedLines())): + if self.ignoreLine( + "\n".join(failRegex.getMatchedLines()) + "\n"): # The ignoreregex matched. Remove ignored match. self.__lineBuffer = failRegex.getUnmatchedLines() continue