~/paste/1209
~/paste/1209
~/paste/1209

  1. #!/bin/sh
  2.  
  3. test -z "$(which pwgen)" && { echo '"pwgen" not found in $PATH' ; exit 23 ; }
  4.  
  5. rand=$(pwgen 20 1)
  6. test_domain="test.nanl.de"
  7. monitoring_domain="nanl.de"
  8. refresh_time_internal=15
  9. refresh_time_external=0 # if the external server doesn't have a higher TTL than the internal servers, this should be set to 0
  10. poweradmin_url="https://dns.nanl.de"
  11. poweradmin_username="monitoring"
  12. poweradmin_password="duaLeiw2"
  13. poweradmin_key="/etc/ssl/private/nanl_clients.key"
  14. poweradmin_crt="/etc/ssl/certs/nanl_clients.crt"
  15. poweradmin_ca="/etc/ssl/certs/nanl_services.ca"
  16.  
  17. args="-O - --quiet --load-cookies /tmp/dns_${monitoring_domain}.cookie"
  18. test -z "${poweradmin_ca}" || args="$args --ca-certificate ${poweradmin_ca}"
  19. test -z "${poweradmin_key}" || args="$args --private-key ${poweradmin_key}"
  20. test -z "${poweradmin_crt}" || args="$args --certificate ${poweradmin_crt}"
  21.  
  22. output=$(wget $args --keep-session-cookies --save-cookies /tmp/dns_${monitoring_domain}.cookie --post-data "username=${poweradmin_username}&password=${poweradmin_password}&authenticate=+Go+" "${poweradmin_url}")
  23. output=$(wget ${args} "${poweradmin_url}/list_zones.php")
  24. id=$(echo "$output" | grep "${domain}" | grep -o -E "id=[[:digit:]]+" | head -n 1)
  25. output=$(wget ${args} --post-data "record%5B253%5D%5Brid%5D=253&record%5B253%5D%5Bzid%5D=18&record%5B253%5D%5Bname%5D=${test_domain}&record%5B253%5D%5Btype%5D=TXT&record%5B253%5D%5Bcontent%5D=${rand}&record%5B253%5D%5Bprio%5D=0&record%5B253%5D%5Bttl%5D=1&commit=Commit+changes" ${poweradmin_url}/edit.php?${id})
  26.  
  27. sleep ${refresh_time_internal}
  28.  
  29. failed=
  30. nameservers=$(nslookup -type=ns "${monitoring_domain}" | grep -E -io '(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\.$')
  31. for ns in $nameservers; do
  32.     res="$(nslookup -type=txt "${test_domain}" "${ns}" | grep -E -o '[[:alnum:]]{20}')"
  33.     if [ "$res" != "$rand" ]; then
  34.         echo "${ns} failed ($rand (local) != $res (server))"
  35.         failed=1
  36.     fi
  37. done
  38. test -z $failed || exit 1
  39.  
  40. sleep ${refresh_time_external}
  41.  
  42. res="$(nslookup -type=txt ${test_domain} ${ns} | grep -E -o '[[:alnum:]]{20}')"
  43. if [ "$res" != "$rand" ]; then
  44.     echo "propagation failed"
  45.     exit 2
  46. fi
  47.  
  48. exit 0
  49.  
Language: bash
Posted by Anonymous at 13 Oct 2012, 07:19:41 UTC