acme.sh/dnsapi/dns_lexicon.sh

114 lines
3.5 KiB
Bash
Raw Normal View History

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