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.

182 lines
4.8 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_durabledns_info='DurableDNS.com
  4. Site: DurableDNS.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_durabledns
  6. Options:
  7. DD_API_User API User
  8. DD_API_Key API Key
  9. Issues: github.com/acmesh-official/acme.sh/issues/2281
  10. '
  11. _DD_BASE="https://durabledns.com/services/dns"
  12. ######## Public functions #####################
  13. #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  14. dns_durabledns_add() {
  15. fulldomain=$1
  16. txtvalue=$2
  17. DD_API_User="${DD_API_User:-$(_readaccountconf_mutable DD_API_User)}"
  18. DD_API_Key="${DD_API_Key:-$(_readaccountconf_mutable DD_API_Key)}"
  19. if [ -z "$DD_API_User" ] || [ -z "$DD_API_Key" ]; then
  20. DD_API_User=""
  21. DD_API_Key=""
  22. _err "You didn't specify a durabledns api user or key yet."
  23. _err "You can get yours from here https://durabledns.com/dashboard/index.php"
  24. return 1
  25. fi
  26. #save the api key and email to the account conf file.
  27. _saveaccountconf_mutable DD_API_User "$DD_API_User"
  28. _saveaccountconf_mutable DD_API_Key "$DD_API_Key"
  29. _debug "First detect the root zone"
  30. if ! _get_root "$fulldomain"; then
  31. _err "invalid domain"
  32. return 1
  33. fi
  34. _debug _sub_domain "$_sub_domain"
  35. _debug _domain "$_domain"
  36. _dd_soap createRecord string zonename "$_domain." string name "$_sub_domain" string type "TXT" string data "$txtvalue" int aux 0 int ttl 10 string ddns_enabled N
  37. _contains "$response" "createRecordResponse"
  38. }
  39. dns_durabledns_rm() {
  40. fulldomain=$1
  41. txtvalue=$2
  42. DD_API_User="${DD_API_User:-$(_readaccountconf_mutable DD_API_User)}"
  43. DD_API_Key="${DD_API_Key:-$(_readaccountconf_mutable DD_API_Key)}"
  44. if [ -z "$DD_API_User" ] || [ -z "$DD_API_Key" ]; then
  45. DD_API_User=""
  46. DD_API_Key=""
  47. _err "You didn't specify a durabledns api user or key yet."
  48. _err "You can get yours from here https://durabledns.com/dashboard/index.php"
  49. return 1
  50. fi
  51. _debug "First detect the root zone"
  52. if ! _get_root "$fulldomain"; then
  53. _err "invalid domain"
  54. return 1
  55. fi
  56. _debug _sub_domain "$_sub_domain"
  57. _debug _domain "$_domain"
  58. _debug "Find record id"
  59. if ! _dd_soap listRecords string zonename "$_domain."; then
  60. _err "can not listRecords"
  61. return 1
  62. fi
  63. subtxt="$(echo "$txtvalue" | cut -c 1-30)"
  64. record="$(echo "$response" | sed 's/<item\>/#<item>/g' | tr '#' '\n' | grep ">$subtxt")"
  65. _debug record "$record"
  66. if [ -z "$record" ]; then
  67. _err "can not find record for txtvalue" "$txtvalue"
  68. _err "$response"
  69. return 1
  70. fi
  71. recordid="$(echo "$record" | _egrep_o '<id xsi:type="xsd:int">[0-9]*</id>' | cut -d '>' -f 2 | cut -d '<' -f 1)"
  72. _debug recordid "$recordid"
  73. if [ -z "$recordid" ]; then
  74. _err "can not find record id"
  75. return 1
  76. fi
  77. if ! _dd_soap deleteRecord string zonename "$_domain." int id "$recordid"; then
  78. _err "delete error"
  79. return 1
  80. fi
  81. _contains "$response" "Success"
  82. }
  83. #_acme-challenge.www.domain.com
  84. #returns
  85. # _sub_domain=_acme-challenge.www
  86. # _domain=domain.com
  87. _get_root() {
  88. domain=$1
  89. if ! _dd_soap "listZones"; then
  90. return 1
  91. fi
  92. i=1
  93. p=1
  94. while true; do
  95. h=$(printf "%s" "$domain" | cut -d . -f $i-100)
  96. _debug h "$h"
  97. if [ -z "$h" ]; then
  98. #not valid
  99. return 1
  100. fi
  101. if _contains "$response" ">$h.</origin>"; then
  102. _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
  103. _domain=$h
  104. return 0
  105. fi
  106. p=$i
  107. i=$(_math "$i" + 1)
  108. done
  109. return 1
  110. }
  111. #method
  112. _dd_soap() {
  113. _method="$1"
  114. shift
  115. _urn="${_method}wsdl"
  116. # put the parameters to xml
  117. body="<tns:$_method>
  118. <apiuser xsi:type=\"xsd:string\">$DD_API_User</apiuser>
  119. <apikey xsi:type=\"xsd:string\">$DD_API_Key</apikey>
  120. "
  121. while [ "$1" ]; do
  122. _t="$1"
  123. shift
  124. _k="$1"
  125. shift
  126. _v="$1"
  127. shift
  128. body="$body<$_k xsi:type=\"xsd:$_t\">$_v</$_k>"
  129. done
  130. body="$body</tns:$_method>"
  131. _debug2 "SOAP request ${body}"
  132. # build SOAP XML
  133. _xml='<?xml version="1.0" encoding="utf-8"?>
  134. <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  135. xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  136. xmlns:tns="urn:'$_urn'"
  137. xmlns:types="urn:'$_urn'/encodedTypes"
  138. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  139. xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  140. <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'"$body"'</soap:Body>
  141. </soap:Envelope>'
  142. _debug2 _xml "$_xml"
  143. # set SOAP headers
  144. _action="SOAPAction: \"urn:$_urn#$_method\""
  145. _debug2 "_action" "$_action"
  146. export _H1="$_action"
  147. export _H2="Content-Type: text/xml; charset=utf-8"
  148. _url="$_DD_BASE/$_method.php"
  149. _debug "_url" "$_url"
  150. if ! response="$(_post "${_xml}" "${_url}")"; then
  151. _err "Error <$1>"
  152. return 1
  153. fi
  154. _debug2 "response" "$response"
  155. response="$(echo "$response" | tr -d "\r\n" | _egrep_o ":${_method}Response .*:${_method}Response><")"
  156. _debug2 "response" "$response"
  157. return 0
  158. }