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.

145 lines
3.2 KiB

7 years ago
2 months ago
2 months ago
7 years ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_zilore_info='Zilore.com
  4. Site: Zilore.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_zilore
  6. Options:
  7. Zilore_Key API Key
  8. '
  9. Zilore_API="https://api.zilore.com/dns/v1"
  10. ######## Public functions #####################
  11. dns_zilore_add() {
  12. fulldomain=$1
  13. txtvalue=$2
  14. _info "Using Zilore"
  15. _debug fulldomain "$fulldomain"
  16. _debug txtvalue "$txtvalue"
  17. Zilore_Key="${Zilore_Key:-$(_readaccountconf_mutable Zilore_Key)}"
  18. if [ -z "$Zilore_Key" ]; then
  19. Zilore_Key=""
  20. _err "Please define Zilore API key"
  21. return 1
  22. fi
  23. _saveaccountconf_mutable Zilore_Key "$Zilore_Key"
  24. if ! _get_root "$fulldomain"; then
  25. _err "Unable to determine root domain"
  26. return 1
  27. else
  28. _debug _domain "$_domain"
  29. fi
  30. if _zilore_rest POST "domains/$_domain/records?record_type=TXT&record_ttl=600&record_name=$fulldomain&record_value=\"$txtvalue\""; then
  31. if _contains "$response" '"added"' >/dev/null; then
  32. _info "Added TXT record, waiting for validation"
  33. return 0
  34. else
  35. _debug response "$response"
  36. _err "Error while adding DNS records"
  37. return 1
  38. fi
  39. fi
  40. return 1
  41. }
  42. dns_zilore_rm() {
  43. fulldomain=$1
  44. txtvalue=$2
  45. _info "Using Zilore"
  46. _debug fulldomain "$fulldomain"
  47. _debug txtvalue "$txtvalue"
  48. Zilore_Key="${Zilore_Key:-$(_readaccountconf_mutable Zilore_Key)}"
  49. if [ -z "$Zilore_Key" ]; then
  50. Zilore_Key=""
  51. _err "Please define Zilore API key"
  52. return 1
  53. fi
  54. _saveaccountconf_mutable Zilore_Key "$Zilore_Key"
  55. if ! _get_root "$fulldomain"; then
  56. _err "Unable to determine root domain"
  57. return 1
  58. else
  59. _debug _domain "$_domain"
  60. fi
  61. _debug "Getting TXT records"
  62. _zilore_rest GET "domains/${_domain}/records?search_text=$txtvalue&search_record_type=TXT"
  63. _debug response "$response"
  64. if ! _contains "$response" '"ok"' >/dev/null; then
  65. _err "Error while getting records list"
  66. return 1
  67. else
  68. _record_id=$(printf "%s\n" "$response" | _egrep_o "\"record_id\":\"[^\"]+\"" | cut -d : -f 2 | tr -d \" | _head_n 1)
  69. if [ -z "$_record_id" ]; then
  70. _err "Cannot determine _record_id"
  71. return 1
  72. else
  73. _debug _record_id "$_record_id"
  74. fi
  75. if ! _zilore_rest DELETE "domains/${_domain}/records?record_id=$_record_id"; then
  76. _err "Error while deleting chosen record"
  77. return 1
  78. fi
  79. _contains "$response" '"ok"'
  80. fi
  81. }
  82. #################### Private functions below ##################################
  83. _get_root() {
  84. domain=$1
  85. i=1
  86. while true; do
  87. h=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
  88. _debug h "$h"
  89. if [ -z "$h" ]; then
  90. #not valid
  91. return 1
  92. fi
  93. if ! _zilore_rest GET "domains?search_text=$h"; then
  94. return 1
  95. fi
  96. if _contains "$response" "\"$h\"" >/dev/null; then
  97. _domain=$h
  98. return 0
  99. else
  100. _debug "$h not found"
  101. fi
  102. i=$(_math "$i" + 1)
  103. done
  104. return 1
  105. }
  106. _zilore_rest() {
  107. method=$1
  108. param=$2
  109. data=$3
  110. export _H1="X-Auth-Key: $Zilore_Key"
  111. if [ "$method" != "GET" ]; then
  112. response="$(_post "$data" "$Zilore_API/$param" "" "$method")"
  113. else
  114. response="$(_get "$Zilore_API/$param")"
  115. fi
  116. if [ "$?" != "0" ]; then
  117. _err "error $param"
  118. return 1
  119. fi
  120. _debug2 response "$response"
  121. return 0
  122. }