Image: Ubuntu and DansGuardian--Great for Libraries!

Ubuntu Lucid and DansGuardian for
Filtering and Public Wireless Access

By John C. Rucker

This guide is a quick step-by-step guide to how I implement DansGuardian on Ubuntu systems. This one is all command-line with no hand-holding. For that, try some of my earlier tutorials. I may yet do another GUI-oriented, in-depth tutorial, if I get time.

Introduction

Below are my local install notes for putting together a DansGuardian filtering system on Ubuntu Lucid, including multiple filtering profiles and statistics. You'll need to be pretty comfortable with Linux and the command line to replicate this. But it's really nothing too complicated. Basic steps needing no explanation are omitted.

The Nitty-Gritty

$ sudo passwd root
$ su
# mv /etc/securetty /etc/securetty.bak
# touch /etc/securetty
# mv /etc/sudoers /etc/sudoers.bak
*******************************************************************************
                              NOTICE TO USERS

This computer system is the property of the Branch District Library.  It is
for authorized use only.  Users (authorized or unauthorized) have no explicit
or implicit expectation of privacy.

Any or all uses of this system and all files on this system may be intercepted,
monitored, recorded, copied, audited, inspected, and disclosed to authorized
officials of law enforcement and government agencies.

By using this system, the user consents to such interception, monitoring,
recording, auditing, inspection, and disclosure at the discretion of the Branch
District Library or other authorized officials of law enforcement or government
agencies.

Unauthorized or improper use of this system may result in civil and criminal
penalties and administrative or disciplinary action, as appropriate.  By
continuing to use this system you indicate your awareness of and consent to
these terms and conditions of use.  LOG OFF IMMEDIATELY if you do not agree to
the conditions stated in this notice.

*******************************************************************************
auto eth1
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway [gateway from eth0]
# mv /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.bak
authoritative;
default-lease-time 3600;
max-lease-time 3600;
ddns-update-style none;
log-facility local7;
option routers 192.168.1.1;
option domain-name-servers [your-DNS-1,yourDNS-2];

subnet [IP address of eth0] netmask 255.255.255.0 
{
}

subnet 192.168.1.1 netmask 255.255.255.0 
{
    range 192.168.1.100 192.168.1.254; # desired public service IP address range
    host [host name here] # host names for static IP assignment
    {
        hardware ethernet [MAC address];
        fixed-address [IP address];
    }
}
# cp /usr/share/doc/shorewall/default-config/* /etc/shorewall/
#ZONE   INTERFACE   BROADCAST   OPTIONS

net     eth0        detect
loc     eth1        detect      dhcp
eth0          192.168.1.0/24
eth0          192.168.40.0/24
loc         all         REJECT
fw          all         REJECT
net         all         DROP
all         all         REJECT
# Accept SSH connections for administration
ACCEPT      loc                     fw      tcp     22
ACCEPT      net                     fw      tcp     22

# Accept HTTP for the wifi stats
ACCEPT      loc                     fw      tcp     80
ACCEPT      net                     fw      tcp     80

# All pinging the web filter
ACCEPT      loc        net        icmp
        
# Allow DNS requests
ACCEPT      loc        net        tcp     53
ACCEPT      loc        net        udp     53 

# Allow POP3 email
ACCEPT      loc        net        tcp     110

# Allow NTP (Network Time Protocol)
ACCEPT      loc        net        udp     123

# Allow IMAP email
ACCEPT      loc        net        tcp     143   
        
# Allow secure web sites
ACCEPT      loc        net        tcp     443

# Secure SMTP
ACCEPT      loc                     net     tcp     465

# Allow DHCP requests
ACCEPT      loc        fw         tcp     546,547
ACCEPT      loc        fw         udp     67,68

# smtp submission
ACCEPT      loc                     net     tcp     587

# Allow Secure IMAP email
ACCEPT      loc        net        tcp    993

# Allow Secure POP3 email
ACCEPT      loc        net        tcp    995

# Allow both sides of the firewall to access the filter
ACCEPT      net       fw          tcp    8080

# Route all HTTP traffic from patron laptops to the passive filter
REDIRECT    loc        8080       tcp    80,8000,8001,8080

