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.

147 lines
3.6 KiB

  1. #!/usr/bin/env sh
  2. # DNS API for Domain-Offensive / Resellerinterface / Domainrobot
  3. # Report bugs at https://github.com/seidler2547/acme.sh/issues
  4. # set these environment variables to match your customer ID and password:
  5. # DO_PID="KD-1234567"
  6. # DO_PW="cdfkjl3n2"
  7. DO_URL="https://soap.resellerinterface.de/"
  8. ######## Public functions #####################
  9. #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  10. dns_do_add() {
  11. fulldomain=$1
  12. txtvalue=$2
  13. if _dns_do_authenticate; then
  14. _info "Adding TXT record to ${_domain} as ${fulldomain}"
  15. _dns_do_soap createRR origin "${_domain}" name "${fulldomain}" type TXT data "${txtvalue}" ttl 300
  16. if _contains "${response}" '>success<'; then
  17. return 0
  18. fi
  19. _err "Could not create resource record, check logs"
  20. fi
  21. return 1
  22. }
  23. #fulldomain
  24. dns_do_rm() {
  25. fulldomain=$1
  26. if _dns_do_authenticate; then
  27. if _dns_do_list_rrs; then
  28. _dns_do_had_error=0
  29. for _rrid in ${_rr_list}; do
  30. _info "Deleting resource record $_rrid for $_domain"
  31. _dns_do_soap deleteRR origin "${_domain}" rrid "${_rrid}"
  32. if ! _contains "${response}" '>success<'; then
  33. _dns_do_had_error=1
  34. _err "Could not delete resource record for ${_domain}, id ${_rrid}"
  35. fi
  36. done
  37. return $_dns_do_had_error
  38. fi
  39. fi
  40. return 1
  41. }
  42. #################### Private functions below ##################################
  43. _dns_do_authenticate() {
  44. _info "Authenticating as ${DO_PID}"
  45. _dns_do_soap authPartner partner "${DO_PID}" password "${DO_PW}"
  46. if _contains "${response}" '>success<'; then
  47. _get_root "$fulldomain"
  48. _debug "_domain $_domain"
  49. return 0
  50. else
  51. _err "Authentication failed, are DO_PID and DO_PW set correctly?"
  52. fi
  53. return 1
  54. }
  55. _dns_do_list_rrs() {
  56. _dns_do_soap getRRList origin "${_domain}"
  57. if ! _contains "${response}" 'SOAP-ENC:Array'; then
  58. _err "getRRList origin ${_domain} failed"
  59. return 1
  60. fi
  61. _rr_list="$(echo "${response}" \
  62. | tr -d "\n\r\t" \
  63. | sed -e 's/<item xsi:type="ns2:Map">/\n/g' \
  64. | grep ">$(_regexcape "$fulldomain")</value>" \
  65. | sed -e 's/<\/item>/\n/g' \
  66. | grep '>id</key><value' \
  67. | _egrep_o '>[0-9]{1,16}<' \
  68. | tr -d '><')"
  69. [ "${_rr_list}" ]
  70. }
  71. _dns_do_soap() {
  72. func="$1"
  73. shift
  74. # put the parameters to xml
  75. body="<tns:${func} xmlns:tns=\"${DO_URL}\">"
  76. while [ "$1" ]; do
  77. _k="$1"
  78. shift
  79. _v="$1"
  80. shift
  81. body="$body<$_k>$_v</$_k>"
  82. done
  83. body="$body</tns:${func}>"
  84. _debug2 "SOAP request ${body}"
  85. # build SOAP XML
  86. _xml='<?xml version="1.0" encoding="UTF-8"?>
  87. <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  88. <env:Body>'"$body"'</env:Body>
  89. </env:Envelope>'
  90. # set SOAP headers
  91. export _H1="SOAPAction: ${DO_URL}#${func}"
  92. if ! response="$(_post "${_xml}" "${DO_URL}")"; then
  93. _err "Error <$1>"
  94. return 1
  95. fi
  96. _debug2 "SOAP response $response"
  97. # retrieve cookie header
  98. export _H2="$(_egrep_o 'Cookie: [^;]+' <"$HTTP_HEADER" | _head_n 1)"
  99. return 0
  100. }
  101. _get_root() {
  102. domain=$1
  103. i=1
  104. _dns_do_soap getDomainList
  105. _all_domains="$(echo "${response}" \
  106. | tr -d "\n\r\t " \
  107. | _egrep_o 'domain</key><value[^>]+>[^<]+' \
  108. | sed -e 's/^domain<\/key><value[^>]*>//g')"
  109. while true; do
  110. h=$(printf "%s" "$domain" | cut -d . -f $i-100)
  111. if [ -z "$h" ]; then
  112. return 1
  113. fi
  114. if _contains "${_all_domains}" "^$(_regexcape "$h")\$"; then
  115. _domain="$h"
  116. return 0
  117. fi
  118. i=$(_math $i + 1)
  119. done
  120. _debug "$domain not found"
  121. return 1
  122. }
  123. _regexcape() {
  124. echo "$1" | sed -e 's/\([]\.$*^[]\)/\\\1/g'
  125. }