custom_rules_init.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. ACTDIR=$(dirname "$0")
  3. KIDS_IP="172.24.42.100-172.24.42.110"
  4. KIDS_MAC="00:e0:53:13:1b:f1 88:79:7e:f7:05:60 d0:04:01:9f:b4:09"
  5. FOR_OUT_KIDS="forwarding_lan_rules_kids"
  6. FOR_OUT_GAMES="forwarding_lan_rules_games"
  7. FOR_IN_KIDS="forwarding_wan_rules_kids"
  8. YOUTUBE="forwarding_wan_rules_youtube"
  9. iptables -N ${FOR_OUT_KIDS}
  10. iptables -I ${FOR_OUT_GAMES} -m limit --limit 1/min -j LOG --log-prefix "Surfing kid: "
  11. iptables -A ${FOR_OUT_KIDS} -j DROP
  12. iptables -N ${FOR_OUT_GAMES}
  13. iptables -I ${FOR_OUT_GAMES} -m limit --limit 1/min -j LOG --log-prefix "Playing kid: "
  14. iptables -A ${FOR_OUT_GAMES} -j DROP
  15. iptables -N ${FOR_IN_KIDS}
  16. iptables -A ${FOR_IN_KIDS} -j DROP
  17. iptables -N ${YOUTUBE}
  18. iptables -A ${YOUTUBE} -j DROP
  19. # Time restriction for games
  20. iptables -I ${FOR_OUT_GAMES} 1 -m time --timestart 14:00 --timestop 21:00 --weekdays Mon,Tue,Wed,Thu,Sun -j ACCEPT
  21. iptables -I ${FOR_OUT_GAMES} 1 -m time --timestart 08:00 --timestop 23:00 --weekdays Sat -j ACCEPT
  22. iptables -I ${FOR_OUT_GAMES} 1 -m time --timestart 12:00 --timestop 23:00 --weekdays Fri -j ACCEPT
  23. # allow WhatsApp
  24. iptables -I ${FOR_OUT_KIDS} 1 -p tcp -m multiport --dports 4244,5222,5223,5228,5242,50318,59234 -m comment --comment "TCP Whatsapp" -j ACCEPT
  25. iptables -I ${FOR_OUT_KIDS} 1 -p udp -m multiport --dports 3478,45395,50318,59234 -m comment --comment "UDP Whatsapp" -j ACCEPT
  26. # redirect games
  27. iptables -I ${FOR_OUT_KIDS} -p udp -m multiport --dports 29995:30005 -m comment --comment "Minetest" -j ${FOR_OUT_GAMES}
  28. # populate list
  29. ${ACTDIR}/filter_mac.sh start
  30. iptables -I FORWARD -m iprange --dst-range ${KIDS_IP} -m conntrack --ctstatus RELATED,ESTABLISHED -j ${FOR_IN_KIDS}
  31. # web access - time restriction
  32. iptables -I ${FOR_OUT_KIDS} 1 -p tcp -m multiport --dports 80,443 -m time --timestart 08:00 --timestop 23:00 -j ACCEPT
  33. iptables -I ${FOR_IN_KIDS} 1 -p tcp -m multiport --sports 80,443 -m time --timestart 08:00 --timestop 23:00 -j ACCEPT
  34. # Youtube
  35. while read -r line; do
  36. iptables -I ${FOR_IN_KIDS} -m iprange --src-range ${line} -m length --length 2048:65535 -p tcp -j ${YOUTUBE}
  37. done < "${ACTDIR}/youtube.txt"