- "reload <jail>" reloads a single jail and the parameters in fail2ban.conf.

- Look for fail2ban-server in sys.path[0]. Thanks to Bill Heaton.

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_8@655 a942ae1a-1317-0410-a47c-b1dcaea8d605
_tent/ipv6_via_aInfo
Cyril Jaquier 2008-03-04 00:13:39 +00:00
parent c79e9ecec5
commit 6779814d91
3 changed files with 53 additions and 17 deletions

View File

@ -60,9 +60,9 @@ class Configurator:
def getEarlyOptions(self): def getEarlyOptions(self):
return self.__fail2ban.getEarlyOptions() return self.__fail2ban.getEarlyOptions()
def getAllOptions(self): def getOptions(self, jail = None):
self.__fail2ban.getOptions() self.__fail2ban.getOptions()
return self.__jails.getOptions() return self.__jails.getOptions(jail)
def convertToProtocol(self): def convertToProtocol(self):
self.__streams["general"] = self.__fail2ban.convert() self.__streams["general"] = self.__fail2ban.convert()

View File

@ -40,10 +40,24 @@ class JailsReader(ConfigReader):
def read(self): def read(self):
ConfigReader.read(self, "jail") ConfigReader.read(self, "jail")
def getOptions(self): def getOptions(self, section = None):
opts = [] opts = []
self.__opts = ConfigReader.getOptions(self, "Definition", opts) self.__opts = ConfigReader.getOptions(self, "Definition", opts)
if section:
# Get the options of a specific jail.
jail = JailReader(section)
jail.read()
ret = jail.getOptions()
if ret:
if jail.isEnabled():
# We only add enabled jails
self.__jails.append(jail)
else:
logSys.error("Errors in jail '%s'. Skipping..." % section)
return False
else:
# Get the options of all jails.
for sec in self.sections(): for sec in self.sections():
jail = JailReader(sec) jail = JailReader(sec)
jail.read() jail.read()

View File

@ -48,7 +48,8 @@ logSys = logging.getLogger("fail2ban.client")
class Fail2banClient: class Fail2banClient:
prompt = "fail2ban> " SERVER = "fail2ban-server"
PROMPT = "fail2ban> "
def __init__(self): def __init__(self):
self.__argv = None self.__argv = None
@ -208,6 +209,19 @@ class Fail2banClient:
else: else:
logSys.error("Could not find server") logSys.error("Could not find server")
return False return False
elif len(cmd) == 2 and cmd[0] == "reload":
if self.__ping():
jail = cmd[1]
ret = self.__readJailConfig(jail)
# Do not continue if configuration is not 100% valid
if not ret:
return False
self.__processCmd([['stop', jail]], False)
# Configure the server
return self.__processCmd(self.__stream, False)
else:
logSys.error("Could not find server")
return False
else: else:
return self.__processCmd([cmd]) return self.__processCmd([cmd])
@ -222,7 +236,7 @@ class Fail2banClient:
pid = os.fork() pid = os.fork()
if pid == 0: if pid == 0:
args = list() args = list()
args.append("fail2ban-server") args.append(self.SERVER)
# Start in background mode. # Start in background mode.
args.append("-b") args.append("-b")
# Set the socket path. # Set the socket path.
@ -232,14 +246,15 @@ class Fail2banClient:
if force: if force:
args.append("-x") args.append("-x")
try: try:
# Use the PATH env # Use the current directory.
os.execvp("fail2ban-server", args) exe = os.path.abspath(os.path.join(sys.path[0], self.SERVER))
os.execv(exe, args)
except OSError: except OSError:
try: try:
# Use the current directory # Use the PATH env.
os.execv("fail2ban-server", args) os.execvp(self.SERVER, args)
except OSError: except OSError:
print "Could not find fail2ban-server" print "Could not find %s" % self.SERVER
os.exit(-1) os.exit(-1)
@ -333,7 +348,7 @@ class Fail2banClient:
readline.parse_and_bind("tab: complete") readline.parse_and_bind("tab: complete")
self.dispInteractive() self.dispInteractive()
while True: while True:
cmd = raw_input(self.prompt) cmd = raw_input(self.PROMPT)
if cmd == "exit" or cmd == "quit": if cmd == "exit" or cmd == "quit":
# Exit # Exit
return True return True
@ -352,7 +367,14 @@ class Fail2banClient:
def __readConfig(self): def __readConfig(self):
# Read the configuration # Read the configuration
self.__configurator.readAll() self.__configurator.readAll()
ret = self.__configurator.getAllOptions() ret = self.__configurator.getOptions()
self.__configurator.convertToProtocol()
self.__stream = self.__configurator.getConfigStream()
return ret
def __readJailConfig(self, jail):
self.__configurator.readAll()
ret = self.__configurator.getOptions(jail)
self.__configurator.convertToProtocol() self.__configurator.convertToProtocol()
self.__stream = self.__configurator.getConfigStream() self.__stream = self.__configurator.getConfigStream()
return ret return ret