4 #AD_API_KEY="sdfsdfsdfljlbjkljlkjsdfoiwje"
6 #This is the Alwaysdata api wrapper for acme.sh
9 #Report Bugs here: https://github.com/wpk-/acme.sh
11 AD_API_URL
="https://$AD_API_KEY:@api.alwaysdata.com/v1"
13 ######## Public functions #####################
15 #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
20 if [ -z "$AD_API_KEY" ]; then
22 _err
"You didn't specify the AD api key yet."
23 _err
"Please create you key and try again."
27 _saveaccountconf AD_API_KEY
"$AD_API_KEY"
29 _debug
"First detect the root zone"
30 if ! _get_root
"$fulldomain"; then
34 _debug _domain_id
"$_domain_id"
35 _debug _sub_domain
"$_sub_domain"
36 _debug _domain
"$_domain"
38 _ad_tmpl_json
="{\"domain\":$_domain_id,\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"value\":\"$txtvalue\"}"
40 if _ad_rest POST
"record/" "$_ad_tmpl_json" && [ -z "$response" ]; then
41 _info
"txt record updated success."
53 _debug
"First detect the root zone"
54 if ! _get_root
"$fulldomain"; then
58 _debug _domain_id
"$_domain_id"
59 _debug _sub_domain
"$_sub_domain"
60 _debug _domain
"$_domain"
62 _debug
"Getting txt records"
63 _ad_rest GET
"record/?domain=$_domain_id&name=$_sub_domain"
65 if [ -n "$response" ]; then
66 record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":\s*[0-9]+" | cut
-d : -f 2 |
tr -d " " | _head_n
1)
67 _debug record_id
"$record_id"
68 if [ -z "$record_id" ]; then
69 _err
"Can not get record id to remove."
72 if _ad_rest DELETE
"record/$record_id/" && [ -z "$response" ]; then
73 _info
"txt record deleted success."
76 _debug response
"$response"
83 #################### Private functions below ##################################
84 #_acme-challenge.www.domain.com
86 # _sub_domain=_acme-challenge.www
94 if _ad_rest GET
"domain/"; then
95 response
="$(echo "$response" | tr -d "\n" | sed 's/{/\n&/g')"
97 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
104 hostedzone
="$(echo "$response" | _egrep_o "{.
*\"name
\":\s
*\"$h\".
*}")"
105 if [ "$hostedzone" ]; then
106 _domain_id
=$
(printf "%s\n" "$hostedzone" | _egrep_o
"\"id\":\s*[0-9]+" | _head_n
1 | cut
-d : -f 2 |
tr -d \
)
107 if [ "$_domain_id" ]; then
108 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
121 #method uri qstr data
130 export _H1
="Accept: application/json"
131 export _H2
="Content-Type: application/json"
133 if [ "$mtd" != "GET" ]; then
134 # both POST and DELETE.
136 response
="$(_post "$data" "$AD_API_URL/$ep" "" "$mtd")"
138 response
="$(_get "$AD_API_URL/$ep")"
141 if [ "$?" != "0" ]; then
145 _debug2 response
"$response"