mirror of https://github.com/fail2ban/fail2ban
- Regular expressions are now compiled
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@261 a942ae1a-1317-0410-a47c-b1dcaea8d6050.x
parent
b5c0f7bae2
commit
79fc53bc04
|
@ -61,10 +61,12 @@ class Filter(JailThread):
|
||||||
self.logPath = ''
|
self.logPath = ''
|
||||||
## The regular expression matching the date.
|
## The regular expression matching the date.
|
||||||
self.timeRegex = ''
|
self.timeRegex = ''
|
||||||
|
self.timeRegexObj = None
|
||||||
## The pattern matching the date.
|
## The pattern matching the date.
|
||||||
self.timePattern = ''
|
self.timePattern = ''
|
||||||
## The regular expression matching the failure.
|
## The regular expression matching the failure.
|
||||||
self.failRegex = ''
|
self.failRegex = ''
|
||||||
|
self.failRegexObj = None
|
||||||
## The amount of time to look back.
|
## The amount of time to look back.
|
||||||
self.findTime = 6000
|
self.findTime = 6000
|
||||||
## The ignore IP list.
|
## The ignore IP list.
|
||||||
|
@ -103,6 +105,7 @@ class Filter(JailThread):
|
||||||
|
|
||||||
def setTimeRegex(self, value):
|
def setTimeRegex(self, value):
|
||||||
self.timeRegex = value
|
self.timeRegex = value
|
||||||
|
self.timeRegexObj = re.compile(value)
|
||||||
logSys.info("Set timeregex = %s" % value)
|
logSys.info("Set timeregex = %s" % value)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -139,6 +142,7 @@ class Filter(JailThread):
|
||||||
|
|
||||||
def setFailRegex(self, value):
|
def setFailRegex(self, value):
|
||||||
self.failRegex = value
|
self.failRegex = value
|
||||||
|
self.failRegexObj = re.compile(value)
|
||||||
logSys.info("Set failregex = %s" % value)
|
logSys.info("Set failregex = %s" % value)
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -369,15 +373,19 @@ class Filter(JailThread):
|
||||||
|
|
||||||
def findFailure(self, line):
|
def findFailure(self, line):
|
||||||
failList = list()
|
failList = list()
|
||||||
match = re.search(self.failRegex, line)
|
match = self.failRegexObj.search(line)
|
||||||
if match:
|
if match:
|
||||||
timeMatch = re.search(self.timeRegex, match.string)
|
timeMatch = self.timeRegexObj.search(match.string)
|
||||||
if timeMatch:
|
if timeMatch:
|
||||||
date = self.getUnixTime(timeMatch.group())
|
date = self.getUnixTime(timeMatch.group())
|
||||||
ipMatch = textToIp(match.string)
|
try:
|
||||||
if ipMatch:
|
ipMatch = textToIp(match.group("host"))
|
||||||
for ip in ipMatch:
|
if ipMatch:
|
||||||
failList.append([ip, date])
|
for ip in ipMatch:
|
||||||
|
failList.append([ip, date])
|
||||||
|
except IndexError:
|
||||||
|
logSys.error("There is no 'host' group in the rule. " +
|
||||||
|
"Please correct your configuration.")
|
||||||
return failList
|
return failList
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
Loading…
Reference in New Issue