3 #######################################################
5 # easyDNS REST API for acme.sh by Neilpang based on dns_cf.sh
7 # API Documentation: https://sandbox.rest.easydns.net:3001/
9 # Author: wurzelpanzer [wurzelpanzer@maximolider.net]
10 # Report Bugs here: https://github.com/acmesh-official/acme.sh/issues/2647
12 #################### Public functions #################
14 #EASYDNS_Key="xxxxxxxxxxxxxxxxxxxxxxxx"
15 #EASYDNS_Token="xxxxxxxxxxxxxxxxxxxxxxxx"
16 EASYDNS_Api
="https://rest.easydns.net"
18 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
23 EASYDNS_Token
="${EASYDNS_Token:-$(_readaccountconf_mutable EASYDNS_Token)}"
24 EASYDNS_Key
="${EASYDNS_Key:-$(_readaccountconf_mutable EASYDNS_Key)}"
26 if [ -z "$EASYDNS_Token" ] ||
[ -z "$EASYDNS_Key" ]; then
27 _err
"You didn't specify an easydns.net token or api key. Signup at https://cp.easydns.com/manage/security/api/signup.php"
30 _saveaccountconf_mutable EASYDNS_Token
"$EASYDNS_Token"
31 _saveaccountconf_mutable EASYDNS_Key
"$EASYDNS_Key"
34 _debug
"First detect the root zone"
35 if ! _get_root
"$fulldomain"; then
39 _debug _sub_domain
"$_sub_domain"
40 _debug _domain
"$_domain"
42 _debug
"Getting txt records"
43 _EASYDNS_rest GET
"zones/records/all/${_domain}/search/${_sub_domain}"
45 if ! printf "%s" "$response" |
grep \"status
\":200 >/dev
/null
; then
51 if _EASYDNS_rest PUT
"zones/records/add/$_domain/TXT" "{\"host\":\"$_sub_domain\",\"rdata\":\"$txtvalue\"}"; then
52 if _contains
"$response" "\"status\":201"; then
55 elif _contains
"$response" "Record already exists"; then
56 _info
"Already exists, OK"
59 _err
"Add txt record error."
63 _err
"Add txt record error."
72 EASYDNS_Token
="${EASYDNS_Token:-$(_readaccountconf_mutable EASYDNS_Token)}"
73 EASYDNS_Key
="${EASYDNS_Key:-$(_readaccountconf_mutable EASYDNS_Key)}"
75 _debug
"First detect the root zone"
76 if ! _get_root
"$fulldomain"; then
80 _debug _sub_domain
"$_sub_domain"
81 _debug _domain
"$_domain"
83 _debug
"Getting txt records"
84 _EASYDNS_rest GET
"zones/records/all/${_domain}/search/${_sub_domain}"
86 if ! printf "%s" "$response" |
grep \"status
\":200 >/dev
/null
; then
91 count
=$
(printf "%s\n" "$response" | _egrep_o
"\"count\":[^,]*" | cut
-d : -f 2)
93 if [ "$count" = "0" ]; then
94 _info
"Don't need to remove."
96 record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":\"[^\"]*\"" | cut
-d : -f 2 |
tr -d \" |
head -n 1)
97 _debug
"record_id" "$record_id"
98 if [ -z "$record_id" ]; then
99 _err
"Can not get record id to remove."
102 if ! _EASYDNS_rest DELETE
"zones/records/$_domain/$record_id"; then
103 _err
"Delete record error."
106 _contains
"$response" "\"status\":200"
111 #################### Private functions below ##################################
112 #_acme-challenge.www.domain.com
114 # _sub_domain=_acme-challenge.www
121 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
128 if ! _EASYDNS_rest GET
"zones/records/all/$h"; then
132 if _contains
"$response" "\"status\":200"; then
133 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
150 basicauth
=$
(printf "%s" "$EASYDNS_Token":"$EASYDNS_Key" | _base64
)
152 export _H1
="accept: application/json"
153 if [ "$basicauth" ]; then
154 export _H2
="Authorization: Basic $basicauth"
157 if [ "$m" != "GET" ]; then
158 export _H3
="Content-Type: application/json"
160 response
="$(_post "$data" "$EASYDNS_Api/$ep" "" "$m")"
162 response
="$(_get "$EASYDNS_Api/$ep")"
165 if [ "$?" != "0" ]; then
169 _debug2 response
"$response"