You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.0 KiB

8 years ago
8 years ago
  1. #!/usr/bin/env sh
  2. ######## Public functions #####################
  3. #Usage: dns_nsupdate_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  4. dns_nsupdate_add() {
  5. fulldomain=$1
  6. txtvalue=$2
  7. _checkKeyFile || return 1
  8. [ -n "${NSUPDATE_SERVER}" ] || NSUPDATE_SERVER="localhost"
  9. [ -n "${NSUPDATE_SERVER_PORT}" ] || NSUPDATE_SERVER_PORT=53
  10. # save the dns server and key to the account conf file.
  11. _saveaccountconf NSUPDATE_SERVER "${NSUPDATE_SERVER}"
  12. _saveaccountconf NSUPDATE_SERVER_PORT "${NSUPDATE_SERVER_PORT}"
  13. _saveaccountconf NSUPDATE_KEY "${NSUPDATE_KEY}"
  14. _info "adding ${fulldomain}. 60 in txt \"${txtvalue}\""
  15. [ -n "$DEBUG" ] && [ "$DEBUG" -ge "$DEBUG_LEVEL_1" ] && nsdebug="-d"
  16. [ -n "$DEBUG" ] && [ "$DEBUG" -ge "$DEBUG_LEVEL_2" ] && nsdebug="-D"
  17. nsupdate -k "${NSUPDATE_KEY}" $nsdebug <<EOF
  18. server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}
  19. update add ${fulldomain}. 60 in txt "${txtvalue}"
  20. send
  21. EOF
  22. if [ $? -ne 0 ]; then
  23. _err "error updating domain"
  24. return 1
  25. fi
  26. return 0
  27. }
  28. #Usage: dns_nsupdate_rm _acme-challenge.www.domain.com
  29. dns_nsupdate_rm() {
  30. fulldomain=$1
  31. _checkKeyFile || return 1
  32. [ -n "${NSUPDATE_SERVER}" ] || NSUPDATE_SERVER="localhost"
  33. [ -n "${NSUPDATE_SERVER_PORT}" ] || NSUPDATE_SERVER_PORT=53
  34. _info "removing ${fulldomain}. txt"
  35. [ -n "$DEBUG" ] && [ "$DEBUG" -ge "$DEBUG_LEVEL_1" ] && nsdebug="-d"
  36. [ -n "$DEBUG" ] && [ "$DEBUG" -ge "$DEBUG_LEVEL_2" ] && nsdebug="-D"
  37. nsupdate -k "${NSUPDATE_KEY}" $nsdebug <<EOF
  38. server ${NSUPDATE_SERVER} ${NSUPDATE_SERVER_PORT}
  39. update delete ${fulldomain}. txt
  40. send
  41. EOF
  42. if [ $? -ne 0 ]; then
  43. _err "error updating domain"
  44. return 1
  45. fi
  46. return 0
  47. }
  48. #################### Private functions below ##################################
  49. _checkKeyFile() {
  50. if [ -z "${NSUPDATE_KEY}" ]; then
  51. _err "you must specify a path to the nsupdate key file"
  52. return 1
  53. fi
  54. if [ ! -r "${NSUPDATE_KEY}" ]; then
  55. _err "key ${NSUPDATE_KEY} is unreadable"
  56. return 1
  57. fi
  58. }