|
|
@ -40,7 +40,7 @@ from optparse import OptionParser, Option
|
|
|
|
|
|
|
|
|
|
|
|
from ConfigParser import NoOptionError, NoSectionError, MissingSectionHeaderError
|
|
|
|
from ConfigParser import NoOptionError, NoSectionError, MissingSectionHeaderError
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try: # pragma: no cover
|
|
|
|
from systemd import journal
|
|
|
|
from systemd import journal
|
|
|
|
from ..server.filtersystemd import FilterSystemd
|
|
|
|
from ..server.filtersystemd import FilterSystemd
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
@ -80,7 +80,7 @@ def pprint_list(l, header=None):
|
|
|
|
s = ''
|
|
|
|
s = ''
|
|
|
|
output( s + "| " + "\n| ".join(l) + '\n`-' )
|
|
|
|
output( s + "| " + "\n| ".join(l) + '\n`-' )
|
|
|
|
|
|
|
|
|
|
|
|
def journal_lines_gen(myjournal):
|
|
|
|
def journal_lines_gen(myjournal): # pragma: no cover
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
entry = myjournal.get_next()
|
|
|
|
entry = myjournal.get_next()
|
|
|
@ -342,7 +342,7 @@ class Fail2banRegex(object):
|
|
|
|
found = True
|
|
|
|
found = True
|
|
|
|
regex = self._ignoreregex[ret].inc()
|
|
|
|
regex = self._ignoreregex[ret].inc()
|
|
|
|
except RegexException as e:
|
|
|
|
except RegexException as e:
|
|
|
|
output( e )
|
|
|
|
output( 'ERROR: %s' % e )
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
return found
|
|
|
|
return found
|
|
|
|
|
|
|
|
|
|
|
@ -359,10 +359,7 @@ class Fail2banRegex(object):
|
|
|
|
regex.inc()
|
|
|
|
regex.inc()
|
|
|
|
regex.appendIP(match)
|
|
|
|
regex.appendIP(match)
|
|
|
|
except RegexException as e:
|
|
|
|
except RegexException as e:
|
|
|
|
output( e )
|
|
|
|
output( 'ERROR: %s' % e )
|
|
|
|
return False
|
|
|
|
|
|
|
|
except IndexError:
|
|
|
|
|
|
|
|
output( "Sorry, but no <HOST> found in regex" )
|
|
|
|
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
for bufLine in orgLineBuffer[int(fullBuffer):]:
|
|
|
|
for bufLine in orgLineBuffer[int(fullBuffer):]:
|
|
|
|
if bufLine not in self._filter._Filter__lineBuffer:
|
|
|
|
if bufLine not in self._filter._Filter__lineBuffer:
|
|
|
@ -508,11 +505,14 @@ class Fail2banRegex(object):
|
|
|
|
|
|
|
|
|
|
|
|
cmd_log, cmd_regex = args[:2]
|
|
|
|
cmd_log, cmd_regex = args[:2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
if not self.readRegex(cmd_regex, 'fail'):
|
|
|
|
if not self.readRegex(cmd_regex, 'fail'):
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
if len(args) == 3 and not self.readRegex(args[2], 'ignore'):
|
|
|
|
if len(args) == 3 and not self.readRegex(args[2], 'ignore'):
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
except RegexException as e:
|
|
|
|
|
|
|
|
output( 'ERROR: %s' % e )
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.isfile(cmd_log):
|
|
|
|
if os.path.isfile(cmd_log):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -558,18 +558,17 @@ class Fail2banRegex(object):
|
|
|
|
def exec_command_line(*args):
|
|
|
|
def exec_command_line(*args):
|
|
|
|
parser = get_opt_parser()
|
|
|
|
parser = get_opt_parser()
|
|
|
|
(opts, args) = parser.parse_args(*args)
|
|
|
|
(opts, args) = parser.parse_args(*args)
|
|
|
|
if opts.print_no_missed and opts.print_all_missed:
|
|
|
|
errors = []
|
|
|
|
sys.stderr.write("ERROR: --print-no-missed and --print-all-missed are mutually exclusive.\n\n")
|
|
|
|
if opts.print_no_missed and opts.print_all_missed: # pragma: no cover
|
|
|
|
parser.print_help()
|
|
|
|
errors.append("ERROR: --print-no-missed and --print-all-missed are mutually exclusive.")
|
|
|
|
sys.exit(-1)
|
|
|
|
if opts.print_no_ignored and opts.print_all_ignored: # pragma: no cover
|
|
|
|
if opts.print_no_ignored and opts.print_all_ignored:
|
|
|
|
errors.append("ERROR: --print-no-ignored and --print-all-ignored are mutually exclusive.")
|
|
|
|
sys.stderr.write("ERROR: --print-no-ignored and --print-all-ignored are mutually exclusive.\n\n")
|
|
|
|
|
|
|
|
parser.print_help()
|
|
|
|
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# We need 2 or 3 parameters
|
|
|
|
# We need 2 or 3 parameters
|
|
|
|
if not len(args) in (2, 3):
|
|
|
|
if not len(args) in (2, 3):
|
|
|
|
sys.stderr.write("ERROR: provide both <LOG> and <REGEX>.\n\n")
|
|
|
|
errors.append("ERROR: provide both <LOG> and <REGEX>.")
|
|
|
|
|
|
|
|
if errors:
|
|
|
|
|
|
|
|
sys.stderr.write("\n".join(errors) + "\n\n")
|
|
|
|
parser.print_help()
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(-1)
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
|
|
|
|