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.

85 lines
2.7 KiB

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