commit | author | age
|
bbc4ad
|
1 |
#!/bin/bash |
CS |
2 |
#### Config ################################ |
|
3 |
|
|
4 |
DBHOST="localhost" |
|
5 |
DBUSER="powerdns" |
|
6 |
DBPASS="password" |
|
7 |
DATABASE="powerdns" |
|
8 |
|
|
9 |
DEBUG="no" |
|
10 |
|
|
11 |
#### End of Config ######################### |
|
12 |
|
|
13 |
REQUIRED_COMMANDS=" |
|
14 |
mysql |
|
15 |
host |
|
16 |
grep |
|
17 |
awk |
|
18 |
tail |
|
19 |
" |
|
20 |
|
|
21 |
# print debug messages to STDERR |
|
22 |
function debug { |
|
23 |
if [ "${DEBUG}" == "yes" ] ; then |
|
24 |
echo "DEBUG: $@" >&2 |
|
25 |
fi |
|
26 |
} |
|
27 |
|
|
28 |
for CMD in ${REQUIRED_COMMANDS} ; do |
|
29 |
CMDNAME=`echo ${CMD} | awk '{print toupper($1) }' | sed -e s@"-"@""@g` |
|
30 |
export $(eval "echo ${CMDNAME}")=`which ${CMD} 2>/dev/null` |
|
31 |
if [ -z "${!CMDNAME}" ] ; then |
|
32 |
debug "Command: ${CMD} not found!" |
|
33 |
exit 1 |
|
34 |
else |
|
35 |
debug "Found command $(echo $CMDNAME) in ${!CMDNAME}" |
|
36 |
fi |
|
37 |
done |
|
38 |
|
|
39 |
MYSQLCMD="${MYSQL} -h ${DBHOST} -u ${DBUSER} -p${DBPASS} --skip-column-name --silent -e" |
|
40 |
|
|
41 |
check() { |
|
42 |
AUTH=`${HOST} -t SOA ${2} ${1} | ${TAIL} -n1 | ${GREP} "has no SOA record"` |
|
43 |
if [ "${AUTH}" == "${2} has no SOA record" ]; then |
|
44 |
debug "Server ${1} has no SOA for ${2} - removing zone..." |
|
45 |
DOMAIN_ID=`${MYSQLCMD} "USE ${DATABASE}; SELECT id FROM domains WHERE name='${2}' AND type='SLAVE' AND master='${1}' LIMIT 1;"` |
|
46 |
${MYSQLCMD} "USE ${DATABASE}; DELETE FROM records WHERE domain_id='${DOMAIN_ID}';" |
|
47 |
${MYSQLCMD} "USE ${DATABASE}; DELETE FROM domains WHERE id='${DOMAIN_ID}';" |
|
48 |
fi |
|
49 |
} |
|
50 |
|
|
51 |
MASTERS=(`${MYSQLCMD} "USE ${DATABASE}; SELECT DISTINCT ip FROM supermasters;"`) |
|
52 |
for m in "${MASTERS[@]}"; do |
|
53 |
NAMES=(`${MYSQLCMD} "USE ${DATABASE}; SELECT name FROM domains WHERE type = 'SLAVE' AND master = '${m}';"`) |
|
54 |
for d in "${NAMES[@]}"; do |
|
55 |
check ${m} ${d} |
|
56 |
done |
|
57 |
done |