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.

77 lines
2.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. #!/usr/bin/env sh
  2. ## Acmeproxy DNS provider to be used with acmeproxy (http://github.com/mdbraber/acmeproxy)
  3. ## API integration by Maarten den Braber
  4. ##
  5. ## Report any bugs via https://github.com/mdbraber/acme.sh
  6. dns_acmeproxy_add() {
  7. fulldomain="${1}"
  8. txtvalue="${2}"
  9. action="present"
  10. _debug "Calling: _acmeproxy_request() '${fulldomain}' '${txtvalue}' '${action}'"
  11. _acmeproxy_request "$fulldomain" "$txtvalue" "$action"
  12. }
  13. dns_acmeproxy_rm() {
  14. fulldomain="${1}"
  15. txtvalue="${2}"
  16. action="cleanup"
  17. _debug "Calling: _acmeproxy_request() '${fulldomain}' '${txtvalue}' '${action}'"
  18. _acmeproxy_request "$fulldomain" "$txtvalue" "$action"
  19. }
  20. _acmeproxy_request() {
  21. ## Nothing to see here, just some housekeeping
  22. fulldomain=$1
  23. txtvalue=$2
  24. action=$3
  25. _info "Using acmeproxy"
  26. _debug fulldomain "$fulldomain"
  27. _debug txtvalue "$txtvalue"
  28. ACMEPROXY_ENDPOINT="${ACMEPROXY_ENDPOINT:-$(_readaccountconf_mutable ACMEPROXY_ENDPOINT)}"
  29. ACMEPROXY_USERNAME="${ACMEPROXY_USERNAME:-$(_readaccountconf_mutable ACMEPROXY_USERNAME)}"
  30. ACMEPROXY_PASSWORD="${ACMEPROXY_PASSWORD:-$(_readaccountconf_mutable ACMEPROXY_PASSWORD)}"
  31. ## Check for the endpoint
  32. if [ -z "$ACMEPROXY_ENDPOINT" ]; then
  33. ACMEPROXY_ENDPOINT=""
  34. _err "You didn't specify the endpoint"
  35. _err "Please set them via 'export ACMEPROXY_ENDPOINT=https://ip:port' and try again."
  36. return 1
  37. fi
  38. ## Save the credentials to the account file
  39. _saveaccountconf_mutable ACMEPROXY_ENDPOINT "$ACMEPROXY_ENDPOINT"
  40. _saveaccountconf_mutable ACMEPROXY_USERNAME "$ACMEPROXY_USERNAME"
  41. _saveaccountconf_mutable ACMEPROXY_PASSWORD "$ACMEPROXY_PASSWORD"
  42. ## Base64 encode the credentials
  43. credentials=$(printf "%b" "$ACMEPROXY_USERNAME:$ACMEPROXY_PASSWORD" | _base64)
  44. ## Construct the HTTP Authorization header
  45. export _H1="Authorization: Basic $credentials"
  46. export _H2="Accept: application/json"
  47. export _H3="Content-Type: application/json"
  48. ## Add the challenge record to the acmeproxy grid member
  49. response="$(_post "{\"fqdn\": \"$fulldomain.\", \"value\": \"$txtvalue\"}" "$ACMEPROXY_ENDPOINT/$action" "" "POST")"
  50. ## Let's see if we get something intelligible back from the unit
  51. if echo "$response" | grep "\"$txtvalue\"" >/dev/null; then
  52. _info "Successfully updated the txt record"
  53. return 0
  54. else
  55. _err "Error encountered during record addition"
  56. _err "$response"
  57. return 1
  58. fi
  59. }
  60. #################### Private functions below ##################################