]> git.proxmox.com Git - mirror_acme.sh.git/blame - dnsapi/dns_do.sh
Merge pull request #4547 from eastonman/master
[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
bf8ffade 5# Report bugs at https://github.com/seidler2547/acme.sh/issues
6
7# set these environment variables to match your customer ID and password:
7b2fa1ed
SS
8# DO_PID="KD-1234567"
9# DO_PW="cdfkjl3n2"
10
11DO_URL="https://soap.resellerinterface.de/"
12
13######## Public functions #####################
14
15#Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
16dns_do_add() {
17 fulldomain=$1
18 txtvalue=$2
7b2fa1ed
SS
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
31dns_do_rm() {
32 fulldomain=$1
7b2fa1ed
SS
33 if _dns_do_authenticate; then
34 if _dns_do_list_rrs; then
cdec38ba 35 _dns_do_had_error=0
7b2fa1ed
SS
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
cdec38ba 40 _dns_do_had_error=1
7b2fa1ed
SS
41 _err "Could not delete resource record for ${_domain}, id ${_rrid}"
42 fi
43 done
1633d145 44 return $_dns_do_had_error
7b2fa1ed
SS
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
743f821f 59 _err "Authentication failed, are DO_PID and DO_PW set correctly?"
7b2fa1ed
SS
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
19c43451 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 '><')"
7b2fa1ed
SS
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}\">"
88ed5e50 86 while [ "$1" ]; do
7b2fa1ed
SS
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
9efd40a3 103 export _H1="SOAPAction: ${DO_URL}#${func}"
7b2fa1ed
SS
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
2b2b65fe 112 _H2="$(_egrep_o 'Cookie: [^;]+' <"$HTTP_HEADER" | _head_n 1)"
113 export _H2
7b2fa1ed
SS
114
115 return 0
116}
117
118_get_root() {
119 domain=$1
120 i=1
121
7b2fa1ed 122 _dns_do_soap getDomainList
19c43451 123 _all_domains="$(echo "${response}" |
124 tr -d "\n\r\t " |
125 _egrep_o 'domain</key><value[^>]+>[^<]+' |
126 sed -e 's/^domain<\/key><value[^>]*>//g')"
7b2fa1ed
SS
127
128 while true; do
129 h=$(printf "%s" "$domain" | cut -d . -f $i-100)
130 if [ -z "$h" ]; then
131 return 1
132 fi
133
d1d2f6f4 134 if _contains "${_all_domains}" "^$(_regexcape "$h")\$"; then
7b2fa1ed
SS
135 _domain="$h"
136 return 0
137 fi
138
139 i=$(_math $i + 1)
140 done
141 _debug "$domain not found"
142
143 return 1
144}
0d4035e9
SS
145
146_regexcape() {
147 echo "$1" | sed -e 's/\([]\.$*^[]\)/\\\1/g'
148}