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.

64 lines
2.2 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. #!/usr/bin/env sh
  2. # Author: non7top@gmail.com
  3. # 07 Jul 2017
  4. # report bugs at https://github.com/non7top/acme.sh
  5. # Values to export:
  6. # export PDD_Token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  7. ######## Public functions #####################
  8. #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  9. dns_yandex_add() {
  10. fulldomain="${1}"
  11. txtvalue="${2}"
  12. _debug "Calling: dns_yandex_add() '${fulldomain}' '${txtvalue}'"
  13. _PDD_credentials || return 1
  14. export _H1="PddToken: $PDD_Token"
  15. curDomain="$(echo "${fulldomain}" | rev | cut -d . -f 1-2 | rev)"
  16. curSubdomain="$(echo "${fulldomain}" | rev | cut -d . -f 3- | rev)"
  17. curData="domain=${curDomain}&type=TXT&subdomain=${curSubdomain}&ttl=360&content=${txtvalue}"
  18. curUri="https://pddimp.yandex.ru/api2/admin/dns/add"
  19. curResult="$(_post "${curData}" "${curUri}")"
  20. _debug "Result: $curResult"
  21. }
  22. #Usage: dns_myapi_rm _acme-challenge.www.domain.com
  23. dns_yandex_rm() {
  24. fulldomain="${1}"
  25. _debug "Calling: dns_yandex_rm() '${fulldomain}'"
  26. _PDD_credentials || return 1
  27. export _H1="PddToken: $PDD_Token"
  28. record_id=$(pdd_get_record_id "${fulldomain}")
  29. _debug "Result: $record_id"
  30. curDomain="$(echo "${fulldomain}" | rev | cut -d . -f 1-2 | rev)"
  31. curSubdomain="$(echo "${fulldomain}" | rev | cut -d . -f 3- | rev)"
  32. curUri="https://pddimp.yandex.ru/api2/admin/dns/del"
  33. curData="domain=${curDomain}&record_id=${record_id}"
  34. curResult="$(_post "${curData}" "${curUri}")"
  35. _debug "Result: $curResult"
  36. }
  37. #################### Private functions below ##################################
  38. _PDD_credentials() {
  39. if [ -z "${PDD_Token}" ]; then
  40. PDD_Token=""
  41. _err "You haven't specified the ISPConfig Login data."
  42. return 1
  43. else
  44. _saveaccountconf PDD_Token "${PDD_Token}"
  45. fi
  46. }
  47. pdd_get_record_id() {
  48. fulldomain="${1}"
  49. curDomain="$(echo "${fulldomain}" | rev | cut -d . -f 1-2 | rev)"
  50. curSubdomain="$(echo "${fulldomain}" | rev | cut -d . -f 3- | rev)"
  51. curUri="https://pddimp.yandex.ru/api2/admin/dns/list?domain=${curDomain}"
  52. curResult="$(_get "${curUri}" | _normalizeJson)"
  53. _debug "Result: $curResult"
  54. echo "$curResult" | _egrep_o "{[^{]*\"content\":[^{]*\"subdomain\":\"${curSubdomain}\"" | sed -n -e 's#.* "record_id": \(.*\),[^,]*#\1#p'
  55. }