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.

117 lines
3.7 KiB

4 years ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_lexicon_info='Lexicon DNS client
  4. Site: github.com/AnalogJ/lexicon
  5. Docs: github.com/acmesh-official/acme.sh/wiki/How-to-use-lexicon-DNS-API
  6. Options:
  7. PROVIDER Provider
  8. '
  9. lexicon_cmd="lexicon"
  10. wiki="https://github.com/acmesh-official/acme.sh/wiki/How-to-use-lexicon-dns-api"
  11. _lexicon_init() {
  12. if ! _exists "$lexicon_cmd"; then
  13. _err "Please install $lexicon_cmd first: $wiki"
  14. return 1
  15. fi
  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. _savedomainconf PROVIDER "$PROVIDER"
  23. export PROVIDER
  24. # e.g. busybox-ash does not know [:upper:]
  25. # shellcheck disable=SC2018,SC2019
  26. Lx_name=$(echo LEXICON_"${PROVIDER}"_USERNAME | tr 'a-z' 'A-Z')
  27. eval "$Lx_name=\${$Lx_name:-$(_readaccountconf_mutable "$Lx_name")}"
  28. Lx_name_v=$(eval echo \$"$Lx_name")
  29. _secure_debug "$Lx_name" "$Lx_name_v"
  30. if [ "$Lx_name_v" ]; then
  31. _saveaccountconf_mutable "$Lx_name" "$Lx_name_v"
  32. eval export "$Lx_name"
  33. fi
  34. # shellcheck disable=SC2018,SC2019
  35. Lx_token=$(echo LEXICON_"${PROVIDER}"_TOKEN | tr 'a-z' 'A-Z')
  36. eval "$Lx_token=\${$Lx_token:-$(_readaccountconf_mutable "$Lx_token")}"
  37. Lx_token_v=$(eval echo \$"$Lx_token")
  38. _secure_debug "$Lx_token" "$Lx_token_v"
  39. if [ "$Lx_token_v" ]; then
  40. _saveaccountconf_mutable "$Lx_token" "$Lx_token_v"
  41. eval export "$Lx_token"
  42. fi
  43. # shellcheck disable=SC2018,SC2019
  44. Lx_password=$(echo LEXICON_"${PROVIDER}"_PASSWORD | tr 'a-z' 'A-Z')
  45. eval "$Lx_password=\${$Lx_password:-$(_readaccountconf_mutable "$Lx_password")}"
  46. Lx_password_v=$(eval echo \$"$Lx_password")
  47. _secure_debug "$Lx_password" "$Lx_password_v"
  48. if [ "$Lx_password_v" ]; then
  49. _saveaccountconf_mutable "$Lx_password" "$Lx_password_v"
  50. eval export "$Lx_password"
  51. fi
  52. # shellcheck disable=SC2018,SC2019
  53. Lx_domaintoken=$(echo LEXICON_"${PROVIDER}"_DOMAINTOKEN | tr 'a-z' 'A-Z')
  54. eval "$Lx_domaintoken=\${$Lx_domaintoken:-$(_readaccountconf_mutable "$Lx_domaintoken")}"
  55. Lx_domaintoken_v=$(eval echo \$"$Lx_domaintoken")
  56. _secure_debug "$Lx_domaintoken" "$Lx_domaintoken_v"
  57. if [ "$Lx_domaintoken_v" ]; then
  58. _saveaccountconf_mutable "$Lx_domaintoken" "$Lx_domaintoken_v"
  59. eval export "$Lx_domaintoken"
  60. fi
  61. # shellcheck disable=SC2018,SC2019
  62. Lx_api_key=$(echo LEXICON_"${PROVIDER}"_API_KEY | tr 'a-z' 'A-Z')
  63. eval "$Lx_api_key=\${$Lx_api_key:-$(_readaccountconf_mutable "$Lx_api_key")}"
  64. Lx_api_key_v=$(eval echo \$"$Lx_api_key")
  65. _secure_debug "$Lx_api_key" "$Lx_api_key_v"
  66. if [ "$Lx_api_key_v" ]; then
  67. _saveaccountconf_mutable "$Lx_api_key" "$Lx_api_key_v"
  68. eval export "$Lx_api_key"
  69. fi
  70. }
  71. ######## Public functions #####################
  72. #Usage: dns_lexicon_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  73. dns_lexicon_add() {
  74. fulldomain=$1
  75. txtvalue=$2
  76. if ! _lexicon_init; then
  77. return 1
  78. fi
  79. domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
  80. _secure_debug LEXICON_OPTS "$LEXICON_OPTS"
  81. _savedomainconf LEXICON_OPTS "$LEXICON_OPTS"
  82. # shellcheck disable=SC2086
  83. $lexicon_cmd "$PROVIDER" $LEXICON_OPTS create "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" --output QUIET
  84. }
  85. #Usage: dns_lexicon_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  86. dns_lexicon_rm() {
  87. fulldomain=$1
  88. txtvalue=$2
  89. if ! _lexicon_init; then
  90. return 1
  91. fi
  92. domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
  93. # shellcheck disable=SC2086
  94. $lexicon_cmd "$PROVIDER" $LEXICON_OPTS delete "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" --output QUIET
  95. }