mirror of https://github.com/fail2ban/fail2ban
- Added "backend" option
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@409 a942ae1a-1317-0410-a47c-b1dcaea8d6050.x
parent
e28fec6d5d
commit
0fab1bbf01
|
@ -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
|
||||
----------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue