2 TRANSIP_Api_Url
="https://api.transip.nl/v6"
3 TRANSIP_Token_Read_Only
="false"
4 TRANSIP_Token_Expiration
="30 minutes"
5 # You can't reuse a label token, so we leave this empty normally
8 ######## Public functions #####################
9 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
12 _debug fulldomain
="$fulldomain"
14 _debug txtvalue
="$txtvalue"
15 _transip_setup
"$fulldomain" ||
return 1
16 _info
"Creating TXT record."
17 if ! _transip_rest POST
"domains/$_domain/dns" "{\"dnsEntry\":{\"name\":\"$_sub_domain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"expire\":300}}"; then
18 _err
"Could not add TXT record."
26 _debug fulldomain
="$fulldomain"
28 _debug txtvalue
="$txtvalue"
29 _transip_setup
"$fulldomain" ||
return 1
30 _info
"Removing TXT record."
31 if ! _transip_rest DELETE
"domains/$_domain/dns" "{\"dnsEntry\":{\"name\":\"$_sub_domain\",\"type\":\"TXT\",\"content\":\"$txtvalue\",\"expire\":300}}"; then
32 _err
"Could not remove TXT record $_sub_domain for $domain"
38 #################### Private functions below ##################################
39 #_acme-challenge.www.domain.com
41 # _sub_domain=_acme-challenge.www
48 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
55 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
58 if _transip_rest GET
"domains/$h/dns" && _contains
"$response" "dnsEntries"; then
65 _err
"Unable to parse this domain"
74 export _H1
="Accept: application/json"
75 export _H2
="Authorization: Bearer $_token"
76 export _H4
="Content-Type: application/json"
77 if [ "$m" != "GET" ]; then
79 response
="$(_post "$data" "$TRANSIP_Api_Url/$ep" "" "$m")"
82 response
="$(_get "$TRANSIP_Api_Url/$ep")"
86 if [ "$retcode" != "0" ]; then
90 _debug2 response
"$response"
94 _transip_get_token
() {
95 nonce
=$
(echo "TRANSIP$(_time)" | _digest sha1 hex | cut
-c 1-32)
98 # make IP whitelisting configurable
99 TRANSIP_Token_Global_Key
="${TRANSIP_Token_Global_Key:-$(_readaccountconf_mutable TRANSIP_Token_Global_Key)}"
100 _saveaccountconf_mutable TRANSIP_Token_Global_Key
"$TRANSIP_Token_Global_Key"
102 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:-false}\"}"
105 #_signature=$(printf "%s" "$data" | openssl dgst -sha512 -sign "$TRANSIP_Key_File" | _base64)
106 _signature
=$
(printf "%s" "$data" | _sign
"$TRANSIP_Key_File" "sha512")
107 _debug2 _signature
"$_signature"
109 export _H1
="Signature: $_signature"
110 export _H2
="Content-Type: application/json"
112 response
="$(_post "$data" "$TRANSIP_Api_Url/auth
" "" "POST
")"
114 _debug2 response
"$response"
115 if [ "$retcode" != "0" ]; then
116 _err
"Authentication failed."
119 if _contains
"$response" "token"; then
120 _token
="$(echo "$response" | _normalizeJson | sed -n 's/^{"token
":"\
(.
*\
)"}/\1/p')"
121 _debug _token
"$_token"
130 # retrieve the transip creds
131 TRANSIP_Username
="${TRANSIP_Username:-$(_readaccountconf_mutable TRANSIP_Username)}"
132 TRANSIP_Key_File
="${TRANSIP_Key_File:-$(_readaccountconf_mutable TRANSIP_Key_File)}"
133 # check their vals for null
134 if [ -z "$TRANSIP_Username" ] ||
[ -z "$TRANSIP_Key_File" ]; then
137 _err
"You didn't specify a TransIP username and api key file location"
138 _err
"Please set those values and try again."
141 # save the username and api key to the account conf file.
142 _saveaccountconf_mutable TRANSIP_Username
"$TRANSIP_Username"
143 _saveaccountconf_mutable TRANSIP_Key_File
"$TRANSIP_Key_File"
145 # download key file if it's an URL
146 if _startswith
"$TRANSIP_Key_File" "http"; then
147 _debug
"download transip key file"
148 TRANSIP_Key_URL
=$TRANSIP_Key_File
149 TRANSIP_Key_File
="$(_mktemp)"
150 chmod 600 "$TRANSIP_Key_File"
151 if ! _get
"$TRANSIP_Key_URL" >"$TRANSIP_Key_File"; then
152 _err
"Error getting key file from : $TRANSIP_Key_URL"
157 if [ -f "$TRANSIP_Key_File" ]; then
158 if ! grep "BEGIN PRIVATE KEY" "$TRANSIP_Key_File" >/dev
/null
2>&1; then
159 _err
"Key file doesn't seem to be a valid key: ${TRANSIP_Key_File}"
163 _err
"Can't read private key file: ${TRANSIP_Key_File}"
167 if [ -z "$_token" ]; then
168 if ! _transip_get_token
; then
169 _err
"Can not get token."
174 if [ -n "${TRANSIP_Key_URL}" ]; then
175 _debug
"delete transip key file"
176 rm "${TRANSIP_Key_File}"
177 TRANSIP_Key_File
=$TRANSIP_Key_URL
180 _get_root
"$fulldomain" ||
return 1