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.

58 lines
1.4 KiB

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