Skip to content

Commit 2b7377d

Browse files
author
LaoDC
committed
Removed PATCH logic of updating acme records as this doesn't work for wildcard DNS.
Revised rm() function to do explicit record matching.
1 parent 24782c4 commit 2b7377d

1 file changed

Lines changed: 17 additions & 55 deletions

File tree

dnsapi/dns_laodc.sh

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,14 @@ dns_laodc_add() {
5050
_debug _sub_domain "$_sub_domain"
5151
_debug _domain_hash "$domain_hash"
5252

53-
if _laodc_api "GET" "$domain_hash" "$_sub_domain"; then
54-
if [ "$_code" = "200" ]; then
55-
subdomain_hash=$(echo "$response" | _egrep_o "\"hash\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \")
56-
_debug _sub_domain_hash "$subdomain_hash"
57-
58-
_info "Updating acme record"
59-
if _laodc_api "PATCH" "$domain_hash" "$subdomain_hash" "$txtvalue"; then
60-
if [ "$_code" = "201" ]; then
61-
_info "Updated, OK"
62-
return 0
63-
else
64-
_err "Update TXT record error, invalid code. Code: $_code"
65-
return 1
66-
fi
67-
fi
53+
_info "Adding acme record"
54+
if _laodc_api "POST" "$domain_hash" "$_sub_domain" "$txtvalue"; then
55+
if [ "$_code" = "201" ]; then
56+
_info "Added, OK"
57+
return 0
6858
else
69-
_info "Adding acme record"
70-
if _laodc_api "POST" "$domain_hash" "$_sub_domain" "$txtvalue"; then
71-
if [ "$_code" = "201" ]; then
72-
_info "Added, OK"
73-
return 0
74-
else
75-
_err "Add TXT record error, invalid code. Code: $_code"
76-
return 1
77-
fi
78-
fi
59+
_err "Add TXT record error, invalid code. Code: $_code"
60+
return 1
7961
fi
8062
fi
8163

@@ -100,21 +82,14 @@ dns_laodc_rm() {
10082
_debug _sub_domain "$_sub_domain"
10183
_debug _domain_hash "$domain_hash"
10284

103-
if _laodc_api "GET" "$domain_hash" "$_sub_domain"; then
104-
if [ "$_code" = "200" ]; then
105-
subdomain_hash=$(echo "$response" | _egrep_o "\"hash\":\"[^\"]*\"" | _head_n 1 | cut -d : -f 2 | tr -d \")
106-
_debug _sub_domain_hash "$subdomain_hash"
107-
108-
_info "Deleting acme record"
109-
if _laodc_api "DELETE" "$domain_hash" "$subdomain_hash" ""; then
110-
if [ "$_code" = "204" ]; then
111-
_info "Deleted, OK"
112-
return 0
113-
else
114-
_err "Delete TXT record error, invalid code. Code: $_code"
115-
return 1
116-
fi
117-
fi
85+
_info "Deleting acme record"
86+
if _laodc_api "DELETE" "$domain_hash" "$_sub_domain" "$txtvalue"; then
87+
if [ "$_code" = "204" ]; then
88+
_info "Deleted, OK"
89+
return 0
90+
else
91+
_err "Delete TXT record error, invalid code. Code: $_code"
92+
return 1
11893
fi
11994
fi
12095

@@ -195,27 +170,14 @@ _laodc_api() {
195170
response="$(echo "$response" | _json_decode | _normalizeJson)"
196171
fi
197172

198-
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
199-
_debug "http response code $_code"
200-
_debug response "$response"
201-
return 0
202-
;;
203-
PATCH)
204-
data="{ \"type\": \"TXT\", \"value\": \"$value\", \"ttl\": \"60\" }"
205-
response="$(_post "$data" "$LAODC_API_ENDPOINT/$domain/$subdomain" "" "PATCH" "application/json")"
206-
responseHeaders="$(cat "$HTTP_HEADER")"
207-
208-
if echo "$responseHeaders" | grep -i "Content-Type: *application/json" >/dev/null 2>&1; then
209-
response="$(echo "$response" | _json_decode | _normalizeJson)"
210-
fi
211-
212173
_code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
213174
_debug "http response code $_code"
214175
_debug response "$response"
215176
return 0
216177
;;
217178
DELETE)
218-
response="$(_post "" "$LAODC_API_ENDPOINT/$domain/$subdomain" "" "DELETE" "application/json")"
179+
data="{ \"type\": \"TXT\", \"value\": \"$value\" }"
180+
response="$(_post "$data" "$LAODC_API_ENDPOINT/$domain/$subdomain" "" "DELETE" "application/json")"
219181
responseHeaders="$(cat "$HTTP_HEADER")"
220182

221183
if echo "$responseHeaders" | grep -i "Content-Type: *application/json" >/dev/null 2>&1; then

0 commit comments

Comments
 (0)