I've been using ebox/Zentyal at home as my internet gateway for a couple of years now. Since I have Windows machines in the house I use SpyBot to deal with spyware. SpyBot does something very nice;They modify the hosts file and redirect those spyware places to the loopback address. It turns out this is a great way to block additional sites that are banned for the kids as well.
I realized I could use that hosts file to populate the Domain filtering in Zentyal and let it block all those sites from one place, giving me control from one location. I tried it and it worked flawlessly. Considering there were 10,000+ items in my hosts file I needed a better way to deal with it. As a result I wrote a little script to do the work for me. I have attached it below for anyone to use.
---------------------
#!/bin/bash
# Host file must be scrubbed and very clean. Sorted, uniq and one entry per line.
# Remove localhost entry and comments.
# Creates tarball of the hosts file.
clear
file1=~/hosts/hosts
file2=~/hosts/hosts.clean1
file3=~/hosts/hosts.sort1
file4=~/hosts/hosts.uniq1
file5=~/hosts/my.hosts
file6=~/hosts/hosts.tmp1
tarball=~/hosts/blacklist.tar.gz
folder=~/hosts
cd $folder
cat $file5 > $file6 # Push my custom hosts file to temp file
cat $file1 >> $file6 # Append windows hosts file to temp file
cat $file6 > $file1 # Overwrite original hosts file with combined data
# Ignore comment lines, localhost, strip loopback address and all whitespace
cat $file1 | grep -v '^#' | grep -v 'localhost' | sed -e 's/127.0.0.1//g' -e 's/[[:space:]]//g' > $file2
sort $file2 > $file3 # Sort the list
uniq $file3 > $file4 # Create a list of only unique items
cp -v $file4 $folder/blacklists/hosts/domains # Copy finished file into folder
tar cvpfz $tarball $folder/blacklists/* # Tar it up for import
echo
echo "Complete. Check for errors. If none it's ready to import into Zentyal."
exit
# To import into Zentyal, use HTTP Proxy>Filter Profiles>default. Add under Domains filtering tab, Domains Lists Files, Add new and import.
# Name it MyHostsFile. On MyHostsFile, click icon under Categories and switch policy to always deny. Save it, changes are immediate.
---------------------
I have commented it so it's easier to follow. The last 2 commented lines tell you how to get it into Zentyal. (That's a reminder for me since I don't have to mess with it all that often. Could that be considered a testimonial? lol)
Now for a couple of comments after the fact.
I have custom host file entries I want blocked at all times, beyond what SpyBot does for me. Those go into file5 or my.hosts. The original Windows hosts file is copied in as hosts and is used as is. Of course, I already cleaned mine up.
Very important:One entry per line. Yes you can stack multiple host entries in a hosts file but we are converting this to something you can import into the filtering section. This is what I meant by cleaning mine up already. Also, strip out anything you DON'T want to filter out, like legitimate server names and IP addresses in your local network. Otherwise they will be blocked by the filter.
I hope you find this script useful.