3 #Author: Timur Umarov <inbox@tumarov.com>
5 FORNEX_API_URL
="https://fornex.com/api/dns/v0.1"
7 ######## Public functions #####################
9 #Usage: dns_fornex_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
14 if ! _Fornex_API
; then
18 if ! _get_root
"$fulldomain"; then
19 _err
"Unable to determine root domain"
22 _debug _domain
"$_domain"
26 if _rest POST
"$_domain/entry_set/add/" "host=$fulldomain&type=TXT&value=$txtvalue&apikey=$FORNEX_API_KEY"; then
27 _debug _response
"$response"
28 if _contains
"$response" '"ok": true' || _contains
"$response" 'Такая запись уже существует.'; then
33 _err
"Add txt record error."
37 #Usage: dns_fornex_rm _acme-challenge.www.domain.com
42 if ! _Fornex_API
; then
46 if ! _get_root
"$fulldomain"; then
47 _err
"Unable to determine root domain"
50 _debug _domain
"$_domain"
53 _debug
"Getting txt records"
54 _rest GET
"$_domain/entry_set.json?apikey=$FORNEX_API_KEY"
56 if ! _contains
"$response" "$txtvalue"; then
57 _err
"Txt record not found"
61 _record_id
="$(echo "$response" | _egrep_o "{[^
{]*\"value
\"*:*\"$txtvalue\"[^
}]*}" | sed -n -e 's#.*"id
": \([0-9]*\).*#\1#p')"
62 _debug
"_record_id" "$_record_id"
63 if [ -z "$_record_id" ]; then
64 _err
"can not find _record_id"
68 if ! _rest POST
"$_domain/entry_set/$_record_id/delete/" "apikey=$FORNEX_API_KEY"; then
69 _err
"Delete record error."
75 #################### Private functions below ##################################
77 #_acme-challenge.www.domain.com
79 # _sub_domain=_acme-challenge.www
86 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
93 if ! _rest GET
"domain_list.json?q=$h&apikey=$FORNEX_API_KEY"; then
97 if _contains
"$response" "\"$h\"" >/dev
/null
; then
101 _debug
"$h not found"
110 FORNEX_API_KEY
="${FORNEX_API_KEY:-$(_readaccountconf_mutable FORNEX_API_KEY)}"
111 if [ -z "$FORNEX_API_KEY" ]; then
114 _err
"You didn't specify the Fornex API key yet."
115 _err
"Please create your key and try again."
120 _saveaccountconf_mutable FORNEX_API_KEY
"$FORNEX_API_KEY"
123 #method method action data
130 export _H1
="Accept: application/json"
132 if [ "$m" != "GET" ]; then
134 response
="$(_post "$data" "$FORNEX_API_URL/$ep" "" "$m")"
136 response
="$(_get "$FORNEX_API_URL/$ep" | _normalizeJson)"
140 if [ "$_ret" != "0" ]; then
144 _debug2 response
"$response"