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.

127 lines
3.6 KiB

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