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.

95 lines
2.7 KiB

  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2020 Gregory L. Dietsche <Gregory.Dietsche@cuw.edu>
  4. # This is free software, licensed under the MIT License
  5. #
  6. . /lib/functions.sh
  7. config_load 'family-dns'
  8. config_get_bool enabled default enabled 0
  9. config_get_bool redirect_dns default redirect_dns 0
  10. config_get dns default dns default
  11. #uninstall and disable are designed to be equivalent.
  12. if [ "$1" = "uninstall" ] ; then
  13. enabled=0
  14. fi
  15. # Set OpenWrt Defaults
  16. uci -q batch <<-EOT
  17. set network.wan.peerdns='1'
  18. set network.wan6.peerdns='1'
  19. delete network.wan.dns
  20. delete network.wan6.dns
  21. delete firewall.family_dns_lan
  22. EOT
  23. if [ "$enabled" -ne 1 ] ; then
  24. echo 'Activating Default ISP DNS server(s)'
  25. else
  26. # We don't want to use ISP DNS servers because they don't filter queries
  27. uci set network.wan.peerdns='0'
  28. uci set network.wan6.peerdns='0'
  29. # Configure the DNS server(s) that will handle filtering.
  30. echo "Activating $dns"
  31. case $dns in
  32. cleanbrowsing-adult-filter)
  33. uci add_list network.wan.dns=185.228.168.10
  34. uci add_list network.wan.dns=185.228.169.11
  35. uci add_list network.wan6.dns=2a0d:2a00:1::1
  36. uci add_list network.wan6.dns=2a0d:2a00:2::1
  37. ;;
  38. cleanbrowsing-family-filter)
  39. uci add_list network.wan.dns=185.228.168.168
  40. uci add_list network.wan.dns=185.228.169.168
  41. uci add_list network.wan6.dns=2a0d:2a00:1::
  42. uci add_list network.wan6.dns=2a0d:2a00:2::
  43. ;;
  44. cloudflare-malware-and-adult-content)
  45. uci add_list network.wan.dns=1.1.1.3
  46. uci add_list network.wan.dns=1.0.0.3
  47. uci add_list network.wan6.dns=2606:4700:4700::1113
  48. uci add_list network.wan6.dns=2606:4700:4700::1003
  49. ;;
  50. cisco-family-shield)
  51. uci add_list network.wan.dns=208.67.222.123
  52. uci add_list network.wan.dns=208.67.220.123
  53. uci add_list network.wan6.dns=::ffff:d043:de7b
  54. uci add_list network.wan6.dns=::ffff:d043:dc7b
  55. ;;
  56. *)
  57. echo "$dns" is not supported.
  58. uci revert network
  59. redirect_dns=0
  60. ;;
  61. esac
  62. if [ "$redirect_dns" -eq 1 ] ; then
  63. echo Activating DNS redirect
  64. zone=lan
  65. ip=$(uci get network.$zone.ipaddr)
  66. uci -q batch <<-EOT
  67. set firewall.family_dns_lan=redirect
  68. add_list firewall.family_dns_lan.proto='tcp'
  69. add_list firewall.family_dns_lan.proto='udp'
  70. set firewall.family_dns_lan.src_dport='53'
  71. set firewall.family_dns_lan.dest_ip='$ip'
  72. set firewall.family_dns_lan.target='DNAT'
  73. set firewall.family_dns_lan.src='$zone'
  74. set firewall.family_dns_lan.dest='$zone'
  75. set firewall.family_dns_lan.name='family-dns redirect for $zone zone'
  76. EOT
  77. fi
  78. fi
  79. uci -q batch <<-EOT
  80. commit network
  81. commit firewall
  82. EOT
  83. /etc/init.d/network reload
  84. /etc/init.d/dnsmasq reload
  85. /etc/init.d/firewall reload 2>/dev/null