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.

86 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. ## Check for the credentials
  39. if [ -z "$ACMEPROXY_USERNAME" ] || [ -z "$ACMEPROXY_PASSWORD" ]; then
  40. ACMEPROXY_USERNAME=""
  41. ACMEPROXY_PASSWORD=""
  42. _err "You didn't set username and password"
  43. _err "Please set them via 'export ACMEPROXY_USERNAME=...' and 'export ACMEPROXY_PASSWORD=...' and try again."
  44. return 1
  45. fi
  46. ## Save the credentials to the account file
  47. _saveaccountconf_mutable ACMEPROXY_ENDPOINT "$ACMEPROXY_ENDPOINT"
  48. _saveaccountconf_mutable ACMEPROXY_USERNAME "$ACMEPROXY_USERNAME"
  49. _saveaccountconf_mutable ACMEPROXY_PASSWORD "$ACMEPROXY_PASSWORD"
  50. ## Base64 encode the credentials
  51. credentials=$(printf "%b" "$ACMEPROXY_USERNAME:$ACMEPROXY_PASSWORD" | _base64)
  52. ## Construct the HTTP Authorization header
  53. export _H1="Authorization: Basic $credentials"
  54. export _H2="Accept: application/json"
  55. export _H3="Content-Type: application/json"
  56. ## Add the challenge record to the acmeproxy grid member
  57. response="$(_post "{\"fqdn\": \"$fulldomain.\", \"value\": \"$txtvalue\"}" "$ACMEPROXY_ENDPOINT/$action" "" "POST")"
  58. ## Let's see if we get something intelligible back from the unit
  59. if echo "$response" | grep "\"$txtvalue\"" >/dev/null; then
  60. _info "Successfully updated the txt record"
  61. return 0
  62. else
  63. _err "Error encountered during record addition"
  64. _err "$response"
  65. return 1
  66. fi
  67. }
  68. #################### Private functions below ##################################