Browse Source

ENH: Suppress configuration warnings if non-critical options are not set

pull/678/head
Steven Hiscocks 11 years ago
parent
commit
638c013557
  1. 10
      fail2ban/client/actionreader.py
  2. 4
      fail2ban/client/configreader.py
  3. 2
      fail2ban/client/filterreader.py
  4. 17
      fail2ban/client/jailreader.py
  5. 2
      fail2ban/server/filter.py
  6. 37
      fail2ban/tests/clientreadertestcase.py
  7. 2
      fail2ban/tests/config/jail.conf

10
fail2ban/client/actionreader.py

@ -34,11 +34,11 @@ logSys = logging.getLogger(__name__)
class ActionReader(DefinitionInitConfigReader):
_configOpts = [
["string", "actionstart", ""],
["string", "actionstop", ""],
["string", "actioncheck", ""],
["string", "actionban", ""],
["string", "actionunban", ""],
["string", "actionstart", None],
["string", "actionstop", None],
["string", "actioncheck", None],
["string", "actionban", None],
["string", "actionunban", None],
]
def __init__(self, file_, jailName, initOpts, **kwargs):

4
fail2ban/client/configreader.py

@ -120,6 +120,10 @@ class ConfigReader(SafeConfigParserWithIncludes):
logSys.warning("'%s' not defined in '%s'. Using default one: %r"
% (option[1], sec, option[2]))
values[option[1]] = option[2]
else:
logSys.debug(
"Non essential option '%s' not defined in '%s'.",
option[1], sec)
except ValueError:
logSys.warning("Wrong value for '" + option[1] + "' in '" + sec +
"'. Using default one: '" + `option[2]` + "'")

2
fail2ban/client/filterreader.py

@ -35,7 +35,7 @@ logSys = logging.getLogger(__name__)
class FilterReader(DefinitionInitConfigReader):
_configOpts = [
["string", "ignoreregex", ""],
["string", "ignoreregex", None],
["string", "failregex", ""],
]

17
fail2ban/client/jailreader.py

@ -68,7 +68,8 @@ class JailReader(ConfigReader):
return out
def isEnabled(self):
return self.__force_enable or ( self.__opts and self.__opts["enabled"] )
return self.__force_enable or (
self.__opts and self.__opts.get("enabled", False))
@staticmethod
def _glob(path):
@ -85,14 +86,14 @@ class JailReader(ConfigReader):
return pathList
def getOptions(self):
opts = [["bool", "enabled", "false"],
["string", "logpath", "/var/log/messages"],
["string", "logencoding", "auto"],
opts = [["bool", "enabled", False],
["string", "logpath", None],
["string", "logencoding", None],
["string", "backend", "auto"],
["int", "maxretry", 3],
["int", "findtime", 600],
["int", "bantime", 600],
["string", "usedns", "warn"],
["int", "maxretry", None],
["int", "findtime", None],
["int", "bantime", None],
["string", "usedns", None],
["string", "failregex", None],
["string", "ignoreregex", None],
["string", "ignorecommand", None],

2
fail2ban/server/filter.py

@ -63,7 +63,7 @@ class Filter(JailThread):
## Use DNS setting
self.setUseDns(useDns)
## The amount of time to look back.
self.__findTime = 6000
self.__findTime = 600
## The ignore IP list.
self.__ignoreIpList = []
## Size of line buffer

37
fail2ban/tests/clientreadertestcase.py

@ -349,31 +349,9 @@ class JailsReaderTest(LogCaptureTestCase):
self.maxDiff = None
self.assertEqual(sorted(comm_commands),
sorted([['add', 'emptyaction', 'auto'],
['set', 'emptyaction', 'usedns', 'warn'],
['set', 'emptyaction', 'maxretry', 3],
['set', 'emptyaction', 'findtime', 600],
['set', 'emptyaction', 'logencoding', 'auto'],
['set', 'emptyaction', 'bantime', 600],
['add', 'special', 'auto'],
['set', 'special', 'usedns', 'warn'],
['set', 'special', 'maxretry', 3],
['set', 'special', 'addfailregex', '<IP>'],
['set', 'special', 'findtime', 600],
['set', 'special', 'logencoding', 'auto'],
['set', 'special', 'bantime', 600],
['add', 'missinglogfiles', 'auto'],
['set', 'missinglogfiles', 'usedns', 'warn'],
['set', 'missinglogfiles', 'maxretry', 3],
['set', 'missinglogfiles', 'findtime', 600],
['set', 'missinglogfiles', 'logencoding', 'auto'],
['set', 'missinglogfiles', 'bantime', 600],
['set', 'missinglogfiles', 'addfailregex', '<IP>'],
['add', 'brokenaction', 'auto'],
['set', 'brokenaction', 'usedns', 'warn'],
['set', 'brokenaction', 'maxretry', 3],
['set', 'brokenaction', 'findtime', 600],
['set', 'brokenaction', 'logencoding', 'auto'],
['set', 'brokenaction', 'bantime', 600],
['set', 'brokenaction', 'addfailregex', '<IP>'],
['set', 'brokenaction', 'addaction', 'brokenaction'],
['set',
@ -382,23 +360,9 @@ class JailsReaderTest(LogCaptureTestCase):
'brokenaction',
'actionban',
'hit with big stick <ip>'],
['set', 'brokenaction', 'action', 'brokenaction',
'actionstop', ''],
['set', 'brokenaction', 'action', 'brokenaction',
'actionstart', ''],
['set', 'brokenaction', 'action', 'brokenaction',
'actionunban', ''],
['set', 'brokenaction', 'action', 'brokenaction',
'actioncheck', ''],
['add', 'parse_to_end_of_jail.conf', 'auto'],
['set', 'parse_to_end_of_jail.conf', 'usedns', 'warn'],
['set', 'parse_to_end_of_jail.conf', 'maxretry', 3],
['set', 'parse_to_end_of_jail.conf', 'findtime', 600],
['set', 'parse_to_end_of_jail.conf', 'logencoding', 'auto'],
['set', 'parse_to_end_of_jail.conf', 'bantime', 600],
['set', 'parse_to_end_of_jail.conf', 'addfailregex', '<IP>'],
['start', 'emptyaction'],
['start', 'special'],
['start', 'missinglogfiles'],
['start', 'brokenaction'],
['start', 'parse_to_end_of_jail.conf'],]))
@ -572,6 +536,7 @@ class JailsReaderTest(LogCaptureTestCase):
jailfd = open(os.path.join(basedir, "jail.conf"), 'w')
jailfd.write("""
[testjail1]
enabled = true
action = testaction1[actname=test1]
testaction1[actname=test2]
testaction.py

2
fail2ban/tests/config/jail.conf

@ -14,6 +14,7 @@ ignoreregex =
ignoreip =
[missinglogfiles]
enabled = true
logpath = /weapons/of/mass/destruction
[brokenactiondef]
@ -25,6 +26,7 @@ enabled = true
action = brokenaction
[missingbitsjail]
enabled = true
filter = catchallthebadies
action = thefunkychickendance

Loading…
Cancel
Save