Skip to content

Commit 025bebb

Browse files
authored
Merge pull request #5 from AlvinSchiller/dev
domain lookup for DNS_MAP changed.
2 parents c4df809 + d4cf03c commit 025bebb

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

dnsapi/dns_selfhost.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
# Report Bugs here: https://github.com/Marvo2011/acme.sh/issues/1
55
# Last Edit: 17.02.2022
66

7+
DNS_CHALLENGE_PREFIX_ESCAPED="_acme-challenge\."
8+
79
dns_selfhost_add() {
8-
domain=$1
10+
fulldomain=$1
911
txt=$2
1012
_info "Calling acme-dns on selfhost"
11-
_debug fulldomain "$domain"
13+
_debug fulldomain "$fulldomain"
1214
_debug txtvalue "$txt"
1315

1416
SELFHOSTDNS_UPDATE_URL="https://selfhost.de/cgi-bin/api.pl"
@@ -31,7 +33,16 @@ dns_selfhost_add() {
3133
SELFHOSTDNS_LAST_SLOT=1
3234
fi
3335

34-
rid=$(echo "$SELFHOSTDNS_MAP" | grep -Eoi "$domain:(\d+)" | tr -d "$domain:")
36+
# cut DNS_CHALLENGE_PREFIX_ESCAPED from fulldomain if present at the beginning of the string
37+
lookupdomain=$(echo "$fulldomain" | sed "s/^$DNS_CHALLENGE_PREFIX_ESCAPED//")
38+
_debug lookupdomain "$lookupdomain"
39+
40+
# get the RID for lookupdomain or fulldomain from SELFHOSTDNS_MAP
41+
# only match full domains (at the beginning of the string or with a leading whitespace),
42+
# e.g. don't match mytest.example.com or sub.test.example.com for test.example.com
43+
# replace the whole string with the RID (matching group 3) for assignment
44+
# if the domain is defined multiple times only the last occurance will be matched
45+
rid=$(echo "$SELFHOSTDNS_MAP" | sed -E "s/(^|^.*[[:space:]])($lookupdomain:|$fulldomain:)([0-9][0-9]*)(.*)/\3/")
3546

3647
if test -z "$rid"; then
3748
if [ $SELFHOSTDNS_LAST_SLOT = "2" ]; then
@@ -69,9 +80,9 @@ dns_selfhost_add() {
6980
}
7081

7182
dns_selfhost_rm() {
72-
domain=$1
83+
fulldomain=$1
7384
txt=$2
74-
_debug fulldomain "$domain"
85+
_debug fulldomain "$fulldomain"
7586
_debug txtvalue "$txt"
7687
_info "Creating and removing of records is not supported by selfhost API, will not delete anything."
7788
}

0 commit comments

Comments
 (0)