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.

78 lines
2.1 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. ######## Public functions #####################
  7. #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  8. dns_lexicon_add() {
  9. fulldomain=$1
  10. txtvalue=$2
  11. domain=$(printf "%s" "$fulldomain" | cut -d . -f 2-999)
  12. if ! _exists "$lexicon_cmd"; then
  13. _err "Please install $lexicon_cmd first: $wiki"
  14. return 1
  15. fi
  16. if [ -z "$PROVIDER" ]; then
  17. PROVIDER=""
  18. _err "Please define env PROVIDER first: $wiki"
  19. return 1
  20. fi
  21. _savedomainconf PROVIDER "$PROVIDER"
  22. export PROVIDER
  23. # e.g. busybox-ash does not know [:upper:]
  24. # shellcheck disable=SC2018,SC2019
  25. Lx_name=$(echo LEXICON_"${PROVIDER}"_USERNAME | tr 'a-z' 'A-Z')
  26. Lx_name_v=$(eval echo \$"$Lx_name")
  27. _secure_debug "$Lx_name" "$Lx_name_v"
  28. if [ "$Lx_name_v" ]; then
  29. _saveaccountconf "$Lx_name" "$Lx_name_v"
  30. eval export "$Lx_name"
  31. fi
  32. # shellcheck disable=SC2018,SC2019
  33. Lx_token=$(echo LEXICON_"${PROVIDER}"_TOKEN | tr 'a-z' 'A-Z')
  34. Lx_token_v=$(eval echo \$"$Lx_token")
  35. _secure_debug "$Lx_token" "$Lx_token_v"
  36. if [ "$Lx_token_v" ]; then
  37. _saveaccountconf "$Lx_token" "$Lx_token_v"
  38. eval export "$Lx_token"
  39. fi
  40. # shellcheck disable=SC2018,SC2019
  41. Lx_password=$(echo LEXICON_"${PROVIDER}"_PASSWORD | tr 'a-z' 'A-Z')
  42. Lx_password_v=$(eval echo \$"$Lx_password")
  43. _secure_debug "$Lx_password" "$Lx_password_v"
  44. if [ "$Lx_password_v" ]; then
  45. _saveaccountconf "$Lx_password" "$Lx_password_v"
  46. eval export "$Lx_password"
  47. fi
  48. # shellcheck disable=SC2018,SC2019
  49. Lx_domaintoken=$(echo LEXICON_"${PROVIDER}"_DOMAINTOKEN | tr 'a-z' 'A-Z')
  50. Lx_domaintoken_v=$(eval echo \$"$Lx_domaintoken")
  51. _secure_debug "$Lx_domaintoken" "$Lx_domaintoken_v"
  52. if [ "$Lx_domaintoken_v" ]; then
  53. eval export "$Lx_domaintoken"
  54. _saveaccountconf "$Lx_domaintoken" "$Lx_domaintoken_v"
  55. fi
  56. $lexicon_cmd "$PROVIDER" create "${domain}" TXT --name="_acme-challenge.${domain}." --content="${txtvalue}"
  57. }
  58. #fulldomain
  59. dns_lexicon_rm() {
  60. fulldomain=$1
  61. }