From 7bbfe5c67cac6dfcd44c4028bd01e49bafbce0a8 Mon Sep 17 00:00:00 2001 From: "bes.internal" Date: Tue, 22 Oct 2013 18:26:47 +0300 Subject: [PATCH] Revert to upstream --- client/filterreader.py | 26 ++++--- client/jailreader.py | 29 ++++---- common/protocol.py | 72 +++++++++---------- config/jail.conf | 3 - server/filter.py | 40 +++-------- server/server.py | 158 ++++++++++++++++++++--------------------- server/transmitter.py | 32 ++++----- 7 files changed, 157 insertions(+), 203 deletions(-) diff --git a/client/filterreader.py b/client/filterreader.py index 0c81f083..f75190f9 100644 --- a/client/filterreader.py +++ b/client/filterreader.py @@ -18,7 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Author: Cyril Jaquier -# +# __author__ = "Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" @@ -31,34 +31,32 @@ from configreader import ConfigReader logSys = logging.getLogger("fail2ban.client.config") class FilterReader(ConfigReader): - + def __init__(self, fileName, name, **kwargs): ConfigReader.__init__(self, **kwargs) self.__file = fileName self.__name = name - + def setFile(self, fileName): self.__file = fileName - + def getFile(self): return self.__file - + def setName(self, name): self.__name = name - + def getName(self): return self.__name - + def read(self): return ConfigReader.read(self, "filter.d/" + self.__file) - + def getOptions(self, pOpts): opts = [["string", "ignoreregex", ""], - ["string", "failregex", ""], - ["string", "ignorecommand", ""] - ] + ["string", "failregex", ""]] self.__opts = ConfigReader.getOptions(self, "Definition", opts, pOpts) - + def convert(self): stream = list() for opt in self.__opts: @@ -71,6 +69,6 @@ class FilterReader(ConfigReader): for regex in self.__opts[opt].split('\n'): # Do not send a command if the rule is empty. if regex != '': - stream.append(["set", self.__name, "addignoreregex", regex]) + stream.append(["set", self.__name, "addignoreregex", regex]) return stream - + diff --git a/client/jailreader.py b/client/jailreader.py index 7073c0cb..7fbac423 100644 --- a/client/jailreader.py +++ b/client/jailreader.py @@ -18,7 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Author: Cyril Jaquier -# +# __author__ = "Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" @@ -34,25 +34,25 @@ from actionreader import ActionReader logSys = logging.getLogger("fail2ban.client.config") class JailReader(ConfigReader): - + actionCRE = re.compile("^((?:\w|-|_|\.)+)(?:\[(.*)\])?$") - + def __init__(self, name, force_enable=False, **kwargs): ConfigReader.__init__(self, **kwargs) self.__name = name self.__filter = None self.__force_enable = force_enable self.__actions = list() - + def setName(self, value): self.__name = value - + def getName(self): return self.__name - + def read(self): return ConfigReader.read(self, "jail") - + def isEnabled(self): return self.__force_enable or self.__opts["enabled"] @@ -81,13 +81,12 @@ class JailReader(ConfigReader): ["int", "bantime", 600], ["string", "usedns", "warn"], ["string", "failregex", None], - ["string", "ignorecommand", None], ["string", "ignoreregex", None], ["string", "ignoreip", None], ["string", "filter", ""], ["string", "action", ""]] self.__opts = ConfigReader.getOptions(self, self.__name, opts) - + if self.isEnabled(): # Read filter self.__filter = FilterReader(self.__opts["filter"], self.__name, @@ -98,7 +97,7 @@ class JailReader(ConfigReader): else: logSys.error("Unable to read the filter") return False - + # Read action for act in self.__opts["action"].split('\n'): try: @@ -119,7 +118,7 @@ class JailReader(ConfigReader): if not len(self.__actions): logSys.warn("No actions were defined for %s" % self.__name) return True - + def convert(self, allow_no_files=False): """Convert read before __opts to the commands stream @@ -161,8 +160,6 @@ class JailReader(ConfigReader): stream.append(["set", self.__name, "usedns", self.__opts[opt]]) elif opt == "failregex": stream.append(["set", self.__name, "addfailregex", self.__opts[opt]]) - elif opt == "ignorecommand": - stream.append(["set", self.__name, "ignorecommand", self.__opts[opt]]) elif opt == "ignoreregex": for regex in self.__opts[opt].split('\n'): # Do not send a command if the rule is empty. @@ -173,7 +170,7 @@ class JailReader(ConfigReader): stream.extend(action.convert()) stream.insert(0, ["add", self.__name, backend]) return stream - + #@staticmethod def splitAction(action): m = JailReader.actionCRE.match(action) @@ -205,12 +202,12 @@ class JailReader(ConfigReader): actions += "" else: actions += c - + # Split using , actionsSplit = actions.split(',') # Replace the tag with , actionsSplit = [n.replace("", ',') for n in actionsSplit] - + for param in actionsSplit: p = param.split('=') try: diff --git a/common/protocol.py b/common/protocol.py index 9e5ede7a..9309ce7f 100644 --- a/common/protocol.py +++ b/common/protocol.py @@ -18,7 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Author: Cyril Jaquier -# +# __author__ = "Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" @@ -31,51 +31,49 @@ import textwrap protocol = [ ['', "BASIC", ""], -["start", "starts the server and the jails"], -["reload", "reloads the configuration"], -["reload ", "reloads the jail "], -["stop", "stops all jails and terminate the server"], -["status", "gets the current status of the server"], -["ping", "tests if the server is alive"], -["help", "return this output"], +["start", "starts the server and the jails"], +["reload", "reloads the configuration"], +["reload ", "reloads the jail "], +["stop", "stops all jails and terminate the server"], +["status", "gets the current status of the server"], +["ping", "tests if the server is alive"], +["help", "return this output"], ['', "LOGGING", ""], -["set loglevel ", "sets logging level to . 0 is minimal, 4 is debug"], -["get loglevel", "gets the logging level"], -["set logtarget ", "sets logging target to . Can be STDOUT, STDERR, SYSLOG or a file"], -["get logtarget", "gets logging target"], +["set loglevel ", "sets logging level to . 0 is minimal, 4 is debug"], +["get loglevel", "gets the logging level"], +["set logtarget ", "sets logging target to . Can be STDOUT, STDERR, SYSLOG or a file"], +["get logtarget", "gets logging target"], ['', "JAIL CONTROL", ""], -["add ", "creates using "], -["start ", "starts the jail "], -["stop ", "stops the jail . The jail is removed"], +["add ", "creates using "], +["start ", "starts the jail "], +["stop ", "stops the jail . The jail is removed"], ["status ", "gets the current status of "], ['', "JAIL CONFIGURATION", ""], -["set ignorecommand ", "sets ignorecommand of "], -["set idle on|off", "sets the idle state of "], -["set addignoreip ", "adds to the ignore list of "], -["set delignoreip ", "removes from the ignore list of "], -["set addlogpath ", "adds to the monitoring list of "], +["set idle on|off", "sets the idle state of "], +["set addignoreip ", "adds to the ignore list of "], +["set delignoreip ", "removes from the ignore list of "], +["set addlogpath ", "adds to the monitoring list of "], ["set dellogpath ", "removes from the monitoring list of "], -["set addfailregex ", "adds the regular expression which must match failures for "], -["set delfailregex ", "removes the regular expression at for failregex"], +["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