various fixed to RBL scripts

This commit is contained in:
Oliver Ladner 2018-10-09 13:37:19 +02:00
commit ef64b181cc
3 changed files with 24 additions and 29 deletions

0
foo
View file

View file

@ -8,13 +8,12 @@ if ! [[ "$listtype" =~ ^[4,6]+$ ]]; then
exit 1
fi
rblfile="/var/lib/rbldns/listv$listtype"
maxage=96 # in hours
maxage=168 # in hours
if [ $listtype -eq 4 ]; then
egrep '^[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}' $rblfile | while read -r ip delimiter timestamp foo; do
if [ "$timestamp" -gt "0" ]; then
expiration=$(echo "$(date +%s)-$timestamp" | bc)
if [ "$expiration" -gt "$(($maxage * 3600))" ]; then
#echo "DEBUG: entry $ip older than $maxage hours (expired $(($expiration / 3600)) hours ago)"
sed -i "/^$ip.*# $timestamp.*$/d" $rblfile || echo "Error while deleting $ip: $?"
@ -27,3 +26,5 @@ fi
if [ $listtype -eq 6 ]; then
:
fi
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

View file

@ -14,12 +14,9 @@ fi
rblfile="/var/lib/rbldns/listv$listtype"
function dnsq {
if [ $listtype == "4" ]; then
echo "$(dig +short $1)"
elif [ $listtype == "6" ]; then
echo "$(dig +short AAAA $1)"
else
echo "unknown, fix it"
if [ $listtype == "4" ]; then echo "$(dig +short $1)"
elif [ $listtype == "6" ]; then echo "$(dig +short AAAA $1)"
else echo "unknown, fix it"
fi
}
@ -28,7 +25,6 @@ $(dnsq lugh.ch)
$(dnsq ipv6.lugh.ch)
$(dnsq oxi.ch)
$(dnsq mail.zephry.ch)
$(dnsq moni-und-oli.ch)
)
static_black=(
$(dnsq www.uceprotect.net)
@ -36,20 +32,13 @@ $(dnsq rsync-mirrors.uceprotect.net)
$(dnsq www.backscatterer.org)
$(dnsq unimatrix.admins.ws)
)
fail2ban_chains=(
fail2ban-dovecot
fail2ban-sasl
fail2ban-ssh
fail2ban-ssh-ddos
fail2ban-tumgreyspf
fail2ban-apache-digest
)
fail2ban_chains=$(/sbin/iptables -nL | grep ^f2b | awk {'print $1'})
ban_ip=()
# Get currently banned IPs from fail2ban chains
iptables_banned=(
$(for chain in ${fail2ban_chains[@]}; do
/sbin/iptables -nL $chain | grep '^DROP' | awk {'print $4'} | grep -v '0.0.0.0/0'
$(for chain in $fail2ban_chains; do
/sbin/iptables -w 1 -nL "$chain" | grep '^REJECT' | awk {'print $4'} | grep -v '0.0.0.0/0'
done | sort | uniq)
)
@ -71,7 +60,7 @@ cat << HEREDOC > $rblfile
# Test entry http://www.ietf.org/rfc/rfc5782.txt
$testentry
:127.0.0.2:$ is listed because of misbehaviour. See http://lugh.ch/dnsbl.html for details
:127.0.0.2:$ is listed because of misbehaviour. See https://lugh.ch/dnsbl.html for details
# Whitelist
$(printf "!%s # 0\n" "${static_white[@]}")
@ -124,4 +113,9 @@ for timestamp in $(grep -e '^[0-9]' /var/www/virtsrv/lugh.ch/listv$listtype.txt
done
# Concatenate IPv4 and IPv6 lists together
cat /var/www/virtsrv/lugh.ch/listv4.txt $(grep -e '^[0-9]' /var/www/virtsrv/lugh.ch/listv6.txt) > /var/www/virtsrv/lugh.ch/list.txt
echo -e "IP\t\tDate listed\t\t\tCause\t\t\t\t\tCountry" > /var/www/virtsrv/lugh.ch/list.txt
echo -e "--\t\t-----------\t\t\t-----\t\t\t\t\t-------" >> /var/www/virtsrv/lugh.ch/list.txt
tail -n+3 /var/www/virtsrv/lugh.ch/listv4.txt >> /var/www/virtsrv/lugh.ch/list.txt
tail -n+3 /var/www/virtsrv/lugh.ch/listv6.txt >> /var/www/virtsrv/lugh.ch/list.txt
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4