mirror of https://github.com/fail2ban/fail2ban
- 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-b1dcaea8d6050.6
parent
b5eb68d884
commit
f4b083d79b
|
@ -29,29 +29,39 @@ import os, sys, time
|
||||||
from ConfigParser import *
|
from ConfigParser import *
|
||||||
|
|
||||||
class ConfigReader:
|
class ConfigReader:
|
||||||
""" Reads a log file and reports information about IP that make password
|
""" This class allow the handling of the configuration options.
|
||||||
failure, bad user or anything else that is considered as doubtful login
|
The DEFAULT section contains the global information about
|
||||||
attempt.
|
Fail2Ban. Each other section is for a different log file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
optionValues = ("logfile", "timeregex", "timepattern", "failregex")
|
optionValues = ("logfile", "timeregex", "timepattern", "failregex")
|
||||||
|
|
||||||
def __init__(self, confPath):
|
def __init__(self, logSys, confPath):
|
||||||
self.confPath = confPath
|
self.confPath = confPath
|
||||||
self.configParser = SafeConfigParser()
|
self.configParser = SafeConfigParser()
|
||||||
|
self.logSys = logSys
|
||||||
|
|
||||||
def openConf(self):
|
def openConf(self):
|
||||||
|
""" Opens the configuration file.
|
||||||
|
"""
|
||||||
self.configParser.read(self.confPath)
|
self.configParser.read(self.confPath)
|
||||||
|
|
||||||
def getSections(self):
|
def getSections(self):
|
||||||
|
""" Returns all the sections present in the configuration
|
||||||
|
file except the DEFAULT section.
|
||||||
|
"""
|
||||||
return self.configParser.sections()
|
return self.configParser.sections()
|
||||||
|
|
||||||
def getLogOptions(self, sec):
|
def getLogOptions(self, sec):
|
||||||
|
""" Gets all the options of a given section. The options
|
||||||
|
are defined in the optionValues list.
|
||||||
|
"""
|
||||||
values = dict()
|
values = dict()
|
||||||
for option in self.optionValues:
|
for option in self.optionValues:
|
||||||
|
try:
|
||||||
v = self.configParser.get(sec, option)
|
v = self.configParser.get(sec, option)
|
||||||
values[option] = v
|
values[option] = v
|
||||||
|
except NoOptionError:
|
||||||
|
self.logSys.info("No "+option+" defined in "+sec)
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue