3 # Author: Marvin Edeler
4 # Report Bugs here: https://github.com/Marvo2011/acme.sh/issues/1
5 # Last Edit: 17.02.2022
10 _info
"Calling acme-dns on selfhost"
11 _debug fulldomain
"$fulldomain"
12 _debug txtvalue
"$txt"
14 SELFHOSTDNS_UPDATE_URL
="https://selfhost.de/cgi-bin/api.pl"
16 # Get values, but don't save until we successfully validated
17 SELFHOSTDNS_USERNAME
="${SELFHOSTDNS_USERNAME:-$(_readaccountconf_mutable SELFHOSTDNS_USERNAME)}"
18 SELFHOSTDNS_PASSWORD
="${SELFHOSTDNS_PASSWORD:-$(_readaccountconf_mutable SELFHOSTDNS_PASSWORD)}"
19 # These values are domain dependent, so read them from there
20 SELFHOSTDNS_MAP
="${SELFHOSTDNS_MAP:-$(_readdomainconf SELFHOSTDNS_MAP)}"
21 # Selfhost api can't dynamically add TXT record,
22 # so we have to store the last used RID of the domain to support a second RID for wildcard domains
23 # (format: 'fulldomainA:lastRid fulldomainB:lastRid ...')
24 SELFHOSTDNS_MAP_LAST_USED_INTERNAL
=$
(_readdomainconf SELFHOSTDNS_MAP_LAST_USED_INTERNAL
)
26 if [ -z "${SELFHOSTDNS_USERNAME:-}" ] ||
[ -z "${SELFHOSTDNS_PASSWORD:-}" ]; then
27 _err
"SELFHOSTDNS_USERNAME and SELFHOSTDNS_PASSWORD must be set"
31 # get the domain entry from SELFHOSTDNS_MAP
32 # only match full domains (at the beginning of the string or with a leading whitespace),
33 # e.g. don't match mytest.example.com or sub.test.example.com for test.example.com
34 # if the domain is defined multiple times only the last occurance will be matched
35 mapEntry
=$
(echo "$SELFHOSTDNS_MAP" |
sed -n -E "s/(^|^.*[[:space:]])($fulldomain)(:[[:digit:]]+)([:]?[[:digit:]]*)(.*)/\2\3\4/p")
36 _debug2 mapEntry
"$mapEntry"
37 if test -z "$mapEntry"; then
38 _err
"SELFHOSTDNS_MAP must contain the fulldomain incl. prefix and at least one RID"
42 # get the RIDs from the map entry
43 rid1
=$
(echo "$mapEntry" | cut
-d: -f2)
44 rid2
=$
(echo "$mapEntry" | cut
-d: -f3)
46 # read last used rid domain
47 lastUsedRidForDomainEntry
=$
(echo "$SELFHOSTDNS_MAP_LAST_USED_INTERNAL" |
sed -n -E "s/(^|^.*[[:space:]])($fulldomain:[[:digit:]]+)(.*)/\2/p")
48 _debug2 lastUsedRidForDomainEntry
"$lastUsedRidForDomainEntry"
49 lastUsedRidForDomain
=$
(echo "$lastUsedRidForDomainEntry" | cut
-d: -f2)
52 if [ "$lastUsedRidForDomain" = "$rid" ] && ! test -z "$rid2"; then
56 _info
"Trying to add $txt on selfhost for rid: $rid"
58 data
="?username=$SELFHOSTDNS_USERNAME&password=$SELFHOSTDNS_PASSWORD&rid=$rid&content=$txt"
59 response
="$(_get "$SELFHOSTDNS_UPDATE_URL$data")"
61 if ! echo "$response" |
grep "200 OK" >/dev
/null
; then
62 _err
"Invalid response of acme-dns for selfhost"
66 # write last used rid domain
67 newLastUsedRidForDomainEntry
="$fulldomain:$rid"
68 if ! test -z "$lastUsedRidForDomainEntry"; then
69 # replace last used rid entry for domain
70 SELFHOSTDNS_MAP_LAST_USED_INTERNAL
=$
(echo "$SELFHOSTDNS_MAP_LAST_USED_INTERNAL" |
sed -n -E "s/$lastUsedRidForDomainEntry/$newLastUsedRidForDomainEntry/p")
72 # add last used rid entry for domain
73 if test -z "$SELFHOSTDNS_MAP_LAST_USED_INTERNAL"; then
74 SELFHOSTDNS_MAP_LAST_USED_INTERNAL
="$newLastUsedRidForDomainEntry"
76 SELFHOSTDNS_MAP_LAST_USED_INTERNAL
="$SELFHOSTDNS_MAP_LAST_USED_INTERNAL $newLastUsedRidForDomainEntry"
80 # Now that we know the values are good, save them
81 _saveaccountconf_mutable SELFHOSTDNS_USERNAME
"$SELFHOSTDNS_USERNAME"
82 _saveaccountconf_mutable SELFHOSTDNS_PASSWORD
"$SELFHOSTDNS_PASSWORD"
83 # These values are domain dependent, so store them there
84 _savedomainconf SELFHOSTDNS_MAP
"$SELFHOSTDNS_MAP"
85 _savedomainconf SELFHOSTDNS_MAP_LAST_USED_INTERNAL
"$SELFHOSTDNS_MAP_LAST_USED_INTERNAL"
91 _debug fulldomain
"$fulldomain"
92 _debug txtvalue
"$txt"
93 _info
"Creating and removing of records is not supported by selfhost API, will not delete anything."