mirror of https://github.com/fail2ban/fail2ban
BF: fail2ban-regex does not read '.local' file of given filter (gh-954)
parent
3fb2becddb
commit
74c6f6ac4b
|
@ -36,6 +36,7 @@ ver. 0.9.2 (2014/XX/XXX) - wanna-be-released
|
||||||
issue (gh-161)
|
issue (gh-161)
|
||||||
* filter.d/postfix-sasl.conf - tweak failregex and add ignoreregex to ignore
|
* filter.d/postfix-sasl.conf - tweak failregex and add ignoreregex to ignore
|
||||||
system authentication issues
|
system authentication issues
|
||||||
|
* fail2ban-regex reads filter file(s) completely, incl. '.local' file etc. (gh-954)
|
||||||
|
|
||||||
- New Features:
|
- New Features:
|
||||||
- New filter:
|
- New filter:
|
||||||
|
|
|
@ -220,6 +220,7 @@ class Fail2banRegex(object):
|
||||||
self._datepattern_set = False
|
self._datepattern_set = False
|
||||||
self._journalmatch = None
|
self._journalmatch = None
|
||||||
|
|
||||||
|
self.share_config=dict()
|
||||||
self._filter = Filter(None)
|
self._filter = Filter(None)
|
||||||
self._ignoreregex = list()
|
self._ignoreregex = list()
|
||||||
self._failregex = list()
|
self._failregex = list()
|
||||||
|
@ -260,38 +261,47 @@ class Fail2banRegex(object):
|
||||||
def readRegex(self, value, regextype):
|
def readRegex(self, value, regextype):
|
||||||
assert(regextype in ('fail', 'ignore'))
|
assert(regextype in ('fail', 'ignore'))
|
||||||
regex = regextype + 'regex'
|
regex = regextype + 'regex'
|
||||||
if os.path.isfile(value):
|
if os.path.isfile(value) or os.path.isfile(value + '.conf'):
|
||||||
print "Use %11s file : %s" % (regex, value)
|
if os.path.basename(os.path.dirname(value)) == 'filter.d':
|
||||||
reader = FilterReader(value, 'fail2ban-regex-jail', {})
|
## within filter.d folder - use standard loading algorithm to load filter completely (with .local etc.):
|
||||||
reader.setBaseDir(None)
|
basedir = os.path.dirname(os.path.dirname(value))
|
||||||
|
value = os.path.splitext(os.path.basename(value))[0]
|
||||||
if reader.readexplicit():
|
print "Use %11s filter file : %s, basedir: %s" % (regex, value, basedir)
|
||||||
reader.getOptions(None)
|
reader = FilterReader(value, 'fail2ban-regex-jail', {}, share_config=self.share_config, basedir=basedir)
|
||||||
readercommands = reader.convert()
|
if not reader.read():
|
||||||
regex_values = [
|
print "ERROR: failed to load filter %s" % value
|
||||||
RegexStat(m[3])
|
return False
|
||||||
for m in filter(
|
|
||||||
lambda x: x[0] == 'set' and x[2] == "add%sregex" % regextype,
|
|
||||||
readercommands)]
|
|
||||||
# Read out and set possible value of maxlines
|
|
||||||
for command in readercommands:
|
|
||||||
if command[2] == "maxlines":
|
|
||||||
maxlines = int(command[3])
|
|
||||||
try:
|
|
||||||
self.setMaxLines(maxlines)
|
|
||||||
except ValueError:
|
|
||||||
print "ERROR: Invalid value for maxlines (%(maxlines)r) " \
|
|
||||||
"read from %(value)s" % locals()
|
|
||||||
return False
|
|
||||||
elif command[2] == 'addjournalmatch':
|
|
||||||
journalmatch = command[3]
|
|
||||||
self.setJournalMatch(shlex.split(journalmatch))
|
|
||||||
elif command[2] == 'datepattern':
|
|
||||||
datepattern = command[3]
|
|
||||||
self.setDatePattern(datepattern)
|
|
||||||
else:
|
else:
|
||||||
print "ERROR: failed to read %s" % value
|
## foreign file - readexplicit this file and includes if possible:
|
||||||
return False
|
print "Use %11s file : %s" % (regex, value)
|
||||||
|
reader = FilterReader(value, 'fail2ban-regex-jail', {}, share_config=self.share_config)
|
||||||
|
reader.setBaseDir(None)
|
||||||
|
if not reader.readexplicit():
|
||||||
|
print "ERROR: failed to read %s" % value
|
||||||
|
return False
|
||||||
|
reader.getOptions(None)
|
||||||
|
readercommands = reader.convert()
|
||||||
|
regex_values = [
|
||||||
|
RegexStat(m[3])
|
||||||
|
for m in filter(
|
||||||
|
lambda x: x[0] == 'set' and x[2] == "add%sregex" % regextype,
|
||||||
|
readercommands)]
|
||||||
|
# Read out and set possible value of maxlines
|
||||||
|
for command in readercommands:
|
||||||
|
if command[2] == "maxlines":
|
||||||
|
maxlines = int(command[3])
|
||||||
|
try:
|
||||||
|
self.setMaxLines(maxlines)
|
||||||
|
except ValueError:
|
||||||
|
print "ERROR: Invalid value for maxlines (%(maxlines)r) " \
|
||||||
|
"read from %(value)s" % locals()
|
||||||
|
return False
|
||||||
|
elif command[2] == 'addjournalmatch':
|
||||||
|
journalmatch = command[3]
|
||||||
|
self.setJournalMatch(shlex.split(journalmatch))
|
||||||
|
elif command[2] == 'datepattern':
|
||||||
|
datepattern = command[3]
|
||||||
|
self.setDatePattern(datepattern)
|
||||||
else:
|
else:
|
||||||
print "Use %11s line : %s" % (regex, shortstr(value))
|
print "Use %11s line : %s" % (regex, shortstr(value))
|
||||||
regex_values = [RegexStat(value)]
|
regex_values = [RegexStat(value)]
|
||||||
|
|
Loading…
Reference in New Issue