1
1
#! /usr/bin/env sh
2
2
# shellcheck disable=SC2034
3
- dns_active24_info=' Active24.com
4
- Site: Active24.com
3
+ dns_active24_info=' Active24.cz
4
+ Site: Active24.cz
5
5
Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_active24
6
6
Options:
7
- ACTIVE24_Token API Token
7
+ Active24_ApiKey API Key. Called "Identifier" in the Active24 Admin
8
+ Active24_ApiSecret API Secret. Called "Secret key" in the Active24 Admin
8
9
Issues: github.com/acmesh-official/acme.sh/issues/2059
9
- Author: Milan Pála
10
10
'
11
11
12
- ACTIVE24_Api =" https://api .active24.com "
13
-
14
- # ####### Public functions #####################
12
+ Active24_Api =" https://rest .active24.cz "
13
+ # export Active24_ApiKey=ak48l3h7-ak5d-qn4t-p8gc-b6fs8c3l
14
+ # export Active24_ApiSecret=ajvkeo3y82ndsu2smvxy3o36496dcascksldncsq
15
15
16
16
# Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
17
17
# Used to add txt record
@@ -22,15 +22,16 @@ dns_active24_add() {
22
22
_active24_init
23
23
24
24
_info " Adding txt record"
25
- if _active24_rest POST " dns/ $_domain /txt/v1 " " {\" name\" :\" $_sub_domain \" ,\" text \" :\" $txtvalue \" ,\" ttl\" :0 }" ; then
26
- if _contains " $response " " errors " ; then
25
+ if _active24_rest POST " /v2/service/ $_service_id /dns/record " " {\" type \" : \" TXT \" , \" name\" :\" $_sub_domain \" ,\" content \" :\" $txtvalue \" ,\" ttl\" :300 }" ; then
26
+ if _contains " $response " " error " ; then
27
27
_err " Add txt record error."
28
28
return 1
29
29
else
30
30
_info " Added, OK"
31
31
return 0
32
32
fi
33
33
fi
34
+
34
35
_err " Add txt record error."
35
36
return 1
36
37
}
@@ -44,19 +45,25 @@ dns_active24_rm() {
44
45
_active24_init
45
46
46
47
_debug " Getting txt records"
47
- _active24_rest GET " dns/$_domain /records/v1"
48
+ # The API needs to send data in body in order the filter to work
49
+ # TODO: web can also add content $txtvalue to filter and then get the id from response
50
+ _active24_rest GET " /v2/service/$_service_id /dns/record" " {\" page\" :1,\" descending\" :true,\" sortBy\" :\" name\" ,\" rowsPerPage\" :100,\" totalRecords\" :0,\" filters\" :{\" type\" :[\" TXT\" ],\" name\" :\" ${_sub_domain} \" }}"
51
+ # _active24_rest GET "/v2/service/$_service_id/dns/record?rowsPerPage=100"
48
52
49
- if _contains " $response " " errors " ; then
53
+ if _contains " $response " " error " ; then
50
54
_err " Error"
51
55
return 1
52
56
fi
53
57
54
- hash_ids=$( echo " $response " | _egrep_o " [^{]+${txtvalue} [^}]+" | _egrep_o " hashId\" :\" [^\" ]+" | cut -c10-)
58
+ # Note: it might never be more than one record actually, NEEDS more INVESTIGATION
59
+ record_ids=$( printf " %s" " $response " | _egrep_o " [^{]+${txtvalue} [^}]+" | _egrep_o ' "id" *: *[^,]+' | cut -d ' :' -f 2)
60
+ _debug2 record_ids " $record_ids "
55
61
56
- for hash_id in $hash_ids ; do
57
- _debug " Removing hash_id" " $hash_id "
58
- if _active24_rest DELETE " dns/$_domain /$hash_id /v1" " " ; then
59
- if _contains " $response " " errors" ; then
62
+ for redord_id in $record_ids ; do
63
+ _debug " Removing record_id" " $redord_id "
64
+ _debug " txtvalue" " $txtvalue "
65
+ if _active24_rest DELETE " /v2/service/$_service_id /dns/record/$redord_id " " " ; then
66
+ if _contains " $response " " error" ; then
60
67
_err " Unable to remove txt record."
61
68
return 1
62
69
else
@@ -70,21 +77,15 @@ dns_active24_rm() {
70
77
return 1
71
78
}
72
79
73
- # ################### Private functions below ##################################
74
- # _acme-challenge.www.domain.com
75
- # returns
76
- # _sub_domain=_acme-challenge.www
77
- # _domain=domain.com
78
- # _domain_id=sdjkglgdfewsdfg
79
80
_get_root () {
80
81
domain=$1
82
+ i=1
83
+ p=1
81
84
82
- if ! _active24_rest GET " dns/domains/v1 " ; then
85
+ if ! _active24_rest GET " /v1/user/self/service " ; then
83
86
return 1
84
87
fi
85
88
86
- i=1
87
- p=1
88
89
while true ; do
89
90
h=$( printf " %s" " $domain " | cut -d . -f " $i " -100)
90
91
_debug " h" " $h "
@@ -104,45 +105,102 @@ _get_root() {
104
105
return 1
105
106
}
106
107
107
- _active24_rest () {
108
- m=$1
109
- ep=" $2 "
110
- data=" $3 "
111
- _debug " $ep "
112
-
113
- export _H1=" Authorization: Bearer $ACTIVE24_Token "
114
-
115
- if [ " $m " != " GET" ]; then
116
- _debug " data" " $data "
117
- response=" $( _post " $data " " $ACTIVE24_Api /$ep " " " " $m " " application/json" ) "
118
- else
119
- response=" $( _get " $ACTIVE24_Api /$ep " ) "
108
+ _active24_init () {
109
+ Active24_ApiKey=" ${Active24_ApiKey:- $(_readaccountconf_mutable Active24_ApiKey)} "
110
+ Active24_ApiSecret=" ${Active24_ApiSecret:- $(_readaccountconf_mutable Active24_ApiSecret)} "
111
+ # Active24_ServiceId="${Active24_ServiceId:-$(_readaccountconf_mutable Active24_ServiceId)}"
112
+
113
+ if [ -z " $Active24_ApiKey " ] || [ -z " $Active24_ApiSecret " ]; then
114
+ Active24_ApiKey=" "
115
+ Active24_ApiSecret=" "
116
+ _err " You don't specify Active24 api key and ApiSecret yet."
117
+ _err " Please create your key and try again."
118
+ return 1
120
119
fi
121
120
122
- if [ " $? " != " 0" ]; then
123
- _err " error $ep "
121
+ # save the credentials to the account conf file.
122
+ _saveaccountconf_mutable Active24_ApiKey " $Active24_ApiKey "
123
+ _saveaccountconf_mutable Active24_ApiSecret " $Active24_ApiSecret "
124
+
125
+ _debug " A24 API CHECK"
126
+ if ! _active24_rest GET " /v2/check" ; then
127
+ _err " A24 API check failed with: $response "
124
128
return 1
125
129
fi
126
- _debug2 response " $response "
127
- return 0
128
- }
129
130
130
- _active24_init () {
131
- ACTIVE24_Token=" ${ACTIVE24_Token:- $(_readaccountconf_mutable ACTIVE24_Token)} "
132
- if [ -z " $ACTIVE24_Token " ]; then
133
- ACTIVE24_Token=" "
134
- _err " You didn't specify a Active24 api token yet."
135
- _err " Please create the token and try again."
131
+ if ! echo " $response " | tr -d " " | grep \" verified\" :true > /dev/null; then
132
+ _err " A24 API check failed with: $response "
136
133
return 1
137
134
fi
138
135
139
- _saveaccountconf_mutable ACTIVE24_Token " $ACTIVE24_Token "
140
-
141
136
_debug " First detect the root zone"
142
137
if ! _get_root " $fulldomain " ; then
143
138
_err " invalid domain"
144
139
return 1
145
140
fi
141
+
146
142
_debug _sub_domain " $_sub_domain "
147
143
_debug _domain " $_domain "
144
+ _active24_get_service_id " $_domain "
145
+ _debug _service_id " $_service_id "
146
+ }
147
+
148
+ _active24_get_service_id () {
149
+ _d=$1
150
+ if ! _active24_rest GET " /v1/user/self/zone/${_d} " ; then
151
+ return 1
152
+ else
153
+ response=$( echo " $response " | _json_decode)
154
+ _service_id=$( echo " $response " | _egrep_o ' "id" *: *[^,]+' | cut -d ' :' -f 2)
155
+ fi
156
+ }
157
+
158
+ _active24_rest () {
159
+ m=$1
160
+ ep_qs=$2 # with query string
161
+ # ep=$2
162
+ ep=$( printf " %s" " $ep_qs " | cut -d ' ?' -f1) # no query string
163
+ data=" $3 "
164
+
165
+ _debug " A24 $ep "
166
+ _debug " A24 $Active24_ApiKey "
167
+ _debug " A24 $Active24_ApiSecret "
168
+
169
+ timestamp=$( _time)
170
+ datez=$( date -u +" %Y%m%dT%H%M%SZ" )
171
+ canonicalRequest=" ${m} ${ep} ${timestamp} "
172
+ signature=$( printf " %s" " $canonicalRequest " | _hmac sha1 " $( printf " %s" " $Active24_ApiSecret " | _hex_dump | tr -d " " ) " hex)
173
+ authorization64=" $( printf " %s:%s" " $Active24_ApiKey " " $signature " | _base64) "
174
+
175
+ export _H1=" Date: ${datez} "
176
+ export _H2=" Accept: application/json"
177
+ export _H3=" Content-Type: application/json"
178
+ export _H4=" Authorization: Basic ${authorization64} "
179
+
180
+ _debug2 H1 " $_H1 "
181
+ _debug2 H2 " $_H2 "
182
+ _debug2 H3 " $_H3 "
183
+ _debug2 H4 " $_H4 "
184
+
185
+ # _sleep 1
186
+
187
+ if [ " $m " != " GET" ]; then
188
+ _debug2 " ${m} $Active24_Api ${ep_qs} "
189
+ _debug " data" " $data "
190
+ response=" $( _post " $data " " $Active24_Api ${ep_qs} " " " " $m " " application/json" ) "
191
+ else
192
+ if [ -z " $data " ]; then
193
+ _debug2 " GET $Active24_Api ${ep_qs} "
194
+ response=" $( _get " $Active24_Api ${ep_qs} " ) "
195
+ else
196
+ _debug2 " GET $Active24_Api ${ep_qs} with data: ${data} "
197
+ response=" $( _post " $data " " $Active24_Api ${ep_qs} " " " " $m " " application/json" ) "
198
+ fi
199
+ fi
200
+ if [ " $? " != " 0" ]; then
201
+ _err " error $ep "
202
+ return 1
203
+ fi
204
+ _debug2 response " $response "
205
+ return 0
148
206
}
0 commit comments