#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE
fw      firewall
net     ipv4
loc     ipv4
# shorewall restart
########Squid Delay Pools#########
# a simple global throttle, users sharing 5 Mbit/s
delay_pools 1
delay_class 1 1
# 5 Mbit/s fill rate, 6 Mbit/s reserve
delay_parameters 1 655360/786432
acl All src 0/0
delay_access 1 allow All
# ln -s /usr/sbin/dansguardian /usr/sbin/dansguardian1
# ln -s /usr/sbin/dansguardian /usr/sbin/dansguardian2
# ln -s /usr/sbin/dansguardian /usr/sbin/dansguardian3
# mkdir /etc/dansguardian1
# mkdir /etc/dansguardian2
# mkdir /etc/dansguardian3
# mkdir /var/log/dansguardian1
# mkdir /var/log/dansguardian2
# mkdir /var/log/dansguardian3
# chown dansguardian:dansguardian /etc/dansguardian1
# chown dansguardian:dansguardian /etc/dansguardian2
# chown dansguardian:dansguardian /etc/dansguardian3
# chown dansguardian:dansguardian /var/log/dansguardian1
# chown dansguardian:dansguardian /var/log/dansguardian2
# chown dansguardian:dansguardian /var/log/dansguardian3
# cp /etc/dansguardian/dansguardian.conf /etc/dansguardian1/
# cp /etc/dansguardian/dansguardian.conf /etc/dansguardian2/
# cp /etc/dansguardian/dansguardian.conf /etc/dansguardian3/
# cp /etc/dansguardian/dansguardianf1.conf /etc/dansguardian1/
# cp /etc/dansguardian/dansguardianf1.conf /etc/dansguardian2/
# cp /etc/dansguardian/dansguardianf1.conf /etc/dansguardian3/
# ln -s /etc/dansguardian/authplugins /etc/dansguardian1/authplugins
# ln -s /etc/dansguardian/authplugins /etc/dansguardian2/authplugins
# ln -s /etc/dansguardian/authplugins /etc/dansguardian3/authplugins
# ln -s /etc/dansguardian/contentscanners /etc/dansguardian1/contentscanners
# ln -s /etc/dansguardian/contentscanners /etc/dansguardian2/contentscanners
# ln -s /etc/dansguardian/contentscanners /etc/dansguardian3/contentscanners
# ln -s /etc/dansguardian/downloadmanagers /etc/dansguardian1/downloadmanagers
# ln -s /etc/dansguardian/downloadmanagers /etc/dansguardian2/downloadmanagers
# ln -s /etc/dansguardian/downloadmanagers /etc/dansguardian3/downloadmanagers
# ln -s /etc/dansguardian/languages /etc/dansguardian1/languages
# ln -s /etc/dansguardian/languages /etc/dansguardian2/languages
# ln -s /etc/dansguardian/languages /etc/dansguardian3/languages
# ln -s /etc/dansguardian/lists /etc/dansguardian1/lists
# ln -s /etc/dansguardian/lists /etc/dansguardian2/lists
# ln -s /etc/dansguardian/lists /etc/dansguardian3/lists
# ln -s /usr/sbin/dansguardian /usr/sbin/dansguardian1; ln -s /usr/sbin/dansguardian /usr/sbin/dansguardian2; ln -s /usr/sbin/dansguardian /usr/sbin/dansguardian3; mkdir /etc/dansguardian1; mkdir /etc/dansguardian2; mkdir /etc/dansguardian3; mkdir /var/log/dansguardian1; mkdir /var/log/dansguardian2; mkdir /var/log/dansguardian3; chown dansguardian:dansguardian /etc/dansguardian1; chown dansguardian:dansguardian /etc/dansguardian2; chown dansguardian:dansguardian /etc/dansguardian3; chown dansguardian:dansguardian /var/log/dansguardian1; chown dansguardian:dansguardian /var/log/dansguardian2; chown dansguardian:dansguardian /var/log/dansguardian3; cp /etc/dansguardian/dansguardian.conf /etc/dansguardian1/; cp /etc/dansguardian/dansguardian.conf /etc/dansguardian2/; cp /etc/dansguardian/dansguardian.conf /etc/dansguardian3/; cp /etc/dansguardian/dansguardianf1.conf /etc/dansguardian1/; cp /etc/dansguardian/dansguardianf1.conf /etc/dansguardian2/; cp /etc/dansguardian/dansguardianf1.conf /etc/dansguardian3/; ln -s /etc/dansguardian/authplugins /etc/dansguardian1/authplugins; ln -s /etc/dansguardian/authplugins /etc/dansguardian2/authplugins; ln -s /etc/dansguardian/authplugins /etc/dansguardian3/authplugins; ln -s /etc/dansguardian/contentscanners /etc/dansguardian1/contentscanners; ln -s /etc/dansguardian/contentscanners /etc/dansguardian2/contentscanners; ln -s /etc/dansguardian/contentscanners /etc/dansguardian3/contentscanners; ln -s /etc/dansguardian/downloadmanagers /etc/dansguardian1/downloadmanagers; ln -s /etc/dansguardian/downloadmanagers /etc/dansguardian2/downloadmanagers; ln -s /etc/dansguardian/downloadmanagers /etc/dansguardian3/downloadmanagers; ln -s /etc/dansguardian/languages /etc/dansguardian1/languages; ln -s /etc/dansguardian/languages /etc/dansguardian2/languages; ln -s /etc/dansguardian/languages /etc/dansguardian3/languages; ln -s /etc/dansguardian/lists /etc/dansguardian1/lists; ln -s /etc/dansguardian/lists /etc/dansguardian2/lists; ln -s /etc/dansguardian/lists /etc/dansguardian3/lists;
# cd /etc/init.d/
# mv dansguardian dansguardian.orig
# update-rc.d dansguardian remove
#! /bin/sh
# Startup script for dansguardian
#
# description: A web content filtering plugin for web \
#              proxies, developed to filter using lists of \
#              banned phrases, MIME types, filename \
#              extensions and PICS labling.
# processname: dansguardian1
# pidfile: /var/run/dansguardian1.pid
# config: /etc/dansguardian1/dansguardian.conf

