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 #See https://developer.leaseweb.com for more information.
7 ######## Public functions #####################
9 LSW_API
="https://api.leaseweb.com/hosting/v2/domains"
11 #Usage: dns_leaseweb_add _acme-challenge.www.domain.com
16 LSW_Key
="${LSW_Key:-$(_readaccountconf_mutable LSW_Key)}"
17 if [ -z "$LSW_Key" ]; then
19 _err
"You don't specify Leaseweb api key yet."
20 _err
"Please create your key and try again."
24 #save the api key to the account conf file.
25 _saveaccountconf_mutable LSW_Key
"$LSW_Key"
27 _debug
"First detect the root zone"
28 if ! _get_root
"$fulldomain"; then
33 _debug _root_domain
"$_domain"
34 _debug _domain
"$fulldomain"
36 if _lsw_api
"POST" "$_domain" "$fulldomain" "$txtvalue"; then
37 if [ "$_code" = "201" ]; then
41 _err
"Add txt record error, invalid code. Code: $_code"
45 _err
"Add txt record error."
50 #Usage: fulldomain txtvalue
51 #Remove the txt record after validation.
56 LSW_Key
="${LSW_Key:-$(_readaccountconf_mutable LSW_Key)}"
58 _debug
"First detect the root zone"
59 if ! _get_root
"$fulldomain"; then
64 _debug _root_domain
"$_domain"
65 _debug _domain
"$fulldomain"
67 if _lsw_api
"DELETE" "$_domain" "$fulldomain" "$txtvalue"; then
68 if [ "$_code" = "204" ]; then
72 _err
"Delete txt record error."
76 _err
"Delete txt record error."
81 #################### Private functions below ##################################
82 # _acme-challenge.www.domain.com
87 i
="$(echo "$rdomain" | tr '.' ' ' | wc -w)"
91 h
=$
(printf "%s" "$rdomain" | cut
-d .
-f "$i"-100)
94 return 1 #not valid domain
97 #Check API if domain exists
98 if _lsw_api
"GET" "$h"; then
99 if [ "$_code" = "200" ]; then
105 if [ "$i" -lt 2 ]; then
106 return 1 #not found, no need to check _acme-challenge.sub.domain in leaseweb api.
119 # Construct the HTTP Authorization header
120 export _H2
="Content-Type: application/json"
121 export _H1
="X-Lsw-Auth: ${LSW_Key}"
123 if [ "$cmd" = "GET" ]; then
124 response
="$(_get "$LSW_API/$d")"
125 _code
="$(grep "^HTTP
" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r
\\n
")"
126 _debug
"http response code $_code"
127 _debug response
"$response"
131 if [ "$cmd" = "POST" ]; then
132 data
="{\"name\": \"$fd.\",\"type\": \"TXT\",\"content\": [\"$tvalue\"],\"ttl\": 60}"
133 response
="$(_post "$data" "$LSW_API/$d/resourceRecordSets
" "$data" "POST
")"
134 _code
="$(grep "^HTTP
" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r
\\n
")"
135 _debug
"http response code $_code"
136 _debug response
"$response"
140 if [ "$cmd" = "DELETE" ]; then
141 response
="$(_post "" "$LSW_API/$d/resourceRecordSets
/$fd/TXT
" "" "DELETE
")"
142 _code
="$(grep "^HTTP
" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r
\\n
")"
143 _debug
"http response code $_code"
144 _debug response
"$response"