diff --git a/CHANGELOG b/CHANGELOG index 4dfe51c4..148b8d4d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,7 +12,8 @@ ver. 0.7.4 (2006/09/28) - 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 +- Added "-s" option to specify the socket path and "socket" + option in "fail2ban.conf" ver. 0.7.3 (2006/09/28) - beta ---------- diff --git a/client/configurator.py b/client/configurator.py index 4802dd52..b59f5192 100644 --- a/client/configurator.py +++ b/client/configurator.py @@ -46,9 +46,15 @@ class Configurator: def getBaseDir(self): return ConfigReader.getBaseDir() - def readAll(self): + def readEarly(self): self.__fail2ban.read() + + def readAll(self): + self.readEarly() self.__jails.read() + + def getEarlyOptions(self): + return self.__fail2ban.getEarlyOptions() def getAllOptions(self): self.__settings["general"] = self.__fail2ban.getOptions() diff --git a/client/fail2banreader.py b/client/fail2banreader.py index e8242cf4..99bc522e 100644 --- a/client/fail2banreader.py +++ b/client/fail2banreader.py @@ -38,6 +38,10 @@ class Fail2banReader(ConfigReader): def read(self): ConfigReader.read(self, "fail2ban") + def getEarlyOptions(self): + opts = [["string", "socket", "/tmp/fail2ban.sock"]] + return ConfigReader.getOptions(self, "Definition", opts) + def getOptions(self): opts = [["int", "loglevel", 1], ["string", "logtarget", "STDERR"]] diff --git a/fail2ban-client b/fail2ban-client index fdb6da39..fd88d6e1 100755 --- a/fail2ban-client +++ b/fail2ban-client @@ -52,13 +52,14 @@ class Fail2banClient: def __init__(self): self.__argv = None self.__stream = None + self.__configurator = Configurator() self.__conf = dict() self.__conf["conf"] = "/etc/fail2ban" self.__conf["dump"] = False self.__conf["force"] = False self.__conf["verbose"] = 2 self.__conf["interactive"] = False - self.__conf["socket"] = "/tmp/fail2ban.sock" + self.__conf["socket"] = None def dispVersion(self): print "Fail2Ban v" + version @@ -273,6 +274,16 @@ class Fail2banClient: stdout.setFormatter(formatter) logSys.addHandler(stdout) + # Set the configuration path + self.__configurator.setBaseDir(self.__conf["conf"]) + + # Set socket path + self.__configurator.readEarly() + socket = self.__configurator.getEarlyOptions() + if self.__conf["socket"] == None: + self.__conf["socket"] = socket["socket"] + logSys.warn("Using socket file " + self.__conf["socket"]) + if self.__conf["dump"]: self.__readConfig() self.dumpConfig(self.__stream) @@ -306,12 +317,10 @@ class Fail2banClient: def __readConfig(self): # Read the configuration - cfg = Configurator() - cfg.setBaseDir(self.__conf["conf"]) - cfg.readAll() - cfg.getAllOptions() - cfg.convertToProtocol() - self.__stream = cfg.getConfigStream() + self.__configurator.readAll() + self.__configurator.getAllOptions() + self.__configurator.convertToProtocol() + self.__stream = self.__configurator.getConfigStream() @staticmethod def dumpConfig(cmd):