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.

70 lines
2.2 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 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 || exit 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 || exit 1
  27. export _H1="PddToken: $PDD_Token"
  28. record_id=$(pdd_get_record_id "${fulldomain}")
  29. curDomain="$(echo "${fulldomain}" | rev | cut -d . -f 1-2 | rev )"
  30. curSubdomain="$(echo "${fulldomain}" | rev | cut -d . -f 3- | rev )"
  31. curUri="https://pddimp.yandex.ru/api2/admin/dns/del"
  32. curData="domain=${curDomain}&record_id=${record_id}"
  33. curResult="$(_post "${curData}" "${curUri}")"
  34. _debug "Result: $curResult"
  35. }
  36. #################### Private functions below ##################################
  37. _PDD_credentials() {
  38. if [ -z "${PDD_Token}" ]; then
  39. PDD_Token=""
  40. _err "You haven't specified the ISPConfig Login data."
  41. return 1
  42. else
  43. _saveaccountconf PDD_Token "${PDD_Token}"
  44. fi
  45. }
  46. pdd_get_record_id() {
  47. fulldomain="${1}"
  48. curDomain="$(echo "${fulldomain}" | awk -F. '{printf("%s.%s\n",$(NF-1), $NF)}')"
  49. curUri="https://pddimp.yandex.ru/api2/admin/dns/list?domain=${curDomain}"
  50. curResult="$(_get "${curUri}")"
  51. echo "${curResult}" \
  52. | python -c "
  53. import sys, json;
  54. rs=json.load(sys.stdin)[\"records\"]
  55. for r in rs:
  56. if r[\"fqdn\"]==\"${fulldomain}\":
  57. print r[\"record_id\"]
  58. exit
  59. "
  60. }