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.

188 lines
4.3 KiB

2 months ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_dnsexit_info='DNSExit.com
  4. Site: DNSExit.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_dnsexit
  6. Options:
  7. DNSEXIT_API_KEY API Key
  8. DNSEXIT_AUTH_USER Username
  9. DNSEXIT_AUTH_PASS Password
  10. Issues: github.com/acmesh-official/acme.sh/issues/4719
  11. Author: Samuel Jimenez
  12. '
  13. DNSEXIT_API_URL="https://api.dnsexit.com/dns/"
  14. DNSEXIT_HOSTS_URL="https://update.dnsexit.com/ipupdate/hosts.jsp"
  15. ######## Public functions #####################
  16. #Usage: dns_dnsexit_add _acme-challenge.*.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  17. dns_dnsexit_add() {
  18. fulldomain=$1
  19. txtvalue=$2
  20. _info "Using DNSExit.com"
  21. _debug fulldomain "$fulldomain"
  22. _debug txtvalue "$txtvalue"
  23. _debug 'Load account auth'
  24. if ! get_account_info; then
  25. return 1
  26. fi
  27. _debug 'First detect the root zone'
  28. if ! _get_root "$fulldomain"; then
  29. return 1
  30. fi
  31. _debug _sub_domain "$_sub_domain"
  32. _debug _domain "$_domain"
  33. if ! _dnsexit_rest "{\"domain\":\"$_domain\",\"add\":{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":0,\"overwrite\":false}}"; then
  34. _err "$response"
  35. return 1
  36. fi
  37. _debug2 _response "$response"
  38. return 0
  39. }
  40. #Usage: fulldomain txtvalue
  41. #Remove the txt record after validation.
  42. dns_dnsexit_rm() {
  43. fulldomain=$1
  44. txtvalue=$2
  45. _info "Using DNSExit.com"
  46. _debug fulldomain "$fulldomain"
  47. _debug txtvalue "$txtvalue"
  48. _debug 'Load account auth'
  49. if ! get_account_info; then
  50. return 1
  51. fi
  52. _debug 'First detect the root zone'
  53. if ! _get_root "$fulldomain"; then
  54. _err "$response"
  55. return 1
  56. fi
  57. _debug _sub_domain "$_sub_domain"
  58. _debug _domain "$_domain"
  59. if ! _dnsexit_rest "{\"domain\":\"$_domain\",\"delete\":{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\"}}"; then
  60. _err "$response"
  61. return 1
  62. fi
  63. _debug2 _response "$response"
  64. return 0
  65. }
  66. #################### Private functions below ##################################
  67. #_acme-challenge.www.domain.com
  68. #returns
  69. # _sub_domain=_acme-challenge.www
  70. # _domain=domain.com
  71. _get_root() {
  72. domain=$1
  73. i=1
  74. while true; do
  75. _domain=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
  76. _debug h "$_domain"
  77. if [ -z "$_domain" ]; then
  78. return 1
  79. fi
  80. _debug login "$DNSEXIT_AUTH_USER"
  81. _debug password "$DNSEXIT_AUTH_PASS"
  82. _debug domain "$_domain"
  83. _dnsexit_http "login=$DNSEXIT_AUTH_USER&password=$DNSEXIT_AUTH_PASS&domain=$_domain"
  84. if _contains "$response" "0=$_domain"; then
  85. _sub_domain="$(echo "$fulldomain" | sed "s/\\.$_domain\$//")"
  86. return 0
  87. else
  88. _debug "Go to next level of $_domain"
  89. fi
  90. i=$(_math "$i" + 1)
  91. done
  92. return 1
  93. }
  94. _dnsexit_rest() {
  95. m=POST
  96. ep=""
  97. data="$1"
  98. _debug _dnsexit_rest "$ep"
  99. _debug data "$data"
  100. api_key_trimmed=$(echo "$DNSEXIT_API_KEY" | tr -d '"')
  101. export _H1="apikey: $api_key_trimmed"
  102. export _H2='Content-Type: application/json'
  103. if [ "$m" != "GET" ]; then
  104. _debug data "$data"
  105. response="$(_post "$data" "$DNSEXIT_API_URL/$ep" "" "$m")"
  106. else
  107. response="$(_get "$DNSEXIT_API_URL/$ep")"
  108. fi
  109. if [ "$?" != "0" ]; then
  110. _err "Error $ep"
  111. return 1
  112. fi
  113. _debug2 response "$response"
  114. return 0
  115. }
  116. _dnsexit_http() {
  117. m=GET
  118. param="$1"
  119. _debug param "$param"
  120. _debug get "$DNSEXIT_HOSTS_URL?$param"
  121. response="$(_get "$DNSEXIT_HOSTS_URL?$param")"
  122. _debug response "$response"
  123. if [ "$?" != "0" ]; then
  124. _err "Error $param"
  125. return 1
  126. fi
  127. _debug2 response "$response"
  128. return 0
  129. }
  130. get_account_info() {
  131. DNSEXIT_API_KEY="${DNSEXIT_API_KEY:-$(_readaccountconf_mutable DNSEXIT_API_KEY)}"
  132. if test -z "$DNSEXIT_API_KEY"; then
  133. DNSEXIT_API_KEY=''
  134. _err 'DNSEXIT_API_KEY was not exported'
  135. return 1
  136. fi
  137. _saveaccountconf_mutable DNSEXIT_API_KEY "$DNSEXIT_API_KEY"
  138. DNSEXIT_AUTH_USER="${DNSEXIT_AUTH_USER:-$(_readaccountconf_mutable DNSEXIT_AUTH_USER)}"
  139. if test -z "$DNSEXIT_AUTH_USER"; then
  140. DNSEXIT_AUTH_USER=""
  141. _err 'DNSEXIT_AUTH_USER was not exported'
  142. return 1
  143. fi
  144. _saveaccountconf_mutable DNSEXIT_AUTH_USER "$DNSEXIT_AUTH_USER"
  145. DNSEXIT_AUTH_PASS="${DNSEXIT_AUTH_PASS:-$(_readaccountconf_mutable DNSEXIT_AUTH_PASS)}"
  146. if test -z "$DNSEXIT_AUTH_PASS"; then
  147. DNSEXIT_AUTH_PASS=""
  148. _err 'DNSEXIT_AUTH_PASS was not exported'
  149. return 1
  150. fi
  151. _saveaccountconf_mutable DNSEXIT_AUTH_PASS "$DNSEXIT_AUTH_PASS"
  152. return 0
  153. }