mirror of https://github.com/fail2ban/fail2ban
ENH: make fail2ban-regex aware of possible maxlines in the filter config file
parent
a648cc29e8
commit
1fcb5efbd7
|
@ -70,6 +70,7 @@ class Fail2banRegex:
|
||||||
self.__ignoreregex = list()
|
self.__ignoreregex = list()
|
||||||
self.__failregex = list()
|
self.__failregex = list()
|
||||||
self.__verbose = False
|
self.__verbose = False
|
||||||
|
self.__maxlines_set = False # so we allow to override maxlines in cmdline
|
||||||
self.encoding = locale.getpreferredencoding()
|
self.encoding = locale.getpreferredencoding()
|
||||||
# Setup logging
|
# Setup logging
|
||||||
logging.getLogger("fail2ban").handlers = []
|
logging.getLogger("fail2ban").handlers = []
|
||||||
|
@ -126,6 +127,11 @@ class Fail2banRegex:
|
||||||
print "Report bugs to https://github.com/fail2ban/fail2ban/issues"
|
print "Report bugs to https://github.com/fail2ban/fail2ban/issues"
|
||||||
dispUsage = staticmethod(dispUsage)
|
dispUsage = staticmethod(dispUsage)
|
||||||
|
|
||||||
|
def setMaxLines(self, v):
|
||||||
|
if not self.__maxlines_set:
|
||||||
|
self.__filter.setMaxLines(int(v))
|
||||||
|
self.__maxlines_set = True
|
||||||
|
|
||||||
def getCmdLineOptions(self, optList):
|
def getCmdLineOptions(self, optList):
|
||||||
""" Gets the command line options
|
""" Gets the command line options
|
||||||
"""
|
"""
|
||||||
|
@ -142,7 +148,7 @@ class Fail2banRegex:
|
||||||
self.encoding = opt[1]
|
self.encoding = opt[1]
|
||||||
elif opt[0] in ["-l", "--maxlines"]:
|
elif opt[0] in ["-l", "--maxlines"]:
|
||||||
try:
|
try:
|
||||||
self.__filter.setMaxLines(int(opt[1]))
|
self.setMaxLines(opt[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print "Invlaid value for maxlines: %s" % (
|
print "Invlaid value for maxlines: %s" % (
|
||||||
opt[1])
|
opt[1])
|
||||||
|
@ -203,6 +209,20 @@ class Fail2banRegex:
|
||||||
print "No section headers in " + value
|
print "No section headers in " + value
|
||||||
print
|
print
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# Read out and set possible value of maxlines
|
||||||
|
try:
|
||||||
|
maxlines = reader.get("Init", "maxlines")
|
||||||
|
except NoSectionError, NoOptionError:
|
||||||
|
# No [Init].maxlines found.
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.setMaxLines(maxlines)
|
||||||
|
except ValueError:
|
||||||
|
print "ERROR: Invalid value for maxlines (%(maxlines)r) " \
|
||||||
|
"read from %(value)s" % locals()
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
if len(value) > 53:
|
if len(value) > 53:
|
||||||
stripReg = value[0:50] + "..."
|
stripReg = value[0:50] + "..."
|
||||||
|
@ -210,6 +230,8 @@ class Fail2banRegex:
|
||||||
stripReg = value
|
stripReg = value
|
||||||
print "Use regex line : " + stripReg
|
print "Use regex line : " + stripReg
|
||||||
self.__failregex = [RegexStat(value)]
|
self.__failregex = [RegexStat(value)]
|
||||||
|
|
||||||
|
print "Use maxlines : %d" % self.__filter.getMaxLines()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def testIgnoreRegex(self, line):
|
def testIgnoreRegex(self, line):
|
||||||
|
|
Loading…
Reference in New Issue