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.

87 lines
2.2 KiB

7 years ago
7 years ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_zonomi_info='zonomi.com
  4. Site: zonomi.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_zonomi
  6. Options:
  7. ZM_Key API Key
  8. '
  9. ZM_Api="https://zonomi.com/app/dns/dyndns.jsp"
  10. ######## Public functions #####################
  11. #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  12. dns_zonomi_add() {
  13. fulldomain=$1
  14. txtvalue=$2
  15. ZM_Key="${ZM_Key:-$(_readaccountconf_mutable ZM_Key)}"
  16. if [ -z "$ZM_Key" ]; then
  17. ZM_Key=""
  18. _err "You don't specify zonomi api key yet."
  19. _err "Please create your key and try again."
  20. return 1
  21. fi
  22. #save the api key to the account conf file.
  23. _saveaccountconf_mutable ZM_Key "$ZM_Key"
  24. _info "Get existing txt records for $fulldomain"
  25. if ! _zm_request "action=QUERY&name=$fulldomain"; then
  26. _err "error"
  27. return 1
  28. fi
  29. if _contains "$response" "<record"; then
  30. _debug "get and update records"
  31. _qstr="action[1]=SET&type[1]=TXT&name[1]=$fulldomain&value[1]=$txtvalue"
  32. _qindex=2
  33. for t in $(echo "$response" | tr -d "\r\n" | _egrep_o '<action.*</action>' | tr "<" "\n" | grep record | grep 'type="TXT"' | cut -d '"' -f 6); do
  34. _debug2 t "$t"
  35. _qstr="$_qstr&action[$_qindex]=SET&type[$_qindex]=TXT&name[$_qindex]=$fulldomain&value[$_qindex]=$t"
  36. _qindex="$(_math "$_qindex" + 1)"
  37. done
  38. _zm_request "$_qstr"
  39. else
  40. _debug "Just add record"
  41. _zm_request "action=SET&type=TXT&name=$fulldomain&value=$txtvalue"
  42. fi
  43. }
  44. #fulldomain txtvalue
  45. dns_zonomi_rm() {
  46. fulldomain=$1
  47. txtvalue=$2
  48. ZM_Key="${ZM_Key:-$(_readaccountconf_mutable ZM_Key)}"
  49. if [ -z "$ZM_Key" ]; then
  50. ZM_Key=""
  51. _err "You don't specify zonomi api key yet."
  52. _err "Please create your key and try again."
  53. return 1
  54. fi
  55. _zm_request "action=DELETE&type=TXT&name=$fulldomain"
  56. }
  57. #################### Private functions below ##################################
  58. #qstr
  59. _zm_request() {
  60. qstr="$1"
  61. _debug2 "qstr" "$qstr"
  62. _zm_url="$ZM_Api?api_key=$ZM_Key&$qstr"
  63. _debug2 "_zm_url" "$_zm_url"
  64. response="$(_get "$_zm_url")"
  65. if [ "$?" != "0" ]; then
  66. return 1
  67. fi
  68. _debug2 response "$response"
  69. _contains "$response" "<is_ok>OK:"
  70. }