]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_lexicon.sh
Correct edits to README.md this time
[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/Neilpang/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
68 ######## Public functions #####################
69
70 #Usage: dns_lexicon_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
71 dns_lexicon_add() {
72 fulldomain=$1
73 txtvalue=$2
74
75 if ! _lexicon_init; then
76 return 1
77 fi
78
79 domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
80
81 _secure_debug LEXICON_OPTS "$LEXICON_OPTS"
82 _savedomainconf LEXICON_OPTS "$LEXICON_OPTS"
83
84 # shellcheck disable=SC2086
85 $lexicon_cmd "$PROVIDER" $LEXICON_OPTS create "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}"
86
87 }
88
89 #Usage: dns_lexicon_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
90 dns_lexicon_rm() {
91 fulldomain=$1
92 txtvalue=$2
93
94 if ! _lexicon_init; then
95 return 1
96 fi
97
98 domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
99
100 # shellcheck disable=SC2086
101 $lexicon_cmd "$PROVIDER" $LEXICON_OPTS delete "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}"
102
103 }