36 lines
951 B
Bash
Executable File
36 lines
951 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# IP should be first arg
|
|
if [ -n "$1" ]; then
|
|
IP=$1
|
|
else
|
|
echo "IP not set"
|
|
exit 1
|
|
fi
|
|
|
|
LAST_LINE=`grep -i "ban $IP" /var/log/fail2ban.log|tail -1`
|
|
|
|
if [ -z "$LAST_LINE" ]; then
|
|
# no bans found, doing search for Found
|
|
LAST_LINE=`grep "Found $IP" /var/log/fail2ban.log|tail -1`
|
|
if [ -z "$LAST_LINE" ]; then
|
|
echo "No matches for $IP"
|
|
exit
|
|
fi
|
|
fi
|
|
|
|
ACTION=`echo $LAST_LINE|awk '{ print $7 }'`
|
|
FILTER=`echo $LAST_LINE|awk -F'[][]' '{ print $4 }'`
|
|
|
|
if [ $ACTION = 'Ban' ] || [ $ACTION = 'Restore' ]; then
|
|
echo "unbanning & whitelisting $FILTER:$IP"
|
|
fail2ban-client set $FILTER unbanip $IP
|
|
fail2ban-client set $FILTER addignoreip $IP
|
|
elif [ $ACTION = 'Unban' ]; then
|
|
echo "$FILTER:$IP already autounbanned, whitelisting now"
|
|
fail2ban-client set $FILTER addignoreip $IP
|
|
elif [ $ACTION = 'Found' ]; then
|
|
echo "$IP not banned, but Found $FILTER:$IP, whitelisting now"
|
|
fail2ban-client set $FILTER addignoreip $IP
|
|
fi
|