acme.sh/dnsapi/dns_lexicon.sh

114 lines
3.5 KiB
Bash
Raw Permalink Normal View History

2016-05-08 10:20:56 +00:00
#!/usr/bin/env sh
# dns api wrapper of lexicon for acme.sh
# https://github.com/AnalogJ/lexicon
2016-05-08 10:20:56 +00:00
lexicon_cmd="lexicon"
2020-01-30 04:06:39 +00:00
wiki="https://github.com/acmesh-official/acme.sh/wiki/How-to-use-lexicon-dns-api"
2016-05-08 10:20:56 +00:00
2018-07-24 20:14:39 +00:00
_lexicon_init() {
2016-11-11 15:30:14 +00:00
if ! _exists "$lexicon_cmd"; then
2016-05-08 10:20:56 +00:00
_err "Please install $lexicon_cmd first: $wiki"
return 1
fi
2016-11-09 11:30:39 +00:00
2018-07-24 20:14:39 +00:00
PROVIDER="${PROVIDER:-$(_readdomainconf PROVIDER)}"
2016-11-09 11:30:39 +00:00
if [ -z "$PROVIDER" ]; then
2016-11-12 03:13:40 +00:00
PROVIDER=""
2016-05-08 10:20:56 +00:00
_err "Please define env PROVIDER first: $wiki"
return 1
fi
_savedomainconf PROVIDER "$PROVIDER"
export PROVIDER
# e.g. busybox-ash does not know [:upper:]
# shellcheck disable=SC2018,SC2019
Lx_name=$(echo LEXICON_"${PROVIDER}"_USERNAME | tr 'a-z' 'A-Z')
2018-07-25 08:40:57 +00:00
eval "$Lx_name=\${$Lx_name:-$(_readaccountconf_mutable "$Lx_name")}"
2016-11-12 03:45:30 +00:00
Lx_name_v=$(eval echo \$"$Lx_name")
2017-02-19 05:24:00 +00:00
_secure_debug "$Lx_name" "$Lx_name_v"
2016-11-09 11:30:39 +00:00
if [ "$Lx_name_v" ]; then
2018-07-24 20:14:39 +00:00
_saveaccountconf_mutable "$Lx_name" "$Lx_name_v"
2016-11-12 03:40:30 +00:00
eval export "$Lx_name"
2016-05-08 10:20:56 +00:00
fi
2016-11-09 11:30:39 +00:00
# shellcheck disable=SC2018,SC2019
Lx_token=$(echo LEXICON_"${PROVIDER}"_TOKEN | tr 'a-z' 'A-Z')
2018-07-25 08:40:57 +00:00
eval "$Lx_token=\${$Lx_token:-$(_readaccountconf_mutable "$Lx_token")}"
2016-11-12 03:45:30 +00:00
Lx_token_v=$(eval echo \$"$Lx_token")
2017-02-19 05:24:00 +00:00
_secure_debug "$Lx_token" "$Lx_token_v"
2016-11-09 11:30:39 +00:00
if [ "$Lx_token_v" ]; then
2018-07-24 20:14:39 +00:00
_saveaccountconf_mutable "$Lx_token" "$Lx_token_v"
2016-11-12 03:40:30 +00:00
eval export "$Lx_token"
2016-05-08 10:20:56 +00:00
fi
2016-11-09 11:30:39 +00:00
# shellcheck disable=SC2018,SC2019
Lx_password=$(echo LEXICON_"${PROVIDER}"_PASSWORD | tr 'a-z' 'A-Z')
2018-07-25 08:40:57 +00:00
eval "$Lx_password=\${$Lx_password:-$(_readaccountconf_mutable "$Lx_password")}"
2016-11-12 03:45:30 +00:00
Lx_password_v=$(eval echo \$"$Lx_password")
2017-02-19 05:24:00 +00:00
_secure_debug "$Lx_password" "$Lx_password_v"
2016-11-09 11:30:39 +00:00
if [ "$Lx_password_v" ]; then
2018-07-24 20:14:39 +00:00
_saveaccountconf_mutable "$Lx_password" "$Lx_password_v"
2016-11-12 03:40:30 +00:00
eval export "$Lx_password"
2016-05-08 10:20:56 +00:00
fi
2016-11-09 11:30:39 +00:00
# shellcheck disable=SC2018,SC2019
Lx_domaintoken=$(echo LEXICON_"${PROVIDER}"_DOMAINTOKEN | tr 'a-z' 'A-Z')
2018-07-25 08:40:57 +00:00
eval "$Lx_domaintoken=\${$Lx_domaintoken:-$(_readaccountconf_mutable "$Lx_domaintoken")}"
2016-11-12 03:45:30 +00:00
Lx_domaintoken_v=$(eval echo \$"$Lx_domaintoken")
2017-02-19 05:24:00 +00:00
_secure_debug "$Lx_domaintoken" "$Lx_domaintoken_v"
2016-11-09 11:30:39 +00:00
if [ "$Lx_domaintoken_v" ]; then
2018-07-24 20:14:39 +00:00
_saveaccountconf_mutable "$Lx_domaintoken" "$Lx_domaintoken_v"
2016-11-12 03:40:30 +00:00
eval export "$Lx_domaintoken"
2016-05-08 10:20:56 +00:00
fi
# shellcheck disable=SC2018,SC2019
Lx_api_key=$(echo LEXICON_"${PROVIDER}"_API_KEY | tr 'a-z' 'A-Z')
eval "$Lx_api_key=\${$Lx_api_key:-$(_readaccountconf_mutable "$Lx_api_key")}"
Lx_api_key_v=$(eval echo \$"$Lx_api_key")
_secure_debug "$Lx_api_key" "$Lx_api_key_v"
if [ "$Lx_api_key_v" ]; then
_saveaccountconf_mutable "$Lx_api_key" "$Lx_api_key_v"
eval export "$Lx_api_key"
fi
}
######## Public functions #####################
#Usage: dns_lexicon_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_lexicon_add() {
fulldomain=$1
txtvalue=$2
2018-07-24 20:14:39 +00:00
if ! _lexicon_init; then
return 1
fi
domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
2016-05-08 10:20:56 +00:00
_secure_debug LEXICON_OPTS "$LEXICON_OPTS"
_savedomainconf LEXICON_OPTS "$LEXICON_OPTS"
# shellcheck disable=SC2086
2020-07-07 12:52:00 +00:00
$lexicon_cmd "$PROVIDER" $LEXICON_OPTS create "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" --output QUIET
2016-05-08 10:20:56 +00:00
}
#Usage: dns_lexicon_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
dns_lexicon_rm() {
fulldomain=$1
txtvalue=$2
2018-07-24 20:14:39 +00:00
if ! _lexicon_init; then
return 1
fi
domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
# shellcheck disable=SC2086
2020-06-09 07:57:36 +00:00
$lexicon_cmd "$PROVIDER" $LEXICON_OPTS delete "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" --output QUIET
}