From e8c751bbcc6d33737d554b0003dbe7f9ec13ae6b Mon Sep 17 00:00:00 2001 From: lostcontrol Date: Fri, 18 Feb 2005 21:48:34 +0000 Subject: [PATCH] - Added more comments - Catch exception when option not present in section git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@53 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- confreader/configreader.py | 62 ++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/confreader/configreader.py b/confreader/configreader.py index 5f8679dd..1b43cf4f 100644 --- a/confreader/configreader.py +++ b/confreader/configreader.py @@ -29,29 +29,39 @@ import os, sys, time from ConfigParser import * class ConfigReader: - """ Reads a log file and reports information about IP that make password - failure, bad user or anything else that is considered as doubtful login - attempt. - """ - - optionValues = ("logfile", "timeregex", "timepattern", "failregex") - - def __init__(self, confPath): - self.confPath = confPath - self.configParser = SafeConfigParser() - - def openConf(self): - self.configParser.read(self.confPath) - - def getSections(self): - return self.configParser.sections() - - def getLogOptions(self, sec): - values = dict() - for option in self.optionValues: - v = self.configParser.get(sec, option) - values[option] = v - return values - - - + """ This class allow the handling of the configuration options. + The DEFAULT section contains the global information about + Fail2Ban. Each other section is for a different log file. + """ + + optionValues = ("logfile", "timeregex", "timepattern", "failregex") + + def __init__(self, logSys, confPath): + self.confPath = confPath + self.configParser = SafeConfigParser() + self.logSys = logSys + + def openConf(self): + """ Opens the configuration file. + """ + self.configParser.read(self.confPath) + + def getSections(self): + """ Returns all the sections present in the configuration + file except the DEFAULT section. + """ + return self.configParser.sections() + + def getLogOptions(self, sec): + """ Gets all the options of a given section. The options + are defined in the optionValues list. + """ + values = dict() + for option in self.optionValues: + try: + v = self.configParser.get(sec, option) + values[option] = v + except NoOptionError: + self.logSys.info("No "+option+" defined in "+sec) + return values + \ No newline at end of file