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.

185 lines
4.3 KiB

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