3 #Author: Rolph Haspers <r.haspers@global.leaseweb.com>
4 #Utilize leaseweb.com API to finish dns-01 verifications.
5 #Requires a Leaseweb API Key (export LSW_Key="Your Key")
6 ######## Public functions #####################
8 LSW_API
="https://api.leaseweb.com/hosting/v2/domains/"
10 #Usage: dns_leaseweb_add _acme-challenge.www.domain.com
15 LSW_Key
="${LSW_Key:-$(_readaccountconf_mutable LSW_Key)}"
16 if [ -z "$LSW_Key" ]; then
18 _err
"You don't specify Leaseweb api key yet."
19 _err
"Please create your key and try again."
23 #save the api key to the account conf file.
24 _saveaccountconf_mutable LSW_Key
"$LSW_Key"
26 _debug
"First detect the root zone"
27 if ! _get_root
"$fulldomain"; then
32 _debug _root_domain
"$_domain"
33 _debug _domain
"$fulldomain"
35 if _lsw_api
"POST" "$_domain" "$fulldomain" "$txtvalue"; then
36 if [ "$_code" = "201" ]; then
40 _err
"Add txt record error, invalid code. Code: $_code"
44 _err
"Add txt record error."
49 #Usage: fulldomain txtvalue
50 #Remove the txt record after validation.
55 LSW_Key
="${LSW_Key:-$(_readaccountconf_mutable LSW_Key)}"
57 _debug
"First detect the root zone"
58 if ! _get_root
"$fulldomain"; then
63 _debug _root_domain
"$_domain"
64 _debug _domain
"$fulldomain"
66 if _lsw_api
"DELETE" "$_domain" "$fulldomain" "$txtvalue"; then
67 if [ "$_code" = "204" ]; then
71 _err
"Delete txt record error."
75 _err
"Delete txt record error."
80 #################### Private functions below ##################################
81 # _acme-challenge.www.domain.com
86 i
="$(echo "$fulldomain" | tr '.' ' ' | wc -w)"
90 h
=$
(printf "%s" "$domain" | cut
-d .
-f "$i"-100)
97 _debug
"$domain not found"
107 # Construct the HTTP Authorization header
108 export _H2
="Content-Type: application/json"
109 export _H1
="X-Lsw-Auth: ${LSW_Key}"
111 if [ "$cmd" = "POST" ]; then
112 data
="{\"name\": \"$fulldomain.\",\"type\": \"TXT\",\"content\": [\"$txtvalue\"],\"ttl\": 60}"
113 response
="$(_post "$data" "$LSW_API/$domain/resourceRecordSets
" "$data" "POST
")"
114 _code
="$(grep "^HTTP
" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r
\\n
")"
115 _debug
"http response code $_code"
116 _debug response
"$response"
120 if [ "$cmd" = "DELETE" ]; then
121 response
="$(_post "" "$LSW_API/$domain/resourceRecordSets
/$fulldomain/TXT
" "" "DELETE
")"
122 _code
="$(grep "^HTTP
" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r
\\n
")"
123 _debug
"http response code $_code"
124 _debug response
"$response"