2022-01-05 14:03:32 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
#
|
|
|
|
# Author: Marvin Edeler
|
|
|
|
# Report Bugs here: https://github.com/Marvo2011/acme.sh/issues/1
|
2022-02-17 18:02:35 +00:00
|
|
|
# Last Edit: 17.02.2022
|
2022-01-05 14:03:32 +00:00
|
|
|
|
2022-05-10 05:09:31 +00:00
|
|
|
DNS_CHALLENGE_PREFIX_ESCAPED="_acme-challenge\."
|
|
|
|
|
2022-01-05 14:03:32 +00:00
|
|
|
dns_selfhost_add() {
|
2022-05-10 05:09:31 +00:00
|
|
|
fulldomain=$1
|
2022-01-05 14:03:32 +00:00
|
|
|
txt=$2
|
|
|
|
_info "Calling acme-dns on selfhost"
|
2022-05-10 05:09:31 +00:00
|
|
|
_debug fulldomain "$fulldomain"
|
2022-01-05 14:03:32 +00:00
|
|
|
_debug txtvalue "$txt"
|
|
|
|
|
|
|
|
SELFHOSTDNS_UPDATE_URL="https://selfhost.de/cgi-bin/api.pl"
|
2022-04-29 20:26:36 +00:00
|
|
|
|
|
|
|
# Get values, but don't save until we successfully validated
|
2022-01-05 14:03:32 +00:00
|
|
|
SELFHOSTDNS_USERNAME="${SELFHOSTDNS_USERNAME:-$(_readaccountconf_mutable SELFHOSTDNS_USERNAME)}"
|
|
|
|
SELFHOSTDNS_PASSWORD="${SELFHOSTDNS_PASSWORD:-$(_readaccountconf_mutable SELFHOSTDNS_PASSWORD)}"
|
2022-04-29 20:26:36 +00:00
|
|
|
# These values are domain dependent, so read them from there
|
|
|
|
_getdeployconf SELFHOSTDNS_MAP
|
|
|
|
_getdeployconf SELFHOSTDNS_RID
|
|
|
|
_getdeployconf SELFHOSTDNS_RID2
|
|
|
|
_getdeployconf SELFHOSTDNS_LAST_SLOT
|
2022-01-05 14:03:32 +00:00
|
|
|
|
2022-04-29 20:23:39 +00:00
|
|
|
if [ -z "${SELFHOSTDNS_USERNAME:-}" ] || [ -z "${SELFHOSTDNS_PASSWORD:-}" ]; then
|
|
|
|
_err "SELFHOSTDNS_USERNAME and SELFHOSTDNS_PASSWORD must be set"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2022-01-05 14:03:32 +00:00
|
|
|
if test -z "$SELFHOSTDNS_LAST_SLOT"; then
|
|
|
|
SELFHOSTDNS_LAST_SLOT=1
|
|
|
|
fi
|
|
|
|
|
2022-05-10 05:09:31 +00:00
|
|
|
# cut DNS_CHALLENGE_PREFIX_ESCAPED from fulldomain if present at the beginning of the string
|
|
|
|
lookupdomain=$(echo "$fulldomain" | sed "s/^$DNS_CHALLENGE_PREFIX_ESCAPED//")
|
|
|
|
_debug lookupdomain "$lookupdomain"
|
|
|
|
|
|
|
|
# get the RID for lookupdomain or fulldomain from SELFHOSTDNS_MAP
|
|
|
|
# only match full domains (at the beginning of the string or with a leading whitespace),
|
|
|
|
# e.g. don't match mytest.example.com or sub.test.example.com for test.example.com
|
|
|
|
# replace the whole string with the RID (matching group 3) for assignment
|
|
|
|
# if the domain is defined multiple times only the last occurance will be matched
|
2022-05-18 09:48:48 +00:00
|
|
|
rid=$(echo "$SELFHOSTDNS_MAP" | sed -E "s/(^|^.*[[:space:]])($lookupdomain:|$fulldomain:)([0-9][0-9]*)(.*)/\3/")
|
2022-02-17 18:30:56 +00:00
|
|
|
|
2022-02-17 18:02:35 +00:00
|
|
|
if test -z "$rid"; then
|
|
|
|
if [ $SELFHOSTDNS_LAST_SLOT = "2" ]; then
|
|
|
|
rid=$SELFHOSTDNS_RID
|
|
|
|
SELFHOSTDNS_LAST_SLOT=1
|
|
|
|
else
|
|
|
|
rid=$SELFHOSTDNS_RID2
|
|
|
|
SELFHOSTDNS_LAST_SLOT=2
|
|
|
|
fi
|
2022-01-05 14:03:32 +00:00
|
|
|
fi
|
|
|
|
|
2022-04-29 20:23:39 +00:00
|
|
|
if test -z "$rid"; then
|
|
|
|
_err "SELFHOSTDNS_RID and SELFHOSTDNS_RID2, or SELFHOSTDNS_MAP must be set"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2022-01-05 14:03:32 +00:00
|
|
|
_info "Trying to add $txt on selfhost for rid: $rid"
|
|
|
|
|
|
|
|
data="?username=$SELFHOSTDNS_USERNAME&password=$SELFHOSTDNS_PASSWORD&rid=$rid&content=$txt"
|
|
|
|
response="$(_get "$SELFHOSTDNS_UPDATE_URL$data")"
|
|
|
|
|
|
|
|
if ! echo "$response" | grep "200 OK" >/dev/null; then
|
|
|
|
_err "Invalid response of acme-dns for selfhost"
|
|
|
|
return 1
|
|
|
|
fi
|
2022-04-29 20:26:36 +00:00
|
|
|
|
|
|
|
# Now that we know the values are good, save them
|
|
|
|
_saveaccountconf_mutable SELFHOSTDNS_USERNAME "$SELFHOSTDNS_USERNAME"
|
|
|
|
_saveaccountconf_mutable SELFHOSTDNS_PASSWORD "$SELFHOSTDNS_PASSWORD"
|
|
|
|
# These values are domain dependent, so store them there
|
|
|
|
_savedeployconf SELFHOSTDNS_MAP "$SELFHOSTDNS_MAP"
|
|
|
|
_savedeployconf SELFHOSTDNS_RID "$SELFHOSTDNS_RID"
|
|
|
|
_savedeployconf SELFHOSTDNS_RID2 "$SELFHOSTDNS_RID2"
|
|
|
|
_savedeployconf SELFHOSTDNS_LAST_SLOT "$SELFHOSTDNS_LAST_SLOT"
|
2022-01-05 14:03:32 +00:00
|
|
|
}
|
|
|
|
|
2022-03-28 11:03:02 +00:00
|
|
|
dns_selfhost_rm() {
|
2022-05-10 05:09:31 +00:00
|
|
|
fulldomain=$1
|
2022-01-05 14:03:32 +00:00
|
|
|
txt=$2
|
2022-05-10 05:09:31 +00:00
|
|
|
_debug fulldomain "$fulldomain"
|
2022-01-05 14:03:32 +00:00
|
|
|
_debug txtvalue "$txt"
|
2022-03-28 11:03:02 +00:00
|
|
|
_info "Creating and removing of records is not supported by selfhost API, will not delete anything."
|
2022-01-05 14:03:32 +00:00
|
|
|
}
|