You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.9 KiB

  1. #!/usr/bin/env sh
  2. # dns api wrapper of lexicon for acme.sh
  3. # https://github.com/AnalogJ/lexicon
  4. lexicon_cmd="lexicon"
  5. wiki="https://github.com/Neilpang/acme.sh/wiki/How-to-use-lexicon-dns-api"
  6. _lexicon_init() {
  7. if ! _exists "$lexicon_cmd"; then
  8. _err "Please install $lexicon_cmd first: $wiki"
  9. return 1
  10. fi
  11. PROVIDER="${PROVIDER:-$(_readdomainconf PROVIDER)}"
  12. if [ -z "$PROVIDER" ]; then
  13. PROVIDER=""
  14. _err "Please define env PROVIDER first: $wiki"
  15. return 1
  16. fi
  17. _savedomainconf PROVIDER "$PROVIDER"
  18. export PROVIDER
  19. # e.g. busybox-ash does not know [:upper:]
  20. # shellcheck disable=SC2018,SC2019
  21. Lx_name=$(echo LEXICON_"${PROVIDER}"_USERNAME | tr 'a-z' 'A-Z')
  22. eval "$Lx_name=\${$Lx_name:-$(_readaccountconf_mutable "$Lx_name")}"
  23. Lx_name_v=$(eval echo \$"$Lx_name")
  24. _secure_debug "$Lx_name" "$Lx_name_v"
  25. if [ "$Lx_name_v" ]; then
  26. _saveaccountconf_mutable "$Lx_name" "$Lx_name_v"
  27. eval export "$Lx_name"
  28. fi
  29. # shellcheck disable=SC2018,SC2019
  30. Lx_token=$(echo LEXICON_"${PROVIDER}"_TOKEN | tr 'a-z' 'A-Z')
  31. eval "$Lx_token=\${$Lx_token:-$(_readaccountconf_mutable "$Lx_token")}"
  32. Lx_token_v=$(eval echo \$"$Lx_token")
  33. _secure_debug "$Lx_token" "$Lx_token_v"
  34. if [ "$Lx_token_v" ]; then
  35. _saveaccountconf_mutable "$Lx_token" "$Lx_token_v"
  36. eval export "$Lx_token"
  37. fi
  38. # shellcheck disable=SC2018,SC2019
  39. Lx_password=$(echo LEXICON_"${PROVIDER}"_PASSWORD | tr 'a-z' 'A-Z')
  40. eval "$Lx_password=\${$Lx_password:-$(_readaccountconf_mutable "$Lx_password")}"
  41. Lx_password_v=$(eval echo \$"$Lx_password")
  42. _secure_debug "$Lx_password" "$Lx_password_v"
  43. if [ "$Lx_password_v" ]; then
  44. _saveaccountconf_mutable "$Lx_password" "$Lx_password_v"
  45. eval export "$Lx_password"
  46. fi
  47. # shellcheck disable=SC2018,SC2019
  48. Lx_domaintoken=$(echo LEXICON_"${PROVIDER}"_DOMAINTOKEN | tr 'a-z' 'A-Z')
  49. eval "$Lx_domaintoken=\${$Lx_domaintoken:-$(_readaccountconf_mutable "$Lx_domaintoken")}"
  50. Lx_domaintoken_v=$(eval echo \$"$Lx_domaintoken")
  51. _secure_debug "$Lx_domaintoken" "$Lx_domaintoken_v"
  52. if [ "$Lx_domaintoken_v" ]; then
  53. _saveaccountconf_mutable "$Lx_domaintoken" "$Lx_domaintoken_v"
  54. eval export "$Lx_domaintoken"
  55. fi
  56. }
  57. ######## Public functions #####################
  58. #Usage: dns_lexicon_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  59. dns_lexicon_add() {
  60. fulldomain=$1
  61. txtvalue=$2
  62. if ! _lexicon_init; then
  63. return 1
  64. fi
  65. domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
  66. $lexicon_cmd "$PROVIDER" create "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}"
  67. }
  68. #Usage: dns_lexicon_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  69. dns_lexicon_rm() {
  70. fulldomain=$1
  71. txtvalue=$2
  72. if ! _lexicon_init; then
  73. return 1
  74. fi
  75. domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
  76. $lexicon_cmd "$PROVIDER" delete "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}"
  77. }