Project

General

Profile

Download (2.67 KB) Statistics
| Branch: | Tag: | Revision:
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
if [ "$1" = "" ]; then
11
    # Grab a random value  
12
    value=`od -A n -d -N2 /dev/random | awk '{ print $1 }'`
13
    echo "rc.update_bogons.sh is sleeping for $value" | logger
14
    sleep $value
15
fi    
16

    
17
echo "rc.update_bogons.sh is beginning the update cycle." | logger
18

    
19
# Load custom bogon configuration
20
if [ -f /var/etc/bogon_custom ]; then
21
	. /var/etc/bogon_custom
22
fi
23

    
24
# Set default values if not overriden
25
v4url=${v4url:-"http://files.pfsense.org/lists/fullbogons-ipv4.txt"}
26
v6url=${v6url:-"http://files.pfsense.org/lists/fullbogons-ipv6.txt"}
27
v4urlcksum=${v4urlcksum:-"${v4url}.md5"}
28
v6urlcksum=${v6urlcksum:-"${v6url}.md5"}
29

    
30
/usr/bin/fetch -q -o /tmp/bogons "${v4url}"
31
/usr/bin/fetch -q -o /tmp/bogonsv6 "${v6url}"
32
if [ ! -f /tmp/bogons ]; then
33
	echo "Could not download ${v4url}" | logger
34
	dl_error="true"
35
fi
36
if [ ! -f /tmp/bogonsv6 ]; then
37
	echo "Could not download ${v6url}" | logger
38
	dl_error="true"
39
fi
40

    
41
if [ "$dl_error" != "" ];then
42
	# Relaunch and sleep
43
	sh /etc/rc.update_bogons.sh & 
44
	exit
45
fi
46

    
47
BOGON_V4_CKSUM=`/usr/bin/fetch -q -o - "${v4urlcksum}" | awk '{ print $4 }'`
48
ON_DISK_V4_CKSUM=`md5 /tmp/bogons | awk '{ print $4 }'`
49
BOGON_V6_CKSUM=`/usr/bin/fetch -q -o - "${v6urlcksum}" | awk '{ print $4 }'`
50
ON_DISK_V6_CKSUM=`md5 /tmp/bogonsv6 | awk '{ print $4 }'`
51

    
52
if [ "$BOGON_V4_CKSUM" = "$ON_DISK_V4_CKSUM" ] || [ "$BOGON_V6_CKSUM" = "$ON_DISK_V6_CKSUM" ]; then
53
	# At least one of the downloaded MD5s matches, so mount RW
54
	/etc/rc.conf_mount_rw
55
fi
56

    
57
if [ "$BOGON_V4_CKSUM" = "$ON_DISK_V4_CKSUM" ]; then
58
	egrep -v "^192.168.0.0/16|^172.16.0.0/12|^10.0.0.0/8" /tmp/bogons > /etc/bogons
59
	RESULT=`/sbin/pfctl -t bogons -T replace -f /etc/bogons 2>&1`
60
	rm /tmp/bogons
61
	echo "$RESULT" |awk '{ print "Bogons V4 file downloaded: " $0 }' | logger
62
else
63
	echo "Could not download ${v4urlcksum} (checksum mismatch)" | logger
64
	checksum_error="true"
65
fi
66

    
67
if [ "$BOGON_V6_CKSUM" = "$ON_DISK_V6_CKSUM" ]; then
68
	egrep -v "^fc00::/7" /tmp/bogonsv6 > /etc/bogonsv6
69
	RESULT=`/sbin/pfctl -t bogonsv6 -T replace -f /etc/bogonsv6 2>&1`
70
	rm /tmp/bogonsv6
71
	echo "$RESULT" |awk '{ print "Bogons V6 file downloaded: " $0 }' | logger
72
else
73
	echo "Could not download ${v6urlcksum} (checksum mismatch)" | logger
74
	checksum_error="true"
75
fi
76

    
77
if [ "$BOGON_V4_CKSUM" = "$ON_DISK_V4_CKSUM" ] || [ "$BOGON_V6_CKSUM" = "$ON_DISK_V6_CKSUM" ]; then
78
	# We mounted RW, so switch back to RO
79
	/etc/rc.conf_mount_ro
80
fi
81

    
82
if [ "$checksum_error" != "" ];then
83
	# Relaunch and sleep
84
	sh /etc/rc.update_bogons.sh & 
85
	exit
86
fi
87

    
88
echo "rc.update_bogons.sh is ending the update cycle." | logger
(98-98/108)