]> git.proxmox.com Git - mirror_acme.sh.git/blame - dnsapi/dns_do.sh
remove cookiejar temp file
[mirror_acme.sh.git] / dnsapi / dns_do.sh
CommitLineData
7b2fa1ed
SS
1#!/usr/bin/env sh
2
3# DNS API for Domain-Offensive / Resellerinterface / Domainrobot
4
5# DO_PID="KD-1234567"
6# DO_PW="cdfkjl3n2"
7
8DO_URL="https://soap.resellerinterface.de/"
9
10######## Public functions #####################
11
12#Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
13dns_do_add() {
14 fulldomain=$1
15 txtvalue=$2
16 _cookiejar="$(_mktemp)"
17 if _dns_do_authenticate; then
18 _info "Adding TXT record to ${_domain} as ${fulldomain}"
19 _dns_do_soap createRR origin "${_domain}" name "${fulldomain}" type TXT data "${txtvalue}" ttl 300
20 if _contains "${response}" '>success<'; then
21 return 0
22 fi
23 _err "Could not create resource record, check logs"
24 fi
25 return 1
26}
27
28#fulldomain
29dns_do_rm() {
30 fulldomain=$1
31 _cookiejar="$(_mktemp)"
32 if _dns_do_authenticate; then
33 if _dns_do_list_rrs; then
34 for _rrid in ${_rr_list}; do
35 _info "Deleting resource record $_rrid for $_domain"
36 _dns_do_soap deleteRR origin "${_domain}" rrid "${_rrid}"
37 if ! _contains "${response}" '>success<'; then
38 _err "Could not delete resource record for ${_domain}, id ${_rrid}"
39 fi
40 done
41 return 0
42 fi
43 fi
44 return 1
45}
46
47#################### Private functions below ##################################
48_dns_do_authenticate() {
49 _info "Authenticating as ${DO_PID}"
50 _dns_do_soap authPartner partner "${DO_PID}" password "${DO_PW}"
51 if _contains "${response}" '>success<'; then
52 _get_root "$fulldomain"
53 _debug "_domain $_domain"
54 return 0
55 else
56 _err "Authentication failed, check logs"
57 fi
58 return 1
59}
60
61_dns_do_list_rrs() {
62 _dns_do_soap getRRList origin "${_domain}"
63 if ! _contains "${response}" 'SOAP-ENC:Array'; then
64 _err "getRRList origin ${_domain} failed"
65 return 1
66 fi
67 _rr_list="$(echo "${response}" \
68 | tr -d "\n\r\t" \
69 | sed -e 's/<item xsi:type="ns2:Map">/\n/g' \
0d4035e9 70 | grep ">$(_regexcape "$fulldomain")</value>" \
76a3371b
SS
71 | sed -e 's/<\/item>/\n/g' \
72 | grep '>id</key><value' \
73 | _egrep_o '>[0-9]{1,16}<' \
74 | tr -d '><')"
7b2fa1ed
SS
75 [ "${_rr_list}" ]
76}
77
78_dns_do_soap() {
79 func="$1"
80 shift
81 # put the parameters to xml
82 body="<tns:${func} xmlns:tns=\"${DO_URL}\">"
88ed5e50 83 while [ "$1" ]; do
7b2fa1ed
SS
84 _k="$1"
85 shift
86 _v="$1"
87 shift
88 body="$body<$_k>$_v</$_k>"
89 done
90 body="$body</tns:${func}>"
91 _debug2 "SOAP request ${body}"
92
93 # build SOAP XML
94 _xml='<?xml version="1.0" encoding="UTF-8"?>
95<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
96 <env:Body>'"$body"'</env:Body>
97</env:Envelope>'
98
99 # set SOAP headers
100 _H1="SOAPAction: ${DO_URL}#${func}"
7b2fa1ed
SS
101
102 if ! response="$(_post "${_xml}" "${DO_URL}")"; then
103 _err "Error <$1>"
104 return 1
105 fi
106 _debug2 "SOAP response $response"
107
108 # retrieve cookie header
b95a99e0 109 _H2="$(_egrep_o 'Cookie: [^;]+' <"$HTTP_HEADER" | head -1)"
7b2fa1ed
SS
110
111 return 0
112}
113
114_get_root() {
115 domain=$1
116 i=1
117
118 _all_domains="$(_mktemp)"
119 _dns_do_soap getDomainList
88ed5e50 120 echo "${response}" | tr -d "\n\r\t " | _egrep_o 'domain</key><value[^>]+>[^<]+' | sed -e 's/^domain<\/key><value[^>]+>//g' >"${_all_domains}"
7b2fa1ed
SS
121
122 while true; do
123 h=$(printf "%s" "$domain" | cut -d . -f $i-100)
124 if [ -z "$h" ]; then
125 return 1
126 fi
127
0d4035e9 128 if grep -q "$(_regexcape "$h")" "${_all_domains}"; then
7b2fa1ed
SS
129 _domain="$h"
130 return 0
131 fi
132
133 i=$(_math $i + 1)
134 done
135 _debug "$domain not found"
136
137 return 1
138}
0d4035e9
SS
139
140_regexcape() {
141 echo "$1" | sed -e 's/\([]\.$*^[]\)/\\\1/g'
142}