mirror of https://github.com/fail2ban/fail2ban
- Improved checking when parsing the configuration
git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@336 a942ae1a-1317-0410-a47c-b1dcaea8d6050.x
parent
7864bdc953
commit
46dee1bd9a
|
@ -51,7 +51,7 @@ class ActionReader(ConfigReader):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
ConfigReader.read(self, "action.d/" + self.file)
|
return ConfigReader.read(self, "action.d/" + self.file)
|
||||||
|
|
||||||
def getOptions(self, pOpts):
|
def getOptions(self, pOpts):
|
||||||
opts = [["string", "actionstart", ""],
|
opts = [["string", "actionstart", ""],
|
||||||
|
|
|
@ -24,7 +24,7 @@ __date__ = "$Date$"
|
||||||
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||||||
__license__ = "GPL"
|
__license__ = "GPL"
|
||||||
|
|
||||||
import logging
|
import logging, os
|
||||||
from ConfigParser import *
|
from ConfigParser import *
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Gets the instance of the logger.
|
||||||
|
@ -53,7 +53,14 @@ class ConfigReader(SafeConfigParser):
|
||||||
global basedir
|
global basedir
|
||||||
basename = basedir + filename
|
basename = basedir + filename
|
||||||
logSys.debug("Reading " + basename)
|
logSys.debug("Reading " + basename)
|
||||||
SafeConfigParser.read(self, [basename + ".conf", basename + ".local"])
|
bConf = basename + ".conf"
|
||||||
|
bLocal = basename + ".local"
|
||||||
|
if os.path.exists(bConf) or os.path.exists(bLocal):
|
||||||
|
SafeConfigParser.read(self, [bConf, bLocal])
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logSys.error(bConf + " and " + bLocal + " do not exist")
|
||||||
|
return False
|
||||||
|
|
||||||
##
|
##
|
||||||
# Read the options.
|
# Read the options.
|
||||||
|
|
|
@ -50,7 +50,7 @@ class FilterReader(ConfigReader):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
ConfigReader.read(self, "filter.d/" + self.file)
|
return ConfigReader.read(self, "filter.d/" + self.file)
|
||||||
|
|
||||||
def getOptions(self, pOpts):
|
def getOptions(self, pOpts):
|
||||||
opts = [["string", "timeregex", None],
|
opts = [["string", "timeregex", None],
|
||||||
|
|
|
@ -67,20 +67,29 @@ class JailReader(ConfigReader):
|
||||||
if self.isEnabled():
|
if self.isEnabled():
|
||||||
# Read filter
|
# Read filter
|
||||||
self.filter = FilterReader(self.opts["filter"], self.name)
|
self.filter = FilterReader(self.opts["filter"], self.name)
|
||||||
self.filter.read()
|
ret = self.filter.read()
|
||||||
|
if ret:
|
||||||
self.filter.getOptions(self.opts)
|
self.filter.getOptions(self.opts)
|
||||||
|
else:
|
||||||
|
logSys.error("Unable to read the filter")
|
||||||
|
return False
|
||||||
|
|
||||||
# Read action
|
# Read action
|
||||||
for act in self.opts["action"].split('\n'):
|
for act in self.opts["action"].split('\n'):
|
||||||
try:
|
try:
|
||||||
splitAct = JailReader.splitAction(act)
|
splitAct = JailReader.splitAction(act)
|
||||||
action = ActionReader(splitAct, self.name)
|
action = ActionReader(splitAct, self.name)
|
||||||
action.read()
|
ret = action.read()
|
||||||
|
if ret:
|
||||||
action.getOptions(self.opts)
|
action.getOptions(self.opts)
|
||||||
self.actions.append(action)
|
self.actions.append(action)
|
||||||
|
else:
|
||||||
|
raise AttributeError("Unable to read action")
|
||||||
except AttributeError, e:
|
except AttributeError, e:
|
||||||
logSys.error("Error in action definition " + act)
|
logSys.error("Error in action definition " + act)
|
||||||
logSys.debug(e)
|
logSys.debug(e)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def convert(self):
|
def convert(self):
|
||||||
stream = [["add", self.name]]
|
stream = [["add", self.name]]
|
||||||
|
|
|
@ -47,10 +47,13 @@ class JailsReader(ConfigReader):
|
||||||
for sec in self.sections():
|
for sec in self.sections():
|
||||||
jail = JailReader(sec)
|
jail = JailReader(sec)
|
||||||
jail.read()
|
jail.read()
|
||||||
jail.getOptions()
|
ret = jail.getOptions()
|
||||||
|
if ret:
|
||||||
if jail.isEnabled():
|
if jail.isEnabled():
|
||||||
# We only add enabled jails
|
# We only add enabled jails
|
||||||
self.jails.append(jail)
|
self.jails.append(jail)
|
||||||
|
else:
|
||||||
|
logSys.error("Errors in jail '" + sec + "'. Skipping...")
|
||||||
|
|
||||||
def getFilterOptions(self, file):
|
def getFilterOptions(self, file):
|
||||||
filter = FilterReader(file)
|
filter = FilterReader(file)
|
||||||
|
|
Loading…
Reference in New Issue