3 #Script to use with curanet.dk, scannet.dk, wannafind.dk, dandomain.dk DNS management.
4 #Requires api credentials with scope: dns
5 #Author: Peter L. Hansen <peter@r12.dk>
8 CURANET_REST_URL
="https://api.curanet.dk/dns/v1/Domains"
9 CURANET_AUTH_URL
="https://apiauth.dk.team.blue/auth/realms/Curanet/protocol/openid-connect/token"
10 CURANET_ACCESS_TOKEN
=""
12 ######## Public functions #####################
14 #Usage: dns_curanet_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
19 _debug fulldomain
"$fulldomain"
20 _debug txtvalue
"$txtvalue"
22 CURANET_AUTHCLIENTID
="${CURANET_AUTHCLIENTID:-$(_readaccountconf_mutable CURANET_AUTHCLIENTID)}"
23 CURANET_AUTHSECRET
="${CURANET_AUTHSECRET:-$(_readaccountconf_mutable CURANET_AUTHSECRET)}"
24 if [ -z "$CURANET_AUTHCLIENTID" ] ||
[ -z "$CURANET_AUTHSECRET" ]; then
25 CURANET_AUTHCLIENTID
=""
27 _err
"You don't specify curanet api client and secret."
28 _err
"Please create your auth info and try again."
32 #save the credentials to the account conf file.
33 _saveaccountconf_mutable CURANET_AUTHCLIENTID
"$CURANET_AUTHCLIENTID"
34 _saveaccountconf_mutable CURANET_AUTHSECRET
"$CURANET_AUTHSECRET"
37 _err
"Unable to get token"
41 if ! _get_root
"$fulldomain"; then
46 export _H1
="Content-Type: application/json-patch+json"
47 export _H2
="Accept: application/json"
48 export _H3
="Authorization: Bearer $CURANET_ACCESS_TOKEN"
49 data
="{\"name\": \"$fulldomain\",\"type\": \"TXT\",\"ttl\": 60,\"priority\": 0,\"data\": \"$txtvalue\"}"
50 response
="$(_post "$data" "$CURANET_REST_URL/${_domain}/Records
" "" "")"
52 if _contains
"$response" "$txtvalue"; then
53 _debug
"TXT record added OK"
55 _err
"Unable to add TXT record"
62 #Usage: fulldomain txtvalue
63 #Remove the txt record after validation.
68 _debug fulldomain
"$fulldomain"
69 _debug txtvalue
"$txtvalue"
71 CURANET_AUTHCLIENTID
="${CURANET_AUTHCLIENTID:-$(_readaccountconf_mutable CURANET_AUTHCLIENTID)}"
72 CURANET_AUTHSECRET
="${CURANET_AUTHSECRET:-$(_readaccountconf_mutable CURANET_AUTHSECRET)}"
75 _err
"Unable to get token"
79 if ! _get_root
"$fulldomain"; then
84 _debug
"Getting current record list to identify TXT to delete"
86 export _H1
="Content-Type: application/json"
87 export _H2
="Accept: application/json"
88 export _H3
="Authorization: Bearer $CURANET_ACCESS_TOKEN"
90 response
="$(_get "$CURANET_REST_URL/${_domain}/Records
" "" "")"
92 if ! _contains
"$response" "$txtvalue"; then
93 _err
"Unable to delete record (does not contain $txtvalue )"
97 recordid
=$
(echo "$response" | _egrep_o
"{\"id\":[0-9]+,\"name\":\"$fulldomain\",\"type\":\"TXT\",\"ttl\":60,\"priority\":0,\"data\":\"..$txtvalue" | _egrep_o
"id\":[0-9]+" | cut
-c 5-)
99 if [ -z "$recordid" ]; then
100 _err
"Unable to get recordid"
101 _debug
"regex {\"id\":[0-9]+,\"name\":\"$fulldomain\",\"type\":\"TXT\",\"ttl\":60,\"priority\":0,\"data\":\"..$txtvalue"
102 _debug
"response $response"
106 _debug
"Deleting recordID $recordid"
107 response
="$(_post "" "$CURANET_REST_URL/${_domain}/Records
/$recordid" "" "DELETE
")"
111 #################### Private functions below ##################################
114 response
="$(_post "grant_type
=client_credentials
&client_id
=$CURANET_AUTHCLIENTID&client_secret
=$CURANET_AUTHSECRET&scope
=dns
" "$CURANET_AUTH_URL" "" "")"
115 if ! _contains
"$response" "access_token"; then
116 _err
"Unable get access token"
119 CURANET_ACCESS_TOKEN
=$
(echo "$response" | _egrep_o
"\"access_token\":\"[^\"]+" | cut
-c 17-)
121 if [ -z "$CURANET_ACCESS_TOKEN" ]; then
122 _err
"Unable to get token"
130 #_acme-challenge.www.domain.com
133 # _domain_id=sdjkglgdfewsdfg
139 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
146 export _H1
="Content-Type: application/json"
147 export _H2
="Accept: application/json"
148 export _H3
="Authorization: Bearer $CURANET_ACCESS_TOKEN"
149 response
="$(_get "$CURANET_REST_URL/$h/Records
" "" "")"
151 if [ ! "$(echo "$response" | _egrep_o "Entity not found
")" ]; then