1
|
#!/bin/sh
|
2
|
|
3
|
# Update bogons file
|
4
|
# Part of the pfSense project
|
5
|
# www.pfsense.com
|
6
|
|
7
|
echo "rc.update_bogons.sh is starting up." | logger
|
8
|
|
9
|
# Sleep for some time, unless an argument is specified.
|
10
|
|
11
|
if [ "$1" = "" ]; then
|
12
|
# Grab a random value
|
13
|
value=`od -A n -d -N2 /dev/random | awk '{ print $1 }'`
|
14
|
echo "rc.update_bogons.sh is sleeping for $value" | logger
|
15
|
sleep $value
|
16
|
fi
|
17
|
|
18
|
echo "rc.update_bogons.sh is beginning the update cycle." | logger
|
19
|
|
20
|
/usr/bin/fetch -q -o /tmp/bogons "http://files.pfsense.org/lists/fullbogons-ipv4.txt"
|
21
|
/usr/bin/fetch -q -o /tmp/bogonsv6 "http://files.pfsense.org/lists/fullbogons-ipv6.txt"
|
22
|
if [ ! -f /tmp/bogons ]; then
|
23
|
echo "Could not download http://files.pfsense.org/lists/fullbogons-ipv4.txt" | logger
|
24
|
dl_error="true"
|
25
|
fi
|
26
|
if [ ! -f /tmp/bogonsv6 ]; then
|
27
|
echo "Could not download http://files.pfsense.org/lists/fullbogons-ipv6.txt" | logger
|
28
|
dl_error="true"
|
29
|
fi
|
30
|
|
31
|
if [ "$dl_error" != "" ];then
|
32
|
# Relaunch and sleep
|
33
|
sh /etc/rc.update_bogons.sh &
|
34
|
exit
|
35
|
fi
|
36
|
|
37
|
BOGON_V4_MD5=`/usr/bin/fetch -q -o - "http://files.pfsense.org/lists/fullbogons-ipv4.txt.md5" | awk '{ print $4 }'`
|
38
|
ON_DISK_V4_MD5=`md5 /tmp/bogons | awk '{ print $4 }'`
|
39
|
BOGON_V6_MD5=`/usr/bin/fetch -q -o - "http://files.pfsense.org/lists/fullbogons-ipv6.txt.md5" | awk '{ print $4 }'`
|
40
|
ON_DISK_V6_MD5=`md5 /tmp/bogonsv6 | awk '{ print $4 }'`
|
41
|
|
42
|
if [ "$BOGON_V4_MD5" = "$ON_DISK_V4_MD5" ] || [ "$BOGON_V6_MD5" = "$ON_DISK_V6_MD5" ]; then
|
43
|
# At least one of the downloaded MD5s matches, so mount RW
|
44
|
/etc/rc.conf_mount_rw
|
45
|
fi
|
46
|
|
47
|
if [ "$BOGON_V4_MD5" = "$ON_DISK_V4_MD5" ]; then
|
48
|
egrep -v "^192.168.0.0/16|^172.16.0.0/12|^10.0.0.0/8" /tmp/bogons > /etc/bogons
|
49
|
RESULT=`/sbin/pfctl -t bogons -T replace -f /etc/bogons 2>&1`
|
50
|
rm /tmp/bogons
|
51
|
echo "Bogons V4 file downloaded: $RESULT" | logger
|
52
|
else
|
53
|
echo "Could not download http://files.pfsense.org/lists/fullbogons-ipv4.txt.md5 (md5 mismatch)" | logger
|
54
|
md5_error="true"
|
55
|
fi
|
56
|
|
57
|
if [ "$BOGON_V6_MD5" = "$ON_DISK_V6_MD5" ]; then
|
58
|
egrep -v "^#" /tmp/bogonsv6 > /etc/bogonsv6
|
59
|
RESULT=`/sbin/pfctl -t bogonsv6 -T replace -f /etc/bogonsv6 2>&1`
|
60
|
rm /tmp/bogonsv6
|
61
|
echo "Bogons V6 file downloaded: $RESULT" | logger
|
62
|
else
|
63
|
echo "Could not download http://files.pfsense.org/lists/fullbogons-ipv6.txt.md5 (md5 mismatch)" | logger
|
64
|
md5_error="true"
|
65
|
fi
|
66
|
|
67
|
if [ "$BOGON_V4_MD5" = "$ON_DISK_V4_MD5" ] || [ "$BOGON_V6_MD5" = "$ON_DISK_V6_MD5" ]; then
|
68
|
# We mounted RW, so switch back to RO
|
69
|
/etc/rc.conf_mount_ro
|
70
|
fi
|
71
|
|
72
|
if [ "$md5_error" != "" ];then
|
73
|
# Relaunch and sleep
|
74
|
sh /etc/rc.update_bogons.sh &
|
75
|
exit
|
76
|
fi
|
77
|
|
78
|
echo "rc.update_bogons.sh is ending the update cycle." | logger
|