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