diff --git a/fail2ban/client/beautifier.py b/fail2ban/client/beautifier.py index 21c49b94..0ad7e7a6 100644 --- a/fail2ban/client/beautifier.py +++ b/fail2ban/client/beautifier.py @@ -252,7 +252,7 @@ class Beautifier: sep = " " if len(inC) <= 3 else inC[3] if sep == "--with-time": sep = "\n" - msg = sep.join(response) + msg = sep.join([str(res) for res in response]) except Exception: logSys.warning("Beautifier error. Please report the error") logSys.error("Beautify %r with %r failed", response, self.__inputCmd, diff --git a/fail2ban/helpers.py b/fail2ban/helpers.py index 220753a7..0e1da5bd 100644 --- a/fail2ban/helpers.py +++ b/fail2ban/helpers.py @@ -28,6 +28,7 @@ import re import sys import traceback +from ast import literal_eval from threading import Lock from .server.mytime import MyTime @@ -317,6 +318,16 @@ def _merge_copy_dicts(x, y): """ return {**x, **y} +def parseExpressions(value): + def parseExpr(v): + try: + return literal_eval(v) + except SyntaxError: + return v + if value: + return list(map(parseExpr, value)) if isinstance(value, (list, tuple)) else parseExpr(value) + return None + # # Following function used for parse options from parameter (e.g. `name[p1=0, p2="..."][p3='...']`). # diff --git a/fail2ban/protocol.py b/fail2ban/protocol.py index 872da37b..641edb6e 100644 --- a/fail2ban/protocol.py +++ b/fail2ban/protocol.py @@ -54,9 +54,9 @@ protocol = [ ["reload [--restart] [--unban] [--if-exists] ", "reloads the jail , or restarts it (if option '--restart' specified)"], ["stop", "stops all jails and terminate the server"], ["unban --all", "unbans all IP addresses (in all jails and database)"], -["unban ... ", "unbans (in all jails and database)"], +["unban [--expr] [--] ... ", "unbans (in all jails and database)"], ["banned", "return jails with banned IPs as dictionary"], -["banned ... ]", "return list(s) of jails where given IP(s) are banned"], +["banned [--expr] [--] ... ]", "return list(s) of jails where given IP(s) are banned"], ["status", "gets the current status of the server"], ["status --all [FLAVOR]", "gets the current status of all jails, with optional output style [FLAVOR]. Flavors: 'basic' (default), 'cymru', 'short', 'stats'"], ["stat[istic]s", "gets the current statistics of all jails as table"], @@ -87,8 +87,8 @@ protocol = [ ['', "JAIL CONFIGURATION", ""], ["set idle on|off", "sets the idle state of "], ["set ignoreself true|false", "allows the ignoring of own IP addresses"], -["set addignoreip ", "adds to the ignore list of "], -["set delignoreip ", "removes from the ignore list of "], +["set addignoreip [--expr] [--] ... ", "adds to the ignore list of "], +["set delignoreip [--expr] [--] ... ", "removes from the ignore list of "], ["set ignorecommand ", "sets ignorecommand of "], ["set ignorecache ", "sets ignorecache of "], ["set addlogpath ['tail']", "adds to the monitoring list of , optionally starting at the 'tail' of the file (default 'head')."], @@ -104,9 +104,9 @@ protocol = [ ["set bantime