3 # bug reports to support+acmesh@misaka.io
4 # based on dns_nsone.sh by dev@1e.ca
7 #Misaka_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
10 Misaka_Api
="https://dnsapi.misaka.io/dns"
12 ######## Public functions #####################
14 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
19 if [ -z "$Misaka_Key" ]; then
21 _err
"You didn't specify misaka.io dns api key yet."
22 _err
"Please create you key and try again."
26 #save the api key and email to the account conf file.
27 _saveaccountconf Misaka_Key
"$Misaka_Key"
29 _debug
"checking root zone [$fulldomain]"
30 if ! _get_root
"$fulldomain"; then
34 _debug _sub_domain
"$_sub_domain"
35 _debug _domain
"$_domain"
37 _debug
"Getting txt records"
38 _misaka_rest GET
"zones/${_domain}/recordsets?search=${_sub_domain}"
40 if ! _contains
"$response" "\"results\":"; then
45 count
=$
(printf "%s\n" "$response" | _egrep_o
"\"name\":\"$_sub_domain\",[^{]*\"type\":\"TXT\"" |
wc -l |
tr -d " ")
47 if [ "$count" = "0" ]; then
50 if _misaka_rest POST
"zones/${_domain}/recordsets/${_sub_domain}/TXT" "{\"records\":[{\"value\":\"\\\"$txtvalue\\\"\"}],\"filters\":[],\"ttl\":1}"; then
51 _debug response
"$response"
52 if _contains
"$response" "$_sub_domain"; then
56 _err
"Add txt record error."
60 _err
"Add txt record error."
62 _info
"Updating record"
64 _misaka_rest PUT
"zones/${_domain}/recordsets/${_sub_domain}/TXT?append=true" "{\"records\": [{\"value\": \"\\\"$txtvalue\\\"\"}],\"ttl\":1}"
65 if [ "$?" = "0" ] && _contains
"$response" "$_sub_domain"; then
67 #todo: check if the record takes effect
80 _debug
"First detect the root zone"
81 if ! _get_root
"$fulldomain"; then
85 _debug _sub_domain
"$_sub_domain"
86 _debug _domain
"$_domain"
88 _debug
"Getting txt records"
89 _misaka_rest GET
"zones/${_domain}/recordsets?search=${_sub_domain}"
91 count
=$
(printf "%s\n" "$response" | _egrep_o
"\"name\":\"$_sub_domain\",[^{]*\"type\":\"TXT\"" |
wc -l |
tr -d " ")
93 if [ "$count" = "0" ]; then
94 _info
"Don't need to remove."
96 if ! _misaka_rest DELETE
"zones/${_domain}/recordsets/${_sub_domain}/TXT"; then
97 _err
"Delete record error."
100 _contains
"$response" ""
104 #################### Private functions below ##################################
105 #_acme-challenge.www.domain.com
107 # _sub_domain=_acme-challenge.www
109 # _domain_id=sdjkglgdfewsdfg
114 if ! _misaka_rest GET
"zones?limit=1000"; then
118 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
125 if _contains
"$response" "\"name\":\"$h\""; then
126 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
142 export _H1
="Content-Type: application/json"
143 export _H2
="User-Agent: acme.sh/$VER misaka-dns-acmesh/20191213"
144 export _H3
="Authorization: Token $Misaka_Key"
146 if [ "$m" != "GET" ]; then
148 response
="$(_post "$data" "$Misaka_Api/$ep" "" "$m")"
150 response
="$(_get "$Misaka_Api/$ep")"
153 if [ "$?" != "0" ]; then
157 _debug2 response
"$response"