4 #AURORA_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
6 #AURORA_Secret="sdfsdfsdfljlbjkljlkjsdfoiwje"
8 AURORA_Api
="https://api.auroradns.eu"
10 ######## Public functions #####################
12 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
17 AURORA_Key
="${AURORA_Key:-$(_readaccountconf_mutable AURORA_Key)}"
18 AURORA_Secret
="${AURORA_Secret:-$(_readaccountconf_mutable AURORA_Secret)}"
20 if [ -z "$AURORA_Key" ] ||
[ -z "$AURORA_Secret" ]; then
23 _err
"You didn't specify an Aurora api key and secret yet."
24 _err
"You can get yours from here https://cp.pcextreme.nl/auroradns/users."
28 #save the api key and secret to the account conf file.
29 _saveaccountconf_mutable AURORA_Key
"$AURORA_Key"
30 _saveaccountconf_mutable AURORA_Secret
"$AURORA_Secret"
32 _debug
"First detect the root zone"
33 if ! _get_root
"$fulldomain"; then
37 _debug _domain_id
"$_domain_id"
38 _debug _sub_domain
"$_sub_domain"
39 _debug _domain
"$_domain"
42 if _aurora_rest POST
"zones/$_domain_id/records" "{\"type\":\"TXT\",\"name\":\"$_sub_domain\",\"content\":\"$txtvalue\",\"ttl\":300}"; then
43 if _contains
"$response" "$txtvalue"; then
46 elif _contains
"$response" "RecordExistsError"; then
47 _info
"Already exists, OK"
50 _err
"Add txt record error."
54 _err
"Add txt record error."
64 AURORA_Key
="${AURORA_Key:-$(_readaccountconf_mutable AURORA_Key)}"
65 AURORA_Secret
="${AURORA_Secret:-$(_readaccountconf_mutable AURORA_Secret)}"
67 _debug
"First detect the root zone"
68 if ! _get_root
"$fulldomain"; then
72 _debug _domain_id
"$_domain_id"
73 _debug _sub_domain
"$_sub_domain"
74 _debug _domain
"$_domain"
76 _debug
"Getting records"
77 _aurora_rest GET
"zones/${_domain_id}/records"
79 if ! _contains
"$response" "$txtvalue"; then
80 _info
"Don't need to remove."
82 records
=$
(echo "$response" | _normalizeJson |
tr -d "[]" |
sed "s/},{/}|{/g" |
tr "|" "\n")
83 if [ "$(echo "$records" | wc -l)" -le 2 ]; then
84 _err
"Can not parse records."
87 record_id
=$
(echo "$records" |
grep "\"type\": *\"TXT\"" |
grep "\"name\": *\"$_sub_domain\"" |
grep "\"content\": *\"$txtvalue\"" | _egrep_o
"\"id\": *\"[^\"]*\"" | cut
-d : -f 2 |
tr -d \" | _head_n
1 |
tr -d " ")
88 _debug
"record_id" "$record_id"
89 if [ -z "$record_id" ]; then
90 _err
"Can not get record id to remove."
93 if ! _aurora_rest DELETE
"zones/$_domain_id/records/$record_id"; then
94 _err
"Delete record error."
102 #################### Private functions below ##################################
103 #_acme-challenge.www.domain.com
105 # _sub_domain=_acme-challenge.www
107 # _domain_id=sdjkglgdfewsdfg
114 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
121 if ! _aurora_rest GET
"zones/$h"; then
125 if _contains
"$response" "\"name\": \"$h\""; then
126 _domain_id
=$
(echo "$response" | _normalizeJson |
tr -d "{}" |
tr "," "\n" |
grep "\"id\": *\"" | cut
-d : -f 2 |
tr -d \" | _head_n
1 |
tr -d " ")
127 _debug _domain_id
"$_domain_id"
128 if [ "$_domain_id" ]; then
129 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
147 key_trimmed
=$
(echo "$AURORA_Key" |
tr -d '"')
148 secret_trimmed
=$
(echo "$AURORA_Secret" |
tr -d '"')
150 timestamp
=$
(date -u +"%Y%m%dT%H%M%SZ")
151 signature
=$
(printf "%s/%s%s" "$m" "$ep" "$timestamp" | _hmac sha256
"$(printf "%s
" "$secret_trimmed" | _hex_dump | tr -d " ")" | _base64
)
152 authorization
=$
(printf "AuroraDNSv1 %s" "$(printf "%s
:%s
" "$key_trimmed" "$signature" | _base64)")
154 export _H1
="Content-Type: application/json; charset=UTF-8"
155 export _H2
="X-AuroraDNS-Date: $timestamp"
156 export _H3
="Authorization: $authorization"
158 if [ "$m" != "GET" ]; then
160 response
="$(_post "$data" "$AURORA_Api/$ep" "" "$m")"
162 response
="$(_get "$AURORA_Api/$ep")"
165 if [ "$?" != "0" ]; then
169 _debug2 response
"$response"