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+
79dns_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
7182dns_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