3 # bug reports to dev@1e.ca
6 #LUA_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
8 #LUA_Email="user@luadns.net"
10 LUA_Api
="https://api.luadns.com/v1"
12 ######## Public functions #####################
14 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
19 LUA_Key
="${LUA_Key:-$(_readaccountconf_mutable LUA_Key)}"
20 LUA_Email
="${LUA_Email:-$(_readaccountconf_mutable LUA_Email)}"
21 LUA_auth
=$
(printf "%s" "$LUA_Email:$LUA_Key" | _base64
)
23 if [ -z "$LUA_Key" ] ||
[ -z "$LUA_Email" ]; then
26 _err
"You don't specify luadns api key and email yet."
27 _err
"Please create you key and try again."
31 #save the api key and email to the account conf file.
32 _saveaccountconf_mutable LUA_Key
"$LUA_Key"
33 _saveaccountconf_mutable LUA_Email
"$LUA_Email"
35 _debug
"First detect the root zone"
36 if ! _get_root
"$fulldomain"; then
40 _debug _domain_id
"$_domain_id"
41 _debug _sub_domain
"$_sub_domain"
42 _debug _domain
"$_domain"
45 if _LUA_rest POST
"zones/$_domain_id/records" "{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
46 if _contains
"$response" "$fulldomain"; then
48 #todo: check if the record takes effect
51 _err
"Add txt record error."
62 LUA_Key
="${LUA_Key:-$(_readaccountconf_mutable LUA_Key)}"
63 LUA_Email
="${LUA_Email:-$(_readaccountconf_mutable LUA_Email)}"
64 LUA_auth
=$
(printf "%s" "$LUA_Email:$LUA_Key" | _base64
)
65 _debug
"First detect the root zone"
66 if ! _get_root
"$fulldomain"; then
70 _debug _domain_id
"$_domain_id"
71 _debug _sub_domain
"$_sub_domain"
72 _debug _domain
"$_domain"
74 _debug
"Getting txt records"
75 _LUA_rest GET
"zones/${_domain_id}/records"
77 count
=$
(printf "%s\n" "$response" | _egrep_o
"\"name\":\"$fulldomain.\",\"type\":\"TXT\"" |
wc -l |
tr -d " ")
79 if [ "$count" = "0" ]; then
80 _info
"Don't need to remove."
82 record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":[^,]*,\"name\":\"$fulldomain.\",\"type\":\"TXT\"" | _head_n
1 | cut
-d: -f2 | cut
-d, -f1)
83 _debug
"record_id" "$record_id"
84 if [ -z "$record_id" ]; then
85 _err
"Can not get record id to remove."
88 if ! _LUA_rest DELETE
"/zones/$_domain_id/records/$record_id"; then
89 _err
"Delete record error."
92 _contains
"$response" "$record_id"
96 #################### Private functions below ##################################
97 #_acme-challenge.www.domain.com
99 # _sub_domain=_acme-challenge.www
101 # _domain_id=sdjkglgdfewsdfg
106 if ! _LUA_rest GET
"zones"; then
110 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
117 if _contains
"$response" "\"name\":\"$h\""; then
118 _domain_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":[^,]*,\"name\":\"$h\"" | cut
-d : -f 2 | cut
-d , -f 1)
119 _debug _domain_id
"$_domain_id"
120 if [ "$_domain_id" ]; then
121 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
139 export _H1
="Accept: application/json"
140 export _H2
="Authorization: Basic $LUA_auth"
141 if [ "$m" != "GET" ]; then
143 response
="$(_post "$data" "$LUA_Api/$ep" "" "$m")"
145 response
="$(_get "$LUA_Api/$ep")"
148 if [ "$?" != "0" ]; then
152 _debug2 response
"$response"