4 #Dynu_ClientId="0b71cae7-a099-4f6b-8ddf-94571cdb760d"
7 #Dynu_Secret="aCUEY4BDCV45KI8CSIC3sp2LKQ9"
13 Dynu_EndPoint
="https://api.dynu.com/v2"
15 #Author: Dynu Systems, Inc.
16 #Report Bugs here: https://github.com/shar0119/acme.sh
18 ######## Public functions #####################
20 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
25 if [ -z "$Dynu_ClientId" ] ||
[ -z "$Dynu_Secret" ]; then
28 _err
"Dynu client id and secret is not specified."
29 _err
"Please create you API client id and secret and try again."
33 #save the client id and secret to the account conf file.
34 _saveaccountconf Dynu_ClientId
"$Dynu_ClientId"
35 _saveaccountconf Dynu_Secret
"$Dynu_Secret"
37 if [ -z "$Dynu_Token" ]; then
38 _info
"Getting Dynu token."
39 if ! _dynu_authentication
; then
40 _err
"Can not get token."
44 _debug
"Detect root zone"
45 if ! _get_root
"$fulldomain"; then
46 _err
"Invalid domain."
51 _debug _domain_name
"$_domain_name"
53 _info
"Creating TXT record."
54 if ! _dynu_rest POST
"dns/$dnsId/record" "{\"domainId\":\"$dnsId\",\"nodeName\":\"$_node\",\"recordType\":\"TXT\",\"textData\":\"$txtvalue\",\"state\":true,\"ttl\":90}"; then
58 if ! _contains
"$response" "200"; then
59 _err
"Could not add TXT record."
66 #Usage: rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
71 if [ -z "$Dynu_ClientId" ] ||
[ -z "$Dynu_Secret" ]; then
74 _err
"Dynu client id and secret is not specified."
75 _err
"Please create you API client id and secret and try again."
79 #save the client id and secret to the account conf file.
80 _saveaccountconf Dynu_ClientId
"$Dynu_ClientId"
81 _saveaccountconf Dynu_Secret
"$Dynu_Secret"
83 if [ -z "$Dynu_Token" ]; then
84 _info
"Getting Dynu token."
85 if ! _dynu_authentication
; then
86 _err
"Can not get token."
90 _debug
"Detect root zone."
91 if ! _get_root
"$fulldomain"; then
92 _err
"Invalid domain."
97 _debug _domain_name
"$_domain_name"
99 _info
"Checking for TXT record."
100 if ! _get_recordid
"$fulldomain" "$txtvalue"; then
101 _err
"Could not get TXT record id."
105 if [ "$_dns_record_id" = "" ]; then
106 _err
"TXT record not found."
110 _info
"Removing TXT record."
111 if ! _delete_txt_record
"$_dns_record_id"; then
112 _err
"Could not remove TXT record $_dns_record_id."
118 ######## Private functions below ##################################
119 #_acme-challenge.www.domain.com
121 # _node=_acme-challenge.www
122 # _domain_name=domain.com
128 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
135 if ! _dynu_rest GET
"dns/getroot/$h"; then
139 if _contains
"$response" "\"domainName\":\"$h\"" >/dev
/null
; then
140 dnsId
=$
(printf "%s" "$response" |
tr -d "{}" | cut
-d , -f 2 | cut
-d : -f 2)
142 _node
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
156 if ! _dynu_rest GET
"dns/$dnsId/record"; then
160 if ! _contains
"$response" "$txtvalue"; then
165 _dns_record_id
=$
(printf "%s" "$response" |
sed -e 's/[^{]*\({[^}]*}\)[^{]*/\1\n/g' |
grep "\"textData\":\"$txtvalue\"" |
sed -e 's/.*"id":\([^,]*\).*/\1/')
169 _delete_txt_record
() {
172 if ! _dynu_rest DELETE
"dns/$dnsId/record/$_dns_record_id"; then
176 if ! _contains
"$response" "200"; then
189 export _H1
="Authorization: Bearer $Dynu_Token"
190 export _H2
="Content-Type: application/json"
192 if [ "$data" ] ||
[ "$m" = "DELETE" ]; then
194 response
="$(_post "$data" "$Dynu_EndPoint/$ep" "" "$m")"
196 _info
"Getting $Dynu_EndPoint/$ep"
197 response
="$(_get "$Dynu_EndPoint/$ep")"
200 if [ "$?" != "0" ]; then
204 _debug2 response
"$response"
208 _dynu_authentication
() {
209 realm
="$(printf "%s
" "$Dynu_ClientId:$Dynu_Secret" | _base64)"
211 export _H1
="Authorization: Basic $realm"
212 export _H2
="Content-Type: application/json"
214 response
="$(_get "$Dynu_EndPoint/oauth
2/token
")"
215 if [ "$?" != "0" ]; then
216 _err
"Authentication failed."
219 if _contains
"$response" "Authentication Exception"; then
220 _err
"Authentication failed."
223 if _contains
"$response" "access_token"; then
224 Dynu_Token
=$
(printf "%s" "$response" |
tr -d "{}" | cut
-d , -f 1 | cut
-d : -f 2 | cut
-d '"' -f 2)
226 if _contains
"$Dynu_Token" "null"; then
230 _debug2 response
"$response"