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.

62 lines
1.5 KiB

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