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.

70 lines
1.8 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_nsd_info='NLnetLabs NSD Server
  4. Site: github.com/NLnetLabs/nsd
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#nsd
  6. Options:
  7. Nsd_ZoneFile Zone File path. E.g. "/etc/nsd/zones/example.com.zone"
  8. Nsd_Command Command. E.g. "sudo nsd-control reload"
  9. Issues: github.com/acmesh-official/acme.sh/issues/2245
  10. '
  11. # args: fulldomain txtvalue
  12. dns_nsd_add() {
  13. fulldomain=$1
  14. txtvalue=$2
  15. ttlvalue=300
  16. Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
  17. Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
  18. # Arg checks
  19. if [ -z "$Nsd_ZoneFile" ] || [ -z "$Nsd_Command" ]; then
  20. Nsd_ZoneFile=""
  21. Nsd_Command=""
  22. _err "Specify ENV vars Nsd_ZoneFile and Nsd_Command"
  23. return 1
  24. fi
  25. if [ ! -f "$Nsd_ZoneFile" ]; then
  26. Nsd_ZoneFile=""
  27. Nsd_Command=""
  28. _err "No such file: $Nsd_ZoneFile"
  29. return 1
  30. fi
  31. _savedomainconf Nsd_ZoneFile "$Nsd_ZoneFile"
  32. _savedomainconf Nsd_Command "$Nsd_Command"
  33. echo "$fulldomain. $ttlvalue IN TXT \"$txtvalue\"" >>"$Nsd_ZoneFile"
  34. _info "Added TXT record for $fulldomain"
  35. _debug "Running $Nsd_Command"
  36. if eval "$Nsd_Command"; then
  37. _info "Successfully updated the zone"
  38. return 0
  39. else
  40. _err "Problem updating the zone"
  41. return 1
  42. fi
  43. }
  44. # args: fulldomain txtvalue
  45. dns_nsd_rm() {
  46. fulldomain=$1
  47. txtvalue=$2
  48. ttlvalue=300
  49. Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
  50. Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
  51. _sed_i "/$fulldomain. $ttlvalue IN TXT \"$txtvalue\"/d" "$Nsd_ZoneFile"
  52. _info "Removed TXT record for $fulldomain"
  53. _debug "Running $Nsd_Command"
  54. if eval "$Nsd_Command"; then
  55. _info "Successfully reloaded NSD "
  56. return 0
  57. else
  58. _err "Problem reloading NSD"
  59. return 1
  60. fi
  61. }