]>
Commit | Line | Data |
---|---|---|
ace947e6 | 1 | #!/usr/bin/env sh |
2 | ||
ace947e6 | 3 | #DD_API_User="xxxxx" |
4 | #DD_API_Key="xxxxxx" | |
5 | ||
6 | _DD_BASE="https://durabledns.com/services/dns" | |
7 | ||
8 | ######## Public functions ##################### | |
9 | ||
10 | #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" | |
11 | dns_durabledns_add() { | |
12 | fulldomain=$1 | |
13 | txtvalue=$2 | |
14 | ||
15 | DD_API_User="${DD_API_User:-$(_readaccountconf_mutable DD_API_User)}" | |
16 | DD_API_Key="${DD_API_Key:-$(_readaccountconf_mutable DD_API_Key)}" | |
17 | if [ -z "$DD_API_User" ] || [ -z "$DD_API_Key" ]; then | |
18 | DD_API_User="" | |
19 | DD_API_Key="" | |
20 | _err "You didn't specify a durabledns api user or key yet." | |
21 | _err "You can get yours from here https://durabledns.com/dashboard/index.php" | |
22 | return 1 | |
23 | fi | |
24 | ||
25 | #save the api key and email to the account conf file. | |
26 | _saveaccountconf_mutable DD_API_User "$DD_API_User" | |
27 | _saveaccountconf_mutable DD_API_Key "$DD_API_Key" | |
28 | ||
29 | _debug "First detect the root zone" | |
30 | if ! _get_root "$fulldomain"; then | |
31 | _err "invalid domain" | |
32 | return 1 | |
33 | fi | |
34 | ||
35 | _debug _sub_domain "$_sub_domain" | |
36 | _debug _domain "$_domain" | |
37 | ||
38 | _dd_soap createRecord string zonename "$_domain." string name "$_sub_domain" string type "TXT" string data "$txtvalue" int aux 0 int ttl 10 string ddns_enabled N | |
39 | _contains "$response" "createRecordResponse" | |
40 | } | |
41 | ||
ace947e6 | 42 | dns_durabledns_rm() { |
43 | fulldomain=$1 | |
44 | txtvalue=$2 | |
45 | ||
46 | DD_API_User="${DD_API_User:-$(_readaccountconf_mutable DD_API_User)}" | |
47 | DD_API_Key="${DD_API_Key:-$(_readaccountconf_mutable DD_API_Key)}" | |
48 | if [ -z "$DD_API_User" ] || [ -z "$DD_API_Key" ]; then | |
49 | DD_API_User="" | |
50 | DD_API_Key="" | |
51 | _err "You didn't specify a durabledns api user or key yet." | |
52 | _err "You can get yours from here https://durabledns.com/dashboard/index.php" | |
53 | return 1 | |
54 | fi | |
55 | ||
56 | _debug "First detect the root zone" | |
57 | if ! _get_root "$fulldomain"; then | |
58 | _err "invalid domain" | |
59 | return 1 | |
60 | fi | |
61 | _debug _sub_domain "$_sub_domain" | |
62 | _debug _domain "$_domain" | |
63 | ||
64 | _debug "Find record id" | |
65 | if ! _dd_soap listRecords string zonename "$_domain."; then | |
66 | _err "can not listRecords" | |
67 | return 1 | |
68 | fi | |
69 | ||
70 | subtxt="$(echo "$txtvalue" | cut -c 1-30)" | |
71 | record="$(echo "$response" | sed 's/<item\>/#<item>/g' | tr '#' '\n' | grep ">$subtxt")" | |
72 | _debug record "$record" | |
73 | if [ -z "$record" ]; then | |
74 | _err "can not find record for txtvalue" "$txtvalue" | |
75 | _err "$response" | |
76 | return 1 | |
77 | fi | |
78 | ||
79 | recordid="$(echo "$record" | _egrep_o '<id xsi:type="xsd:int">[0-9]*</id>' | cut -d '>' -f 2 | cut -d '<' -f 1)" | |
80 | _debug recordid "$recordid" | |
81 | if [ -z "$recordid" ]; then | |
82 | _err "can not find record id" | |
83 | return 1 | |
84 | fi | |
85 | ||
86 | if ! _dd_soap deleteRecord string zonename "$_domain." int id "$recordid"; then | |
87 | _err "delete error" | |
88 | return 1 | |
89 | fi | |
90 | ||
91 | _contains "$response" "Success" | |
92 | } | |
93 | ||
94 | #_acme-challenge.www.domain.com | |
95 | #returns | |
96 | # _sub_domain=_acme-challenge.www | |
97 | # _domain=domain.com | |
98 | _get_root() { | |
99 | domain=$1 | |
100 | if ! _dd_soap "listZones"; then | |
101 | return 1 | |
102 | fi | |
103 | ||
104 | i=1 | |
105 | p=1 | |
106 | while true; do | |
107 | h=$(printf "%s" "$domain" | cut -d . -f $i-100) | |
108 | _debug h "$h" | |
109 | if [ -z "$h" ]; then | |
110 | #not valid | |
111 | return 1 | |
112 | fi | |
113 | ||
114 | if _contains "$response" ">$h.</origin>"; then | |
115 | _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p) | |
116 | _domain=$h | |
117 | return 0 | |
118 | fi | |
119 | p=$i | |
120 | i=$(_math "$i" + 1) | |
121 | done | |
122 | return 1 | |
123 | ||
124 | } | |
125 | ||
ace947e6 | 126 | #method |
127 | _dd_soap() { | |
128 | _method="$1" | |
129 | shift | |
130 | _urn="${_method}wsdl" | |
131 | # put the parameters to xml | |
132 | body="<tns:$_method> | |
133 | <apiuser xsi:type=\"xsd:string\">$DD_API_User</apiuser> | |
134 | <apikey xsi:type=\"xsd:string\">$DD_API_Key</apikey> | |
135 | " | |
136 | while [ "$1" ]; do | |
137 | _t="$1" | |
138 | shift | |
139 | _k="$1" | |
140 | shift | |
141 | _v="$1" | |
142 | shift | |
143 | body="$body<$_k xsi:type=\"xsd:$_t\">$_v</$_k>" | |
144 | done | |
145 | body="$body</tns:$_method>" | |
146 | _debug2 "SOAP request ${body}" | |
147 | ||
148 | # build SOAP XML | |
149 | _xml='<?xml version="1.0" encoding="utf-8"?> | |
ac9f6e3a PDH |
150 | <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" |
151 | xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" | |
152 | xmlns:tns="urn:'$_urn'" | |
153 | xmlns:types="urn:'$_urn'/encodedTypes" | |
154 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
ace947e6 | 155 | xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
156 | <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'"$body"'</soap:Body> | |
157 | </soap:Envelope>' | |
158 | ||
159 | _debug2 _xml "$_xml" | |
160 | # set SOAP headers | |
161 | _action="SOAPAction: \"urn:$_urn#$_method\"" | |
162 | _debug2 "_action" "$_action" | |
163 | export _H1="$_action" | |
164 | export _H2="Content-Type: text/xml; charset=utf-8" | |
165 | ||
166 | _url="$_DD_BASE/$_method.php" | |
167 | _debug "_url" "$_url" | |
168 | if ! response="$(_post "${_xml}" "${_url}")"; then | |
169 | _err "Error <$1>" | |
170 | return 1 | |
171 | fi | |
172 | _debug2 "response" "$response" | |
173 | response="$(echo "$response" | tr -d "\r\n" | _egrep_o ":${_method}Response .*:${_method}Response><")" | |
174 | _debug2 "response" "$response" | |
175 | return 0 | |
176 | } |