CONFFILELOCATION=/etc/dansguardian1/
BINARYLOCATION=/usr/sbin/
PIDDIR=/var/run/

# See how we were called

case "$1" in
start)
        if [ -f ${BINARYLOCATION}dansguardian1 ] &&
           [ -f ${CONFFILELOCATION}dansguardian.conf ]; then
                echo " * Starting dansguardian1..."
                if ${BINARYLOCATION}dansguardian1 -c /etc/dansguardian1/dansguardian.conf 2> /dev/null; then
                        echo "                                          [ ok ]"
                        touch /var/lock/dansguardian1
                else
                        echo "                                       [ FAILED ]"
                fi
        fi
        ;;
stop)
        echo " * Shutting down dansguardian1..."
        if ${BINARYLOCATION}dansguardian1 -c /etc/dansguardian1/dansguardian.conf -q 2> /dev/null; then
                echo "                                          [ ok ]"
                /bin/rm -f ${PIDDIR}dansguardian1.pid
                /bin/rm -f /tmp/.dguardian1ipc
                /bin/rm -f /var/lock/dansguardian1
        else
                echo "                                      [ FAILED ]"
        fi
        ;;
reload|restart)
        $0 stop
        sleep 3
        $0 start
        ;;
status)
        if [ -f ${BINARYLOCATION}dansguardian1 ]; then ${BINARYLOCATION}dansguardian1 -c /etc/dansguardian1/dansguardian.conf -s
        fi
        ;;
*)
        echo "Usage: {start|stop|restart|status}" >&2
        ;;
esac

exit 0
# cd /etc/init.d/
# chmod +x dansguardian*
# update-rc.d dansguardian1 defaults 50 19
# update-rc.d dansguardian2 defaults 50 19
# update-rc.d dansguardian3 defaults 50 19
# /etc/init.d/dansguardian1 start
# /etc/init.d/dansguardian2 start
# /etc/init.d/dansguardian3 start
# mysql -u root -p
mysql> CREATE DATABASE IF NOT EXISTS `wifi_stats` DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;quit;
# mysql -u root -p wifi_stats < old_exported_wifi_stats.sql
# mysql -u root -p wifi_stats < wifi_stats.sql
1 *  *   *   *     wget http://localhost/DHCPd-parse.php -O /dev/null > /dev/null 2>&1
1 *  *   *   *     /etc/init.d/dansguardian1 restart
1 *  *   *   *     /etc/init.d/dansguardian2 restart
1 *  *   *   *     /etc/init.d/dansguardian3 restart
# mv /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.bak
UPSCABLE usb
UPSTYPE usb
DEVICE
LOCKFILE /var/lock
SCRIPTDIR /etc/apcupsd
PWRFAILDIR /etc/apcupsd
NOLOGINDIR /etc
ONBATTERYDELAY 6
BATTERYLEVEL 5
MINUTES 3
TIMEOUT 60
ANNOY 0
ANNOYDELAY 10
NOLOGON disable
KILLDELAY 0
NETSERVER on
NISIP 127.0.0.1
NISPORT 3551
EVENTSFILE /var/log/apcupsd.events
EVENTSFILEMAX 10
UPSCLASS standalone
UPSMODE disable
STATTIME 0
STATFILE /var/log/apcupsd.status
LOGSTATS off
DATATIME 0

Conclusion

And that is all! Reboot and make sure everything comes back up the way it should.


Originally published on 11 November 2011. Last modified on 2 June 2015.
Copyright © 2011 John C. Rucker
Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved.