mirror of https://github.com/fail2ban/fail2ban
BF+RF: Allow multiple of same action in a single jail
parent
7a29a952c1
commit
45c9c45b41
|
@ -43,27 +43,38 @@ class ActionReader(DefinitionInitConfigReader):
|
|||
["string", "actionunban", ""],
|
||||
]
|
||||
|
||||
def __init__(self, file_, jailName, initOpts, **kwargs):
|
||||
self._name = initOpts.pop("name", file_)
|
||||
DefinitionInitConfigReader.__init__(
|
||||
self, file_, jailName, initOpts, **kwargs)
|
||||
|
||||
def setName(self, name):
|
||||
self._name = name
|
||||
|
||||
def getName(self):
|
||||
return self._name
|
||||
|
||||
def read(self):
|
||||
return ConfigReader.read(self, os.path.join("action.d", self._file))
|
||||
|
||||
def convert(self):
|
||||
head = ["set", self._name]
|
||||
head = ["set", self._jailName]
|
||||
stream = list()
|
||||
stream.append(head + ["addaction", self._file])
|
||||
stream.append(head + ["addaction", self._name])
|
||||
for opt in self._opts:
|
||||
if opt == "actionstart":
|
||||
stream.append(head + ["actionstart", self._file, self._opts[opt]])
|
||||
stream.append(head + ["actionstart", self._name, self._opts[opt]])
|
||||
elif opt == "actionstop":
|
||||
stream.append(head + ["actionstop", self._file, self._opts[opt]])
|
||||
stream.append(head + ["actionstop", self._name, self._opts[opt]])
|
||||
elif opt == "actioncheck":
|
||||
stream.append(head + ["actioncheck", self._file, self._opts[opt]])
|
||||
stream.append(head + ["actioncheck", self._name, self._opts[opt]])
|
||||
elif opt == "actionban":
|
||||
stream.append(head + ["actionban", self._file, self._opts[opt]])
|
||||
stream.append(head + ["actionban", self._name, self._opts[opt]])
|
||||
elif opt == "actionunban":
|
||||
stream.append(head + ["actionunban", self._file, self._opts[opt]])
|
||||
stream.append(head + ["actionunban", self._name, self._opts[opt]])
|
||||
# cInfo
|
||||
if self._initOpts:
|
||||
for p in self._initOpts:
|
||||
stream.append(head + ["setcinfo", self._file, p, self._initOpts[p]])
|
||||
stream.append(head + ["setcinfo", self._name, p, self._initOpts[p]])
|
||||
|
||||
return stream
|
||||
|
|
|
@ -145,7 +145,7 @@ class DefinitionInitConfigReader(ConfigReader):
|
|||
def __init__(self, file_, jailName, initOpts, **kwargs):
|
||||
ConfigReader.__init__(self, **kwargs)
|
||||
self._file = file_
|
||||
self._name = jailName
|
||||
self._jailName = jailName
|
||||
self._initOpts = initOpts
|
||||
|
||||
def setFile(self, fileName):
|
||||
|
@ -154,11 +154,11 @@ class DefinitionInitConfigReader(ConfigReader):
|
|||
def getFile(self):
|
||||
return self.__file
|
||||
|
||||
def setName(self, name):
|
||||
self._name = name
|
||||
def setJailName(self, jailName):
|
||||
self._jailName = jailName
|
||||
|
||||
def getName(self):
|
||||
return self._name
|
||||
def getJailName(self):
|
||||
return self._jailName
|
||||
|
||||
def read(self):
|
||||
return ConfigReader.read(self, self._file)
|
||||
|
|
|
@ -50,14 +50,14 @@ class FilterReader(DefinitionInitConfigReader):
|
|||
for regex in self._opts[opt].split('\n'):
|
||||
# Do not send a command if the rule is empty.
|
||||
if regex != '':
|
||||
stream.append(["set", self._name, "addfailregex", regex])
|
||||
stream.append(["set", self._jailName, "addfailregex", regex])
|
||||
elif opt == "ignoreregex":
|
||||
for regex in self._opts[opt].split('\n'):
|
||||
# Do not send a command if the rule is empty.
|
||||
if regex != '':
|
||||
stream.append(["set", self._name, "addignoreregex", regex])
|
||||
stream.append(["set", self._jailName, "addignoreregex", regex])
|
||||
if self._initOpts:
|
||||
if 'maxlines' in self._initOpts:
|
||||
stream.append(["set", self._name, "maxlines", self._initOpts["maxlines"]])
|
||||
stream.append(["set", self._jailName, "maxlines", self._initOpts["maxlines"]])
|
||||
return stream
|
||||
|
||||
|
|
Loading…
Reference in New Issue