3 #This is the websupport.sk api wrapper for acme.sh
6 #Report Bugs here: https://github.com/trgosk/acme.sh
8 #WS_ApiKey="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
9 #WS_ApiSecret="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
11 WS_Api
="https://rest.websupport.sk"
13 ######## Public functions #####################
15 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
16 dns_websupport_add
() {
20 WS_ApiKey
="${WS_ApiKey:-$(_readaccountconf_mutable WS_ApiKey)}"
21 WS_ApiSecret
="${WS_ApiSecret:-$(_readaccountconf_mutable WS_ApiSecret)}"
23 if [ "$WS_ApiKey" ] && [ "$WS_ApiSecret" ]; then
24 _saveaccountconf_mutable WS_ApiKey
"$WS_ApiKey"
25 _saveaccountconf_mutable WS_ApiSecret
"$WS_ApiSecret"
29 _err
"You didn't specify a api key and/or api secret yet."
30 _err
"You can get yours from here https://admin.websupport.sk/en/auth/apiKey"
34 _debug
"First detect the root zone"
35 if ! _get_root
"$fulldomain"; then
39 _debug _sub_domain
"$_sub_domain"
40 _debug _domain
"$_domain"
42 # For wildcard cert, the main root domain and the wildcard domain have the same txt subdomain name, so
43 # we can not use updating anymore.
44 # count=$(printf "%s\n" "$response" | _egrep_o "\"count\":[^,]*" | cut -d : -f 2)
45 # _debug count "$count"
46 # if [ "$count" = "0" ]; then
48 if _ws_rest POST
"/v1/user/self/zone/$_domain/record" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":120}"; then
49 if _contains
"$response" "$txtvalue"; then
52 elif _contains
"$response" "The record already exists"; then
53 _info
"Already exists, OK"
56 _err
"Add txt record error."
60 _err
"Add txt record error."
70 _debug2 fulldomain
"$fulldomain"
71 _debug2 txtvalue
"$txtvalue"
73 _debug
"First detect the root zone"
74 if ! _get_root
"$fulldomain"; then
79 _debug _sub_domain
"$_sub_domain"
80 _debug _domain
"$_domain"
82 _debug
"Getting txt records"
83 _ws_rest GET
"/v1/user/self/zone/$_domain/record"
85 if [ "$(printf "%s
" "$response" | tr -d " " | grep -c \"items\")" -lt "1" ]; then
86 _err
"Error: $response"
90 record_line
="$(_get_from_array "$response" "$txtvalue")"
91 _debug record_line
"$record_line"
92 if [ -z "$record_line" ]; then
93 _info
"Don't need to remove."
95 record_id
=$
(echo "$record_line" | _egrep_o
"\"id\": *[^,]*" | _head_n
1 | cut
-d : -f 2 |
tr -d \" |
tr -d " ")
96 _debug
"record_id" "$record_id"
97 if [ -z "$record_id" ]; then
98 _err
"Can not get record id to remove."
101 if ! _ws_rest DELETE
"/v1/user/self/zone/$_domain/record/$record_id"; then
102 _err
"Delete record error."
105 if [ "$(printf "%s
" "$response" | tr -d " " | grep -c \"success\")" -lt "1" ]; then
114 #################### Private functions below ##################################
115 #_acme-challenge.www.domain.com
117 # _sub_domain=_acme-challenge.www
125 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
132 if ! _ws_rest GET
"/v1/user/self/zone"; then
136 if _contains
"$response" "\"name\":\"$h\""; then
137 _domain_id
=$
(echo "$response" | _egrep_o
"\[.\"id\": *[^,]*" | _head_n
1 | cut
-d : -f 2 |
tr -d \" |
tr -d " ")
138 if [ "$_domain_id" ]; then
139 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
156 _debug2 api_key
"$WS_ApiKey"
157 _debug2 api_secret
"$WS_ApiSecret"
159 timestamp
="$(date +%s)"
160 datez
=$
(date -u -r "$timestamp" +%Y-
%m-
%dT
%H
:%M
:%S
%z
2>/dev
/null ||
date -u -d@
"$timestamp" +%Y-
%m-
%dT
%H
:%M
:%S
%z
)
161 canonical_request
="${me} ${pa} ${timestamp}"
163 signature_hash
=$
( (printf "%s" "$canonical_request" |
${ACME_OPENSSL_BIN:-openssl} dgst
-"$alg" -mac HMAC
-macopt "key:$WS_ApiSecret" 2>/dev
/null ||
printf "%s" "$canonical_request" |
${ACME_OPENSSL_BIN:-openssl} dgst
-"$alg" -hmac "$(printf "%s
" "$WS_ApiSecret" | _h2b)") | cut
-d = -f 2 |
tr -d ' ')
164 basicauth
="$(printf "%s
:%s
" "$WS_ApiKey" "$signature_hash" | _base64)"
169 _debug2 timestamp
"$timestamp"
170 _debug2 datez
"$datez"
171 _debug2 canonical_request
"$canonical_request"
173 _debug2 signature_hash
"$signature_hash"
174 _debug2 basicauth
"$basicauth"
176 export _H1
="Accept: application/json"
177 export _H2
="Content-Type: application/json"
178 export _H3
="Authorization: Basic ${basicauth}"
179 export _H4
="Date: ${datez}"
186 if [ "$me" != "GET" ]; then
187 _debug2
"${me} $WS_Api${pa}"
189 response
="$(_post "$da" "${WS_Api}${pa}" "" "$me")"
191 _debug2
"GET $WS_Api${pa}"
192 response
="$(_get "$WS_Api${pa}")"
195 _debug2 response
"$response"
202 for i
in $
(echo "$va" |
sed "s/{/ /g"); do
203 if _contains
"$i" "$fi"; then