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.

61 lines
1.7 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. nsupdate -k "${NSUPDATE_KEY}" <<EOF
  16. server ${NSUPDATE_SERVER} -p ${NSUPDATE_SERVER_PORT}
  17. update add ${fulldomain}. 60 in txt "${txtvalue}"
  18. send
  19. EOF
  20. if [ $? -ne 0 ]; then
  21. _err "error updating domain"
  22. return 1
  23. fi
  24. return 0
  25. }
  26. #Usage: dns_nsupdate_rm _acme-challenge.www.domain.com
  27. dns_nsupdate_rm() {
  28. fulldomain=$1
  29. _checkKeyFile || return 1
  30. [ -n "${NSUPDATE_SERVER}" ] || NSUPDATE_SERVER="localhost"
  31. [ -n "${NSUPDATE_SERVER_PORT}" ] || NSUPDATE_SERVER_PORT=53
  32. _info "removing ${fulldomain}. txt"
  33. nsupdate -k "${NSUPDATE_KEY}" <<EOF
  34. server ${NSUPDATE_SERVER} -p ${NSUPDATE_SERVER_PORT}
  35. update delete ${fulldomain}. txt
  36. send
  37. EOF
  38. if [ $? -ne 0 ]; then
  39. _err "error updating domain"
  40. return 1
  41. fi
  42. return 0
  43. }
  44. #################### Private functions below ##################################
  45. _checkKeyFile() {
  46. if [ -z "${NSUPDATE_KEY}" ]; then
  47. _err "you must specify a path to the nsupdate key file"
  48. return 1
  49. fi
  50. if [ ! -r "${NSUPDATE_KEY}" ]; then
  51. _err "key ${NSUPDATE_KEY} is unreadable"
  52. return 1
  53. fi
  54. }