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.

113 lines
3.5 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/acmesh-official/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. # shellcheck disable=SC2018,SC2019
  57. Lx_api_key=$(echo LEXICON_"${PROVIDER}"_API_KEY | tr 'a-z' 'A-Z')
  58. eval "$Lx_api_key=\${$Lx_api_key:-$(_readaccountconf_mutable "$Lx_api_key")}"
  59. Lx_api_key_v=$(eval echo \$"$Lx_api_key")
  60. _secure_debug "$Lx_api_key" "$Lx_api_key_v"
  61. if [ "$Lx_api_key_v" ]; then
  62. _saveaccountconf_mutable "$Lx_api_key" "$Lx_api_key_v"
  63. eval export "$Lx_api_key"
  64. fi
  65. }
  66. ######## Public functions #####################
  67. #Usage: dns_lexicon_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  68. dns_lexicon_add() {
  69. fulldomain=$1
  70. txtvalue=$2
  71. if ! _lexicon_init; then
  72. return 1
  73. fi
  74. domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
  75. _secure_debug LEXICON_OPTS "$LEXICON_OPTS"
  76. _savedomainconf LEXICON_OPTS "$LEXICON_OPTS"
  77. # shellcheck disable=SC2086
  78. $lexicon_cmd "$PROVIDER" $LEXICON_OPTS create "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" >/dev/null
  79. }
  80. #Usage: dns_lexicon_rm _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  81. dns_lexicon_rm() {
  82. fulldomain=$1
  83. txtvalue=$2
  84. if ! _lexicon_init; then
  85. return 1
  86. fi
  87. domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
  88. # shellcheck disable=SC2086
  89. $lexicon_cmd "$PROVIDER" $LEXICON_OPTS delete "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}" >/dev/null
  90. }