2 TRANSIP_Api_Url
="https://api.transip.nl/v6"
3 TRANSIP_Token_Read_Only
="false"
4 TRANSIP_Token_Global_Key
="false"
5 TRANSIP_Token_Expiration
="30 minutes"
6 # You can't reuse a label token, so we leave this empty normally
9 ######## Public functions #####################
10 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
13 _debug fulldomain
="$fulldomain"
15 _debug txtvalue
="$txtvalue"
16 _transip_setup
"$fulldomain" ||
return 1
17 _info
"Creating TXT record."
18 if ! _transip_rest POST
"domains/$_domain/dns" "{\"dnsEntry\":{\"name\":\"$_sub_domain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"expire\":300}}"; then
19 _err
"Could not add TXT record."
27 _debug fulldomain
="$fulldomain"
29 _debug txtvalue
="$txtvalue"
30 _transip_setup
"$fulldomain" ||
return 1
31 _info
"Removing TXT record."
32 if ! _transip_rest DELETE
"domains/$_domain/dns" "{\"dnsEntry\":{\"name\":\"$_sub_domain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"expire\":300}}"; then
33 _err
"Could not remove TXT record $_sub_domain for $domain"
39 #################### Private functions below ##################################
40 #_acme-challenge.www.domain.com
42 # _sub_domain=_acme-challenge.www
49 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
56 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
59 if _transip_rest GET
"domains/$h/dns" && _contains
"$response" "dnsEntries"; then
66 _err
"Unable to parse this domain"
75 export _H1
="Accept: application/json"
76 export _H2
="Authorization: Bearer $_token"
77 export _H4
="Content-Type: application/json"
78 if [ "$m" != "GET" ]; then
80 response
="$(_post "$data" "$TRANSIP_Api_Url/$ep" "" "$m")"
83 response
="$(_get "$TRANSIP_Api_Url/$ep")"
87 if [ "$retcode" != "0" ]; then
91 _debug2 response
"$response"
95 _transip_get_token
() {
96 nonce
=$
(echo "TRANSIP$(_time)" | _digest sha1 hex | cut
-c 1-32)
99 data
="{\"login\":\"${TRANSIP_Username}\",\"nonce\":\"${nonce}\",\"read_only\":\"${TRANSIP_Token_Read_Only}\",\"expiration_time\":\"${TRANSIP_Token_Expiration}\",\"label\":\"${TRANSIP_Token_Label}\",\"global_key\":\"${TRANSIP_Token_Global_Key}\"}"
102 #_signature=$(printf "%s" "$data" | openssl dgst -sha512 -sign "$TRANSIP_Key_File" | _base64)
103 _signature
=$
(printf "%s" "$data" | _sign
"$TRANSIP_Key_File" "sha512")
104 _debug2 _signature
"$_signature"
106 export _H1
="Signature: $_signature"
107 export _H2
="Content-Type: application/json"
109 response
="$(_post "$data" "$TRANSIP_Api_Url/auth
" "" "POST
")"
111 _debug2 response
"$response"
112 if [ "$retcode" != "0" ]; then
113 _err
"Authentication failed."
116 if _contains
"$response" "token"; then
117 _token
="$(echo "$response" | _normalizeJson | sed -n 's/^{"token
":"\
(.
*\
)"}/\1/p')"
118 _debug _token
"$_token"
127 # retrieve the transip creds
128 TRANSIP_Username
="${TRANSIP_Username:-$(_readaccountconf_mutable TRANSIP_Username)}"
129 TRANSIP_Key_File
="${TRANSIP_Key_File:-$(_readaccountconf_mutable TRANSIP_Key_File)}"
130 # check their vals for null
131 if [ -z "$TRANSIP_Username" ] ||
[ -z "$TRANSIP_Key_File" ]; then
134 _err
"You didn't specify a TransIP username and api key file location"
135 _err
"Please set those values and try again."
138 # save the username and api key to the account conf file.
139 _saveaccountconf_mutable TRANSIP_Username
"$TRANSIP_Username"
140 _saveaccountconf_mutable TRANSIP_Key_File
"$TRANSIP_Key_File"
142 if [ -f "$TRANSIP_Key_File" ]; then
143 if ! grep "BEGIN PRIVATE KEY" "$TRANSIP_Key_File" >/dev
/null
2>&1; then
144 _err
"Key file doesn't seem to be a valid key: ${TRANSIP_Key_File}"
148 _err
"Can't read private key file: ${TRANSIP_Key_File}"
152 if [ -z "$_token" ]; then
153 if ! _transip_get_token
; then
154 _err
"Can not get token."
159 _get_root
"$fulldomain" ||
return 1