Compare commits

...

5 Commits

Author SHA1 Message Date
sceox
bccf51d4a4 learn to sh right 2020-11-18 16:21:34 -08:00
sceox
323f926e53 do not cache IP on errors 2020-11-18 16:20:23 -08:00
sceox
17751c93f3 check for literal . when checking IP against cache 2020-11-18 16:18:52 -08:00
sceox
a6fdf3921e update README 2020-11-18 16:17:00 -08:00
sceox
e741dc37ee run systemd service as _forumspam user 2020-11-18 16:13:19 -08:00
4 changed files with 19 additions and 8 deletions

View File

@ -6,18 +6,26 @@ stopforumspam API](https://www.stopforumspam.com/usage) and system firewall
To deploy:
1. Modify the configuration variables in the scripts as neede.
1. Modify the configuration variables in the scripts as needed.
2. Copy the scripts to `/usr/local/bin` (requires root):
install -m 755 -o root -g bin forumspam.sh /usr/local/bin/forumspam.sh
install -m 755 -o root -g bin q2a_usercheck.sh /usr/local/bin/q2a_usercheck.sh
install -m 640 -o _forumspam /dev/null /var/log/forumspam.log
3. Create the user the scripts will run as:
useradd -s /sbin/nologin _forumspam
4. If using `pf`:
4. Set up the firewall program
If using `ufw`, install it:
apt update
apt install ufw
If using `pf`:
Create appropriate permissions for the file:
@ -55,3 +63,6 @@ TODO:
* also check against [botscout](http://botscout.com/api.htm)
* give the scripts more sensible names
* also create an rc script
* support `iptables`
* create a Makefile
* merge the two scripts into one

View File

@ -2,8 +2,8 @@
Description=Forumspam Block Daemon
[Service]
User=forumspam
Group=forumspam
User=_forumspam
Group=_forumspam
ExecStart=/usr/local/bin/q2a_usercheck.sh
[Install]

View File

@ -26,7 +26,7 @@ abort() {
block_ip() {
case "$fw_cmd" in
ufw)
if [ "$getroot" ufw deny from $ip >/dev/null 2>>$logf ]; then
if "$getroot" ufw deny from $ip >/dev/null 2>>$logf; then
echo `date` blocked ip $ip with freq $freq >> $logf
else
abort "failed to block ip $ip"

View File

@ -8,9 +8,9 @@ test -f $cache || install -m 600 /dev/null $cache
tail -F $logf | while read line ; do
case $line in (*"POST"*)
ip=`echo $line | awk '{print $1}'`
if ! grep -q $ip $cache; then
echo $ip >> $cache
/usr/local/bin/forumspam.sh "$ip"
ip_regex=`echo $ip | sed 's/\./\\./g'`
if ! grep -q $ip_regex $cache; then
/usr/local/bin/forumspam.sh "$ip" && echo $ip >> $cache
fi
esac
done