root/alternc-slavedns/branches/r0/slavedns

Revision 1293, 1.9 kB (checked in by anonymous, 4 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/bin/sh
2 # Synchronize a dns server with alternc's remote server :
3 # the configuration files contains definitions for remote masters.
4
5 CONFDIR=/etc/slavedns
6 CACHEDIR=/var/cache/slavedns
7 BINDDIR=/etc/bind/slavedns
8
9 function CreateBindConf {
10     CFILE="$1"
11     MASTER="$2"
12     rm ${BINDDIR}/${CFILE}
13     cat ${CFILE} | (read A; while [ "$A" ];  # Treat each domain one by one.
14           do
15           echo "zone \"$A\" { type slave; allow-query { any; }; file \"$A\"; masters { $MASTER; }; };" >>${BINDDIR}/${CFILE}
16           read A
17           done)
18 }
19
20
21 # Main procedure : parse each config file and download the raw slave list.
22 # if something changed in a list, call CreateBindConf $i
23
24 cd $CONFDIR
25
26 RELOAD=""
27 for i in `ls * | grep -v slavedns.conf`
28   do
29   # HOST LOGIN PASSWORD
30   HOST=""
31   LOGIN=""
32   PASSWORD=""
33   SSL=""
34   . $i
35   if [ -n "$HOST" -o -n "$LOGIN" -o -n "$PASSWORD" ]
36       then
37       echo "Error in the config file '$i'"
38   else
39       echo -n "Processing '$i' "
40       if [ "$SSL" ]
41           then
42           PROTOCOL="https"
43           else
44           PROTOCOL="http"
45       fi
46       touch ${CACHEDIR}/${i}
47       rm -f ${CACHEDIR}/${i}.temp
48       wget ${PROTOCOL}://${HOST}/admin/slavedns.php --http-passwd ${LOGIN} --http-user ${PASSWORD} -o ${CACHEDIR}/${i}.temp -t 1 -T 5 2>/dev/null
49       if [ -s "${CACHEDIR}/${i}.temp" ]
50           then
51           # If the slave file has changed, synchronize it.
52           if diff ${CACHEDIR}/${i}.temp ${CACHEDIR}/${i} -q &>/dev/null
53               then
54               echo "Change detected for '$i', applying"
55               cp -f ${CACHEDIR}/${i}.temp ${CACHEDIR}/${i}
56               # Now parse the slave file and send it to /etc/bind/slavedns
57               CreateBindConf ${i} ${HOST}
58               RELOAD="YES"
59               fi
60           else
61           echo "Error: downloaded file for '$i' has zero size"
62           fi
63       echo " Done"
64   fi
65 done     # Main loop on config files
66
67 if [ "$RELOAD" ]
68 then
69     if [ -e "/etc/init.d/bind" ]
70         then
71         /etc/init.d/bind reload
72         fi
73     if [ -e "/etc/init.d/bind9" ]
74         then
75         /etc/init.d/bind9 reload
76         fi
77 fi
Note: See TracBrowser for help on using the browser.