Compare commits

...

3 Commits

Author SHA1 Message Date
sceox
19ddf883ee improve IP address regex 2021-12-27 15:27:52 -08:00
sceox
c64617f937 set nologin shell correctly on different OSs 2021-12-27 15:26:58 -08:00
sceox
4a28125ee2 automatically set tail -F or -f by checking uname 2021-12-27 15:24:39 -08:00
2 changed files with 7 additions and 3 deletions

View File

@ -16,7 +16,7 @@ To deploy:
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 $(which nologin) _forumspam
4. Set up the firewall program 4. Set up the firewall program

View File

@ -2,14 +2,18 @@
logf='/var/log/nginx/access.log' logf='/var/log/nginx/access.log'
cache='/tmp/forumspam_cache' cache='/tmp/forumspam_cache'
tail_opts='-F' # set to `-f` on OpenBSD!
case `uname` in
(*"BSD"*) tail_opts='-f';;
(*) tail_opts='-F';;
esac
test -f $cache || install -m 600 /dev/null $cache test -f $cache || install -m 600 /dev/null $cache
tail $tail_opts $logf | while read line ; do tail $tail_opts $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'` ip_regex=`echo $ip | sed 's/\./\\./g; s/^/^/; s/$/$/'`
if ! grep -q $ip_regex $cache; then if ! grep -q $ip_regex $cache; then
/usr/local/bin/forumspam.sh "$ip" && echo $ip >> $cache /usr/local/bin/forumspam.sh "$ip" && echo $ip >> $cache
fi fi