4 #Dynu_ClientId="0b71cae7-a099-4f6b-8ddf-94571cdb760d"
7 #Dynu_Secret="aCUEY4BDCV45KI8CSIC3sp2LKQ9"
13 Dynu_EndPoint
="https://api.dynu.com/v1"
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/record/add" "{\"domain_name\":\"$_domain_name\",\"node_name\":\"$_node\",\"record_type\":\"TXT\",\"text_data\":\"$txtvalue\",\"state\":true,\"ttl\":90}"; then
58 if ! _contains
"$response" "text_data"; 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
125 if ! _dynu_rest GET
"dns/getroot/$domain"; then
129 if ! _contains
"$response" "domain_name"; then
130 _debug
"Domain name not found."
134 _domain_name
=$
(printf "%s" "$response" |
tr -d "{}" | cut
-d , -f 1 | cut
-d : -f 2 | cut
-d '"' -f 2)
135 _node
=$
(printf "%s" "$response" |
tr -d "{}" | cut
-d , -f 3 | cut
-d : -f 2 | cut
-d '"' -f 2)
143 if ! _dynu_rest GET
"dns/record/get?hostname=$fulldomain&rrtype=TXT"; then
147 if ! _contains
"$response" "$txtvalue"; then
152 _dns_record_id
=$
(printf "%s" "$response" | _egrep_o
"{[^}]*}" |
grep "\"text_data\":\"$txtvalue\"" |
grep -Po '"id":\K[0-9]+')
157 _delete_txt_record
() {
160 if ! _dynu_rest GET
"dns/record/delete/$_dns_record_id"; then
164 if ! _contains
"$response" "true"; then
177 export _H1
="Authorization: Bearer $Dynu_Token"
178 export _H2
="Content-Type: application/json"
182 response
="$(_post "$data" "$Dynu_EndPoint/$ep" "" "$m")"
184 _info
"Getting $Dynu_EndPoint/$ep"
185 response
="$(_get "$Dynu_EndPoint/$ep")"
188 if [ "$?" != "0" ]; then
192 _debug2 response
"$response"
196 _dynu_authentication
() {
197 realm
="$(printf "%s
" "$Dynu_ClientId:$Dynu_Secret" | _base64)"
199 export _H1
="Authorization: Basic $realm"
200 export _H2
="Content-Type: application/json"
202 response
="$(_get "$Dynu_EndPoint/oauth
2/token
")"
203 if [ "$?" != "0" ]; then
204 _err
"Authentication failed."
207 if _contains
"$response" "accessToken"; then
208 Dynu_Token
=$
(printf "%s" "$response" |
tr -d "[]" | cut
-d , -f 2 | cut
-d : -f 2 | cut
-d '"' -f 2)
210 if _contains
"$Dynu_Token" "null"; then
214 _debug2 response
"$response"