Skip to content

Commit

Permalink
NF: Allow return of list of actions from jail via fail2ban-client
Browse files Browse the repository at this point in the history
  • Loading branch information
kwirk committed Apr 28, 2013
1 parent a3e216b commit 6d2ff47
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions fail2ban/client/beautifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ def beautify(self, response):
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` +
Expand Down
1 change: 1 addition & 0 deletions fail2ban/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
["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>"],
Expand Down
8 changes: 8 additions & 0 deletions fail2ban/server/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def getLastAction(self):
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.
#
Expand Down
3 changes: 3 additions & 0 deletions fail2ban/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def addAction(self, name, value):
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)

Expand Down
2 changes: 2 additions & 0 deletions fail2ban/server/transmitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ def __commandGet(self, command):
# 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":
Expand Down
6 changes: 5 additions & 1 deletion fail2ban/tests/servertestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,12 @@ def testAction(self):
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(
Expand Down

0 comments on commit 6d2ff47

Please sign in to comment.