3 # Anexia CloudDNS acme.sh hook
8 ANX_API
='https://engine.anexia-it.com/api/clouddns/v1'
10 ######## Public functions #####################
16 _info
"Using ANX CDNS API"
18 ANX_Token
="${ANX_Token:-$(_readaccountconf_mutable ANX_Token)}"
19 _debug fulldomain
"$fulldomain"
20 _debug txtvalue
"$txtvalue"
22 if [ "$ANX_Token" ]; then
23 _saveaccountconf_mutable ANX_Token
"$ANX_Token"
25 _err
"You didn't specify a ANEXIA Engine API token."
29 _debug
"First detect the root zone"
30 if ! _get_root
"$fulldomain"; then
35 # Always add records, wildcard need two records with the same name
36 _anx_rest POST
"zone.json/${_domain}/records" "{\"name\":\"$_sub_domain\",\"type\":\"TXT\",\"rdata\":\"$txtvalue\"}"
37 if _contains
"$response" "$txtvalue"; then
48 _info
"Using ANX CDNS API"
50 ANX_Token
="${ANX_Token:-$(_readaccountconf_mutable ANX_Token)}"
52 _debug fulldomain
"$fulldomain"
53 _debug txtvalue
"$txtvalue"
55 _debug
"First detect the root zone"
56 if ! _get_root
"$fulldomain"; then
63 if _is_uuid
"$_record_id"; then
64 if ! _anx_rest DELETE
"zone.json/${_domain}/records/$_record_id"; then
69 _info
"No record found."
71 echo "$response" |
tr -d " " |
grep \"status
\":\"OK
\" >/dev
/null
74 #################### Private functions below ##################################
77 pattern
='^\{?[A-Z0-9a-z]{8}-[A-Z0-9a-z]{4}-[A-Z0-9a-z]{4}-[A-Z0-9a-z]{4}-[A-Z0-9a-z]{12}\}?$'
78 if echo "$1" | _egrep_o
"$pattern" >/dev
/null
; then
85 _debug subdomain
"$_sub_domain"
86 _debug domain
"$_domain"
88 if _anx_rest GET
"zone.json/${_domain}/records?name=$_sub_domain&type=TXT"; then
89 _debug response
"$response"
90 if _contains
"$response" "\"name\":\"$_sub_domain\"" >/dev
/null
; then
91 _record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\[.\"identifier\":\"[^\"]*\"" |
head -n 1 | cut
-d : -f 2 |
tr -d \")
96 _err
"Search existing record"
106 export _H1
="Content-Type: application/json"
107 export _H2
="Authorization: Token $ANX_Token"
109 if [ "$m" != "GET" ]; then
111 response
="$(_post "$data" "${ANX_API}/$ep" "" "$m")"
113 response
="$(_get "${ANX_API}/$ep")"
116 # shellcheck disable=SC2181
117 if [ "$?" != "0" ]; then
121 _debug response
"$response"
130 _anx_rest GET
"zone.json"
133 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
140 if _contains
"$response" "\"name\":\"$h\""; then
141 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)