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.

77 lines
2.1 KiB

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