Browse Source

main changes

pull/3024/head
snv 4 years ago
parent
commit
5d0dde5c15
  1. 67
      dnsapi/dns_regru.sh

67
dnsapi/dns_regru.sh

@ -5,7 +5,6 @@
# #
# REGRU_API_Password="test" # REGRU_API_Password="test"
# #
_domain=$_domain
REGRU_API_URL="https://api.reg.ru/api/regru2" REGRU_API_URL="https://api.reg.ru/api/regru2"
@ -27,10 +26,17 @@ dns_regru_add() {
_saveaccountconf_mutable REGRU_API_Username "$REGRU_API_Username" _saveaccountconf_mutable REGRU_API_Username "$REGRU_API_Username"
_saveaccountconf_mutable REGRU_API_Password "$REGRU_API_Password" _saveaccountconf_mutable REGRU_API_Password "$REGRU_API_Password"
_debug "First detect the root zone"
if ! _get_root "$fulldomain"; then
_err "invalid domain"
return 1
fi
_debug _domain "$_domain"
_info "Adding TXT record to ${fulldomain}" _info "Adding TXT record to ${fulldomain}"
response="$(_get "$REGRU_API_URL/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_acme-challenge%22,%22text%22:%22${txtvalue}%22,%22output_content_type%22:%22plain%22}&input_format=json")"
_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_acme-challenge%22,%22text%22:%22${txtvalue}%22,%22output_content_type%22:%22plain%22}&input_format=json"
if _contains "${response}" 'success'; then
if ! _contains "${response}" 'error'; then
return 0 return 0
fi fi
_err "Could not create resource record, check logs" _err "Could not create resource record, check logs"
@ -51,13 +57,64 @@ dns_regru_rm() {
return 1 return 1
fi fi
_debug "First detect the root zone"
if ! _get_root "$fulldomain"; then
_err "invalid domain"
return 1
fi
_debug _domain "$_domain"
_info "Deleting resource record $fulldomain" _info "Deleting resource record $fulldomain"
response="$(_get "$REGRU_API_URL/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_acme-challenge%22,%22content%22:%22${txtvalue}%22,%22record_type%22:%22TXT%22,%22output_content_type%22:%22plain%22}&input_format=json")"
_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_acme-challenge%22,%22content%22:%22${txtvalue}%22,%22record_type%22:%22TXT%22,%22output_content_type%22:%22plain%22}&input_format=json"
if _contains "${response}" 'success'; then
if ! _contains "${response}" 'error'; then
return 0 return 0
fi fi
_err "Could not delete resource record, check logs" _err "Could not delete resource record, check logs"
_err "${response}" _err "${response}"
return 1 return 1
} }
#################### Private functions below ##################################
#_acme-challenge.www.domain.com
#returns
# _domain=domain.com
_get_root() {
domain=$1
_regru_rest POST "service/get_list" "username=${REGRU_API_Username}&password=${REGRU_API_Password}&output_format=xml&servtype=domain"
domains_list=$(echo "${response}" | grep dname | sed -r "s/.*dname=\"([^\"]+)\".*/\\1/g")
for ITEM in ${domains_list}
do
case "${domain}" in
*${ITEM}*)
_domain=${ITEM}
return 0
;;
esac
done
return 1
}
#returns
# response
_regru_rest() {
m=$1
ep="$2"
data="$3"
_debug "$ep"
export _H1="Content-Type: application/x-www-form-urlencoded"
if [ "$m" != "GET" ]; then
_debug data "$data"
response="$(_post "$data" "$REGRU_API_URL/$ep" "" "$m")"
else
response="$(_get "$REGRU_API_URL/$ep")"
fi
_debug2 response "${response}"
return 0
}
Loading…
Cancel
Save