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.

160 lines
4.1 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_udr_info='united-domains Reselling
  4. Site: ud-reselling.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_udr
  6. Options:
  7. UDR_USER Username
  8. UDR_PASS Password
  9. Issues: github.com/acmesh-official/acme.sh/issues/3923
  10. Author: Andreas Scherer <https://github.com/andischerer>
  11. '
  12. UDR_API="https://api.domainreselling.de/api/call.cgi"
  13. UDR_TTL="30"
  14. ######## Public functions #####################
  15. #Usage: add _acme-challenge.www.domain.com "some_long_string_of_characters_go_here_from_lets_encrypt"
  16. dns_udr_add() {
  17. fulldomain=$1
  18. txtvalue=$2
  19. UDR_USER="${UDR_USER:-$(_readaccountconf_mutable UDR_USER)}"
  20. UDR_PASS="${UDR_PASS:-$(_readaccountconf_mutable UDR_PASS)}"
  21. if [ -z "$UDR_USER" ] || [ -z "$UDR_PASS" ]; then
  22. UDR_USER=""
  23. UDR_PASS=""
  24. _err "You didn't specify an UD-Reselling username and password yet"
  25. return 1
  26. fi
  27. # save the username and password to the account conf file.
  28. _saveaccountconf_mutable UDR_USER "$UDR_USER"
  29. _saveaccountconf_mutable UDR_PASS "$UDR_PASS"
  30. _debug "First detect the root zone"
  31. if ! _get_root "$fulldomain"; then
  32. _err "invalid domain"
  33. return 1
  34. fi
  35. _debug _dnszone "${_dnszone}"
  36. _debug "Getting txt records"
  37. if ! _udr_rest "QueryDNSZoneRRList" "dnszone=${_dnszone}"; then
  38. return 1
  39. fi
  40. rr="${fulldomain}. ${UDR_TTL} IN TXT ${txtvalue}"
  41. _debug resource_record "${rr}"
  42. if _contains "$response" "$rr" >/dev/null; then
  43. _err "Error, it would appear that this record already exists. Please review existing TXT records for this domain."
  44. return 1
  45. fi
  46. _info "Adding record"
  47. if ! _udr_rest "UpdateDNSZone" "dnszone=${_dnszone}&addrr0=${rr}"; then
  48. _err "Adding the record did not succeed, please verify/check."
  49. return 1
  50. fi
  51. _info "Added, OK"
  52. return 0
  53. }
  54. dns_udr_rm() {
  55. fulldomain=$1
  56. txtvalue=$2
  57. UDR_USER="${UDR_USER:-$(_readaccountconf_mutable UDR_USER)}"
  58. UDR_PASS="${UDR_PASS:-$(_readaccountconf_mutable UDR_PASS)}"
  59. if [ -z "$UDR_USER" ] || [ -z "$UDR_PASS" ]; then
  60. UDR_USER=""
  61. UDR_PASS=""
  62. _err "You didn't specify an UD-Reselling username and password yet"
  63. return 1
  64. fi
  65. _debug "First detect the root zone"
  66. if ! _get_root "$fulldomain"; then
  67. _err "invalid domain"
  68. return 1
  69. fi
  70. _debug _dnszone "${_dnszone}"
  71. _debug "Getting txt records"
  72. if ! _udr_rest "QueryDNSZoneRRList" "dnszone=${_dnszone}"; then
  73. return 1
  74. fi
  75. rr="${fulldomain}. ${UDR_TTL} IN TXT ${txtvalue}"
  76. _debug resource_record "${rr}"
  77. if _contains "$response" "$rr" >/dev/null; then
  78. if ! _udr_rest "UpdateDNSZone" "dnszone=${_dnszone}&delrr0=${rr}"; then
  79. _err "Deleting the record did not succeed, please verify/check."
  80. return 1
  81. fi
  82. _info "Removed, OK"
  83. return 0
  84. else
  85. _info "Text record is not present, will not delete anything."
  86. return 0
  87. fi
  88. }
  89. #################### Private functions below ##################################
  90. #_acme-challenge.www.domain.com
  91. #returns
  92. # _sub_domain=_acme-challenge.www
  93. # _domain=domain.com
  94. _get_root() {
  95. domain=$1
  96. i=1
  97. if ! _udr_rest "QueryDNSZoneList" ""; then
  98. return 1
  99. fi
  100. while true; do
  101. h=$(printf "%s" "$domain" | cut -d . -f $i-100)
  102. _debug h "$h"
  103. if [ -z "$h" ]; then
  104. #not valid
  105. return 1
  106. fi
  107. if _contains "${response}" "${h}." >/dev/null; then
  108. _dnszone=$(echo "$response" | _egrep_o "${h}")
  109. if [ "$_dnszone" ]; then
  110. return 0
  111. fi
  112. return 1
  113. fi
  114. i=$(_math "$i" + 1)
  115. done
  116. return 1
  117. }
  118. _udr_rest() {
  119. if [ -n "$2" ]; then
  120. data="command=$1&$2"
  121. else
  122. data="command=$1"
  123. fi
  124. _debug data "${data}"
  125. response="$(_post "${data}" "${UDR_API}?s_login=${UDR_USER}&s_pw=${UDR_PASS}" "" "POST")"
  126. _code=$(echo "$response" | _egrep_o "code = ([0-9]+)" | _head_n 1 | cut -d = -f 2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  127. _description=$(echo "$response" | _egrep_o "description = .*" | _head_n 1 | cut -d = -f 2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
  128. _debug response_code "$_code"
  129. _debug response_description "$_description"
  130. if [ ! "$_code" = "200" ]; then
  131. _err "DNS-API-Error: $_description"
  132. return 1
  133. fi
  134. return 0
  135. }