]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_inwx.sh
Merge branch 'master' into dev
[mirror_acme.sh.git] / dnsapi / dns_inwx.sh
1 #!/usr/bin/env sh
2
3 #
4 #INWX_User="username"
5 #
6 #INWX_Password="password"
7
8 INWX_Api="https://api.domrobot.com/xmlrpc/"
9
10 ######## Public functions #####################
11
12 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
13 dns_inwx_add() {
14 fulldomain=$1
15 txtvalue=$2
16
17 INWX_User="${INWX_User:-$(_readaccountconf_mutable INWX_User)}"
18 INWX_Password="${INWX_Password:-$(_readaccountconf_mutable INWX_Password)}"
19 if [ -z "$INWX_User" ] || [ -z "$INWX_Password" ]; then
20 INWX_User=""
21 INWX_Password=""
22 _err "You don't specify inwx user and password yet."
23 _err "Please create you key and try again."
24 return 1
25 fi
26
27 #save the api key and email to the account conf file.
28 _saveaccountconf_mutable INWX_User "$INWX_User"
29 _saveaccountconf_mutable INWX_Password "$INWX_Password"
30
31 _debug "First detect the root zone"
32 if ! _get_root "$fulldomain"; then
33 _err "invalid domain"
34 return 1
35 fi
36 _debug _sub_domain "$_sub_domain"
37 _debug _domain "$_domain"
38
39 _info "Adding record"
40 _inwx_add_record "$_domain" "$_sub_domain" "$txtvalue"
41
42 }
43
44 #fulldomain txtvalue
45 dns_inwx_rm() {
46
47 fulldomain=$1
48 txtvalue=$2
49
50 INWX_User="${INWX_User:-$(_readaccountconf_mutable INWX_User)}"
51 INWX_Password="${INWX_Password:-$(_readaccountconf_mutable INWX_Password)}"
52 if [ -z "$INWX_User" ] || [ -z "$INWX_Password" ]; then
53 INWX_User=""
54 INWX_Password=""
55 _err "You don't specify inwx user and password yet."
56 _err "Please create you key and try again."
57 return 1
58 fi
59
60 #save the api key and email to the account conf file.
61 _saveaccountconf_mutable INWX_User "$INWX_User"
62 _saveaccountconf_mutable INWX_Password "$INWX_Password"
63
64 _debug "First detect the root zone"
65 if ! _get_root "$fulldomain"; then
66 _err "invalid domain"
67 return 1
68 fi
69 _debug _sub_domain "$_sub_domain"
70 _debug _domain "$_domain"
71
72 _debug "Getting txt records"
73
74 xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
75 <methodCall>
76 <methodName>nameserver.info</methodName>
77 <params>
78 <param>
79 <value>
80 <struct>
81 <member>
82 <name>domain</name>
83 <value>
84 <string>%s</string>
85 </value>
86 </member>
87 <member>
88 <name>type</name>
89 <value>
90 <string>TXT</string>
91 </value>
92 </member>
93 <member>
94 <name>name</name>
95 <value>
96 <string>%s</string>
97 </value>
98 </member>
99 </struct>
100 </value>
101 </param>
102 </params>
103 </methodCall>' "$_domain" "$_sub_domain")
104 response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
105
106 if ! _contains "$response" "Command completed successfully"; then
107 _err "Error could not get txt records"
108 return 1
109 fi
110
111 if ! printf "%s" "$response" | grep "count" >/dev/null; then
112 _info "Do not need to delete record"
113 else
114 _record_id=$(printf '%s' "$response" | _egrep_o '.*(<member><name>record){1}(.*)([0-9]+){1}' | _egrep_o '<name>id<\/name><value><int>[0-9]+' | _egrep_o '[0-9]+')
115 _info "Deleting record"
116 _inwx_delete_record "$_record_id"
117 fi
118
119 }
120
121 #################### Private functions below ##################################
122
123 _inwx_login() {
124
125 xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
126 <methodCall>
127 <methodName>account.login</methodName>
128 <params>
129 <param>
130 <value>
131 <struct>
132 <member>
133 <name>user</name>
134 <value>
135 <string>%s</string>
136 </value>
137 </member>
138 <member>
139 <name>pass</name>
140 <value>
141 <string>%s</string>
142 </value>
143 </member>
144 </struct>
145 </value>
146 </param>
147 </params>
148 </methodCall>' $INWX_User $INWX_Password)
149
150 response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
151
152 printf "Cookie: %s" "$(grep "domrobot=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'domrobot=[^;]*;' | tr -d ';')"
153
154 }
155
156 _get_root() {
157 domain=$1
158 _debug "get root"
159
160 domain=$1
161 i=2
162 p=1
163
164 _H1=$(_inwx_login)
165 export _H1
166 xml_content='<?xml version="1.0" encoding="UTF-8"?>
167 <methodCall>
168 <methodName>nameserver.list</methodName>
169 </methodCall>'
170
171 response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
172 while true; do
173 h=$(printf "%s" "$domain" | cut -d . -f $i-100)
174 _debug h "$h"
175 if [ -z "$h" ]; then
176 #not valid
177 return 1
178 fi
179
180 if _contains "$response" "$h"; then
181 _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
182 _domain="$h"
183 return 0
184 fi
185 p=$i
186 i=$(_math "$i" + 1)
187 done
188 return 1
189
190 }
191
192 _inwx_delete_record() {
193 record_id=$1
194 xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
195 <methodCall>
196 <methodName>nameserver.deleteRecord</methodName>
197 <params>
198 <param>
199 <value>
200 <struct>
201 <member>
202 <name>id</name>
203 <value>
204 <int>%s</int>
205 </value>
206 </member>
207 </struct>
208 </value>
209 </param>
210 </params>
211 </methodCall>' "$record_id")
212
213 response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
214
215 if ! printf "%s" "$response" | grep "Command completed successfully" >/dev/null; then
216 _err "Error"
217 return 1
218 fi
219 return 0
220
221 }
222
223 _inwx_update_record() {
224 record_id=$1
225 txtval=$2
226 xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
227 <methodCall>
228 <methodName>nameserver.updateRecord</methodName>
229 <params>
230 <param>
231 <value>
232 <struct>
233 <member>
234 <name>content</name>
235 <value>
236 <string>%s</string>
237 </value>
238 </member>
239 <member>
240 <name>id</name>
241 <value>
242 <int>%s</int>
243 </value>
244 </member>
245 </struct>
246 </value>
247 </param>
248 </params>
249 </methodCall>' "$txtval" "$record_id")
250
251 response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
252
253 if ! printf "%s" "$response" | grep "Command completed successfully" >/dev/null; then
254 _err "Error"
255 return 1
256 fi
257 return 0
258
259 }
260
261 _inwx_add_record() {
262
263 domain=$1
264 sub_domain=$2
265 txtval=$3
266
267 xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
268 <methodCall>
269 <methodName>nameserver.createRecord</methodName>
270 <params>
271 <param>
272 <value>
273 <struct>
274 <member>
275 <name>domain</name>
276 <value>
277 <string>%s</string>
278 </value>
279 </member>
280 <member>
281 <name>type</name>
282 <value>
283 <string>TXT</string>
284 </value>
285 </member>
286 <member>
287 <name>content</name>
288 <value>
289 <string>%s</string>
290 </value>
291 </member>
292 <member>
293 <name>name</name>
294 <value>
295 <string>%s</string>
296 </value>
297 </member>
298 </struct>
299 </value>
300 </param>
301 </params>
302 </methodCall>' "$domain" "$txtval" "$sub_domain")
303
304 response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
305
306 if ! printf "%s" "$response" | grep "Command completed successfully" >/dev/null; then
307 _err "Error"
308 return 1
309 fi
310 return 0
311 }