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.

93 lines
3.5 KiB

  1. #!/usr/bin/env sh
  2. #
  3. #Author: Wolfgang Ebner
  4. #Author: Sven Neubuaer
  5. #Report Bugs here: https://github.com/dampfklon/acme.sh
  6. #
  7. # Usage:
  8. # export ACMEDNS_BASE_URL="https://auth.acme-dns.io"
  9. #
  10. # You can optionally define an already existing account:
  11. #
  12. # export ACMEDNS_USERNAME="<username>"
  13. # export ACMEDNS_PASSWORD="<password>"
  14. # export ACMEDNS_SUBDOMAIN="<subdomain>"
  15. #
  16. ######## Public functions #####################
  17. #Usage: dns_acmedns_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  18. # Used to add txt record
  19. dns_acmedns_add() {
  20. fulldomain=$1
  21. txtvalue=$2
  22. _info "Using acme-dns"
  23. _debug "fulldomain $fulldomain"
  24. _debug "txtvalue $txtvalue"
  25. #for compatiblity from account conf
  26. ACMEDNS_BASE_URL="${ACMEDNS_BASE_URL:-$(_readaccountconf_mutable ACMEDNS_BASE_URL)}"
  27. ACMEDNS_USERNAME="${ACMEDNS_USERNAME:-$(_readaccountconf_mutable ACMEDNS_USERNAME)}"
  28. ACMEDNS_PASSWORD="${ACMEDNS_PASSWORD:-$(_readaccountconf_mutable ACMEDNS_PASSWORD)}"
  29. ACMEDNS_SUBDOMAIN="${ACMEDNS_SUBDOMAIN:-$(_readaccountconf_mutable ACMEDNS_SUBDOMAIN)}"
  30. _clearaccountconf_mutable ACMEDNS_UPDATE_URL
  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 ##################################