From c8fdabf0018dfdad30f0f935fcfd266affbe19e5 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Mon, 9 Oct 2006 18:05:13 +0000 Subject: [PATCH] - Added "socket" option in "fail2ban.conf" git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@407 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- CHANGELOG | 3 ++- client/configurator.py | 8 +++++++- client/fail2banreader.py | 4 ++++ fail2ban-client | 23 ++++++++++++++++------- 4 files changed, 29 insertions(+), 9 deletions(-) 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):