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"
11 LUA_auth
=$
(printf $LUA_Email:$LUA_Key | _base64
)
13 ######## Public functions #####################
15 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
20 if [ -z "$LUA_Key" ] ||
[ -z "$LUA_Email" ]; then
21 _err
"You don't specify luadns api key and email yet."
22 _err
"Please create you key and try again."
26 #save the api key and email to the account conf file.
27 _saveaccountconf LUA_Key
"$LUA_Key"
28 _saveaccountconf LUA_Email
"$LUA_Email"
30 _debug
"First detect the root zone"
31 if ! _get_root
$fulldomain; then
35 _debug _domain_id
"$_domain_id"
36 _debug _sub_domain
"$_sub_domain"
37 _debug _domain
"$_domain"
39 _debug
"Getting txt records"
40 _LUA_rest GET
"zones/${_domain_id}/records"
42 if ! printf "$response" |
grep \"id
\": >/dev
/null
; then
47 count
=$
(printf "%s\n" "$response" | _egrep_o
\"name
\":\"$fulldomain\" |
wc -l)
49 if [ "$count" = "0" ]; then
51 if _LUA_rest POST
"zones/$_domain_id/records" "{\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
52 if printf -- "%s" "$response" |
grep $fulldomain >/dev
/null
; then
54 #todo: check if the record takes effect
57 _err
"Add txt record error."
61 _err
"Add txt record error."
63 _info
"Updating record"
64 record_id
=$
(printf "%s\n" "$response" | _egrep_o
\"id
\":[^
,]*,\"name
\":\"$fulldomain.
\",\"type\":\"TXT
\" | cut
-d: -f2 | cut
-d, -f1)
65 _debug
"record_id" $record_id
67 _LUA_rest PUT
"zones/$_domain_id/records/$record_id" "{\"id\":\"$record_id\",\"type\":\"TXT\",\"name\":\"$fulldomain.\",\"content\":\"$txtvalue\",\"zone_id\":\"$_domain_id\",\"ttl\":120}"
68 if [ "$?" = "0" ]; then
70 #todo: check if the record takes effect
85 #################### Private functions bellow ##################################
86 #_acme-challenge.www.domain.com
88 # _sub_domain=_acme-challenge.www
90 # _domain_id=sdjkglgdfewsdfg
95 if ! _LUA_rest GET
"zones"; then
99 h
=$
(printf $domain | cut
-d .
-f $i-100)
105 if printf $response |
grep \"name
\":\"$h\" >/dev
/null
; then
106 _domain_id
=$
(printf "%s\n" "$response" | _egrep_o
\"id
\":[^
,]*,\"name
\":\"$h\" | cut
-d : -f 2 | cut
-d , -f 1)
107 if [ "$_domain_id" ]; then
108 _sub_domain
=$
(printf $domain | cut
-d .
-f 1-$p)
126 _H1
="Accept: application/json"
127 _H2
="Authorization: Basic $LUA_auth"
130 response
="$(_post "$data" "$LUA_Api/$ep" "" $m)"
132 response
="$(_get "$LUA_Api/$ep")"
135 if [ "$?" != "0" ]; then
139 _debug2 response
"$response"