3 DOMENESHOP_Api_Endpoint
="https://api.domeneshop.no/v0"
5 ##################### Public functions #####################
7 # Usage: dns_domeneshop_add <full domain> <txt record>
8 # Example: dns_domeneshop_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
13 # Get token and secret
14 DOMENESHOP_Token
="${DOMENESHOP_Token:-$(_readaccountconf_mutable DOMENESHOP_Token)}"
15 DOMENESHOP_Secret
="${DOMENESHOP_Secret:-$(_readaccountconf_mutable DOMENESHOP_Secret)}"
17 if [ -z "$DOMENESHOP_Token" ] ||
[ -z "$DOMENESHOP_Secret" ]; then
20 _err
"You need to spesify a Domeneshop/Domainnameshop API Token and Secret."
24 # Save the api token and secret.
25 _saveaccountconf_mutable DOMENESHOP_Token
"$DOMENESHOP_Token"
26 _saveaccountconf_mutable DOMENESHOP_Secret
"$DOMENESHOP_Secret"
28 # Get the domain name id
29 if ! _get_domainid
"$fulldomain"; then
30 _err
"Did not find domainname"
35 _domeneshop_rest POST
"domains/$_domainid/dns" "{\"type\":\"TXT\",\"host\":\"$_sub_domain\",\"data\":\"$txtvalue\",\"ttl\":120}"
38 # Usage: dns_domeneshop_rm <full domain> <txt record>
39 # Example: dns_domeneshop_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
44 # Get token and secret
45 DOMENESHOP_Token
="${DOMENESHOP_Token:-$(_readaccountconf_mutable DOMENESHOP_Token)}"
46 DOMENESHOP_Secret
="${DOMENESHOP_Secret:-$(_readaccountconf_mutable DOMENESHOP_Secret)}"
48 if [ -z "$DOMENESHOP_Token" ] ||
[ -z "$DOMENESHOP_Secret" ]; then
51 _err
"You need to spesify a Domeneshop/Domainnameshop API Token and Secret."
55 # Get the domain name id
56 if ! _get_domainid
"$fulldomain"; then
57 _err
"Did not find domainname"
62 if ! _get_recordid
"$_domainid" "$_sub_domain" "$txtvalue"; then
63 _err
"Did not find dns record"
68 _domeneshop_rest DELETE
"domains/$_domainid/dns/$_recordid"
71 ##################### Private functions #####################
77 _domeneshop_rest GET
"domains"
79 if ! _contains
"$response" "\"id\":"; then
80 _err
"failed to get domain names"
87 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
94 if _contains
"$response" "\"$h\"" >/dev
/null
; then
95 # We have found the domain name.
96 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
98 _domainid
=$
(printf "%s" "$response" | _egrep_o
"[^{]*\"domain\":\"$_domain\"[^}]*" | _egrep_o
"\"id\":[0-9]+" | cut
-d : -f 2)
112 # Get all dns records for the domainname
113 _domeneshop_rest GET
"domains/$domainid/dns"
115 if ! _contains
"$response" "\"id\":"; then
116 _debug
"No records in dns"
120 if ! _contains
"$response" "\"host\":\"$subdomain\""; then
121 _debug
"Record does not exist"
125 # Get the id of the record in question
126 _recordid
=$
(printf "%s" "$response" | _egrep_o
"[^{]*\"host\":\"$subdomain\"[^}]*" | _egrep_o
"[^{]*\"data\":\"$txtvalue\"[^}]*" | _egrep_o
"\"id\":[0-9]+" | cut
-d : -f 2)
127 if [ -z "$_recordid" ]; then
138 credentials
=$
(printf "%b" "$DOMENESHOP_Token:$DOMENESHOP_Secret" | _base64
)
140 export _H1
="Authorization: Basic $credentials"
141 export _H2
="Content-Type: application/json"
143 if [ "$method" != "GET" ]; then
144 response
="$(_post "$data" "$DOMENESHOP_Api_Endpoint/$endpoint" "" "$method")"
146 response
="$(_get "$DOMENESHOP_Api_Endpoint/$endpoint")"
149 if [ "$?" != "0" ]; then
150 _err
"error $endpoint"