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.

109 lines
3.5 KiB

  1. #!/usr/bin/env sh
  2. #
  3. # Author: Fan Jiang
  4. # Author: Wolfgang Ebner
  5. # Author: Sven Neubuaer
  6. #
  7. # Usage:
  8. # export CFPROXY_BASE_URL="https://auth.acme-dns.io"
  9. # export CFPROXY_USERNAME="<username>"
  10. # export CFPROXY_KEY="<key>"
  11. # export CFPROXY_ZONE="<zone>"
  12. #
  13. #Usage: dns_cfproxy_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  14. # Used to add txt record
  15. dns_cfproxy_add() {
  16. fulldomain=$1
  17. txtvalue=$2
  18. _info "Using cloudflare-proxy"
  19. _debug "fulldomain $fulldomain"
  20. _debug "txtvalue $txtvalue"
  21. CFPROXY_USERNAME="${CFPROXY_USERNAME:-$(_readaccountconf_mutable CFPROXY_USERNAME)}"
  22. _clearaccountconf_mutable CFPROXY_USERNAME
  23. CFPROXY_KEY="${CFPROXY_KEY:-$(_readaccountconf_mutable CFPROXY_KEY)}"
  24. _clearaccountconf_mutable CFPROXY_KEY
  25. CFPROXY_BASE_URL="${CFPROXY_BASE_URL:-$(_readdomainconf CFPROXY_BASE_URL)}"
  26. CFPROXY_ZONE="${CFPROXY_ZONE:-$(_readdomainconf CFPROXY_ZONE)}"
  27. CFPROXY_USERNAME="${CFPROXY_USERNAME:-$(_readdomainconf CFPROXY_USERNAME)}"
  28. CFPROXY_KEY="${CFPROXY_KEY:-$(_readdomainconf CFPROXY_KEY)}"
  29. if [ -z "$CFPROXY_BASE_URL" ]; then
  30. _err "You didn't specify \"CFPROXY_BASE_URL\" token."
  31. return 1
  32. fi
  33. if [ -z "$CFPROXY_ZONE" ]; then
  34. _err "You didn't specify \"CFPROXY_ZONE\" token."
  35. return 1
  36. fi
  37. if [ -z "$CFPROXY_USERNAME" ]; then
  38. _err "You didn't specify \"CFPROXY_USERNAME\" token."
  39. return 1
  40. fi
  41. if [ -z "$CFPROXY_KEY" ]; then
  42. _err "You didn't specify \"CFPROXY_KEY\" token."
  43. return 1
  44. fi
  45. CFPROXY_ADD_URL="$CFPROXY_BASE_URL/add"
  46. _savedomainconf CFPROXY_BASE_URL "$CFPROXY_BASE_URL"
  47. _savedomainconf CFPROXY_ZONE "$CFPROXY_ZONE"
  48. _savedomainconf CFPROXY_USERNAME "$CFPROXY_USERNAME"
  49. _savedomainconf CFPROXY_KEY "$CFPROXY_KEY"
  50. export _H1="Accept: application/json"
  51. export _H2="Content-Type: application/json"
  52. data="{\"user\":\"$CFPROXY_USERNAME\",\"key\":\"$CFPROXY_KEY\",\"zone\":\"$CFPROXY_ZONE\",\"rec\":\"$fulldomain\",\"rectype\":\"TXT\", \"value\":\"$txtvalue\"}"
  53. _debug data "$data"
  54. response="$(_post "$data" "$CFPROXY_ADD_URL" "" "POST")"
  55. _debug response "$response"
  56. if ! echo "$response" | grep "\"success\":true" >/dev/null; then
  57. _err "invalid response of acme-dns"
  58. return 1
  59. fi
  60. }
  61. #Usage: fulldomain txtvalue
  62. #Remove the txt record after validation.
  63. dns_cfproxy_rm() {
  64. fulldomain=$1
  65. txtvalue=$2
  66. _info "Using acme-dns"
  67. _debug "fulldomain $fulldomain"
  68. _debug "txtvalue $txtvalue"
  69. CFPROXY_USERNAME="${CFPROXY_USERNAME:-$(_readaccountconf_mutable CFPROXY_USERNAME)}"
  70. _clearaccountconf_mutable CFPROXY_USERNAME
  71. CFPROXY_KEY="${CFPROXY_KEY:-$(_readaccountconf_mutable CFPROXY_KEY)}"
  72. _clearaccountconf_mutable CFPROXY_KEY
  73. CFPROXY_BASE_URL="${CFPROXY_BASE_URL:-$(_readdomainconf CFPROXY_BASE_URL)}"
  74. CFPROXY_ZONE="${CFPROXY_ZONE:-$(_readdomainconf CFPROXY_ZONE)}"
  75. CFPROXY_USERNAME="${CFPROXY_USERNAME:-$(_readdomainconf CFPROXY_USERNAME)}"
  76. CFPROXY_KEY="${CFPROXY_KEY:-$(_readdomainconf CFPROXY_KEY)}"
  77. CFPROXY_DELETE_URL="$CFPROXY_BASE_URL/delete"
  78. export _H1="Accept: application/json"
  79. export _H2="Content-Type: application/json"
  80. data="{\"user\":\"$CFPROXY_USERNAME\",\"key\":\"$CFPROXY_KEY\",\"zone\":\"$CFPROXY_ZONE\",\"rec\":\"$fulldomain\",\"rectype\":\"TXT\", \"value\":\"$txtvalue\"}"
  81. _debug data "$data"
  82. response="$(_post "$data" "$CFPROXY_DELETE_URL" "" "POST")"
  83. _debug response "$response"
  84. if ! echo "$response" | grep "\"success\":true" >/dev/null; then
  85. _err "invalid response of acme-dns"
  86. return 1
  87. fi
  88. }
  89. #################### Private functions below ##################################