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 ActionReader(ConfigReader):
|
|
|
|
|
2013-02-17 22:03:23 +00:00
|
|
|
def __init__(self, action, name, **kwargs):
|
|
|
|
ConfigReader.__init__(self, **kwargs)
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__file = action[0]
|
|
|
|
self.__cInfo = action[1]
|
|
|
|
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, "action.d/" + self.__file)
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def getOptions(self, pOpts):
|
2006-07-08 16:51:14 +00:00
|
|
|
opts = [["string", "actionstart", ""],
|
2006-06-26 20:05:00 +00:00
|
|
|
["string", "actionstop", ""],
|
|
|
|
["string", "actioncheck", ""],
|
|
|
|
["string", "actionban", ""],
|
|
|
|
["string", "actionunban", ""]]
|
2006-09-19 20:38:32 +00:00
|
|
|
self.__opts = ConfigReader.getOptions(self, "Definition", opts, pOpts)
|
2006-07-16 21:35:08 +00:00
|
|
|
|
|
|
|
if self.has_section("Init"):
|
|
|
|
for opt in self.options("Init"):
|
2006-09-19 20:38:32 +00:00
|
|
|
if not self.__cInfo.has_key(opt):
|
|
|
|
self.__cInfo[opt] = self.get("Init", opt)
|
2006-06-26 20:05:00 +00:00
|
|
|
|
|
|
|
def convert(self):
|
2006-09-19 20:38:32 +00:00
|
|
|
head = ["set", self.__name]
|
2006-06-26 20:05:00 +00:00
|
|
|
stream = list()
|
2006-09-19 20:38:32 +00:00
|
|
|
stream.append(head + ["addaction", self.__file])
|
|
|
|
for opt in self.__opts:
|
2006-07-08 16:51:14 +00:00
|
|
|
if opt == "actionstart":
|
2006-09-19 20:38:32 +00:00
|
|
|
stream.append(head + ["actionstart", self.__file, self.__opts[opt]])
|
2006-06-26 20:05:00 +00:00
|
|
|
elif opt == "actionstop":
|
2006-09-19 20:38:32 +00:00
|
|
|
stream.append(head + ["actionstop", self.__file, self.__opts[opt]])
|
2006-06-26 20:05:00 +00:00
|
|
|
elif opt == "actioncheck":
|
2006-09-19 20:38:32 +00:00
|
|
|
stream.append(head + ["actioncheck", self.__file, self.__opts[opt]])
|
2006-06-26 20:05:00 +00:00
|
|
|
elif opt == "actionban":
|
2006-09-19 20:38:32 +00:00
|
|
|
stream.append(head + ["actionban", self.__file, self.__opts[opt]])
|
2006-06-26 20:05:00 +00:00
|
|
|
elif opt == "actionunban":
|
2006-09-19 20:38:32 +00:00
|
|
|
stream.append(head + ["actionunban", self.__file, self.__opts[opt]])
|
2006-07-16 21:35:08 +00:00
|
|
|
# cInfo
|
2006-09-19 20:38:32 +00:00
|
|
|
if self.__cInfo:
|
|
|
|
for p in self.__cInfo:
|
|
|
|
stream.append(head + ["setcinfo", self.__file, p, self.__cInfo[p]])
|
2006-07-16 21:35:08 +00:00
|
|
|
|
2006-06-26 20:05:00 +00:00
|
|
|
return stream
|
2011-10-07 19:47:50 +00:00
|
|
|
|