diff --git a/bin/fail2ban-regex b/bin/fail2ban-regex index 4a32d6c7..5d06074a 100755 --- a/bin/fail2ban-regex +++ b/bin/fail2ban-regex @@ -88,6 +88,8 @@ IGNOREREGEX: version="%prog " + version) p.add_options([ + Option("-d", "--datepattern", + help="set custom pattern used to match date/times"), Option("-e", "--encoding", help="File encoding. Default: system locale"), Option("-L", "--maxlines", type=int, default=0, @@ -179,6 +181,9 @@ class Fail2banRegex(object): self._maxlines_set = False # so we allow to override maxlines in cmdline self._journalmatch = None + if opts.datepattern: + self.setDatePattern(opts.datepattern) + if opts.encoding: self.encoding = opts.encoding else: @@ -194,6 +199,8 @@ class Fail2banRegex(object): if opts.journalmatch is not None: self.setJournalMatch(opts.journalmatch.split()) + def setDatePattern(self, pattern): + self._filter.setDatePattern(pattern) def setMaxLines(self, v): if not self._maxlines_set: diff --git a/config/filter.d/apache-common.conf b/config/filter.d/apache-common.conf index cc35ae5f..69364247 100644 --- a/config/filter.d/apache-common.conf +++ b/config/filter.d/apache-common.conf @@ -18,4 +18,4 @@ after = apache-common.local # 2.2: [Sat Jun 01 11:23:08 2013] [error] [client 1.2.3.4] # 2.4: [Thu Jun 27 11:55:44.569531 2013] [core:info] [pid 4101:tid 2992634688] [client 1.2.3.4:46652] # Reference: https://github.com/fail2ban/fail2ban/issues/268 -_apache_error_client = \[[^]]+\] \[(error|core:\S+)\]( \[pid \d+:\S+ \d+\])? \[client (:\d{1,5})?\]( \S+:)? +_apache_error_client = \[[^]]*\] \[(error|core:\S+)\]( \[pid \d+:\S+ \d+\])? \[client (:\d{1,5})?\]( \S+:)? diff --git a/fail2ban/__init__.py b/fail2ban/__init__.py index 2b76f4b6..3eae8ee3 100644 --- a/fail2ban/__init__.py +++ b/fail2ban/__init__.py @@ -23,3 +23,8 @@ __author__ = "Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" + +import logging + +# Custom debug level +logging.HEAVYDEBUG = 5 diff --git a/fail2ban/client/__init__.py b/fail2ban/client/__init__.py index 3eae8ee3..2b76f4b6 100644 --- a/fail2ban/client/__init__.py +++ b/fail2ban/client/__init__.py @@ -23,8 +23,3 @@ __author__ = "Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" - -import logging - -# Custom debug level -logging.HEAVYDEBUG = 5 diff --git a/fail2ban/client/beautifier.py b/fail2ban/client/beautifier.py index 0c5e31fb..1c6cdaeb 100644 --- a/fail2ban/client/beautifier.py +++ b/fail2ban/client/beautifier.py @@ -119,6 +119,12 @@ class Beautifier: else: msg = "Current match filter:\n" msg += ' + '.join(" ".join(res) for res in response) + elif inC[2] == "datepattern": + msg = "Current date pattern set to: " + if response is None: + msg = msg + "Default Detectors" + else: + msg = msg + "%s (%s)" % response elif inC[2] in ("ignoreip", "addignoreip", "delignoreip"): if len(response) == 0: msg = "No IP address/network is ignored" diff --git a/fail2ban/client/filterreader.py b/fail2ban/client/filterreader.py index e5fe8f4f..d8a6dbe8 100644 --- a/fail2ban/client/filterreader.py +++ b/fail2ban/client/filterreader.py @@ -56,6 +56,8 @@ class FilterReader(DefinitionInitConfigReader): if self._initOpts: if 'maxlines' in self._initOpts: stream.append(["set", self._jailName, "maxlines", self._initOpts["maxlines"]]) + if 'datepattern' in self._initOpts: + stream.append(["set", self._jailName, "datepattern", self._initOpts["datepattern"]]) # Do not send a command if the match is empty. if self._initOpts.get("journalmatch", '') != '': for match in self._initOpts["journalmatch"].split("\n"): diff --git a/fail2ban/protocol.py b/fail2ban/protocol.py index e0fb018d..25ad3b5c 100644 --- a/fail2ban/protocol.py +++ b/fail2ban/protocol.py @@ -63,6 +63,7 @@ protocol = [ ["set delignoreregex ", "removes the regular expression at for ignoreregex"], ["set findtime