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.

86 lines
2.6 KiB

  1. #!/usr/bin/env sh
  2. ########################################################################
  3. # Hurricane Electric hook script for acme.sh (dynamic TXT API)
  4. #
  5. # These are the pros and cons of dns_he_dyntxt, compared to dns_he:
  6. # Pros:
  7. # - No need to store a dns.he.net account password on your server
  8. # - Uses a very simple write-only API
  9. # Cons:
  10. # - You must manually create placeholder _acme-challenge TXT records,
  11. # and generate/copy the same DDNS key across all records.
  12. # - This script WILL FAIL to issue both a domain and its wildcard, because
  13. # '-d example.com -d *.example.com' requires multiple TXT records.
  14. # Switch to 'dns_he' if you need this feature.
  15. #
  16. # Environment variable:
  17. # HE_DynTXT_Key - DDNS key for all _acme-challenge TXT records
  18. ########################################################################
  19. # Cheat sheet for passing the DNS.yml API test:
  20. # - Set TEST_DNS_NO_WILDCARD=1
  21. # - Create placeholder TXT records for the following domain names:
  22. # - _acme-challenge.$TestingDomain
  23. # - acmetestXyzRandomName.$TestingDomain
  24. HE_DynTXT_Api="https://dyn.dns.he.net/nic/update"
  25. ######## Public functions #####################
  26. #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  27. dns_he_dyntxt_add() {
  28. fulldomain=$1
  29. txtvalue=$2
  30. HE_DynTXT_Key="${HE_DynTXT_Key:-$(_readaccountconf_mutable HE_DynTXT_Key)}"
  31. if [ -z "$HE_DynTXT_Key" ]; then
  32. HE_DynTXT_Key=""
  33. _err "Missing HE_DynTXT_Key. See dnsapi/dns_he_dyntxt.sh for instructions."
  34. return 1
  35. fi
  36. #save the DDNS key to the account conf file.
  37. _saveaccountconf_mutable HE_DynTXT_Key "$HE_DynTXT_Key"
  38. _info "Updating record $fulldomain"
  39. _he_dyntxt_post "$fulldomain" "$txtvalue"
  40. return "$?"
  41. }
  42. dns_he_dyntxt_rm() {
  43. fulldomain=$1
  44. txtvalue='""' # The record is just cleared, not removed.
  45. HE_DynTXT_Key="${HE_DynTXT_Key:-$(_readaccountconf_mutable HE_DynTXT_Key)}"
  46. _info "Clearing record $fulldomain"
  47. _he_dyntxt_post "$fulldomain" "$txtvalue"
  48. return "$?"
  49. }
  50. ##################### Private functions below ##################################
  51. _he_dyntxt_post() {
  52. hostname=$1
  53. txt=$2
  54. response="$(_post "hostname=$hostname&password=$HE_DynTXT_Key&txt=$txt" "$HE_DynTXT_Api")"
  55. if [ "$?" != "0" ]; then
  56. _err "POST failed"
  57. return 1
  58. fi
  59. _debug2 response "$response"
  60. if _contains "$response" "good" || _contains "$response" "nochg"; then
  61. _info "Updated, OK"
  62. return 0
  63. elif _contains "$response" "badauth"; then
  64. _err "'$hostname' missing placeholder TXT record, or DDNS key incorrect"
  65. return 1
  66. else
  67. _err "Unknown POST response: $response"
  68. return 1
  69. fi
  70. }