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 _info
"Adding TXT record"
34 if _constellix_rest POST
"domains/${_domain_id}/records" "[{\"type\":\"txt\",\"add\":true,\"set\":{\"name\":\"${_sub_domain}\",\"ttl\":120,\"roundRobin\":[{\"value\":\"${txtvalue}\"}]}}]"; then
35 if printf -- "%s" "$response" |
grep "{\"success\":\"1 record(s) added, 0 record(s) updated, 0 record(s) deleted\"}" >/dev
/null
; then
39 _err
"Error adding TXT record"
45 # Usage: fulldomain txtvalue
46 # Used to remove the txt record after validation
51 CONSTELLIX_Key
="${CONSTELLIX_Key:-$(_readaccountconf_mutable CONSTELLIX_Key)}"
52 CONSTELLIX_Secret
="${CONSTELLIX_Secret:-$(_readaccountconf_mutable CONSTELLIX_Secret)}"
54 if [ -z "$CONSTELLIX_Key" ] ||
[ -z "$CONSTELLIX_Secret" ]; then
55 _err
"You did not specify the Contellix API key and secret yet."
59 if ! _get_root
"$fulldomain"; then
64 _info
"Removing TXT record"
65 if _constellix_rest POST
"domains/${_domain_id}/records" "[{\"type\":\"txt\",\"delete\":true,\"filter\":{\"field\":\"name\",\"op\":\"eq\",\"value\":\"${_sub_domain}\"}}]"; then
66 if printf -- "%s" "$response" |
grep "{\"success\":\"0 record(s) added, 0 record(s) updated, 1 record(s) deleted\"}" >/dev
/null
; then
70 _err
"Error removing TXT record"
76 #################### Private functions below ##################################
82 _debug
"Detecting root zone"
84 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
89 if ! _constellix_rest GET
"domains/search?name=$h"; then
93 if _contains
"$response" "\"name\":\"$h\""; then
94 _domain_id
=$
(printf "%s\n" "$response" | _egrep_o
"\"id\":[0-9]+" | cut
-d ':' -f 2)
95 if [ "$_domain_id" ]; then
96 _sub_domain
=$
(printf "%s" "$domain" | cut
-d '.' -f 1-$p)
99 _debug _domain_id
"$_domain_id"
100 _debug _sub_domain
"$_sub_domain"
101 _debug _domain
"$_domain"
118 rdate
=$
(date +"%s")"000"
119 hmac
=$
(printf "%s" "$rdate" | _hmac sha1
"$(printf "%s
" "$CONSTELLIX_Secret" | _hex_dump | tr -d ' ')" | _base64
)
121 export _H1
="x-cnsdns-apiKey: $CONSTELLIX_Key"
122 export _H2
="x-cnsdns-requestDate: $rdate"
123 export _H3
="x-cnsdns-hmac: $hmac"
124 export _H4
="Accept: application/json"
125 export _H5
="Content-Type: application/json"
127 if [ "$m" != "GET" ]; then
129 response
="$(_post "$data" "$CONSTELLIX_Api/$ep" "" "$m")"
131 response
="$(_get "$CONSTELLIX_Api/$ep")"
134 if [ "$?" != "0" ]; then
139 _debug response
"$response"