4 #VARIOMEDIA_API_TOKEN=000011112222333344445555666677778888
6 VARIOMEDIA_API
="https://api.variomedia.de"
8 ######## Public functions #####################
10 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
11 dns_variomedia_add
() {
14 _debug fulldomain
"$fulldomain"
15 _debug txtvalue
"$txtvalue"
17 VARIOMEDIA_API_TOKEN
="${VARIOMEDIA_API_TOKEN:-$(_readaccountconf_mutable VARIOMEDIA_API_TOKEN)}"
18 if test -z "$VARIOMEDIA_API_TOKEN"; then
19 VARIOMEDIA_API_TOKEN
=""
20 _err
'VARIOMEDIA_API_TOKEN was not exported'
24 _saveaccountconf_mutable VARIOMEDIA_API_TOKEN
"$VARIOMEDIA_API_TOKEN"
26 _debug
'First detect the root zone'
27 if ! _get_root
"$fulldomain"; then
30 _debug _sub_domain
"$_sub_domain"
31 _debug _domain
"$_domain"
33 if ! _variomedia_rest POST
"dns-records" "{\"data\": {\"type\": \"dns-record\", \"attributes\": {\"record_type\": \"TXT\", \"name\": \"$_sub_domain\", \"domain\": \"$_domain\", \"data\": \"$txtvalue\", \"ttl\":300}}}"; then
38 _debug2 _response
"$response"
46 _debug fulldomain
"$fulldomain"
47 _debug txtvalue
"$txtvalue"
49 VARIOMEDIA_API_TOKEN
="${VARIOMEDIA_API_TOKEN:-$(_readaccountconf_mutable VARIOMEDIA_API_TOKEN)}"
50 if test -z "$VARIOMEDIA_API_TOKEN"; then
51 VARIOMEDIA_API_TOKEN
=""
52 _err
'VARIOMEDIA_API_TOKEN was not exported'
56 _saveaccountconf_mutable VARIOMEDIA_API_TOKEN
"$VARIOMEDIA_API_TOKEN"
58 _debug
'First detect the root zone'
59 if ! _get_root
"$fulldomain"; then
62 _debug _sub_domain
"$_sub_domain"
63 _debug _domain
"$_domain"
65 _debug
'Getting txt records'
67 if ! _variomedia_rest GET
"dns-records?filter[domain]=$_domain"; then
72 _record_id
="$(echo "$response" | cut -d '[' -f2 | cut -d']' -f1 | sed 's/},[ \t]*{/\},§\{/g' | tr § '\n' | grep "$_sub_domain" | grep "$txtvalue" | sed 's/^{//;s/}[,]?$//' | tr , '\n' | tr -d '\"' | grep ^id | cut -d : -f2 | tr -d ' ')"
73 _debug _record_id
"$_record_id"
74 if [ "$_record_id" ]; then
75 _info
"Successfully retrieved the record id for ACME challenge."
77 _info
"Empty record id, it seems no such record."
81 if ! _variomedia_rest DELETE
"/dns-records/$_record_id"; then
86 _debug2 _response
"$response"
90 #################### Private functions below ##################################
91 #_acme-challenge.www.domain.com
93 # _sub_domain=_acme-challenge.www
99 h
=$
(printf "%s" "$fulldomain" | cut
-d .
-f $i-100)
105 if ! _variomedia_rest GET
"domains/$h"; then
109 if _startswith
"$response" "\{\"data\":"; then
110 if _contains
"$response" "\"id\":\"$h\""; then
111 _sub_domain
="$(echo "$fulldomain" | sed "s
/\\.
$h\$
//")"
119 _debug
"root domain not found"
129 export _H1
="Authorization: token $VARIOMEDIA_API_TOKEN"
130 export _H2
="Content-Type: application/vnd.api+json"
131 export _H3
="Accept: application/vnd.variomedia.v1+json"
133 if [ "$m" != "GET" ]; then
135 response
="$(_post "$data" "$VARIOMEDIA_API/$ep" "" "$m")"
137 response
="$(_get "$VARIOMEDIA_API/$ep")"
140 if [ "$?" != "0" ]; then
145 _debug2 response
"$response"