mirror of https://github.com/fail2ban/fail2ban
RF(ENH): JailsReader.getOptions -- avoid code duplication when asking for 1 jail or all
parent
a012b54117
commit
b92316ff17
|
@ -48,13 +48,21 @@ class JailsReader(ConfigReader):
|
||||||
def read(self):
|
def read(self):
|
||||||
return ConfigReader.read(self, "jail")
|
return ConfigReader.read(self, "jail")
|
||||||
|
|
||||||
def getOptions(self, section = None):
|
def getOptions(self, section=None):
|
||||||
|
"""Reads configuration for jail(s) and adds enabled jails to __jails
|
||||||
|
"""
|
||||||
opts = []
|
opts = []
|
||||||
self.__opts = ConfigReader.getOptions(self, "Definition", opts)
|
self.__opts = ConfigReader.getOptions(self, "Definition", opts)
|
||||||
|
|
||||||
if section:
|
if section is None:
|
||||||
# Get the options of a specific jail.
|
sections = self.sections()
|
||||||
jail = JailReader(section, basedir=self.getBaseDir(), force_enable=self.__force_enable)
|
else:
|
||||||
|
sections = [ section ]
|
||||||
|
|
||||||
|
# Get the options of all jails.
|
||||||
|
for sec in sections:
|
||||||
|
jail = JailReader(sec, basedir=self.getBaseDir(),
|
||||||
|
force_enable=self.__force_enable)
|
||||||
jail.read()
|
jail.read()
|
||||||
ret = jail.getOptions()
|
ret = jail.getOptions()
|
||||||
if ret:
|
if ret:
|
||||||
|
@ -62,21 +70,8 @@ class JailsReader(ConfigReader):
|
||||||
# We only add enabled jails
|
# We only add enabled jails
|
||||||
self.__jails.append(jail)
|
self.__jails.append(jail)
|
||||||
else:
|
else:
|
||||||
logSys.error("Errors in jail '%s'. Skipping..." % section)
|
logSys.error("Errors in jail %r. Skipping..." % sec)
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
# Get the options of all jails.
|
|
||||||
for sec in self.sections():
|
|
||||||
jail = JailReader(sec, basedir=self.getBaseDir(), force_enable=self.__force_enable)
|
|
||||||
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 '" + sec + "'. Skipping...")
|
|
||||||
return False
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def convert(self, allow_no_files=False):
|
def convert(self, allow_no_files=False):
|
||||||
|
|
Loading…
Reference in New Issue