Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save acabrol/3d1b9586150d3a1dfc40276c540ea2b8 to your computer and use it in GitHub Desktop.
Save acabrol/3d1b9586150d3a1dfc40276c540ea2b8 to your computer and use it in GitHub Desktop.
Script to automate install of Dansguardian with Squid as transparent proxy on Ubuntu without iptables (assuming that proxy is used by a router)
#!/bin/bash
#based on https://help.ubuntu.com/community/DansGuardian
#refresh repositories
sudo apt-get update
# install packages
sudo apt-get install clamav-freshclam dansguardian squid curl
#turn squid into transparent proxy
sudo sed -i 's/http_port 3128/http_port 3128 transparent/g' /etc/squid/squid.conf
#always direct allow all
sudo sed -i 's/# always_direct allow local-servers/always_direct allow all/g' /etc/squid/squid.conf
#start squid
sudo service squid start
#configure dansguardian
sudo sed -i 's/^UNCONFIGURED .*$/g' /etc/dansguardian/dansguardian.conf
#configure blacklists
curl ftp://ftp.ut-capitole.fr/pub/reseau/cache/squidguard_contrib/blacklists.tar.gz| tar -xzf - -C /etc/dansguardian/lists/blacklists blacklists/
find /etc/dansguardian/lists/blacklists/ -type f -iname "domains"|sed 's/^\(.*\)$/.Include<\1>/g'>/etc/dansguardian/lists/bannedsitelist
find /etc/dansguardian/lists/blacklists/ -type f -iname "urls"|sed 's/^\(.*\)$/.Include<\1>/g'>/etc/dansguardian/lists/bannedurllist
#start dansguardian
sudo service dansguardian start
#refresh list
sudo dansguardian -r
#configure crontab
echo "
00 00 * * * curl ftp://ftp.ut-capitole.fr/pub/reseau/cache/squidguard_contrib/blacklists.tar.gz| tar -xzf - -C /etc/dansguardian/lists/blacklists blacklists/
05 00 * * * find /etc/dansguardian/lists/blacklists/ -type f -iname 'domains'|sed 's/^\(.*\)$/.Include<\1>/g'>/etc/dansguardian/lists/bannedsitelist
10 00 * * * find /etc/dansguardian/lists/blacklists/ -type f -iname 'urls'|sed 's/^\(.*\)$/.Include<\1>/g'>/etc/dansguardian/lists/bannedurllist
15 00 * * * dansguardian -r" >/tmp/crontab
#set crontab
crontab /tmp/crontab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment