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.

124 lines
3.1 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. ########################
  7. #Yucky global variables#
  8. ########################
  9. global_result=0
  10. # A list of adult websites that support both IPv4 and IPv6
  11. IPv4andIPv6EnabledSiteList="https://xhamster.com https://www.watchmyexgf.net https://gaymaletube.com"
  12. expect_not_safe(){
  13. title=$1
  14. size=$2
  15. web=$3
  16. actual=$(wget -4 -O - "$web" | wc -l) 2> /dev/null
  17. if [ "$actual" -gt "$size" ] ; then
  18. echo "$title: IPv4: $size/$actual. NOT SAFE"
  19. else
  20. echo "$title: IPv4: SAFE. $actual (expected not safe!) ***************"
  21. global_result=1
  22. fi
  23. actual=$(wget -6 -O - "$web" | wc -l) 2> /dev/null
  24. if [ "$actual" -gt "$size" ] ; then
  25. echo "$title: IPv6: $size/$actual. NOT SAFE"
  26. else
  27. echo "$title: IPv6: SAFE. $actual (expected not safe!) ***************"
  28. global_result=1
  29. fi
  30. return $global_result
  31. }
  32. expect_safe(){
  33. title=$1
  34. size=$2
  35. web=$3
  36. actual=$(wget -4 -O - "$web" | wc -l) 2> /dev/null
  37. if [ "$actual" -gt "$size" ] ; then
  38. echo "$title: IPv4: $size/$actual. NOT SAFE ******************"
  39. global_result=1
  40. else
  41. echo "$title: IPv4: SAFE. $actual"
  42. fi
  43. actual=$(wget -6 -O - "$web" | wc -l) 2> /dev/null
  44. if [ "$actual" -gt "$size" ] ; then
  45. echo "$title: IPv6: $size/$actual. NOT SAFE ******************"
  46. global_result=1
  47. else
  48. echo "$title: IPv6: SAFE. $actual"
  49. fi
  50. }
  51. test_not_safe(){
  52. uci set family-dns.default.enabled=0
  53. uci commit family-dns
  54. family-dns-update
  55. echo "******************************"
  56. echo "Testing Without Protection ***"
  57. echo "******************************"
  58. c=0
  59. for site in ${IPv4andIPv6EnabledSiteList}; do
  60. expect_not_safe "Site $c" 500 "$site"
  61. c=$((c+1))
  62. done
  63. uci set family-dns.default.enabled=1
  64. uci commit family-dns
  65. family-dns-update
  66. echo
  67. }
  68. test_filter(){
  69. echo "******************************"
  70. echo "Testing With Protection ***"
  71. echo "******************************"
  72. echo testing "$1"
  73. uci set family-dns.default.dns="$1"
  74. uci commit family-dns
  75. family-dns-update
  76. c=0
  77. for site in ${IPv4andIPv6EnabledSiteList}; do
  78. expect_safe "Testing Site $c" 500 "$site"
  79. c=$((c+1))
  80. done
  81. echo
  82. }
  83. #############################################
  84. ## Main Tests ##
  85. #############################################
  86. test_not_safe
  87. test_filter cisco-family-shield
  88. test_filter cloudflare-malware-and-adult-content
  89. test_filter cleanbrowsing-family-filter
  90. test_filter cleanbrowsing-adult-filter
  91. # with cleanbrowsing-adult-filter on, run this test on a different device (not the router)
  92. # the result should be 0 when redirect_dns=1 and the result should be 1 when redirect_dns=0
  93. #count=$(nslookup -query=A www.sex.com 8.8.8.8 | grep NXDOMAIN | wc -l)
  94. #if [ $count -eq 1 ]; then
  95. # echo Clean Browsing returned NXDOMAIN. This is expected.
  96. #else
  97. # echo Clean Browsing did not return NXDOMAIN. This is NOT expected.
  98. #fi
  99. if [ $global_result -ne 0 ]; then
  100. echo '************ Test(s) failed! ********************************************************'
  101. fi
  102. exit $global_result