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.

85 lines
2.1 KiB

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