- Improved checking when parsing the configuration

git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@336 a942ae1a-1317-0410-a47c-b1dcaea8d605
0.x
Cyril Jaquier 2006-09-07 21:00:44 +00:00
parent 7864bdc953
commit 46dee1bd9a
5 changed files with 32 additions and 13 deletions

View File

@ -51,7 +51,7 @@ class ActionReader(ConfigReader):
return self.name
def read(self):
ConfigReader.read(self, "action.d/" + self.file)
return ConfigReader.read(self, "action.d/" + self.file)
def getOptions(self, pOpts):
opts = [["string", "actionstart", ""],

View File

@ -24,7 +24,7 @@ __date__ = "$Date$"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL"
import logging
import logging, os
from ConfigParser import *
# Gets the instance of the logger.
@ -53,7 +53,14 @@ class ConfigReader(SafeConfigParser):
global basedir
basename = basedir + filename
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.

View File

@ -50,7 +50,7 @@ class FilterReader(ConfigReader):
return self.name
def read(self):
ConfigReader.read(self, "filter.d/" + self.file)
return ConfigReader.read(self, "filter.d/" + self.file)
def getOptions(self, pOpts):
opts = [["string", "timeregex", None],

View File

@ -67,20 +67,29 @@ class JailReader(ConfigReader):
if self.isEnabled():
# Read filter
self.filter = FilterReader(self.opts["filter"], self.name)
self.filter.read()
self.filter.getOptions(self.opts)
ret = self.filter.read()
if ret:
self.filter.getOptions(self.opts)
else:
logSys.error("Unable to read the filter")
return False
# Read action
for act in self.opts["action"].split('\n'):
try:
splitAct = JailReader.splitAction(act)
action = ActionReader(splitAct, self.name)
action.read()
action.getOptions(self.opts)
self.actions.append(action)
ret = action.read()
if ret:
action.getOptions(self.opts)
self.actions.append(action)
else:
raise AttributeError("Unable to read action")
except AttributeError, e:
logSys.error("Error in action definition " + act)
logSys.debug(e)
return False
return True
def convert(self):
stream = [["add", self.name]]

View File

@ -47,10 +47,13 @@ class JailsReader(ConfigReader):
for sec in self.sections():
jail = JailReader(sec)
jail.read()
jail.getOptions()
if jail.isEnabled():
# We only add enabled jails
self.jails.append(jail)
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...")
def getFilterOptions(self, file):
filter = FilterReader(file)