Simplify fail2ban output (#2703)

This commit is contained in:
Casper 2022-07-29 18:14:35 +02:00 committed by GitHub
parent 57aeb6db2a
commit 11f8cc7ee9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,7 +9,6 @@ fail2ban-client ping &>/dev/null || _exit_with_error "Fail2ban not running"
unset JAILS unset JAILS
declare -a JAILS declare -a JAILS
IP_REGEXP='((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
for LIST in $(fail2ban-client status | grep "Jail list" | cut -f2- | sed 's/,/ /g') for LIST in $(fail2ban-client status | grep "Jail list" | cut -f2- | sed 's/,/ /g')
do do
@ -22,13 +21,11 @@ then
for JAIL in "${JAILS[@]}" for JAIL in "${JAILS[@]}"
do do
BANNED_IPS=$(fail2ban-client status "${JAIL}" \ BANNED_IPS=$(fail2ban-client status "${JAIL}" | grep -oP '(?<=Banned IP list:\s).+')
| grep 'Banned IP list' \
| grep -oE "${IP_REGEXP}")
if [[ -n ${BANNED_IPS} ]] if [[ -n ${BANNED_IPS} ]]
then then
echo "Banned in ${JAIL}: ${BANNED_IPS//$'\n'/, }" echo "Banned in ${JAIL}: ${BANNED_IPS}"
IPS_BANNED=1 IPS_BANNED=1
fi fi
done done