3 # Acme.sh DNS API wrapper for websupport.sk
5 # Original author: trgo.sk (https://github.com/trgosk)
6 # Tweaks by: akulumbeg (https://github.com/akulumbeg)
7 # Report Bugs here: https://github.com/akulumbeg/acme.sh
9 # Requirements: API Key and Secret from https://admin.websupport.sk/en/auth/apiKey
11 # WS_ApiKey="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
12 # (called "Identifier" in the WS Admin)
14 # WS_ApiSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
15 # (called "Secret key" in the WS Admin)
17 WS_Api
="https://rest.websupport.sk"
19 ######## Public functions #####################
21 dns_websupport_add
() {
25 WS_ApiKey
="${WS_ApiKey:-$(_readaccountconf_mutable WS_ApiKey)}"
26 WS_ApiSecret
="${WS_ApiSecret:-$(_readaccountconf_mutable WS_ApiSecret)}"
28 if [ "$WS_ApiKey" ] && [ "$WS_ApiSecret" ]; then
29 _saveaccountconf_mutable WS_ApiKey
"$WS_ApiKey"
30 _saveaccountconf_mutable WS_ApiSecret
"$WS_ApiSecret"
34 _err
"You did not specify the API Key and/or API Secret"
35 _err
"You can get the API login credentials from https://admin.websupport.sk/en/auth/apiKey"
39 _debug
"First detect the root zone"
40 if ! _get_root
"$fulldomain"; then
44 _debug _sub_domain
"$_sub_domain"
45 _debug _domain
"$_domain"
47 # For wildcard cert, the main root domain and the wildcard domain have the same txt subdomain name, so
48 # we can not use updating anymore.
49 # count=$(printf "%s\n" "$response" | _egrep_o "\"count\":[^,]*" | cut -d : -f 2)
50 # _debug count "$count"
51 # if [ "$count" = "0" ]; then
53 if _ws_rest POST
"/v1/user/self/zone/$_domain/record" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
54 if _contains
"$response" "$txtvalue"; then
57 elif _contains
"$response" "The record already exists"; then
58 _info
"Already exists, OK"
61 _err
"Add txt record error."
65 _err
"Add txt record error."
74 _debug2 fulldomain
"$fulldomain"
75 _debug2 txtvalue
"$txtvalue"
77 _debug
"First detect the root zone"
78 if ! _get_root
"$fulldomain"; then
83 _debug _sub_domain
"$_sub_domain"
84 _debug _domain
"$_domain"
86 _debug
"Getting txt records"
87 _ws_rest GET
"/v1/user/self/zone/$_domain/record"
89 if [ "$(printf "%s
" "$response" | tr -d " " | grep -c \"items\")" -lt "1" ]; then
90 _err
"Error: $response"
94 record_line
="$(_get_from_array "$response" "$txtvalue")"
95 _debug record_line
"$record_line"
96 if [ -z "$record_line" ]; then
97 _info
"Don't need to remove."
99 record_id
=$
(echo "$record_line" | _egrep_o
"\"id\": *[^,]*" | _head_n
1 | cut
-d : -f 2 |
tr -d \" |
tr -d " ")
100 _debug
"record_id" "$record_id"
101 if [ -z "$record_id" ]; then
102 _err
"Can not get record id to remove."
105 if ! _ws_rest DELETE
"/v1/user/self/zone/$_domain/record/$record_id"; then
106 _err
"Delete record error."
109 if [ "$(printf "%s
" "$response" | tr -d " " | grep -c \"success\")" -lt "1" ]; then
118 #################### Private Functions ##################################
126 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
133 if ! _ws_rest GET
"/v1/user/self/zone"; then
137 if _contains
"$response" "\"name\":\"$h\""; then
138 _domain_id
=$
(echo "$response" | _egrep_o
"\[.\"id\": *[^,]*" | _head_n
1 | cut
-d : -f 2 |
tr -d \" |
tr -d " ")
139 if [ "$_domain_id" ]; then
140 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
157 _debug2 api_key
"$WS_ApiKey"
158 _debug2 api_secret
"$WS_ApiSecret"
161 datez
="$(_utc_date | sed "s
/ /T
/" | sed "s
/$
/+0000/")"
162 canonical_request
="${me} ${pa} ${timestamp}"
163 signature_hash
=$
(printf "%s" "$canonical_request" | _hmac sha1
"$(printf "%s
" "$WS_ApiSecret" | _hex_dump | tr -d " ")" hex
)
164 basicauth
="$(printf "%s
:%s
" "$WS_ApiKey" "$signature_hash" | _base64)"
169 _debug2 timestamp
"$timestamp"
170 _debug2 datez
"$datez"
171 _debug2 canonical_request
"$canonical_request"
172 _debug2 signature_hash
"$signature_hash"
173 _debug2 basicauth
"$basicauth"
175 export _H1
="Accept: application/json"
176 export _H2
="Content-Type: application/json"
177 export _H3
="Authorization: Basic ${basicauth}"
178 export _H4
="Date: ${datez}"
185 if [ "$me" != "GET" ]; then
186 _debug2
"${me} $WS_Api${pa}"
188 response
="$(_post "$da" "${WS_Api}${pa}" "" "$me")"
190 _debug2
"GET $WS_Api${pa}"
191 response
="$(_get "$WS_Api${pa}")"
194 _debug2 response
"$response"
201 for i
in $
(echo "$va" |
sed "s/{/ /g"); do
202 if _contains
"$i" "$fi"; then