mirror of https://github.com/fail2ban/fail2ban
NF: Allow return of list of actions from jail via fail2ban-client
parent
a3e216b0b2
commit
6d2ff47e71
|
@ -132,6 +132,12 @@ class Beautifier:
|
|||
msg = msg + "|- [" + str(c) + "]: " + ip + "\n"
|
||||
c += 1
|
||||
msg = msg + "`- [" + str(c) + "]: " + response[len(response)-1]
|
||||
elif inC[2] == "actions":
|
||||
if len(response) == 0:
|
||||
msg = "No actions for jail %s" % inC[1]
|
||||
else:
|
||||
msg = "The jail %s has the following actions:\n" % inC[1]
|
||||
msg += ", ".join(action.getName() for action in response)
|
||||
except Exception:
|
||||
logSys.warning("Beautifier error. Please report the error")
|
||||
logSys.error("Beautify " + `response` + " with " + `self.__inputCmd` +
|
||||
|
|
|
@ -90,6 +90,7 @@ protocol = [
|
|||
["get <JAIL> maxretry", "gets the number of failures allowed for <JAIL>"],
|
||||
["get <JAIL> maxlines", "gets the number of lines to buffer for <JAIL>"],
|
||||
["get <JAIL> addaction", "gets the last action which has been added for <JAIL>"],
|
||||
["get <JAIL> actions", "gets a list of actions for <JAIL>"],
|
||||
["get <JAIL> actionstart <ACT>", "gets the start command for the action <ACT> for <JAIL>"],
|
||||
["get <JAIL> actionstop <ACT>", "gets the stop command for the action <ACT> for <JAIL>"],
|
||||
["get <JAIL> actioncheck <ACT>", "gets the check command for the action <ACT> for <JAIL>"],
|
||||
|
|
|
@ -104,6 +104,14 @@ class Actions(JailThread):
|
|||
self.__actions.append(action)
|
||||
return action
|
||||
|
||||
##
|
||||
# Returns the list of actions
|
||||
#
|
||||
# @return list of actions
|
||||
|
||||
def getActions(self):
|
||||
return self.__actions
|
||||
|
||||
##
|
||||
# Set the ban time.
|
||||
#
|
||||
|
|
|
@ -236,6 +236,9 @@ class Server:
|
|||
def getLastAction(self, name):
|
||||
return self.__jails.getAction(name).getLastAction()
|
||||
|
||||
def getActions(self, name):
|
||||
return self.__jails.getAction(name).getActions()
|
||||
|
||||
def delAction(self, name, value):
|
||||
self.__jails.getAction(name).delAction(value)
|
||||
|
||||
|
|
|
@ -265,6 +265,8 @@ class Transmitter:
|
|||
# Action
|
||||
elif command[1] == "bantime":
|
||||
return self.__server.getBanTime(name)
|
||||
elif command[1] == "actions":
|
||||
return self.__server.getActions(name)
|
||||
elif command[1] == "addaction":
|
||||
return self.__server.getLastAction(name).getName()
|
||||
elif command[1] == "actionstart":
|
||||
|
|
|
@ -440,8 +440,12 @@ class Transmitter(TransmitterBase):
|
|||
self.transm.proceed(["set", self.jailName, "addaction", action]),
|
||||
(0, action))
|
||||
self.assertEqual(
|
||||
self.transm.proceed(["get", self.jailName, "addaction", action]),
|
||||
self.transm.proceed(["get", self.jailName, "addaction"]),
|
||||
(0, action))
|
||||
self.assertEqual(
|
||||
self.transm.proceed(
|
||||
["get", self.jailName, "actions"])[1][0].getName(),
|
||||
action)
|
||||
for cmd, value in zip(cmdList, cmdValueList):
|
||||
self.assertEqual(
|
||||
self.transm.proceed(
|
||||
|
|
Loading…
Reference in New Issue