#!/bin/bash

echo "# Please Wait..."
#service squid stop
groovix-filter-off
mv /var/log/squid/access.log /var/log/squid/access.log.old
#service squid start
# put it into blacklist mode so most sites will not be blocked so we don't have to do this iteratively
# should maybe create special pass-everything filter mode just for creating whitelists
groovix-filter-on blacklist

echo
echo
echo "# Now browse the sites you want included in your black or white list, "
echo "# and then hit Enter AFTER you are done browsing to get the results."
read a
echo

echo "# Please Wait..."

#service squid restart
groovix-filter-off
groovix-filter-on

echo
echo
echo "# here is your list (also available in /tmp/groovix-filter-parse-connection-log.sorted.txt )"
echo

rm -f /tmp/groovix-filter-parse-connection-log.connects.txt /tmp/groovix-filter-parse-connection-log.gets.txt

grep CONNECT /var/log/squid/access.log | perl -pi -e 's/.*CONNECT ([^:]+).*/$1/' |  sort | uniq > /tmp/groovix-filter-parse-connection-log.connects.txt
grep GET /var/log/squid/access.log | perl -pi -e 's/.*GET http:\/\/([^\/]+).*/$1/' | sort | uniq > /tmp/groovix-filter-parse-connection-log.gets.txt

rm -f /tmp/groovix-filter-parse-connection-log.sorted.txt
cat /tmp/groovix-filter-parse-connection-log.connects.txt /tmp/groovix-filter-parse-connection-log.gets.txt |  sort | uniq > /tmp/groovix-filter-parse-connection-log.sorted.txt

cat /tmp/groovix-filter-parse-connection-log.sorted.txt
