mirror of https://github.com/fail2ban/fail2ban
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.5 KiB
88 lines
2.5 KiB
20 years ago
|
# This file is part of Fail2Ban.
|
||
|
#
|
||
|
# Fail2Ban is free software; you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation; either version 2 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# Fail2Ban is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with Fail2Ban; if not, write to the Free Software
|
||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
|
||
|
# Author: Cyril Jaquier
|
||
|
#
|
||
19 years ago
|
# $Revision: 1.6 $
|
||
20 years ago
|
|
||
|
__author__ = "Cyril Jaquier"
|
||
19 years ago
|
__version__ = "$Revision: 1.6 $"
|
||
|
__date__ = "$Date: 2005/11/20 17:07:47 $"
|
||
20 years ago
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
||
|
__license__ = "GPL"
|
||
|
|
||
19 years ago
|
import logging
|
||
20 years ago
|
from ConfigParser import *
|
||
|
|
||
19 years ago
|
# Gets the instance of the logger.
|
||
19 years ago
|
logSys = logging.getLogger("fail2ban.client.config")
|
||
19 years ago
|
|
||
19 years ago
|
class ConfigReader(SafeConfigParser):
|
||
|
|
||
|
basedir = "/etc/fail2ban/"
|
||
|
|
||
|
def __init__(self):
|
||
|
SafeConfigParser.__init__(self)
|
||
|
self.opts = None
|
||
|
|
||
|
@staticmethod
|
||
|
def setBaseDir(dir):
|
||
|
global basedir
|
||
|
path = dir.rstrip('/')
|
||
|
basedir = path + '/'
|
||
20 years ago
|
|
||
19 years ago
|
@staticmethod
|
||
|
def getBaseDir():
|
||
|
global basedir
|
||
|
return basedir
|
||
20 years ago
|
|
||
19 years ago
|
def read(self, filename):
|
||
|
global basedir
|
||
|
basename = basedir + filename
|
||
|
logSys.debug("Reading " + basename)
|
||
|
SafeConfigParser.read(self, [basename + ".conf", basename + ".local"])
|
||
19 years ago
|
|
||
19 years ago
|
##
|
||
|
# Read the options.
|
||
|
#
|
||
|
# Read the given option in the configuration file. Default values
|
||
|
# are used...
|
||
19 years ago
|
# Each optionValues entry is composed of an array with:
|
||
|
# 0 -> the type of the option
|
||
|
# 1 -> the name of the option
|
||
|
# 2 -> the default value for the option
|
||
19 years ago
|
def getOptions(self, sec, options, pOptions = None):
|
||
20 years ago
|
values = dict()
|
||
19 years ago
|
for option in options:
|
||
20 years ago
|
try:
|
||
20 years ago
|
if option[0] == "bool":
|
||
19 years ago
|
v = self.getboolean(sec, option[1])
|
||
20 years ago
|
elif option[0] == "int":
|
||
19 years ago
|
v = self.getint(sec, option[1])
|
||
20 years ago
|
else:
|
||
19 years ago
|
v = self.get(sec, option[1])
|
||
|
if not pOptions == None and option[1] in pOptions:
|
||
|
continue
|
||
20 years ago
|
values[option[1]] = v
|
||
20 years ago
|
except NoOptionError:
|
||
19 years ago
|
if not option[2] == None:
|
||
|
logSys.warn("No '" + option[1] + "' defined in '" + sec + "'")
|
||
|
values[option[1]] = option[2]
|
||
19 years ago
|
except ValueError:
|
||
|
logSys.warn("Wrong value for '" + option[1] + "' in '" + sec +
|
||
|
"'. Using default one: '" + `option[2]` + "'")
|
||
20 years ago
|
values[option[1]] = option[2]
|
||
19 years ago
|
return values
|