From 0f31cc0feb1a393452664aff83c596f139185b52 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sat, 23 Dec 2006 16:31:00 +0000 Subject: [PATCH] - Added support for several "failregex" and "ignoreregex". This should simplify the configuration files. - Configuration files are backward-compatible but need to be updated in order to take advantage of this feature. git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@503 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 3 +- MANIFEST | 2 + client/beautifier.py | 13 +++- client/filterreader.py | 6 +- common/protocol.py | 10 +-- fail2ban-regex | 14 ++-- man/fail2ban-client.1 | 61 +++++++++++------ man/fail2ban-regex.1 | 4 +- man/fail2ban-server.1 | 4 +- server/failregex.py | 62 +++++++++++++++++ server/filter.py | 129 ++++++++++++++++++------------------ server/regex.py | 88 ++++++++++++++++++++++++ server/server.py | 14 ++-- server/transmitter.py | 16 +++-- testcases/filtertestcase.py | 41 ++++++++++-- 15 files changed, 349 insertions(+), 118 deletions(-) create mode 100644 server/failregex.py create mode 100644 server/regex.py diff --git a/CHANGELOG b/CHANGELOG index 75540cfe..c9460d61 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,7 +15,8 @@ ver. 0.7.6 (200?/??/??) - ??? - Fixed removal of host in hosts.deny. Thanks to René Berber - Added new date format (2006-12-21 06:43:20) and Exim4 filter. Thanks to mEDI -- Improved regular expression checking a bit +- Several "failregex" and "ignoreregex" are now accepted. + Creation of rules should be easier now. ver. 0.7.5 (2006/12/07) - beta ---------- diff --git a/MANIFEST b/MANIFEST index db392e40..9908c9f1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -39,6 +39,8 @@ server/dateepoch.py server/banmanager.py server/datetemplate.py server/mytime.py +server/regex.py +server/failregex.py testcases/banmanagertestcase.py testcases/failmanagertestcase.py testcases/clientreadertestcase.py diff --git a/client/beautifier.py b/client/beautifier.py index 2ef8d515..abe562a6 100644 --- a/client/beautifier.py +++ b/client/beautifier.py @@ -109,7 +109,18 @@ class Beautifier: msg = "These IP addresses/networks are ignored:\n" for ip in response[:-1]: msg = msg + "|- " + ip + "\n" - msg = msg + "`- " + response[len(response)-1] + msg = msg + "`- " + response[len(response)-1] + elif inC[2] in ("failregex", "addfailregex", "delfailregex", + "ignoreregex", "addignoreregex", "delignoreregex"): + if len(response) == 0: + msg = "No regular expression is defined" + else: + msg = "The following regular expression are defined:\n" + c = 0 + for ip in response[:-1]: + msg = msg + "|- [" + str(c) + "]: " + ip + "\n" + c += 1 + msg = msg + "`- [" + str(c) + "]: " + response[len(response)-1] except Exception: logSys.warn("Beautifier error. Please report the error") logSys.error("Beautify " + `response` + " with " + `self.__inputCmd` + diff --git a/client/filterreader.py b/client/filterreader.py index 14ffbb91..30cca818 100644 --- a/client/filterreader.py +++ b/client/filterreader.py @@ -67,8 +67,10 @@ class FilterReader(ConfigReader): elif opt == "timepattern": stream.append(["set", self.__name, "timepattern", self.__opts[opt]]) elif opt == "failregex": - stream.append(["set", self.__name, "failregex", self.__opts[opt]]) + for regex in self.__opts[opt].split('\n'): + stream.append(["set", self.__name, "addfailregex", regex]) elif opt == "ignoreregex": - stream.append(["set", self.__name, "ignoreregex", self.__opts[opt]]) + for regex in self.__opts[opt].split('\n'): + stream.append(["set", self.__name, "addignoreregex", regex]) return stream \ No newline at end of file diff --git a/common/protocol.py b/common/protocol.py index e53d121b..d9312f9b 100644 --- a/common/protocol.py +++ b/common/protocol.py @@ -54,8 +54,10 @@ protocol = [ ["set dellogpath ", "removes to the monitoring list of "], ["set timeregex ", "sets the regular expression to match the date format for . This will disable the autodetection feature."], ["set timepattern ", "sets the pattern to match the date format for . This will disable the autodetection feature."], -["set failregex ", "sets the regular expression which must match failures for "], -["set ignoreregex ", "sets the regular expression which should match pattern to exclude for "], +["set addfailregex ", "adds the regular expression which must match failures for "], +["set delfailregex ", "removes the regular expression at for failregex"], +["set addignoreregex ", "adds the regular expression which should match pattern to exclude for "], +["set delignoreregex ", "removes the regular expression at for ignoreregex"], ["set findtime