root/alternc-secondarymx/trunk/secondarymx

Revision 1664, 2.3 kB (checked in by benjamin, 2 years ago)

secondary mx initial package (need to be tested)

Line 
1 #!/bin/sh
2 # Synchronize a dns server with alternc's remote server :
3 # the configuration files contains definitions for remote masters.
4 # if you call it with -f, force the mxlist reloading into postfix map.
5
6 CONFDIR=/etc/secondarymx
7 CACHEDIR=/var/cache/secondarymx
8 POSTMAP=${CACHEDIR}/secondarymx
9 WGETRC=${HOME}/.wgetrc
10
11 TIMEOUT=5
12
13 SetWgetPass() {
14     USER="$1"
15     PASS="$2"
16     if [ -e ${WGETRC} ]; then
17         mv ${WGETRC} ${WGETRC}.$$
18     fi
19     touch ${WGETRC}
20     chmod og-r ${WGETRC}
21     cat >> ${WGETRC} <<EOF
22 http_user = ${USER}
23 http_passwd = ${PASS}
24 EOF
25 }
26
27 ResetWgetConf() {
28     mv -f ${WGETRC}.$$ ${WGETRC} 2>/dev/null || rm -f ${WGETRC}
29 }
30
31 # Main procedure : parse each config file and download the raw domain list.
32 # if something changed in a list, call CreatePostmap $i
33
34 cd $CONFDIR
35
36 RELOAD=""
37
38 for conf in `ls | grep -v secondarymx.conf | grep -v '~$' `
39 do
40   # HOST LOGIN PASSWORD MASTERIP
41   HOST=""
42   MASTERIP=""
43   LOGIN=""
44   PASSWORD=""
45   SSL=""
46   . ./${conf}
47   if [ -z "$HOST" -o -z "$LOGIN" -o -z "$PASSWORD" -o -z "$MASTERIP" ]
48   then
49       echo "error in the config file '${conf}'" >&2
50   else
51       if [ "$SSL" ]
52       then
53           PROTOCOL="https"
54       else
55           PROTOCOL="http"
56       fi
57       touch ${CACHEDIR}/${conf}
58       rm -f ${CACHEDIR}/${conf}.temp
59       SetWgetPass ${LOGIN} ${PASSWORD}
60       wget ${PROTOCOL}://${HOST}/admin/mxlist.php -O ${CACHEDIR}/${conf}.temp -t 1 -T ${TIMEOUT} 2>/dev/null
61       ResetWgetConf
62       if [ -s "${CACHEDIR}/${conf}.temp" ]
63       then
64           # If the slave file has changed, synchronize it.
65           if  [ "$1" != "-f" ] && diff ${CACHEDIR}/${conf}.temp ${CACHEDIR}/${conf} -q &>/dev/null
66           then
67               echo "no change found for '${conf}'"
68               rm -f ${CACHEDIR}/${conf}.tem
69           else
70               echo "change detected for '${conf}', applying"
71               mv -f ${CACHEDIR}/${conf}.temp ${CACHEDIR}/${conf}
72               # Now parse the slave file and send it to /etc/bind/secondarymx
73               RELOAD="YES"
74           fi
75       else
76           echo "error: downloaded file for '${conf}' has zero size" >&2
77       fi
78   fi
79 done     # Main loop on config files
80
81 if [ "$RELOAD" ]
82 then
83     rm ${POSTMAP}
84     for conf in `ls | grep -v secondarymx.conf | grep -v '~$' `
85     do
86       cat ${CACHEDIR}/${conf} | sed -e 's/$/ YES/' >>${POSTMAP}
87     done
88     postmap ${POSTMAP}
89     # FIXME : shall-we reload postfix or not here ?
90 fi
91
Note: See TracBrowser for help on using the browser.