-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-iana.sh
executable file
·65 lines (48 loc) · 1.57 KB
/
check-iana.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
# $Id: check-iana.sh,v 1.2 2008/03/17 22:08:43 ktsaou Exp $
MYMAIL="$1"
if [ -z "${MYMAIL}" ]
then
echo >&2 "Please set your e-mail."
exit 1
fi
IPV4_ADDRESS_SPACE_URL="http://www.iana.org/assignments/ipv4-address-space"
ianafile=iana-reserved.txt
spooldir=/var/spool/firehol
mkdir -p "${spooldir}" || exit 1
cd "${spooldir}" || exit 1
wget -O - --proxy=off "${IPV4_ADDRESS_SPACE_URL}?" >"${spooldir}/${ianafile}.tmp" 2>/dev/null
if [ ! -s "${spooldir}/${ianafile}.tmp" ]
then
logger -p alert -t FireHOL "Cannot fetch '${IPV4_ADDRESS_SPACE_URL}'."
exit 1
fi
if [ ! -s "${spooldir}/${ianafile}" ]
then
logger -p alert -t FireHOL "First fetch of '${IPV4_ADDRESS_SPACE_URL}'."
mv -f "${spooldir}/${ianafile}.tmp" "${spooldir}/${ianafile}"
exit 0
fi
diff "${spooldir}/${ianafile}" "${spooldir}/${ianafile}.tmp" >/dev/null 2>&1
if [ $? -eq 0 ]
then
logger -p alert -t FireHOL "Page '${IPV4_ADDRESS_SPACE_URL}' not changed."
exit 0
else
cat <<EOF | sendmail -bm -i -oi -t
From: IANA Monitor on `hostname` <${MYMAIL}>
To: FireHOL Admins <${MYMAIL}>
Errors-To: FireHOL Admins <${MYMAIL}>
Subject: New IANA Reservations Detected!
Dear admin,
The following changes have been made at IANA Reservations page.
`diff "${spooldir}/${ianafile}" "${spooldir}/${ianafile}.tmp"`
You may have to update your firewall by running the get-iana.sh script.
Regards,
Your IANA Reservations Monitor
EOF
logger -p alert -t FireHOL "Changes detected in '${IPV4_ADDRESS_SPACE_URL}'. Mail sent to '${MYMAIL}'."
mv -f "${spooldir}/${ianafile}.tmp" "${spooldir}/${ianafile}"
exit 0
fi
exit 1