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.

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