-
Notifications
You must be signed in to change notification settings - Fork 0
/
fail2ban.sh
81 lines (67 loc) · 1.49 KB
/
fail2ban.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# BEGIN fail2ban script #
#!/bin/bash
source /etc/bash.d/select.sh
fail2ban() {
# emphasized (bolded) colors
BOLD=$'\033[1m';
COLOR=$'\033[0;33m'
COLOR2=$'\033[0;34m'
WHITE=$'\033[0;37m'
NONE=$'\033[0m'
JAILS=`fail2ban-client status | grep "Jail list" | sed -E 's/^[^:]+:[ \t]+//' | sed 's/,//g'`
IPS=()
for JAIL in $JAILS
do
#echo
fail2ban-client status $JAIL | sed -e "s/Status for the jail:/$WHITE$BOLD\Status:$COLOR2$BOLD/;s/failed/fails/;" -e "s/|-/$COLOR|-$NONE/g;s/\`\-/$COLOR\'-$NONE/g;s/|/$COLOR\|/g;"
echo
result=`fail2ban-client status $JAIL | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"`
for IP in $result
do
#echo [$IP]
IPS+=($IP)
done
done
if [ ${#IPS[@]} -eq 0 ]
then
return
fi
for arg in "$@"
do
if [ "$arg" == "--unban" ] || [ "$arg" == "-u" ]
then
#echo ${IPS[*]}
#for IP in ${IPS[*]}
#do
# echo
# echo $IP
#done
echo 'Current IPS in jail:'
echo
PS3=$'\nChoose IP [#/Enter] to exit # '
optionsAudits=('No')
opt=$(selectWithDefault "${IPS[@]}")
#for item in "${IPS[@]}"; do
# if [[ $item == $opt ]]; then
# break 2
# fi
#done
#echo "You have chosen $opt"
case $opt in
''|'No' )
echo
return
;;
esac
for jail in $JAILS; do fail2ban-client set $jail unbanip $opt > /dev/null 2>&1; done
#echo $opt;
#if ["$opt" = "Exit"]
#then
# break
#fi
#done
#echo $opt
fi
done
}
# END fail2ban script #