1
1
#! /usr/bin/env sh
2
+
3
+ # LA_Id="123"
4
+ # LA_Sk="456"
2
5
# shellcheck disable=SC2034
3
6
dns_la_info=' dns.la
4
7
Site: dns.la
5
8
Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_la
6
9
Options:
7
- LA_Id API ID
8
- LA_Key API key
10
+ LA_Id APIID
11
+ LA_Sk APISecret
12
+ LA_Token 用冒号连接 APIID APISecret 再base64生成
9
13
Issues: github.com/acmesh-official/acme.sh/issues/4257
10
14
'
11
-
12
15
LA_Api=" https://api.dns.la/api"
13
16
14
17
# ####### Public functions #####################
@@ -19,18 +22,23 @@ dns_la_add() {
19
22
txtvalue=$2
20
23
21
24
LA_Id=" ${LA_Id:- $(_readaccountconf_mutable LA_Id)} "
22
- LA_Key=" ${LA_Key:- $(_readaccountconf_mutable LA_Key)} "
25
+ LA_Sk=" ${LA_Sk:- $(_readaccountconf_mutable LA_Sk)} "
26
+ _log " LA_Id=$LA_Id "
27
+ _log " LA_Sk=$LA_Sk "
23
28
24
- if [ -z " $LA_Id " ] || [ -z " $LA_Key " ]; then
29
+ if [ -z " $LA_Id " ] || [ -z " $LA_Sk " ]; then
25
30
LA_Id=" "
26
- LA_Key =" "
31
+ LA_Sk =" "
27
32
_err " You didn't specify a dnsla api id and key yet."
28
33
return 1
29
34
fi
30
35
31
36
# save the api key and email to the account conf file.
32
37
_saveaccountconf_mutable LA_Id " $LA_Id "
33
- _saveaccountconf_mutable LA_Key " $LA_Key "
38
+ _saveaccountconf_mutable LA_Sk " $LA_Sk "
39
+
40
+ # generate dnsla token
41
+ _la_token
34
42
35
43
_debug " First detect the root zone"
36
44
if ! _get_root " $fulldomain " ; then
@@ -42,19 +50,21 @@ dns_la_add() {
42
50
_debug _domain " $_domain "
43
51
44
52
_info " Adding record"
45
- 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
46
- if _contains " $response " ' "resultid":' ; then
53
+
54
+ # record type is enum in new api, 16 for TXT
55
+ if _la_post " {\" domainId\" :\" $_domain_id \" ,\" type\" :16,\" host\" :\" $_sub_domain \" ,\" data\" :\" $txtvalue \" ,\" ttl\" :600}" " record" ; then
56
+ if _contains " $response " ' "id":' ; then
47
57
_info " Added, OK"
48
58
return 0
49
- elif _contains " $response " ' "code":532 ' ; then
59
+ elif _contains " $response " ' "msg":"与已有记录冲突" ' ; then
50
60
_info " Already exists, OK"
51
61
return 0
52
62
else
53
63
_err " Add txt record error."
54
64
return 1
55
65
fi
56
66
fi
57
- _err " Add txt record error ."
67
+ _err " Add txt record failed ."
58
68
return 1
59
69
60
70
}
@@ -65,7 +75,9 @@ dns_la_rm() {
65
75
txtvalue=$2
66
76
67
77
LA_Id=" ${LA_Id:- $(_readaccountconf_mutable LA_Id)} "
68
- LA_Key=" ${LA_Key:- $(_readaccountconf_mutable LA_Key)} "
78
+ LA_Sk=" ${LA_Sk:- $(_readaccountconf_mutable LA_Sk)} "
79
+
80
+ _la_token
69
81
70
82
_debug " First detect the root zone"
71
83
if ! _get_root " $fulldomain " ; then
@@ -77,27 +89,29 @@ dns_la_rm() {
77
89
_debug _domain " $_domain "
78
90
79
91
_debug " Getting txt records"
80
- 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
92
+ # record type is enum in new api, 16 for TXT
93
+ if ! _la_get " recordList?pageIndex=1&pageSize=10&domainId=$_domain_id &host=$_sub_domain &type=16&data=$txtvalue " ; then
81
94
_err " Error"
82
95
return 1
83
96
fi
84
97
85
- if ! _contains " $response " ' "recordid ":' ; then
98
+ if ! _contains " $response " ' "id ":' ; then
86
99
_info " Don't need to remove."
87
100
return 0
88
101
fi
89
102
90
- record_id=$( printf " %s" " $response " | grep ' "recordid ":' | cut -d : -f 2 | cut -d , -f 1 | tr -d ' \r ' | tr -d ' \n ' )
103
+ record_id=$( printf " %s" " $response " | grep ' "id ":' | _head_n 1 | sed ' s/.*"id": *"\([^"]*\)".*/\1/ ' )
91
104
_debug " record_id" " $record_id "
92
105
if [ -z " $record_id " ]; then
93
106
_err " Can not get record id to remove."
94
107
return 1
95
108
fi
96
- if ! _la_rest " record.ashx?cmd=remove&apiid=$LA_Id &apipass=$LA_Key &rtype=json&domainid=$_domain_id &domain=$_domain &recordid=$record_id " ; then
109
+ # remove record in new api is RESTful
110
+ if ! _la_post " " " record?id=$record_id " " DELETE" ; then
97
111
_err " Delete record error."
98
112
return 1
99
113
fi
100
- _contains " $response " ' "code":300 '
114
+ _contains " $response " ' "code":200 '
101
115
102
116
}
103
117
@@ -119,12 +133,13 @@ _get_root() {
119
133
return 1
120
134
fi
121
135
122
- if ! _la_rest " domain.ashx?cmd=get&apiid= $LA_Id &apipass= $LA_Key &rtype=json& domain=$h " ; then
136
+ if ! _la_get " domain? domain=$h " ; then
123
137
return 1
124
138
fi
125
139
126
- if _contains " $response " ' "domainid":' ; then
127
- _domain_id=$( printf " %s" " $response " | grep ' "domainid":' | cut -d : -f 2 | cut -d , -f 1 | tr -d ' \r' | tr -d ' \n' )
140
+ if _contains " $response " ' "domain":' ; then
141
+ _domain_id=$( echo " $response " | sed -n ' s/.*"id":"\([^"]*\)".*/\1/p' )
142
+ _log " _domain_id" " $_domain_id "
128
143
if [ " $_domain_id " ]; then
129
144
_sub_domain=$( printf " %s" " $domain " | cut -d . -f 1-" $p " )
130
145
_domain=" $h "
@@ -143,6 +158,21 @@ _la_rest() {
143
158
url=" $LA_Api /$1 "
144
159
_debug " $url "
145
160
161
+ if ! response=" $( _get " $url " " Authorization: Basic $LA_Token " | tr -d ' ' | tr " }" " ," ) " ; then
162
+ _err " Error: $url "
163
+ return 1
164
+ fi
165
+
166
+ _debug2 response " $response "
167
+ return 0
168
+ }
169
+
170
+ _la_get () {
171
+ url=" $LA_Api /$1 "
172
+ _debug " $url "
173
+
174
+ export _H1=" Authorization: Basic $LA_Token "
175
+
146
176
if ! response=" $( _get " $url " | tr -d ' ' | tr " }" " ," ) " ; then
147
177
_err " Error: $url "
148
178
return 1
@@ -151,3 +181,29 @@ _la_rest() {
151
181
_debug2 response " $response "
152
182
return 0
153
183
}
184
+
185
+ # Usage: _la_post body url [POST|PUT|DELETE]
186
+ _la_post () {
187
+ body=$1
188
+ url=" $LA_Api /$2 "
189
+ http_method=$3
190
+ _debug " $body "
191
+ _debug " $url "
192
+
193
+ export _H1=" Authorization: Basic $LA_Token "
194
+
195
+ if ! response=" $( _post " $body " " $url " " " " $http_method " ) " ; then
196
+ _err " Error: $url "
197
+ return 1
198
+ fi
199
+
200
+ _debug2 response " $response "
201
+ return 0
202
+ }
203
+
204
+ _la_token () {
205
+ LA_Token=$( printf " %s:%s" " $LA_Id " " $LA_Sk " | _base64)
206
+ _debug " $LA_Token "
207
+
208
+ return 0
209
+ }
0 commit comments