6 #LA_Key="d1j2fdo4dee3948"
7 DNSLA_API
="https://api.dns.la/api/"
8 ######## Public functions #####################
9 #Usage: dns_la_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
14 LA_Id
="${LA_Id:-$(_readaccountconf_mutable LA_Id)}"
15 LA_Key
="${LA_Key:-$(_readaccountconf_mutable LA_Key)}"
16 if [ -z "$LA_Id" ] ||
[ -z "$LA_Key" ]; then
19 _err
"You don't specify dnsla api id and key yet."
20 _err
"Please create your key and try again."
24 #save the api key and email to the account conf file.
25 _saveaccountconf_mutable LA_Id
"$LA_Id"
26 _saveaccountconf_mutable LA_Key
"$LA_Key"
28 _debug
"detect the root zone"
29 if ! _get_root
"$fulldomain"; then
34 add_record
"$_domain" "$_sub_domain" "$txtvalue"
43 LA_Id
="${LA_Id:-$(_readaccountconf_mutable LA_Id)}"
44 LA_Key
="${LA_Key:-$(_readaccountconf_mutable LA_Key)}"
46 _debug
"First detect the root zone"
47 if ! _get_root
"$fulldomain"; then
52 if ! _rest GET
"record.ashx?cmd=listn&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&domain=$_domain&host=$_sub_domain&recordtype=TXT&recorddata=$txtvalue"; then
53 _err
"get record list error."
57 if ! _contains
"$response" "recordid"; then
58 _info
"no need to remove record."
62 _record_id
=$
(printf "%s" "$response" |
grep '"recordid":' | cut
-d : -f 2 | cut
-d , -f 1 |
tr -d '\r' |
tr -d '\n')
64 _debug delete_rid
"$_record_id"
65 if ! _rest GET
"record.ashx?cmd=remove&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&domain=$_domain&recordid=$_record_id"; then
66 _err
"record remove error."
70 _contains
"$response" "\"code\":300"
74 #usage: root sub txtvalue
79 fulldomain
="$sub.$root"
81 _info
"adding txt record"
82 if ! _rest GET
"record.ashx?cmd=create&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&host=$_sub_domain&recordtype=TXT&recorddata=$txtvalue&recordline="; then
86 if _contains
"$response" "resultid" || _contains
"$response" "\"code\":532"; then
92 #################### Private functions below ##################################
93 #_acme-challenge.www.domain.com
95 # _sub_domain=_acme-challenge.www
97 # _domain_id=sdjkglgdfewsdfg
103 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
109 if ! _rest GET
"domain.ashx?cmd=get&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domain=$h"; then
113 if _contains
"$response" "\"code\":300"; then
114 _domain_id
=$
(printf "%s" "$response" |
grep '"domainid"' | cut
-d : -f 2 | cut
-d , -f 1 |
tr -d '\r' |
tr -d '\n')
115 _debug _domain_id
"$_domain_id"
116 if [ "$_domain_id" ]; then
117 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
118 _debug _sub_domain
"$_sub_domain"
120 _debug _domain
"$_domain"
131 #Usage: method URI data
141 if [ "$m" = "GET" ]; then
142 response
="$(_get "$url" | tr -d ' ' | tr "}" ",")"
145 response
="$(_post "$data" "$url" | tr -d ' ' | tr "}" ",")"
148 if [ "$?" != "0" ]; then
152 _debug2 response
"$response"