2020-10-04 19:07:39 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2020-12-16 14:22:49 +00:00
|
|
|
# load some functions
|
2021-03-17 16:55:56 +00:00
|
|
|
. /opt/entrypoint/utils.sh
|
2020-12-16 10:43:41 +00:00
|
|
|
|
2020-12-16 14:22:49 +00:00
|
|
|
# copy old conf to cache
|
|
|
|
|
cp /etc/nginx/block-abusers.conf /cache
|
|
|
|
|
|
2021-03-16 16:56:24 +00:00
|
|
|
# if we are running nginx
|
|
|
|
|
if [ -f /tmp/nginx.pid ] ; then
|
|
|
|
|
RELOAD="/usr/sbin/nginx -s reload > /dev/null 2>&1"
|
|
|
|
|
# if we are in autoconf
|
2021-03-17 11:16:56 +00:00
|
|
|
elif [ -S /tmp/autoconf.sock ] ; then
|
2021-03-16 16:56:24 +00:00
|
|
|
RELOAD="/opt/entrypoint/reload.py"
|
|
|
|
|
fi
|
|
|
|
|
|
2020-12-16 14:22:49 +00:00
|
|
|
# generate the new conf
|
2020-10-04 19:07:39 +00:00
|
|
|
curl -s "https://iplists.firehol.org/files/firehol_abusers_30d.netset" | grep -v "^\#.*" |
|
|
|
|
|
while read entry ; do
|
2020-10-24 18:48:04 +00:00
|
|
|
check=$(echo $entry | grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/?[0-9]*$")
|
|
|
|
|
if [ "$check" != "" ] ; then
|
2020-12-16 14:22:49 +00:00
|
|
|
echo "deny ${entry};" >> /tmp/block-abusers.conf
|
2020-10-24 18:48:04 +00:00
|
|
|
fi
|
2020-10-04 19:07:39 +00:00
|
|
|
done
|
2020-12-16 10:43:41 +00:00
|
|
|
|
2020-12-16 14:22:49 +00:00
|
|
|
# check if we have at least 1 line
|
|
|
|
|
lines="$(wc -l /tmp/block-abusers.conf | cut -d ' ' -f 1)"
|
2020-12-16 10:43:41 +00:00
|
|
|
if [ "$lines" -gt 1 ] ; then
|
|
|
|
|
job_log "[BLACKLIST] abusers list updated ($lines entries)"
|
2020-12-16 14:22:49 +00:00
|
|
|
# reload nginx with the new config
|
|
|
|
|
mv /tmp/block-abusers.conf /etc/nginx/block-abusers.conf
|
2021-03-16 16:56:24 +00:00
|
|
|
if [ "$RELOAD" != "" ] ; then
|
|
|
|
|
$RELOAD
|
2020-12-16 14:22:49 +00:00
|
|
|
# new config is ok : save it in the cache
|
|
|
|
|
if [ "$?" -eq 0 ] ; then
|
|
|
|
|
cp /etc/nginx/block-abusers.conf /cache
|
|
|
|
|
job_log "[NGINX] successfull nginx reload after abusers list update"
|
|
|
|
|
else
|
|
|
|
|
job_log "[NGINX] failed nginx reload after abusers list update fallback to old list"
|
|
|
|
|
cp /cache/block-abusers.conf /etc/nginx
|
2021-03-16 16:56:24 +00:00
|
|
|
$RELOAD
|
2020-12-16 14:22:49 +00:00
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
cp /etc/nginx/block-abusers.conf /cache
|
|
|
|
|
fi
|
2020-12-16 10:43:41 +00:00
|
|
|
else
|
|
|
|
|
job_log "[BLACKLIST] can't update abusers list"
|
|
|
|
|
fi
|
|
|
|
|
|
2020-12-16 14:22:49 +00:00
|
|
|
rm -f /tmp/block-abusers.conf 2> /dev/null
|
|
|
|
|
|