]>
Commit | Line | Data |
---|---|---|
218dc339 | 1 | #!/usr/bin/env sh |
2 | ||
3 | # dns api wrapper of lexicon for acme.sh | |
4 | ||
3ca93f4a | 5 | # https://github.com/AnalogJ/lexicon |
218dc339 | 6 | lexicon_cmd="lexicon" |
7 | ||
8 | wiki="https://github.com/Neilpang/acme.sh/wiki/How-to-use-lexicon-dns-api" | |
9 | ||
0366e875 | 10 | _lexicon_init() { |
c7b16249 | 11 | if ! _exists "$lexicon_cmd"; then |
218dc339 | 12 | _err "Please install $lexicon_cmd first: $wiki" |
13 | return 1 | |
14 | fi | |
4c2a3841 | 15 | |
0366e875 | 16 | PROVIDER="${PROVIDER:-$(_readdomainconf PROVIDER)}" |
4c2a3841 | 17 | if [ -z "$PROVIDER" ]; then |
422e5026 | 18 | PROVIDER="" |
218dc339 | 19 | _err "Please define env PROVIDER first: $wiki" |
20 | return 1 | |
21 | fi | |
22 | ||
23 | _savedomainconf PROVIDER "$PROVIDER" | |
24 | export PROVIDER | |
25 | ||
800f02ba BB |
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') | |
43694028 | 29 | eval "$Lx_name=\${$Lx_name:-$(_readaccountconf_mutable "$Lx_name")}" |
a8c61111 | 30 | Lx_name_v=$(eval echo \$"$Lx_name") |
e6e85b0c | 31 | _secure_debug "$Lx_name" "$Lx_name_v" |
4c2a3841 | 32 | if [ "$Lx_name_v" ]; then |
0366e875 | 33 | _saveaccountconf_mutable "$Lx_name" "$Lx_name_v" |
3de85700 | 34 | eval export "$Lx_name" |
218dc339 | 35 | fi |
4c2a3841 | 36 | |
800f02ba BB |
37 | # shellcheck disable=SC2018,SC2019 |
38 | Lx_token=$(echo LEXICON_"${PROVIDER}"_TOKEN | tr 'a-z' 'A-Z') | |
43694028 | 39 | eval "$Lx_token=\${$Lx_token:-$(_readaccountconf_mutable "$Lx_token")}" |
a8c61111 | 40 | Lx_token_v=$(eval echo \$"$Lx_token") |
e6e85b0c | 41 | _secure_debug "$Lx_token" "$Lx_token_v" |
4c2a3841 | 42 | if [ "$Lx_token_v" ]; then |
0366e875 | 43 | _saveaccountconf_mutable "$Lx_token" "$Lx_token_v" |
3de85700 | 44 | eval export "$Lx_token" |
218dc339 | 45 | fi |
4c2a3841 | 46 | |
800f02ba BB |
47 | # shellcheck disable=SC2018,SC2019 |
48 | Lx_password=$(echo LEXICON_"${PROVIDER}"_PASSWORD | tr 'a-z' 'A-Z') | |
43694028 | 49 | eval "$Lx_password=\${$Lx_password:-$(_readaccountconf_mutable "$Lx_password")}" |
a8c61111 | 50 | Lx_password_v=$(eval echo \$"$Lx_password") |
e6e85b0c | 51 | _secure_debug "$Lx_password" "$Lx_password_v" |
4c2a3841 | 52 | if [ "$Lx_password_v" ]; then |
0366e875 | 53 | _saveaccountconf_mutable "$Lx_password" "$Lx_password_v" |
3de85700 | 54 | eval export "$Lx_password" |
218dc339 | 55 | fi |
4c2a3841 | 56 | |
800f02ba BB |
57 | # shellcheck disable=SC2018,SC2019 |
58 | Lx_domaintoken=$(echo LEXICON_"${PROVIDER}"_DOMAINTOKEN | tr 'a-z' 'A-Z') | |
43694028 | 59 | eval "$Lx_domaintoken=\${$Lx_domaintoken:-$(_readaccountconf_mutable "$Lx_domaintoken")}" |
a8c61111 | 60 | Lx_domaintoken_v=$(eval echo \$"$Lx_domaintoken") |
e6e85b0c | 61 | _secure_debug "$Lx_domaintoken" "$Lx_domaintoken_v" |
4c2a3841 | 62 | if [ "$Lx_domaintoken_v" ]; then |
0366e875 | 63 | _saveaccountconf_mutable "$Lx_domaintoken" "$Lx_domaintoken_v" |
3de85700 | 64 | eval export "$Lx_domaintoken" |
218dc339 | 65 | fi |
8d230dd7 OJ |
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 | ||
0366e875 | 75 | if ! _lexicon_init; then |
8d230dd7 OJ |
76 | return 1 |
77 | fi | |
78 | ||
79 | domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999) | |
218dc339 | 80 | |
e9f9f515 | 81 | $lexicon_cmd "$PROVIDER" create "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" |
218dc339 | 82 | |
83 | } | |
84 | ||
8d230dd7 | 85 | #Usage: dns_lexicon_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" |
5d6fd809 | 86 | dns_lexicon_rm() { |
87 | fulldomain=$1 | |
8d230dd7 OJ |
88 | txtvalue=$2 |
89 | ||
0366e875 | 90 | if ! _lexicon_init; then |
8d230dd7 OJ |
91 | return 1 |
92 | fi | |
93 | ||
94 | domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999) | |
95 | ||
96 | $lexicon_cmd "$PROVIDER" delete "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" | |
5d6fd809 | 97 | |
98 | } |