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