0afb0c4fa1f8faae5c6e3c13112c5fceca131211
[dragonfly.git] / etc / periodic / daily / 470.status-named
1 #!/bin/sh
2 #
3 # $FreeBSD: src/etc/periodic/daily/470.status-named,v 1.6 2003/11/07 21:55:35 ru Exp $
4 # $DragonFly: src/etc/periodic/daily/470.status-named,v 1.3 2004/11/15 08:11:59 joerg Exp $
5 #
6
7 # If there is a global system configuration file, suck it in.
8 #
9 if [ -r /etc/defaults/periodic.conf ]
10 then
11     . /etc/defaults/periodic.conf
12     source_periodic_confs
13 fi
14
15 catmsgs() {
16         find /var/log -name 'messages.*' -mtime -2 |
17             sort -t. -r -n -k 2,2 |
18             while read f
19             do
20                 case $f in
21                     *.gz)       zcat -f $f;;
22                     *.bz2)      bzcat -f $f;;
23                 esac
24             done
25         [ -f /var/log/messages ] && cat /var/log/messages
26 }
27
28 case "$daily_status_named_enable" in
29     [Yy][Ee][Ss])
30         echo
31         echo 'Checking for denied zone transfers (AXFR and IXFR):'
32
33         start=`date -v-1d '+%b %e'`
34         rc=$(catmsgs |
35             fgrep '^'"$start"'.*named\[[[:digit:]]\+\]: denied [AI]XFR from \[.*\]\.[[:digit:]]\+ for' | \
36             sed -e 's/.*: denied [AI]XFR from \[\(.*\)\]\.[[:digit:]]* for "\(.*\)".*$/\2 from \1/'
37             sort -f | uniq -ic | (
38                 usedns=0
39                 if [ X"${daily_status_named_usedns}" != X"" ]; then
40                         case $daily_status_named_usedns in
41                         [yY][eE][sS])   usedns=1 ;;
42                         esac
43                 fi
44
45                 while read line ;do
46                         ipaddr=`echo "$line" | sed -e 's/^.*from //'`
47                         if [ $usedns -eq 1 ]; then
48                                 name=`host "${ipaddr}" 2>/dev/null | \
49                                    grep 'domain name pointer' | \
50                                    sed -e 's/^.* //'`
51                         fi
52                         if [ X"${name}" != X"" ]; then
53                                 echo "${line} (${name})"
54                         else
55                                 echo "${line}"
56                         fi
57                 done ) | \
58                 tee /dev/stderr | wc -l)
59         [ $rc -gt 0 ] && rc=1
60         ;;
61
62     *)  rc=0;;
63 esac
64
65 exit $rc