acme.sh/dnsapi/dns_yandex.sh

70 lines
2.2 KiB
Bash
Raw Normal View History

2017-07-08 20:35:22 +02: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-09 12:00:42 +02:00
_PDD_credentials || exit 1
2017-07-08 20:35:22 +02:00
export _H1="PddToken: $PDD_Token"
2017-07-09 12:21:55 +02:00
curDomain="$(echo "${fulldomain}" | rev | cut -d . -f 1-2 | rev)"
curSubdomain="$(echo "${fulldomain}" | rev | cut -d . -f 3- | rev)"
2017-07-08 20:35:22 +02: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-09 12:00:42 +02:00
_PDD_credentials || exit 1
2017-07-08 20:35:22 +02:00
export _H1="PddToken: $PDD_Token"
2017-07-08 21:02:34 +02:00
record_id=$(pdd_get_record_id "${fulldomain}")
2017-07-08 20:35:22 +02:00
2017-07-09 12:21:55 +02:00
curDomain="$(echo "${fulldomain}" | rev | cut -d . -f 1-2 | rev)"
curSubdomain="$(echo "${fulldomain}" | rev | cut -d . -f 3- | rev)"
2017-07-08 20:35:22 +02:00
curUri="https://pddimp.yandex.ru/api2/admin/dns/del"
curData="domain=${curDomain}&record_id=${record_id}"
curResult="$(_post "${curData}" "${curUri}")"
_debug "Result: $curResult"
}
#################### Private functions below ##################################
_PDD_credentials() {
if [ -z "${PDD_Token}" ]; then
PDD_Token=""
_err "You haven't specified the ISPConfig Login data."
return 1
else
_saveaccountconf PDD_Token "${PDD_Token}"
fi
}
pdd_get_record_id() {
2017-07-08 20:52:47 +02:00
fulldomain="${1}"
2017-07-08 21:02:34 +02:00
curDomain="$(echo "${fulldomain}" | awk -F. '{printf("%s.%s\n",$(NF-1), $NF)}')"
2017-07-08 20:52:47 +02:00
curUri="https://pddimp.yandex.ru/api2/admin/dns/list?domain=${curDomain}"
curResult="$(_get "${curUri}")"
2017-07-08 20:57:27 +02:00
echo "${curResult}" \
2017-07-08 21:02:34 +02:00
| python -c "
2017-07-08 20:35:22 +02:00
import sys, json;
2017-07-08 20:52:47 +02:00
rs=json.load(sys.stdin)[\"records\"]
2017-07-08 20:35:22 +02:00
for r in rs:
2017-07-08 20:52:47 +02:00
if r[\"fqdn\"]==\"${fulldomain}\":
print r[\"record_id\"]
2017-07-08 20:35:22 +02:00
exit
2017-07-08 20:52:47 +02:00
"
2017-07-08 20:35:22 +02:00
}