4 #LA_Key="d1j2fdo4dee3948"
6 LA_Api
="https://api.dns.la/api"
8 ######## Public functions #####################
10 #Usage: dns_la_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
15 LA_Id
="${LA_Id:-$(_readaccountconf_mutable LA_Id)}"
16 LA_Key
="${LA_Key:-$(_readaccountconf_mutable LA_Key)}"
18 if [ -z "$LA_Id" ] ||
[ -z "$LA_Key" ]; then
21 _err
"You didn't specify a dnsla api id and key yet."
25 #save the api key and email to the account conf file.
26 _saveaccountconf_mutable LA_Id
"$LA_Id"
27 _saveaccountconf_mutable LA_Key
"$LA_Key"
29 _debug
"First detect the root zone"
30 if ! _get_root
"$fulldomain"; then
34 _debug _domain_id
"$_domain_id"
35 _debug _sub_domain
"$_sub_domain"
36 _debug _domain
"$_domain"
39 if _la_rest
"record.ashx?cmd=create&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&host=$_sub_domain&recordtype=TXT&recorddata=$txtvalue&recordline="; then
40 if _contains
"$response" '"resultid":'; then
43 elif _contains
"$response" '"code":532'; then
44 _info
"Already exists, OK"
47 _err
"Add txt record error."
51 _err
"Add txt record error."
61 LA_Id
="${LA_Id:-$(_readaccountconf_mutable LA_Id)}"
62 LA_Key
="${LA_Key:-$(_readaccountconf_mutable LA_Key)}"
64 _debug
"First detect the root zone"
65 if ! _get_root
"$fulldomain"; then
69 _debug _domain_id
"$_domain_id"
70 _debug _sub_domain
"$_sub_domain"
71 _debug _domain
"$_domain"
73 _debug
"Getting txt records"
74 if ! _la_rest
"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
79 if ! _contains
"$response" '"recordid":'; then
80 _info
"Don't need to remove."
84 record_id
=$
(printf "%s" "$response" |
grep '"recordid":' | cut
-d : -f 2 | cut
-d , -f 1 |
tr -d '\r' |
tr -d '\n')
85 _debug
"record_id" "$record_id"
86 if [ -z "$record_id" ]; then
87 _err
"Can not get record id to remove."
90 if ! _la_rest
"record.ashx?cmd=remove&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domainid=$_domain_id&domain=$_domain&recordid=$record_id"; then
91 _err
"Delete record error."
94 _contains
"$response" '"code":300'
98 #################### Private functions below ##################################
99 #_acme-challenge.www.domain.com
101 # _sub_domain=_acme-challenge.www
103 # _domain_id=sdjkglgdfewsdfg
110 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
116 if ! _la_rest
"domain.ashx?cmd=get&apiid=$LA_Id&apipass=$LA_Key&rtype=json&domain=$h"; then
120 if _contains
"$response" '"domainid":'; then
121 _domain_id
=$
(printf "%s" "$response" |
grep '"domainid":' | cut
-d : -f 2 | cut
-d , -f 1 |
tr -d '\r' |
tr -d '\n')
122 if [ "$_domain_id" ]; then
123 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
140 if ! response
="$(_get "$url" | tr -d ' ' | tr "}" ",")"; then
145 _debug2 response
"$response"