Last active 1731172111

ubl-openbsd.sh Raw
1#!/bin/sh
2#
3# Author: Dominic Reich <quick.hat4396@qtztsjosmprqmgtunjyf.com>
4# export the blacklist table from pf (pfctl -t blacklist)
5# to the blocked.txt file on my http webroot
6
7if [[ $USER == "root" ]]; then
8 echo >&2 "user must not be root! exiting."
9 exit 1
10fi
11
12# add ips to table blacklist
13(for ip in `cat ~/ips`; do echo $ip;done) | xargs doas pfctl -t blacklist -T add
14
15# save sorted table blacklist into file /etc/blacklist
16doas pfctl -t blacklist -T show | sort -h | uniq | doas tee /etc/blacklist 1>/dev/null
17
18# continue to update the blocked.txt file in the webserver root
19# available at http://bor.oe7drt.com/blocked.txt
20BLOCKEDTXT=/home/dominic/pub/blocked/web.txt
21FILEBACKUP=3
22
23if [ ${FILEBACKUP} -ne 0 ]; then
24 cp ${BLOCKEDTXT} ${BLOCKEDTXT}.$(date +%Y%m%d)
25fi
26
27BACKUPCOUNT=$(ls ${BLOCKEDTXT}.* | wc -l)
28BACKUPSTODELETE=$(expr ${BACKUPCOUNT} - ${FILEBACKUP})
29if [ ${BACKUPCOUNT} -gt ${FILEBACKUP} ]; then
30 for f in $(ls -tr ${BLOCKEDTXT}.* | head -${BACKUPSTODELETE})
31 do
32 rm ${f}
33 done
34fi
35
36rm -f ~/ips
37
38doas pfctl -t blacklist -T show | tee ${BLOCKEDTXT} 1>/dev/null
39
40doas pfctl -t blacklist -T test $(w | tail -1 | awk '{ print $3}')
41
42echo
43
44#doas pfctl -nf /etc/pf.conf
45
46doas pfctl -vf /etc/pf.conf
47
48echo doas pfctl -ss
49echo doas pfctl -Fs
50