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.

64 lines
1.5 KiB

  1. #!/usr/bin/env sh
  2. #Nsd_ZoneFile="/etc/nsd/zones/example.com.zone"
  3. #Nsd_Command="sudo nsd-control reload"
  4. # args: fulldomain txtvalue
  5. dns_nsd_add() {
  6. fulldomain=$1
  7. txtvalue=$2
  8. ttlvalue=300
  9. Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
  10. Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
  11. # Arg checks
  12. if [ -z "$Nsd_ZoneFile" ] || [ -z "$Nsd_Command" ]; then
  13. Nsd_ZoneFile=""
  14. Nsd_Command=""
  15. _err "Specify ENV vars Nsd_ZoneFile and Nsd_Command"
  16. return 1
  17. fi
  18. if [ ! -f "$Nsd_ZoneFile" ]; then
  19. Nsd_ZoneFile=""
  20. Nsd_Command=""
  21. _err "No such file: $Nsd_ZoneFile"
  22. return 1
  23. fi
  24. _savedomainconf Nsd_ZoneFile "$Nsd_ZoneFile"
  25. _savedomainconf Nsd_Command "$Nsd_Command"
  26. echo "$fulldomain. $ttlvalue IN TXT \"$txtvalue\"" >>"$Nsd_ZoneFile"
  27. _info "Added TXT record for $fulldomain"
  28. _debug "Running $Nsd_Command"
  29. if eval "$Nsd_Command"; then
  30. _info "Successfully updated the zone"
  31. return 0
  32. else
  33. _err "Problem updating the zone"
  34. return 1
  35. fi
  36. }
  37. # args: fulldomain txtvalue
  38. dns_nsd_rm() {
  39. fulldomain=$1
  40. txtvalue=$2
  41. ttlvalue=300
  42. Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}"
  43. Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}"
  44. sed -i "/$fulldomain. $ttlvalue IN TXT \"$txtvalue\"/d" "$Nsd_ZoneFile"
  45. _info "Removed TXT record for $fulldomain"
  46. _debug "Running $Nsd_Command"
  47. if eval "$Nsd_Command"; then
  48. _info "Successfully reloaded NSD "
  49. return 0
  50. else
  51. _err "Problem reloading NSD"
  52. return 1
  53. fi
  54. }