2011-10-07 19:47:50 +00:00
|
|
|
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
# vi: set ft=python sts=4 ts=4 sw=4 noet :
|
|
|
|
|
2006-06-26 20:05:00 +00:00
|
|
|
# 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
|
2011-11-21 12:20:20 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
# Author: Cyril Jaquier
|
|
|
|
#
|
|
|
|
|
|
|
|
__author__ = "Cyril Jaquier"
|
|
|
|
__copyright__ = "Copyright (c) 2004 Cyril Jaquier"
|
|
|
|
__license__ = "GPL"
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from configreader import ConfigReader
|
|
|
|
|
|
|
|
# Gets the instance of the logger.
|
|
|
|
logSys = logging.getLogger("fail2ban.client.config")
|
|
|
|
|
|
|
|
class FilterReader(ConfigReader):
|
|
|
|
|
2013-02-17 22:03:23 +00:00
|
|
|
def __init__(self, fileName, name, **kwargs):
|
|
|
|
ConfigReader.__init__(self, **kwargs)
|
2006-10-24 19:40:51 +00:00
|
|
|
self.__file = fileName
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__name = name
|
2006-06-26 20:05:00 +00:00
|
|
|
|
2006-10-24 19:40:51 +00:00
|
|
|
def setFile(self, fileName):
|
|
|
|
self.__file = fileName
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def getFile(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__file
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def setName(self, name):
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__name = name
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def getName(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return self.__name
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def read(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
return ConfigReader.read(self, "filter.d/" + self.__file)
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def getOptions(self, pOpts):
|
2008-08-12 22:05:13 +00:00
|
|
|
opts = [["string", "ignoreregex", ""],
|
2006-09-04 19:18:57 +00:00
|
|
|
["string", "failregex", ""]]
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__opts = ConfigReader.getOptions(self, "Definition", opts, pOpts)
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def convert(self):
|
|
|
|
stream = list()
|
2006-09-19 20:38:32 +00:00
|
|
|
for opt in self.__opts:
|
2008-08-12 22:05:13 +00:00
|
|
|
if opt == "failregex":
|
2006-12-23 16:31:00 +00:00
|
|
|
for regex in self.__opts[opt].split('\n'):
|
2006-12-23 23:20:16 +00:00
|
|
|
# Do not send a command if the rule is empty.
|
|
|
|
if regex != '':
|
|
|
|
stream.append(["set", self.__name, "addfailregex", regex])
|
2006-11-12 14:52:36 +00:00
|
|
|
elif opt == "ignoreregex":
|
2006-12-23 16:31:00 +00:00
|
|
|
for regex in self.__opts[opt].split('\n'):
|
2006-12-23 23:20:16 +00:00
|
|
|
# Do not send a command if the rule is empty.
|
|
|
|
if regex != '':
|
|
|
|
stream.append(["set", self.__name, "addignoreregex", regex])
|
2006-06-26 20:05:00 +00:00
|
|
|
return stream
|
2011-10-07 19:47:50 +00:00
|
|
|
|