This repository has been archived on 2025-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
q2a-antispam/forumspam.sh
2020-09-06 11:26:45 -07:00

33 lines
701 B
Bash
Executable File

#!/bin/sh
# API reference: https://www.stopforumspam.com/usage
ip=$1
repl=`mktemp`
logf=/var/log/forumspam.log
curl 'http://api.stopforumspam.org/api?ip='$ip 2>/dev/null > $repl
if ! grep -q '<response success="true">' $repl; then
echo error failed to query stopforumspam api >> $logf
rm $repl
exit 1
fi
if ! grep -q '<appears>yes</appears>' $repl; then
rm $repl
exit 0
fi
freq=`grep '<frequency>' $repl | sed 's/<frequency>//; s!</frequency>!!'`
if [ "$freq" -ge 1 ]; then
if ufw deny from $ip >/dev/null 2>>$logf; then
echo `date` blocked ip $ip with freq $freq >> $logf
rm $repl
exit 0
else
echo `date` "error failed to block ip $ip" >> $logf
rm $repl
exit 2
fi
fi
rm $repl