3 # Author: Wout Decre <wout@canodus.be>
5 CONSTELLIX_Api
="https://api.dns.constellix.com/v1"
7 #CONSTELLIX_Secret="XXX"
9 ######## Public functions #####################
11 # Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
12 # Used to add txt record
13 dns_constellix_add
() {
17 CONSTELLIX_Key
="${CONSTELLIX_Key:-$(_readaccountconf_mutable CONSTELLIX_Key)}"
18 CONSTELLIX_Secret
="${CONSTELLIX_Secret:-$(_readaccountconf_mutable CONSTELLIX_Secret)}"
20 if [ -z "$CONSTELLIX_Key" ] ||
[ -z "$CONSTELLIX_Secret" ]; then
21 _err
"You did not specify the Contellix API key and secret yet."
25 _saveaccountconf_mutable CONSTELLIX_Key
"$CONSTELLIX_Key"
26 _saveaccountconf_mutable CONSTELLIX_Secret
"$CONSTELLIX_Secret"
28 if ! _get_root
"$fulldomain"; then
33 # The TXT record might already exist when working with wildcard certificates. In that case, update the record by adding the new value.
34 _debug
"Search TXT record"
35 if _constellix_rest GET
"domains/${_domain_id}/records/TXT/search?exact=${_sub_domain}"; then
36 if printf -- "%s" "$response" |
grep "{\"errors\":\[\"Requested record was not found\"\]}" >/dev
/null
; then
37 _info
"Adding TXT record"
38 if _constellix_rest POST
"domains/${_domain_id}/records" "[{\"type\":\"txt\",\"add\":true,\"set\":{\"name\":\"${_sub_domain}\",\"ttl\":60,\"roundRobin\":[{\"value\":\"${txtvalue}\"}]}}]"; then
39 if printf -- "%s" "$response" |
grep "{\"success\":\"1 record(s) added, 0 record(s) updated, 0 record(s) deleted\"}" >/dev
/null
; then
43 _err
"Error adding TXT record"
47 _record_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":[0-9]*" | cut
-d ':' -f 2)
48 if _constellix_rest GET
"domains/${_domain_id}/records/TXT/${_record_id}"; then
49 _new_rr_values
=$
(printf "%s\n" "$response" | _egrep_o
'"roundRobin":\[[^]]*\]' |
sed "s/\]$/,{\"value\":\"${txtvalue}\"}]/")
50 _debug _new_rr_values
"$_new_rr_values"
51 _info
"Updating TXT record"
52 if _constellix_rest PUT
"domains/${_domain_id}/records/TXT/${_record_id}" "{\"name\":\"${_sub_domain}\",\"ttl\":60,${_new_rr_values}}"; then
53 if printf -- "%s" "$response" |
grep "{\"success\":\"Record.*updated successfully\"}" >/dev
/null
; then
56 elif printf -- "%s" "$response" |
grep "{\"errors\":\[\"Contents are identical\"\]}" >/dev
/null
; then
57 _info
"Already exists, no need to update"
60 _err
"Error updating TXT record"
70 # Usage: fulldomain txtvalue
71 # Used to remove the txt record after validation
76 CONSTELLIX_Key
="${CONSTELLIX_Key:-$(_readaccountconf_mutable CONSTELLIX_Key)}"
77 CONSTELLIX_Secret
="${CONSTELLIX_Secret:-$(_readaccountconf_mutable CONSTELLIX_Secret)}"
79 if [ -z "$CONSTELLIX_Key" ] ||
[ -z "$CONSTELLIX_Secret" ]; then
80 _err
"You did not specify the Contellix API key and secret yet."
84 if ! _get_root
"$fulldomain"; then
89 # The TXT record might have been removed already when working with some wildcard certificates.
90 _debug
"Search TXT record"
91 if _constellix_rest GET
"domains/${_domain_id}/records/TXT/search?exact=${_sub_domain}"; then
92 if printf -- "%s" "$response" |
grep "{\"errors\":\[\"Requested record was not found\"\]}" >/dev
/null
; then
96 _info
"Removing TXT record"
97 if _constellix_rest POST
"domains/${_domain_id}/records" "[{\"type\":\"txt\",\"delete\":true,\"filter\":{\"field\":\"name\",\"op\":\"eq\",\"value\":\"${_sub_domain}\"}}]"; then
98 if printf -- "%s" "$response" |
grep "{\"success\":\"0 record(s) added, 0 record(s) updated, 1 record(s) deleted\"}" >/dev
/null
; then
102 _err
"Error removing TXT record"
111 #################### Private functions below ##################################
117 _debug
"Detecting root zone"
119 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
124 if ! _constellix_rest GET
"domains/search?exact=$h"; then
128 if _contains
"$response" "\"name\":\"$h\""; then
129 _domain_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":[0-9]*" | cut
-d ':' -f 2)
130 if [ "$_domain_id" ]; then
131 _sub_domain
=$
(printf "%s" "$domain" | cut
-d '.' -f 1-$p)
134 _debug _domain_id
"$_domain_id"
135 _debug _sub_domain
"$_sub_domain"
136 _debug _domain
"$_domain"
153 rdate
=$
(date +"%s")"000"
154 hmac
=$
(printf "%s" "$rdate" | _hmac sha1
"$(printf "%s
" "$CONSTELLIX_Secret" | _hex_dump | tr -d ' ')" | _base64
)
156 export _H1
="x-cnsdns-apiKey: $CONSTELLIX_Key"
157 export _H2
="x-cnsdns-requestDate: $rdate"
158 export _H3
="x-cnsdns-hmac: $hmac"
159 export _H4
="Accept: application/json"
160 export _H5
="Content-Type: application/json"
162 if [ "$m" != "GET" ]; then
164 response
="$(_post "$data" "$CONSTELLIX_Api/$ep" "" "$m")"
166 response
="$(_get "$CONSTELLIX_Api/$ep")"
169 if [ "$?" != "0" ]; then
174 _debug response
"$response"