4 #SL_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
7 SL_Api
="https://api.selectel.ru/domains/v1"
9 ######## Public functions #####################
11 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
16 SL_Key
="${SL_Key:-$(_readaccountconf_mutable SL_Key)}"
18 if [ -z "$SL_Key" ]; then
20 _err
"You don't specify selectel.ru api key yet."
21 _err
"Please create you key and try again."
25 #save the api key to the account conf file.
26 _saveaccountconf_mutable SL_Key
"$SL_Key"
28 _debug
"First detect the root zone"
29 if ! _get_root
"$fulldomain"; then
33 _debug _domain_id
"$_domain_id"
34 _debug _sub_domain
"$_sub_domain"
35 _debug _domain
"$_domain"
38 if _sl_rest POST
"/$_domain_id/records/" "{\"type\": \"TXT\", \"ttl\": 60, \"name\": \"$fulldomain\", \"content\": \"$txtvalue\"}"; then
39 if _contains
"$response" "$txtvalue" || _contains
"$response" "record_already_exists"; then
44 _err
"Add txt record error."
53 SL_Key
="${SL_Key:-$(_readaccountconf_mutable SL_Key)}"
55 if [ -z "$SL_Key" ]; then
57 _err
"You don't specify slectel api key yet."
58 _err
"Please create you key and try again."
62 _debug
"First detect the root zone"
63 if ! _get_root
"$fulldomain"; then
67 _debug _domain_id
"$_domain_id"
68 _debug _sub_domain
"$_sub_domain"
69 _debug _domain
"$_domain"
71 _debug
"Getting txt records"
72 _sl_rest GET
"/${_domain_id}/records/"
74 if ! _contains
"$response" "$txtvalue"; then
75 _err
"Txt record not found"
79 _record_seg
="$(echo "$response" | _egrep_o "\"content
\" *: *\"$txtvalue\"[^
}]*}")"
80 _debug2
"_record_seg" "$_record_seg"
81 if [ -z "$_record_seg" ]; then
82 _err
"can not find _record_seg"
86 _record_id
="$(echo "$_record_seg" | tr "," "\n" | tr "}" "\n" | tr -d " " | grep "\"id
\"" | cut -d : -f 2)"
87 _debug2
"_record_id" "$_record_id"
88 if [ -z "$_record_id" ]; then
89 _err
"can not find _record_id"
93 if ! _sl_rest DELETE
"/$_domain_id/records/$_record_id"; then
94 _err
"Delete record error."
100 #################### Private functions below ##################################
101 #_acme-challenge.www.domain.com
103 # _sub_domain=_acme-challenge.www
105 # _domain_id=sdjkglgdfewsdfg
109 if ! _sl_rest GET
"/"; then
116 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
123 if _contains
"$response" "\"name\": \"$h\","; then
124 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
126 _debug
"Getting domain id for $h"
127 if ! _sl_rest GET
"/$h"; then
130 _domain_id
="$(echo "$response" | tr "," "\n" | tr "}" "\n" | tr -d " " | grep "\"id
\":" | cut -d : -f 2)"
145 export _H1
="X-Token: $SL_Key"
146 export _H2
="Content-Type: application/json"
148 if [ "$m" != "GET" ]; then
150 response
="$(_post "$data" "$SL_Api/$ep" "" "$m")"
152 response
="$(_get "$SL_Api/$ep")"
155 if [ "$?" != "0" ]; then
159 _debug2 response
"$response"