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.

83 lines
2.8 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. if [ -z "$ACMEPROXY_USERNAME" ] || [ -z "$ACMEPROXY_PASSWORD" ]; then
  43. _info "ACMEPROXY_USERNAME and/or ACMEPROXY_PASSWORD not set - using without client authentication! Make sure you're using server authentication (e.g. IP-based)"
  44. export _H1="Accept: application/json"
  45. export _H2="Content-Type: application/json"
  46. else
  47. ## Base64 encode the credentials
  48. credentials=$(printf "%b" "$ACMEPROXY_USERNAME:$ACMEPROXY_PASSWORD" | _base64)
  49. ## Construct the HTTP Authorization header
  50. export _H1="Authorization: Basic $credentials"
  51. export _H2="Accept: application/json"
  52. export _H3="Content-Type: application/json"
  53. fi
  54. ## Add the challenge record to the acmeproxy grid member
  55. response="$(_post "{\"fqdn\": \"$fulldomain.\", \"value\": \"$txtvalue\"}" "$ACMEPROXY_ENDPOINT/$action" "" "POST")"
  56. ## Let's see if we get something intelligible back from the unit
  57. if echo "$response" | grep "\"$txtvalue\"" >/dev/null; then
  58. _info "Successfully updated the txt record"
  59. return 0
  60. else
  61. _err "Error encountered during record addition"
  62. _err "$response"
  63. return 1
  64. fi
  65. }
  66. #################### Private functions below ##################################