# Create or update the list of temporarily banned IPs.
#
-BLOCKEDFILE=/home/lonvia/nominatim/settings/ip_blocks
-LOGFILE=/home/lonvia/nominatim/log/ip_blocks.log
+BASEDIR="$( cd "$( dirname "$0" )" && cd .. && pwd )"
+if [ "x$BASEDIR" == "x" ]; then
+ echo "Could not determine base dir."
+ exit -1
+fi
+
+BLOCKEDFILE=$BASEDIR/settings/ip_blocks
+LOGFILE=$BASEDIR/log/ip_blocks.log
LONG_PERIOD='1 hour'
SHORT_PERIOD='10 min'
PSQLCMD='psql -qtA -d nominatim'
+curload=`cat /proc/loadavg | sed 's:[. ].*::'`
+if [ "$curload" -gt "15" ]; then
+ REVSHORT_LIMIT=$((REVSHORT_LIMIT/2))
+fi
+
# Blocking candidates
$PSQLCMD > $BLOCKEDFILE.newblocks << ENDOFQUERY
SELECT ipaddress FROM
mv $BLOCKEDFILE.newblocks $BLOCKEDFILE
else
$PSQLCMD > $BLOCKEDFILE.newlifted << ENDOFQUERY
+ SELECT column1 FROM (
VALUES ('$blocked')
EXCEPT
(SELECT DISTINCT ipaddress FROM new_query_log
WHERE starttime > now() - interval '$COOLOFF_PERIOD')
+ ) as q ORDER BY column1;
ENDOFQUERY
no_lifted=`cat $BLOCKEDFILE.newlifted | wc -w`