diff --git a/fail2ban/client/beautifier.py b/fail2ban/client/beautifier.py index a0ff8ff3..a92e9520 100644 --- a/fail2ban/client/beautifier.py +++ b/fail2ban/client/beautifier.py @@ -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` + diff --git a/fail2ban/protocol.py b/fail2ban/protocol.py index cacde4c2..334e7908 100644 --- a/fail2ban/protocol.py +++ b/fail2ban/protocol.py @@ -90,6 +90,7 @@ protocol = [ ["get maxretry", "gets the number of failures allowed for "], ["get maxlines", "gets the number of lines to buffer for "], ["get addaction", "gets the last action which has been added for "], +["get actions", "gets a list of actions for "], ["get actionstart ", "gets the start command for the action for "], ["get actionstop ", "gets the stop command for the action for "], ["get actioncheck ", "gets the check command for the action for "], diff --git a/fail2ban/server/actions.py b/fail2ban/server/actions.py index b7e58975..c0e6899d 100644 --- a/fail2ban/server/actions.py +++ b/fail2ban/server/actions.py @@ -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. # diff --git a/fail2ban/server/server.py b/fail2ban/server/server.py index 632d0546..092867bf 100644 --- a/fail2ban/server/server.py +++ b/fail2ban/server/server.py @@ -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) diff --git a/fail2ban/server/transmitter.py b/fail2ban/server/transmitter.py index 2a4514da..b293217e 100644 --- a/fail2ban/server/transmitter.py +++ b/fail2ban/server/transmitter.py @@ -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": diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index 385b83d4..67c7e6ae 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -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(