3 #This is the vscale.io api wrapper for acme.sh
6 #Report Bugs here: https://github.com/LAV45/acme.sh
8 #VSCALE_API_KEY="sdfsdfsdfljlbjkljlkjsdfoiwje"
9 VSCALE_API_URL
="https://api.vscale.io/v1"
11 ######## Public functions #####################
13 #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
18 if [ -z "$VSCALE_API_KEY" ]; then
20 _err
"You didn't specify the VSCALE api key yet."
21 _err
"Please create you key and try again."
25 _saveaccountconf VSCALE_API_KEY
"$VSCALE_API_KEY"
27 _debug
"First detect the root zone"
28 if ! _get_root
"$fulldomain"; then
32 _debug _domain_id
"$_domain_id"
33 _debug _sub_domain
"$_sub_domain"
34 _debug _domain
"$_domain"
36 _vscale_tmpl_json
="{\"type\":\"TXT\",\"name\":\"$_sub_domain.$_domain\",\"content\":\"$txtvalue\"}"
38 if _vscale_rest POST
"domains/$_domain_id/records/" "$_vscale_tmpl_json"; then
39 response
=$
(printf "%s\n" "$response" | _egrep_o
"{\"error\": \".+\"" | cut
-d : -f 2)
40 if [ -z "$response" ]; then
41 _info
"txt record updated success."
54 _debug
"First detect the root zone"
55 if ! _get_root
"$fulldomain"; then
59 _debug _domain_id
"$_domain_id"
60 _debug _sub_domain
"$_sub_domain"
61 _debug _domain
"$_domain"
63 _debug
"Getting txt records"
64 _vscale_rest GET
"domains/$_domain_id/records/"
66 if [ -n "$response" ]; then
67 record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"TXT\", \"id\": [0-9]+, \"name\": \"$_sub_domain.$_domain\"" | cut
-d : -f 2 |
tr -d ", \"name\"")
68 _debug record_id
"$record_id"
69 if [ -z "$record_id" ]; then
70 _err
"Can not get record id to remove."
73 if _vscale_rest DELETE
"domains/$_domain_id/records/$record_id" && [ -z "$response" ]; then
74 _info
"txt record deleted success."
77 _debug response
"$response"
84 #################### Private functions below ##################################
85 #_acme-challenge.www.domain.com
87 # _sub_domain=_acme-challenge.www
95 if _vscale_rest GET
"domains/"; then
96 response
="$(echo "$response" | tr -d "\n" | sed 's/{/\n&/g')"
98 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
105 hostedzone
="$(echo "$response" | _egrep_o "{.
*\"name
\":\s
*\"$h\".
*}")"
106 if [ "$hostedzone" ]; then
107 _domain_id
=$
(printf "%s\n" "$hostedzone" | _egrep_o
"\"id\":\s*[0-9]+" | _head_n
1 | cut
-d : -f 2 |
tr -d \
)
108 if [ "$_domain_id" ]; then
109 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
122 #method uri qstr data
131 export _H1
="Accept: application/json"
132 export _H2
="Content-Type: application/json"
133 export _H3
="X-Token: ${VSCALE_API_KEY}"
135 if [ "$mtd" != "GET" ]; then
136 # both POST and DELETE.
138 response
="$(_post "$data" "$VSCALE_API_URL/$ep" "" "$mtd")"
140 response
="$(_get "$VSCALE_API_URL/$ep")"
143 if [ "$?" != "0" ]; then
147 _debug2 response
"$response"