diff --git a/CHANGELOG b/CHANGELOG index 148b8d4d..368e85fd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,13 +7,14 @@ Fail2Ban (version 0.7.4) 2006/??/?? ============================================================= -ver. 0.7.4 (2006/09/28) - beta +ver. 0.7.4 (2006/??/??) - beta ---------- - Improved configuration files. Thanks to Yaroslav Halchenko - Added man page for "fail2ban-regex" - Moved ban/unban messages from "info" level to "warn" - Added "-s" option to specify the socket path and "socket" option in "fail2ban.conf" +- Added "backend" option in "jail.conf" ver. 0.7.3 (2006/09/28) - beta ---------- diff --git a/client/jailreader.py b/client/jailreader.py index b5a36bdd..35510749 100644 --- a/client/jailreader.py +++ b/client/jailreader.py @@ -58,6 +58,7 @@ class JailReader(ConfigReader): def getOptions(self): opts = [["bool", "enabled", "false"], ["string", "logpath", "/var/log/messages"], + ["string", "backend", "auto"], ["int", "maxretry", 3], ["int", "maxtime", 600], ["int", "bantime", 600], @@ -94,7 +95,7 @@ class JailReader(ConfigReader): return True def convert(self): - stream = [["add", self.__name]] + stream = [] for opt in self.__opts: if opt == "logpath": for path in self.__opts[opt].split("\n"): @@ -103,6 +104,8 @@ class JailReader(ConfigReader): logSys.error("No file found for " + path) for p in pathList: stream.append(["set", self.__name, "addlogpath", p]) + elif opt == "backend": + backend = self.__opts[opt] elif opt == "maxretry": stream.append(["set", self.__name, "maxretry", self.__opts[opt]]) elif opt == "ignoreip": @@ -114,6 +117,7 @@ class JailReader(ConfigReader): stream.extend(self.__filter.convert()) for action in self.__actions: stream.extend(action.convert()) + stream.insert(0, ["add", self.__name, backend]) return stream @staticmethod diff --git a/server/jail.py b/server/jail.py index 38035b79..bdbc0f41 100644 --- a/server/jail.py +++ b/server/jail.py @@ -34,21 +34,31 @@ logSys = logging.getLogger("fail2ban.jail") class Jail: - def __init__(self, name): + def __init__(self, name, backend = "auto"): self.__lock = Lock() self.__name = name self.__queue = Queue.Queue() - try: - import gamin - logSys.info("Gamin available. Using it instead of poller") - from filtergamin import FilterGamin - self.__filter = FilterGamin(self) - except ImportError: - logSys.info("Gamin not available. Using poller") - from filterpoll import FilterPoll - self.__filter = FilterPoll(self) + self.__filter = None + if backend == "polling": + self.__initPoller() + else: + try: + self.__initGamin() + except ImportError: + self.__initPoller() self.__action = Actions(self) + def __initPoller(self): + logSys.info("Using poller") + from filterpoll import FilterPoll + self.__filter = FilterPoll(self) + + def __initGamin(self): + import gamin + logSys.info("Using Gamin") + from filtergamin import FilterGamin + self.__filter = FilterGamin(self) + def setName(self, name): self.__lock.acquire() self.__name = name @@ -61,11 +71,6 @@ class Jail: finally: self.__lock.release() - def setFilter(self, filter): - self.__lock.acquire() - self.__filter = filter - self.__lock.release() - def getFilter(self): try: self.__lock.acquire() @@ -73,11 +78,6 @@ class Jail: finally: self.__lock.release() - def setAction(self, action): - self.__lock.acquire() - self.__action = action - self.__lock.release() - def getAction(self): try: self.__lock.acquire() @@ -141,7 +141,7 @@ class Jail: self.__lock.acquire() fStatus = self.__filter.status() aStatus = self.__action.status() - ret = [("filter", fStatus), + ret = [("filter", fStatus), ("action", aStatus)] return ret finally: diff --git a/server/jails.py b/server/jails.py index b4dbb4ed..8ae2ab67 100644 --- a/server/jails.py +++ b/server/jails.py @@ -34,13 +34,13 @@ class Jails: self.__lock = Lock() self.__jails = dict() - def add(self, name): + def add(self, name, backend): self.__lock.acquire() if self.__jails.has_key(name): self.__lock.release() raise DuplicateJailException(name) else: - self.__jails[name] = Jail(name) + self.__jails[name] = Jail(name, backend) self.__lock.release() def remove(self, name): diff --git a/server/server.py b/server/server.py index fb035eb5..ce495989 100644 --- a/server/server.py +++ b/server/server.py @@ -72,8 +72,8 @@ class Server: # Stop communication self.__socket.stop() - def addJail(self, name): - self.__jails.add(name) + def addJail(self, name, backend): + self.__jails.add(name, backend) def delJail(self, name): self.__jails.remove(name) diff --git a/server/transmitter.py b/server/transmitter.py index a326fccf..64ad3919 100644 --- a/server/transmitter.py +++ b/server/transmitter.py @@ -63,7 +63,11 @@ class Transmitter: name = action[1] if name == "all": raise Exception("Reserved name") - self.__server.addJail(name) + try: + backend = action[2] + except IndexError: + backend = "auto" + self.__server.addJail(name, backend) return name elif action[0] == "start": name = action[1]