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.

94 lines
3.6 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_acmedns_info='acme-dns Server API
  4. The acme-dns is a limited DNS server with RESTful API to handle ACME DNS challenges.
  5. Site: github.com/joohoi/acme-dns
  6. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_acmedns
  7. Options:
  8. ACMEDNS_USERNAME Username. Optional.
  9. ACMEDNS_PASSWORD Password. Optional.
  10. ACMEDNS_SUBDOMAIN Subdomain. Optional.
  11. ACMEDNS_BASE_URL API endpoint. Default: "https://auth.acme-dns.io".
  12. Issues: github.com/dampfklon/acme.sh
  13. Author: Wolfgang Ebner, Sven Neubuaer
  14. '
  15. ######## Public functions #####################
  16. #Usage: dns_acmedns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  17. # Used to add txt record
  18. dns_acmedns_add() {
  19. fulldomain=$1
  20. txtvalue=$2
  21. _info "Using acme-dns"
  22. _debug "fulldomain $fulldomain"
  23. _debug "txtvalue $txtvalue"
  24. #for compatiblity from account conf
  25. ACMEDNS_USERNAME="${ACMEDNS_USERNAME:-$(_readaccountconf_mutable ACMEDNS_USERNAME)}"
  26. _clearaccountconf_mutable ACMEDNS_USERNAME
  27. ACMEDNS_PASSWORD="${ACMEDNS_PASSWORD:-$(_readaccountconf_mutable ACMEDNS_PASSWORD)}"
  28. _clearaccountconf_mutable ACMEDNS_PASSWORD
  29. ACMEDNS_SUBDOMAIN="${ACMEDNS_SUBDOMAIN:-$(_readaccountconf_mutable ACMEDNS_SUBDOMAIN)}"
  30. _clearaccountconf_mutable ACMEDNS_SUBDOMAIN
  31. ACMEDNS_BASE_URL="${ACMEDNS_BASE_URL:-$(_readdomainconf ACMEDNS_BASE_URL)}"
  32. ACMEDNS_USERNAME="${ACMEDNS_USERNAME:-$(_readdomainconf ACMEDNS_USERNAME)}"
  33. ACMEDNS_PASSWORD="${ACMEDNS_PASSWORD:-$(_readdomainconf ACMEDNS_PASSWORD)}"
  34. ACMEDNS_SUBDOMAIN="${ACMEDNS_SUBDOMAIN:-$(_readdomainconf ACMEDNS_SUBDOMAIN)}"
  35. if [ "$ACMEDNS_BASE_URL" = "" ]; then
  36. ACMEDNS_BASE_URL="https://auth.acme-dns.io"
  37. fi
  38. ACMEDNS_UPDATE_URL="$ACMEDNS_BASE_URL/update"
  39. ACMEDNS_REGISTER_URL="$ACMEDNS_BASE_URL/register"
  40. if [ -z "$ACMEDNS_USERNAME" ] || [ -z "$ACMEDNS_PASSWORD" ]; then
  41. response="$(_post "" "$ACMEDNS_REGISTER_URL" "" "POST")"
  42. _debug response "$response"
  43. ACMEDNS_USERNAME=$(echo "$response" | sed -n 's/^{.*\"username\":[ ]*\"\([^\"]*\)\".*}/\1/p')
  44. _debug "received username: $ACMEDNS_USERNAME"
  45. ACMEDNS_PASSWORD=$(echo "$response" | sed -n 's/^{.*\"password\":[ ]*\"\([^\"]*\)\".*}/\1/p')
  46. _debug "received password: $ACMEDNS_PASSWORD"
  47. ACMEDNS_SUBDOMAIN=$(echo "$response" | sed -n 's/^{.*\"subdomain\":[ ]*\"\([^\"]*\)\".*}/\1/p')
  48. _debug "received subdomain: $ACMEDNS_SUBDOMAIN"
  49. ACMEDNS_FULLDOMAIN=$(echo "$response" | sed -n 's/^{.*\"fulldomain\":[ ]*\"\([^\"]*\)\".*}/\1/p')
  50. _info "##########################################################"
  51. _info "# Create $fulldomain CNAME $ACMEDNS_FULLDOMAIN DNS entry #"
  52. _info "##########################################################"
  53. _info "Press enter to continue... "
  54. read -r _
  55. fi
  56. _savedomainconf ACMEDNS_BASE_URL "$ACMEDNS_BASE_URL"
  57. _savedomainconf ACMEDNS_USERNAME "$ACMEDNS_USERNAME"
  58. _savedomainconf ACMEDNS_PASSWORD "$ACMEDNS_PASSWORD"
  59. _savedomainconf ACMEDNS_SUBDOMAIN "$ACMEDNS_SUBDOMAIN"
  60. export _H1="X-Api-User: $ACMEDNS_USERNAME"
  61. export _H2="X-Api-Key: $ACMEDNS_PASSWORD"
  62. data="{\"subdomain\":\"$ACMEDNS_SUBDOMAIN\", \"txt\": \"$txtvalue\"}"
  63. _debug data "$data"
  64. response="$(_post "$data" "$ACMEDNS_UPDATE_URL" "" "POST")"
  65. _debug response "$response"
  66. if ! echo "$response" | grep "\"$txtvalue\"" >/dev/null; then
  67. _err "invalid response of acme-dns"
  68. return 1
  69. fi
  70. }
  71. #Usage: fulldomain txtvalue
  72. #Remove the txt record after validation.
  73. dns_acmedns_rm() {
  74. fulldomain=$1
  75. txtvalue=$2
  76. _info "Using acme-dns"
  77. _debug "fulldomain $fulldomain"
  78. _debug "txtvalue $txtvalue"
  79. }
  80. #################### Private functions below ##################################