scripts/rbl_expire.sh

30 lines
935 B
Bash
Raw Normal View History

2015-03-26 19:55:39 +01:00
#!/usr/bin/env bash
#
# Expire old RBL records
2015-06-27 13:00:25 +02:00
listtype=$1
if ! [[ "$listtype" =~ ^[4,6]+$ ]]; then
2018-10-09 13:37:19 +02:00
echo "first parameter is mandatory and must be either 4 or 6."
exit 1
2015-06-27 13:00:25 +02:00
fi
rblfile="/var/lib/rbldns/listv$listtype"
2018-10-09 13:37:19 +02:00
maxage=168 # in hours
2015-03-26 19:55:39 +01:00
2015-06-27 13:00:25 +02:00
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
2018-10-09 13:37:19 +02:00
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: $?"
fi
2015-06-27 13:00:25 +02:00
fi
done
fi
2015-03-26 19:55:39 +01:00
2015-06-27 13:00:25 +02:00
# FIXME: ipv6 regex needed
if [ $listtype -eq 6 ]; then
:
fi
2018-10-09 13:37:19 +02:00
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4