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.

76 lines
2.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. # shellcheck disable=SC2034 disable=SC2154
  3. USE_PROCD=1
  4. # starts after network starts
  5. START=21
  6. # stops before networking stops
  7. STOP=89
  8. PROG=/usr/sbin/nextdns
  9. add_dnsmasq_opt() {
  10. mkdir -p /tmp/dnsmasq.d
  11. echo "$1" >> /tmp/dnsmasq.d/nextdns.conf
  12. }
  13. dnsmasq_reload() {
  14. # Reload dnsmasq is already running.
  15. if /etc/init.d/dnsmasq running; then
  16. /etc/init.d/dnsmasq reload
  17. fi
  18. }
  19. handle_host_config() {
  20. host_config_args="$host_config_args -config=$1"
  21. }
  22. start_service() {
  23. config_load nextdns
  24. config_get_bool enabled main enabled "1"
  25. rm -f /tmp/dnsmasq.d/nextdns.conf
  26. if [ "$enabled" = "1" ]; then
  27. config_get config main config ""
  28. config_list_foreach main host_config handle_host_config
  29. config_get listen main listen "127.0.0.1:5342"
  30. config_get_bool report_client_info main report_client_info "1"
  31. config_get_bool hardened_privacy main hardened_privacy "0"
  32. config_get_bool log_queries main log_queries "0"
  33. # Add a custom configuration for dnsmasq.
  34. server=$(echo "$listen" | sed -e 's/:/#/')
  35. add_dnsmasq_opt "server=$server"
  36. add_dnsmasq_opt "no-resolv"
  37. if [ "$report_client_info" = "1" ]; then
  38. add_dnsmasq_opt "add-mac"
  39. add_dnsmasq_opt "add-subnet=32,128"
  40. fi
  41. procd_open_instance
  42. # shellcheck disable=SC2086
  43. procd_set_param command "$PROG" run \
  44. -listen="$listen" \
  45. $host_config_args \
  46. -config="$config" \
  47. -report-client-info="$report_client_info" \
  48. -hardened-privacy="$hardened_privacy" \
  49. -log-queries="$log_queries"
  50. procd_set_param stdout 1
  51. procd_set_param stderr 1
  52. procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}"
  53. procd_close_instance
  54. fi
  55. dnsmasq_reload
  56. }
  57. stop_service() {
  58. rm -f /tmp/dnsmasq.d/nextdns.conf
  59. dnsmasq_reload
  60. }
  61. service_triggers() {
  62. procd_add_reload_trigger "nextdns"
  63. }