4 # https://help.zone.eu/kb/zoneid-api-v2/
5 # required ZONE_Username and ZONE_Key
7 ZONE_Api
="https://api.zone.eu/v2"
8 ######## Public functions #####################
10 #Usage: dns_zone_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
14 _info
"Using zone.ee dns api"
15 _debug fulldomain
"$fulldomain"
16 _debug txtvalue
"$txtvalue"
17 ZONE_Username
="${ZONE_Username:-$(_readaccountconf_mutable ZONE_Username)}"
18 ZONE_Key
="${ZONE_Key:-$(_readaccountconf_mutable ZONE_Key)}"
19 if [ -z "$ZONE_Username" ] ||
[ -z "$ZONE_Key" ]; then
22 _err
"Zone api key and username must be present."
25 _saveaccountconf_mutable ZONE_Username
"$ZONE_Username"
26 _saveaccountconf_mutable ZONE_Key
"$ZONE_Key"
27 _debug
"First detect the root zone"
28 if ! _get_root
"$fulldomain"; then
33 _debug
"Adding txt record"
35 if _zone_rest POST
"dns/${_domain}/txt" "{\"name\": \"$fulldomain\", \"destination\": \"$txtvalue\"}"; then
36 if printf -- "%s" "$response" |
grep "$fulldomain" >/dev
/null
; then
40 _err
"Adding txt record error."
44 _err
"Adding txt record error."
48 #Usage: fulldomain txtvalue
49 #Remove the txt record after validation.
53 _info
"Using zone.ee dns api"
54 _debug fulldomain
"$fulldomain"
55 _debug txtvalue
"$txtvalue"
56 ZONE_Username
="${ZONE_Username:-$(_readaccountconf_mutable ZONE_Username)}"
57 ZONE_Key
="${ZONE_Key:-$(_readaccountconf_mutable ZONE_Key)}"
58 if [ -z "$ZONE_Username" ] ||
[ -z "$ZONE_Key" ]; then
61 _err
"Zone api key and username must be present."
64 _saveaccountconf_mutable ZONE_Username
"$ZONE_Username"
65 _saveaccountconf_mutable ZONE_Key
"$ZONE_Key"
66 _debug
"First detect the root zone"
67 if ! _get_root
"$fulldomain"; then
72 _debug
"Getting txt records"
73 _debug _domain
"$_domain"
75 _zone_rest GET
"dns/${_domain}/txt"
77 if printf "%s" "$response" |
grep \"error
\" >/dev
/null
; then
82 count
=$
(printf "%s\n" "$response" | _egrep_o
"\"name\":\"$fulldomain\"" |
wc -l)
84 if [ "$count" = "0" ]; then
85 _info
"Nothing to remove."
87 record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":\"[^\"]*\",\"resource_url\":\"[^\"]*\",\"name\":\"$fulldomain\"," | cut
-d : -f2 | cut
-d , -f1 |
tr -d \" | _head_n
1)
88 if [ -z "$record_id" ]; then
89 _err
"No id found to remove."
92 if ! _zone_rest DELETE
"dns/${_domain}/txt/$record_id"; then
93 _err
"Record deleting error."
96 _info
"Record deleted"
102 #################### Private functions below ##################################
110 realm
="$(printf "%s
" "$ZONE_Username:$ZONE_Key" | _base64)"
112 export _H1
="Authorization: Basic $realm"
113 export _H2
="Content-Type: application/json"
115 if [ "$m" != "GET" ]; then
117 response
="$(_post "$data" "$ZONE_Api/$ep" "" "$m")"
119 response
="$(_get "$ZONE_Api/$ep")"
122 if [ "$?" != "0" ]; then
126 _debug2 response
"$response"
134 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
139 if ! _zone_rest GET
"dns/$h"; then
142 if _contains
"$response" "\"identificator\":\"$h\"" >/dev
/null
; then