unbound.ncdi 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. include_guard "unbound"
  2. template unbound {
  3. alias("_arg0") unique_id;
  4. alias("_arg1") access_control_rules;
  5. # Create a temporary directory.
  6. concat("/run/ncd-unbound-", unique_id) run_dir;
  7. run({"/bin/rm", "-rf", run_dir}, {});
  8. run({"/bin/mkdir", run_dir}, {"/bin/rm", "-rf", run_dir});
  9. # Compute path for unbound.conf.
  10. concat(run_dir, "/unbound.conf") unbound_conf_path;
  11. # This is a template for unbound.conf.
  12. value("
  13. server:
  14. verbosity: 1
  15. do-ip4: yes
  16. do-ip6: no
  17. do-udp: yes
  18. do-tcp: no
  19. interface: 0.0.0.0
  20. access-control: 127.0.0.0/8 allow
  21. " ) config;
  22. # Append access control rules.
  23. Foreach (access_control_rules As rule) {
  24. value(rule) rule;
  25. rule->get("0") network;
  26. rule->get("1") prefix;
  27. rule->get("2") action;
  28. concat(" access-control: ", network, "/", prefix, " ", action, "\n") line;
  29. config->append(line);
  30. };
  31. # Write unbound.conf.
  32. file_write(unbound_conf_path, config);
  33. # Start unbound.
  34. daemon({"/usr/sbin/unbound", "-d", "-c", unbound_conf_path});
  35. }