Compare commits

..

No commits in common. "bccf51d4a47a3ace3e35809ae57af804f7946f97" and "a512b79d5847b12c09126076078d453ad23e374e" have entirely different histories.

4 changed files with 8 additions and 19 deletions

View File

@ -6,26 +6,18 @@ stopforumspam API](https://www.stopforumspam.com/usage) and system firewall
To deploy: To deploy:
1. Modify the configuration variables in the scripts as needed. 1. Modify the configuration variables in the scripts as neede.
2. Copy the scripts to `/usr/local/bin` (requires root): 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 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 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: 3. Create the user the scripts will run as:
useradd -s /sbin/nologin _forumspam useradd -s /sbin/nologin _forumspam
4. Set up the firewall program 4. If using `pf`:
If using `ufw`, install it:
apt update
apt install ufw
If using `pf`:
Create appropriate permissions for the file: Create appropriate permissions for the file:
@ -63,6 +55,3 @@ TODO:
* also check against [botscout](http://botscout.com/api.htm) * also check against [botscout](http://botscout.com/api.htm)
* give the scripts more sensible names * give the scripts more sensible names
* also create an rc script * 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 Description=Forumspam Block Daemon
[Service] [Service]
User=_forumspam User=forumspam
Group=_forumspam Group=forumspam
ExecStart=/usr/local/bin/q2a_usercheck.sh ExecStart=/usr/local/bin/q2a_usercheck.sh
[Install] [Install]

View File

@ -26,7 +26,7 @@ abort() {
block_ip() { block_ip() {
case "$fw_cmd" in case "$fw_cmd" in
ufw) 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 echo `date` blocked ip $ip with freq $freq >> $logf
else else
abort "failed to block ip $ip" 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 tail -F $logf | while read line ; do
case $line in (*"POST"*) case $line in (*"POST"*)
ip=`echo $line | awk '{print $1}'` ip=`echo $line | awk '{print $1}'`
ip_regex=`echo $ip | sed 's/\./\\./g'` if ! grep -q $ip $cache; then
if ! grep -q $ip_regex $cache; then echo $ip >> $cache
/usr/local/bin/forumspam.sh "$ip" && echo $ip >> $cache /usr/local/bin/forumspam.sh "$ip"
fi fi
esac esac
done done