|
|
|
@ -252,6 +252,8 @@ class Fail2banRegex(object):
|
|
|
|
|
|
|
|
|
|
self.share_config=dict() |
|
|
|
|
self._filter = Filter(None) |
|
|
|
|
self._prefREMatched = 0 |
|
|
|
|
self._prefREGroups = list() |
|
|
|
|
self._ignoreregex = list() |
|
|
|
|
self._failregex = list() |
|
|
|
|
self._time_elapsed = None |
|
|
|
@ -453,19 +455,33 @@ class Fail2banRegex(object):
|
|
|
|
|
lines = [] |
|
|
|
|
ret = [] |
|
|
|
|
for match in found: |
|
|
|
|
# Append True/False flag depending if line was matched by |
|
|
|
|
# more than one regex |
|
|
|
|
match.append(len(ret)>1) |
|
|
|
|
regex = self._failregex[match[0]] |
|
|
|
|
regex.inc() |
|
|
|
|
regex.appendIP(match) |
|
|
|
|
if not self._opts.out: |
|
|
|
|
# Append True/False flag depending if line was matched by |
|
|
|
|
# more than one regex |
|
|
|
|
match.append(len(ret)>1) |
|
|
|
|
regex = self._failregex[match[0]] |
|
|
|
|
regex.inc() |
|
|
|
|
regex.appendIP(match) |
|
|
|
|
if not match[3].get('nofail'): |
|
|
|
|
ret.append(match) |
|
|
|
|
else: |
|
|
|
|
is_ignored = True |
|
|
|
|
if self._opts.out: # (formated) output - don't need stats: |
|
|
|
|
return None, ret, None |
|
|
|
|
# prefregex stats: |
|
|
|
|
if self._filter.prefRegex: |
|
|
|
|
pre = self._filter.prefRegex |
|
|
|
|
if pre.hasMatched(): |
|
|
|
|
self._prefREMatched += 1 |
|
|
|
|
if self._verbose: |
|
|
|
|
if len(self._prefREGroups) < self._maxlines: |
|
|
|
|
self._prefREGroups.append(pre.getGroups()) |
|
|
|
|
else: |
|
|
|
|
if len(self._prefREGroups) == self._maxlines: |
|
|
|
|
self._prefREGroups.append('...') |
|
|
|
|
except RegexException as e: # pragma: no cover |
|
|
|
|
output( 'ERROR: %s' % e ) |
|
|
|
|
return False |
|
|
|
|
return None, 0, None |
|
|
|
|
if self._filter.getMaxLines() > 1: |
|
|
|
|
for bufLine in orgLineBuffer[int(fullBuffer):]: |
|
|
|
|
if bufLine not in self._filter._Filter__lineBuffer: |
|
|
|
@ -651,7 +667,18 @@ class Fail2banRegex(object):
|
|
|
|
|
pprint_list(out, " #) [# of hits] regular expression") |
|
|
|
|
return total |
|
|
|
|
|
|
|
|
|
# Print title |
|
|
|
|
# Print prefregex: |
|
|
|
|
if self._filter.prefRegex: |
|
|
|
|
#self._filter.prefRegex.hasMatched() |
|
|
|
|
pre = self._filter.prefRegex |
|
|
|
|
out = [pre.getRegex()] |
|
|
|
|
if self._verbose: |
|
|
|
|
for grp in self._prefREGroups: |
|
|
|
|
out.append(" %s" % (grp,)) |
|
|
|
|
output( "\n%s: %d total" % ("Prefregex", self._prefREMatched) ) |
|
|
|
|
pprint_list(out) |
|
|
|
|
|
|
|
|
|
# Print regex's: |
|
|
|
|
total = print_failregexes("Failregex", self._failregex) |
|
|
|
|
_ = print_failregexes("Ignoreregex", self._ignoreregex) |
|
|
|
|
|
|
|
|
|