3 QUICK_WHITELIST=192.168.10.10
5 alias log="logger -st http-ban"
6 alias show="doas /sbin/pfctl -t players -T show"
7 alias ban="doas /sbin/pfctl -t players -T add -f-"
8 alias grace="doas /sbin/pfctl -t players -T delete -f-"
10 # Filter functions returning 'count IP' based on HTTP return code
12 awk '$(NF-1) >= 300 && $(NF-1) < 400 { print $2 }' | sort | uniq -c
16 awk '$(NF-1) >= 400 && $(NF-1) < 500 { print $2 }' | sort | uniq -c
20 awk '$(NF-1) >= 500 && $(NF-1) < 600 { print $2 }' | sort | uniq -c
26 doas /bin/cat /var/www/logs/access.log
27 doas /usr/bin/zcat /var/www/logs/access.log.*gz 2>/dev/null
31 GF=$(for ip in $(printf %s\\n $QUICK_WHITELIST); do printf -- '-ve %s\n' "$ip"; done)
37 awk -vtrig="${1:-10}" ' $1 >= trig { print $2 }'
41 access | IN_500_HOSTS | limit 1
42 access | IN_400_HOSTS | limit 3
43 access | IN_300_HOSTS | limit 3
47 pre_block | sort | uniq | apply_whitelist
52 block | sort >/tmp/http-ban.new
54 show | sort | awk '{ print $1 }' >/tmp/http-ban.current
56 DIFF=$(comm /tmp/http-ban.new /tmp/http-ban.current)
57 NEW=$(comm -23 /tmp/http-ban.new /tmp/http-ban.current)
58 GRACE=$(comm -13 /tmp/http-ban.new /tmp/http-ban.current)
62 test -n "$NEW" -o -n "$GRACE" || exit 0
65 if test -n "$NEW"; then
75 # There's Old IP's not attacking anymore
76 if test -n "$GRACE"; then