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.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_USERNAME="${ACMEDNS_USERNAME:-$(_readaccountconf_mutable ACMEDNS_USERNAME)}"
  27. _clearaccountconf_mutable ACMEDNS_USERNAME
  28. ACMEDNS_PASSWORD="${ACMEDNS_PASSWORD:-$(_readaccountconf_mutable ACMEDNS_PASSWORD)}"
  29. _clearaccountconf_mutable ACMEDNS_PASSWORD
  30. ACMEDNS_SUBDOMAIN="${ACMEDNS_SUBDOMAIN:-$(_readaccountconf_mutable ACMEDNS_SUBDOMAIN)}"
  31. _clearaccountconf_mutable ACMEDNS_SUBDOMAIN
  32. ACMEDNS_BASE_URL="${ACMEDNS_BASE_URL:-$(_readdomainconf ACMEDNS_BASE_URL)}"
  33. ACMEDNS_USERNAME="${ACMEDNS_USERNAME:-$(_readdomainconf ACMEDNS_USERNAME)}"
  34. ACMEDNS_PASSWORD="${ACMEDNS_PASSWORD:-$(_readdomainconf ACMEDNS_PASSWORD)}"
  35. ACMEDNS_SUBDOMAIN="${ACMEDNS_SUBDOMAIN:-$(_readdomainconf ACMEDNS_SUBDOMAIN)}"
  36. if [ "$ACMEDNS_BASE_URL" = "" ]; then
  37. ACMEDNS_BASE_URL="https://auth.acme-dns.io"
  38. fi
  39. ACMEDNS_UPDATE_URL="$ACMEDNS_BASE_URL/update"
  40. ACMEDNS_REGISTER_URL="$ACMEDNS_BASE_URL/register"
  41. if [ -z "$ACMEDNS_USERNAME" ] || [ -z "$ACMEDNS_PASSWORD" ]; then
  42. response="$(_post "" "$ACMEDNS_REGISTER_URL" "" "POST")"
  43. _debug response "$response"
  44. ACMEDNS_USERNAME=$(echo "$response" | sed -n 's/^{.*\"username\":[ ]*\"\([^\"]*\)\".*}/\1/p')
  45. _debug "received username: $ACMEDNS_USERNAME"
  46. ACMEDNS_PASSWORD=$(echo "$response" | sed -n 's/^{.*\"password\":[ ]*\"\([^\"]*\)\".*}/\1/p')
  47. _debug "received password: $ACMEDNS_PASSWORD"
  48. ACMEDNS_SUBDOMAIN=$(echo "$response" | sed -n 's/^{.*\"subdomain\":[ ]*\"\([^\"]*\)\".*}/\1/p')
  49. _debug "received subdomain: $ACMEDNS_SUBDOMAIN"
  50. ACMEDNS_FULLDOMAIN=$(echo "$response" | sed -n 's/^{.*\"fulldomain\":[ ]*\"\([^\"]*\)\".*}/\1/p')
  51. _info "##########################################################"
  52. _info "# Create $fulldomain CNAME $ACMEDNS_FULLDOMAIN DNS entry #"
  53. _info "##########################################################"
  54. _info "Press enter to continue... "
  55. read -r _
  56. fi
  57. _savedomainconf ACMEDNS_BASE_URL "$ACMEDNS_BASE_URL"
  58. _savedomainconf ACMEDNS_USERNAME "$ACMEDNS_USERNAME"
  59. _savedomainconf ACMEDNS_PASSWORD "$ACMEDNS_PASSWORD"
  60. _savedomainconf ACMEDNS_SUBDOMAIN "$ACMEDNS_SUBDOMAIN"
  61. export _H1="X-Api-User: $ACMEDNS_USERNAME"
  62. export _H2="X-Api-Key: $ACMEDNS_PASSWORD"
  63. data="{\"subdomain\":\"$ACMEDNS_SUBDOMAIN\", \"txt\": \"$txtvalue\"}"
  64. _debug data "$data"
  65. response="$(_post "$data" "$ACMEDNS_UPDATE_URL" "" "POST" "application/json")"
  66. _debug response "$response"
  67. if ! echo "$response" | grep "\"$txtvalue\"" >/dev/null; then
  68. _err "invalid response of acme-dns"
  69. return 1
  70. fi
  71. }
  72. #Usage: fulldomain txtvalue
  73. #Remove the txt record after validation.
  74. dns_acmedns_rm() {
  75. fulldomain=$1
  76. txtvalue=$2
  77. _info "Using acme-dns"
  78. _debug "fulldomain $fulldomain"
  79. _debug "txtvalue $txtvalue"
  80. }
  81. #################### Private functions below ##################################