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.

107 lines
3.3 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
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=$(_PDD_get_domain "$fulldomain")
  16. _debug "Found suitable domain in pdd: $curDomain"
  17. curSubdomain="$(echo "${fulldomain}" | sed -e "s@.${curDomain}\$@@")"
  18. curData="domain=${curDomain}&type=TXT&subdomain=${curSubdomain}&ttl=360&content=${txtvalue}"
  19. curUri="https://pddimp.yandex.ru/api2/admin/dns/add"
  20. curResult="$(_post "${curData}" "${curUri}")"
  21. _debug "Result: $curResult"
  22. }
  23. #Usage: dns_myapi_rm _acme-challenge.www.domain.com
  24. dns_yandex_rm() {
  25. fulldomain="${1}"
  26. _debug "Calling: dns_yandex_rm() '${fulldomain}'"
  27. _PDD_credentials || return 1
  28. export _H1="PddToken: $PDD_Token"
  29. record_id=$(pdd_get_record_id "${fulldomain}")
  30. _debug "Result: $record_id"
  31. curDomain=$(_PDD_get_domain "$fulldomain")
  32. _debug "Found suitable domain in pdd: $curDomain"
  33. curSubdomain="$(echo "${fulldomain}" | sed -e "s@.${curDomain}\$@@")"
  34. curUri="https://pddimp.yandex.ru/api2/admin/dns/del"
  35. curData="domain=${curDomain}&record_id=${record_id}"
  36. curResult="$(_post "${curData}" "${curUri}")"
  37. _debug "Result: $curResult"
  38. }
  39. #################### Private functions below ##################################
  40. _PDD_get_domain() {
  41. fulldomain="${1}"
  42. __page=1
  43. __last=0
  44. while [ $__last -eq 0 ]; do
  45. uri1="https://pddimp.yandex.ru/api2/admin/domain/domains?page=${__page}&on_page=20"
  46. res1=$(_get "$uri1" | _normalizeJson)
  47. #_debug "$res1"
  48. __found=$(echo "$res1" | sed -n -e 's#.* "found": \([^,]*\),.*#\1#p')
  49. _debug "found: $__found results on page"
  50. if [ "$__found" -lt 20 ]; then
  51. _debug "last page: $__page"
  52. __last=1
  53. fi
  54. __all_domains="$__all_domains $(echo "$res1" | sed -e "s@,@\n@g" | grep '"name"' | cut -d: -f2 | sed -e 's@"@@g')"
  55. __page=$(_math $__page + 1)
  56. done
  57. k=2
  58. while [ $k -lt 10 ]; do
  59. __t=$(echo "$fulldomain" | cut -d . -f $k-100)
  60. _debug "finding zone for domain $__t"
  61. for d in $__all_domains; do
  62. if [ "$d" = "$__t" ]; then
  63. echo "$__t"
  64. return
  65. fi
  66. done
  67. k=$(_math $k + 1)
  68. done
  69. _err "No suitable domain found in your account"
  70. return 1
  71. }
  72. _PDD_credentials() {
  73. if [ -z "${PDD_Token}" ]; then
  74. PDD_Token=""
  75. _err "You need to export PDD_Token=xxxxxxxxxxxxxxxxx"
  76. _err "You can get it at https://pddimp.yandex.ru/api2/admin/get_token"
  77. return 1
  78. else
  79. _saveaccountconf PDD_Token "${PDD_Token}"
  80. fi
  81. }
  82. pdd_get_record_id() {
  83. fulldomain="${1}"
  84. curDomain=$(_PDD_get_domain "$fulldomain")
  85. _debug "Found suitable domain in pdd: $curDomain"
  86. curSubdomain="$(echo "${fulldomain}" | sed -e "s@.${curDomain}\$@@")"
  87. curUri="https://pddimp.yandex.ru/api2/admin/dns/list?domain=${curDomain}"
  88. curResult="$(_get "${curUri}" | _normalizeJson)"
  89. _debug "Result: $curResult"
  90. echo "$curResult" | _egrep_o "{[^{]*\"content\":[^{]*\"subdomain\":\"${curSubdomain}\"" | sed -n -e 's#.* "record_id": \(.*\),[^,]*#\1#p'
  91. }