2017-07-08 18:35:22 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
# Author: non7top@gmail.com
|
|
|
|
# 07 Jul 2017
|
|
|
|
# report bugs at https://github.com/non7top/acme.sh
|
|
|
|
|
|
|
|
# Values to export:
|
|
|
|
# export PDD_Token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
|
|
|
|
|
|
######## Public functions #####################
|
|
|
|
|
|
|
|
#Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
|
|
|
|
dns_yandex_add() {
|
|
|
|
fulldomain="${1}"
|
|
|
|
txtvalue="${2}"
|
|
|
|
_debug "Calling: dns_yandex_add() '${fulldomain}' '${txtvalue}'"
|
2017-07-10 23:19:39 +00:00
|
|
|
_PDD_credentials || return 1
|
2017-07-08 18:35:22 +00:00
|
|
|
export _H1="PddToken: $PDD_Token"
|
|
|
|
|
2018-05-02 21:58:25 +00:00
|
|
|
_PDD_get_domain "$fulldomain" || return 1
|
2017-07-12 00:51:48 +00:00
|
|
|
_debug "Found suitable domain in pdd: $curDomain"
|
2017-07-08 18:35:22 +00:00
|
|
|
curData="domain=${curDomain}&type=TXT&subdomain=${curSubdomain}&ttl=360&content=${txtvalue}"
|
|
|
|
curUri="https://pddimp.yandex.ru/api2/admin/dns/add"
|
|
|
|
curResult="$(_post "${curData}" "${curUri}")"
|
|
|
|
_debug "Result: $curResult"
|
|
|
|
}
|
|
|
|
|
|
|
|
#Usage: dns_myapi_rm _acme-challenge.www.domain.com
|
|
|
|
dns_yandex_rm() {
|
|
|
|
fulldomain="${1}"
|
|
|
|
_debug "Calling: dns_yandex_rm() '${fulldomain}'"
|
2017-07-10 23:19:39 +00:00
|
|
|
_PDD_credentials || return 1
|
2017-07-08 18:35:22 +00:00
|
|
|
export _H1="PddToken: $PDD_Token"
|
|
|
|
|
2018-05-02 21:58:25 +00:00
|
|
|
_PDD_get_domain "$fulldomain" || return 1
|
2017-07-12 00:51:48 +00:00
|
|
|
_debug "Found suitable domain in pdd: $curDomain"
|
|
|
|
|
2018-05-02 22:00:51 +00:00
|
|
|
record_id=$(pdd_get_record_id "${fulldomain}")
|
|
|
|
_debug "Result: $record_id"
|
|
|
|
|
2018-05-02 22:01:14 +00:00
|
|
|
for rec_i in $record_id; do
|
|
|
|
curUri="https://pddimp.yandex.ru/api2/admin/dns/del"
|
|
|
|
curData="domain=${curDomain}&record_id=${rec_i}"
|
|
|
|
curResult="$(_post "${curData}" "${curUri}")"
|
|
|
|
_debug "Result: $curResult"
|
|
|
|
done
|
2017-07-08 18:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#################### Private functions below ##################################
|
|
|
|
|
2017-07-12 00:51:48 +00:00
|
|
|
_PDD_get_domain() {
|
|
|
|
fulldomain="${1}"
|
|
|
|
__page=1
|
|
|
|
__last=0
|
|
|
|
while [ $__last -eq 0 ]; do
|
|
|
|
uri1="https://pddimp.yandex.ru/api2/admin/domain/domains?page=${__page}&on_page=20"
|
2018-03-18 03:04:14 +00:00
|
|
|
res1="$(_get "$uri1" | _normalizeJson)"
|
|
|
|
_debug2 "res1" "$res1"
|
|
|
|
__found="$(echo "$res1" | sed -n -e 's#.* "found": \([^,]*\),.*#\1#p')"
|
2017-07-12 00:51:48 +00:00
|
|
|
_debug "found: $__found results on page"
|
2018-05-02 21:57:50 +00:00
|
|
|
if [ "0$__found" -lt 20 ]; then
|
2017-07-12 00:51:48 +00:00
|
|
|
_debug "last page: $__page"
|
|
|
|
__last=1
|
|
|
|
fi
|
|
|
|
|
2018-02-07 12:54:05 +00:00
|
|
|
__all_domains="$__all_domains $(echo "$res1" | tr "," "\n" | grep '"name"' | cut -d: -f2 | sed -e 's@"@@g')"
|
2017-07-12 00:51:48 +00:00
|
|
|
|
|
|
|
__page=$(_math $__page + 1)
|
|
|
|
done
|
|
|
|
|
|
|
|
k=2
|
|
|
|
while [ $k -lt 10 ]; do
|
|
|
|
__t=$(echo "$fulldomain" | cut -d . -f $k-100)
|
|
|
|
_debug "finding zone for domain $__t"
|
|
|
|
for d in $__all_domains; do
|
2017-07-12 01:07:18 +00:00
|
|
|
if [ "$d" = "$__t" ]; then
|
2018-02-07 12:54:05 +00:00
|
|
|
p=$(_math $k - 1)
|
2018-02-07 14:18:04 +00:00
|
|
|
curSubdomain="$(echo "$fulldomain" | cut -d . -f "1-$p")"
|
2018-02-19 04:43:56 +00:00
|
|
|
curDomain="$__t"
|
|
|
|
return 0
|
2017-07-12 00:51:48 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
k=$(_math $k + 1)
|
|
|
|
done
|
|
|
|
_err "No suitable domain found in your account"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:35:22 +00:00
|
|
|
_PDD_credentials() {
|
|
|
|
if [ -z "${PDD_Token}" ]; then
|
|
|
|
PDD_Token=""
|
2017-07-12 00:51:48 +00:00
|
|
|
_err "You need to export PDD_Token=xxxxxxxxxxxxxxxxx"
|
|
|
|
_err "You can get it at https://pddimp.yandex.ru/api2/admin/get_token"
|
2017-07-08 18:35:22 +00:00
|
|
|
return 1
|
|
|
|
else
|
|
|
|
_saveaccountconf PDD_Token "${PDD_Token}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
pdd_get_record_id() {
|
2017-07-08 18:52:47 +00:00
|
|
|
fulldomain="${1}"
|
2017-07-12 00:51:48 +00:00
|
|
|
|
2018-02-19 04:43:56 +00:00
|
|
|
_PDD_get_domain "$fulldomain"
|
2017-07-12 00:51:48 +00:00
|
|
|
_debug "Found suitable domain in pdd: $curDomain"
|
|
|
|
|
2017-07-08 18:52:47 +00:00
|
|
|
curUri="https://pddimp.yandex.ru/api2/admin/dns/list?domain=${curDomain}"
|
2017-07-09 17:00:02 +00:00
|
|
|
curResult="$(_get "${curUri}" | _normalizeJson)"
|
|
|
|
_debug "Result: $curResult"
|
2017-07-10 23:19:39 +00:00
|
|
|
echo "$curResult" | _egrep_o "{[^{]*\"content\":[^{]*\"subdomain\":\"${curSubdomain}\"" | sed -n -e 's#.* "record_id": \(.*\),[^,]*#\1#p'
|
2017-07-08 18:35:22 +00:00
|
|
|
}
|