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.

130 lines
3.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_regru_info='reg.ru
  4. Site: reg.ru
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_regru
  6. Options:
  7. REGRU_API_Username Username
  8. REGRU_API_Password Password
  9. Issues: github.com/acmesh-official/acme.sh/issues/2336
  10. '
  11. REGRU_API_URL="https://api.reg.ru/api/regru2"
  12. ######## Public functions #####################
  13. dns_regru_add() {
  14. fulldomain=$1
  15. txtvalue=$2
  16. REGRU_API_Username="${REGRU_API_Username:-$(_readaccountconf_mutable REGRU_API_Username)}"
  17. REGRU_API_Password="${REGRU_API_Password:-$(_readaccountconf_mutable REGRU_API_Password)}"
  18. if [ -z "$REGRU_API_Username" ] || [ -z "$REGRU_API_Password" ]; then
  19. REGRU_API_Username=""
  20. REGRU_API_Password=""
  21. _err "You don't specify regru password or username."
  22. return 1
  23. fi
  24. _saveaccountconf_mutable REGRU_API_Username "$REGRU_API_Username"
  25. _saveaccountconf_mutable REGRU_API_Password "$REGRU_API_Password"
  26. _debug "First detect the root zone"
  27. if ! _get_root "$fulldomain"; then
  28. _err "invalid domain"
  29. return 1
  30. fi
  31. _debug _domain "$_domain"
  32. _subdomain=$(echo "$fulldomain" | sed -r "s/.$_domain//")
  33. _debug _subdomain "$_subdomain"
  34. _info "Adding TXT record to ${fulldomain}"
  35. _regru_rest POST "zone/add_txt" "input_data={%22username%22:%22${REGRU_API_Username}%22,%22password%22:%22${REGRU_API_Password}%22,%22domains%22:[{%22dname%22:%22${_domain}%22}],%22subdomain%22:%22${_subdomain}%22,%22text%22:%22${txtvalue}%22,%22output_content_type%22:%22plain%22}&input_format=json"
  36. if ! _contains "${response}" 'error'; then
  37. return 0
  38. fi
  39. _err "Could not create resource record, check logs"
  40. _err "${response}"
  41. return 1
  42. }
  43. dns_regru_rm() {
  44. fulldomain=$1
  45. txtvalue=$2
  46. REGRU_API_Username="${REGRU_API_Username:-$(_readaccountconf_mutable REGRU_API_Username)}"
  47. REGRU_API_Password="${REGRU_API_Password:-$(_readaccountconf_mutable REGRU_API_Password)}"
  48. if [ -z "$REGRU_API_Username" ] || [ -z "$REGRU_API_Password" ]; then
  49. REGRU_API_Username=""
  50. REGRU_API_Password=""
  51. _err "You don't specify regru password or username."
  52. return 1
  53. fi
  54. _debug "First detect the root zone"
  55. if ! _get_root "$fulldomain"; then
  56. _err "invalid domain"
  57. return 1
  58. fi
  59. _debug _domain "$_domain"
  60. _subdomain=$(echo "$fulldomain" | sed -r "s/.$_domain//")
  61. _debug _subdomain "$_subdomain"
  62. _info "Deleting resource record $fulldomain"
  63. _regru_rest POST "zone/remove_record" "input_data={%22username%22:%22${REGRU_API_Username}%22,%22password%22:%22${REGRU_API_Password}%22,%22domains%22:[{%22dname%22:%22${_domain}%22}],%22subdomain%22:%22${_subdomain}%22,%22content%22:%22${txtvalue}%22,%22record_type%22:%22TXT%22,%22output_content_type%22:%22plain%22}&input_format=json"
  64. if ! _contains "${response}" 'error'; then
  65. return 0
  66. fi
  67. _err "Could not delete resource record, check logs"
  68. _err "${response}"
  69. return 1
  70. }
  71. #################### Private functions below ##################################
  72. #_acme-challenge.www.domain.com
  73. #returns
  74. # _domain=domain.com
  75. _get_root() {
  76. domain=$1
  77. _regru_rest POST "service/get_list" "username=${REGRU_API_Username}&password=${REGRU_API_Password}&output_format=xml&servtype=domain"
  78. domains_list=$(echo "${response}" | grep dname | sed -r "s/.*dname=\"([^\"]+)\".*/\\1/g")
  79. for ITEM in ${domains_list}; do
  80. IDN_ITEM=${ITEM}
  81. case "${domain}" in
  82. *${IDN_ITEM}*)
  83. _domain="$(_idn "${ITEM}")"
  84. _debug _domain "${_domain}"
  85. return 0
  86. ;;
  87. esac
  88. done
  89. return 1
  90. }
  91. #returns
  92. # response
  93. _regru_rest() {
  94. m=$1
  95. ep="$2"
  96. data="$3"
  97. _debug "$ep"
  98. export _H1="Content-Type: application/x-www-form-urlencoded"
  99. if [ "$m" != "GET" ]; then
  100. _debug data "$data"
  101. response="$(_post "$data" "$REGRU_API_URL/$ep" "" "$m")"
  102. else
  103. response="$(_get "$REGRU_API_URL/$ep?$data")"
  104. fi
  105. _debug response "${response}"
  106. return 0
  107. }