]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_lexicon.sh
Merge pull request #4755 from glocknerc/master-1
[mirror_acme.sh.git] / dnsapi / dns_lexicon.sh
1 #!/usr/bin/env sh
2
3 # dns api wrapper of lexicon for acme.sh
4
5 # https://github.com/AnalogJ/lexicon
6 lexicon_cmd="lexicon"
7
8 wiki="https://github.com/acmesh-official/acme.sh/wiki/How-to-use-lexicon-dns-api"
9
10 _lexicon_init() {
11 if ! _exists "$lexicon_cmd"; then
12 _err "Please install $lexicon_cmd first: $wiki"
13 return 1
14 fi
15
16 PROVIDER="${PROVIDER:-$(_readdomainconf PROVIDER)}"
17 if [ -z "$PROVIDER" ]; then
18 PROVIDER=""
19 _err "Please define env PROVIDER first: $wiki"
20 return 1
21 fi
22
23 _savedomainconf PROVIDER "$PROVIDER"
24 export PROVIDER
25
26 # e.g. busybox-ash does not know [:upper:]
27 # shellcheck disable=SC2018,SC2019
28 Lx_name=$(echo LEXICON_"${PROVIDER}"_USERNAME | tr 'a-z' 'A-Z')
29 eval "$Lx_name=\${$Lx_name:-$(_readaccountconf_mutable "$Lx_name")}"
30 Lx_name_v=$(eval echo \$"$Lx_name")
31 _secure_debug "$Lx_name" "$Lx_name_v"
32 if [ "$Lx_name_v" ]; then
33 _saveaccountconf_mutable "$Lx_name" "$Lx_name_v"
34 eval export "$Lx_name"
35 fi
36
37 # shellcheck disable=SC2018,SC2019
38 Lx_token=$(echo LEXICON_"${PROVIDER}"_TOKEN | tr 'a-z' 'A-Z')
39 eval "$Lx_token=\${$Lx_token:-$(_readaccountconf_mutable "$Lx_token")}"
40 Lx_token_v=$(eval echo \$"$Lx_token")
41 _secure_debug "$Lx_token" "$Lx_token_v"
42 if [ "$Lx_token_v" ]; then
43 _saveaccountconf_mutable "$Lx_token" "$Lx_token_v"
44 eval export "$Lx_token"
45 fi
46
47 # shellcheck disable=SC2018,SC2019
48 Lx_password=$(echo LEXICON_"${PROVIDER}"_PASSWORD | tr 'a-z' 'A-Z')
49 eval "$Lx_password=\${$Lx_password:-$(_readaccountconf_mutable "$Lx_password")}"
50 Lx_password_v=$(eval echo \$"$Lx_password")
51 _secure_debug "$Lx_password" "$Lx_password_v"
52 if [ "$Lx_password_v" ]; then
53 _saveaccountconf_mutable "$Lx_password" "$Lx_password_v"
54 eval export "$Lx_password"
55 fi
56
57 # shellcheck disable=SC2018,SC2019
58 Lx_domaintoken=$(echo LEXICON_"${PROVIDER}"_DOMAINTOKEN | tr 'a-z' 'A-Z')
59 eval "$Lx_domaintoken=\${$Lx_domaintoken:-$(_readaccountconf_mutable "$Lx_domaintoken")}"
60 Lx_domaintoken_v=$(eval echo \$"$Lx_domaintoken")
61 _secure_debug "$Lx_domaintoken" "$Lx_domaintoken_v"
62 if [ "$Lx_domaintoken_v" ]; then
63 _saveaccountconf_mutable "$Lx_domaintoken" "$Lx_domaintoken_v"
64 eval export "$Lx_domaintoken"
65 fi
66
67 # shellcheck disable=SC2018,SC2019
68 Lx_api_key=$(echo LEXICON_"${PROVIDER}"_API_KEY | tr 'a-z' 'A-Z')
69 eval "$Lx_api_key=\${$Lx_api_key:-$(_readaccountconf_mutable "$Lx_api_key")}"
70 Lx_api_key_v=$(eval echo \$"$Lx_api_key")
71 _secure_debug "$Lx_api_key" "$Lx_api_key_v"
72 if [ "$Lx_api_key_v" ]; then
73 _saveaccountconf_mutable "$Lx_api_key" "$Lx_api_key_v"
74 eval export "$Lx_api_key"
75 fi
76 }
77
78 ######## Public functions #####################
79
80 #Usage: dns_lexicon_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
81 dns_lexicon_add() {
82 fulldomain=$1
83 txtvalue=$2
84
85 if ! _lexicon_init; then
86 return 1
87 fi
88
89 domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
90
91 _secure_debug LEXICON_OPTS "$LEXICON_OPTS"
92 _savedomainconf LEXICON_OPTS "$LEXICON_OPTS"
93
94 # shellcheck disable=SC2086
95 $lexicon_cmd "$PROVIDER" $LEXICON_OPTS create "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" --output QUIET
96
97 }
98
99 #Usage: dns_lexicon_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
100 dns_lexicon_rm() {
101 fulldomain=$1
102 txtvalue=$2
103
104 if ! _lexicon_init; then
105 return 1
106 fi
107
108 domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
109
110 # shellcheck disable=SC2086
111 $lexicon_cmd "$PROVIDER" $LEXICON_OPTS delete "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" --output QUIET
112
113 }