Installing & Configuring UFDBGuard

And finally we need to install & Configure UFDBGuard.

First, we need to get the source for UFDBGuard (There is a .deb package if you prefer, but I prefer compiling it myself). CD to your home directory cd ~ where the build folder from our squid installation is located.
And then cd into Build. The run wget as in the picture above.

Extract the package after it’s been downloaded.

We also need to install some dependencies.

Then cd into the extracted source directory.

Run ./configure

Once that is done, run make && make install

And that’s the installation done. Now for configuration.

Firstly, let’s rename the default config file, and open a
new file as the config file – since we’ll be using the one I’ll be providing.

Paste the contents below – changing details to match your
environment, into that file and save & exit.

# Email for handling unblock requests

administrator “<a href=%22 mailto:admin@domain.com %22> Log
an Unblock Request </a>”

 

dbhome “/usr/local/ufdbguard/blacklists”

logdir “/usr/local/ufdbguard/logs”

logblock on

logpass off

logall off

squid-version “4.0”

squid-uses-active-bumping on

url-lookup-result-during-database-reload allow

url-lookup-result-when-fatal-error allow

analyse-uncategorised-urls off

ufdb-log-url-details off

ufdb-show-url-details off

check-proxy-tunnels off

safe-search off

youtube-edufilter off

youtube-edufilter-id “ABCD1234567890abcdef”

max-logfile-size  200000000

redirect-https “https://192.168.8.2:10443/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

#http-server { port = 8081, interface = all, images =
/usr/local/ufdbguard/images }

external-status-command “/usr/local/bin/mailx”

mail-server “mailserver.mydomain.com”

admin-email “admin@mydomain.com”

 

# Define the network that contain computer systems that need URL
filtering

 

source AllSystems {

 

ip  192.168.8.0/24

 

}

 

# define the security category

category security {

#   domainlist      “security/domains”

#   expressionlist  “security/expressions”

#   cacerts         “security/cacerts”

    option          enforce-https-with-hostname off

    option          enforce-https-official-certificate off

    option          https-prohibit-insecure-sslv2 on

    option        allow-aim-over-https on

    option        allow-gtalk-over-https on

    option        allow-skype-over-https on

    option        allow-yahoomsg-over-https on

    option        allow-fb-chat-over-https on

    option        allow-citrixonline-over-https on

    option        allow-unknown-protocol-over-https on

   redirect       
“302:https://192.168.8.2:10443/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category safesearch-on {

         option safe-search on

}

 

category safesearch-off {

         option safe-search off

}

 

category alwaysallow {

        domainlist alwaysallow/domains

        redirect
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category alwaysblock {

        domainlist alwaysblock/domains

        redirect “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category ads {

   domainlist      “ads/domains” # Email for handling
unblock requests

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category porn {

   domainlist      “adult/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category arjel {

   domainlist      “arjel/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category astrology {

   domainlist      “astrology/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category audiovideo {

   domainlist      “audio-video/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category bank {

   domainlist      “bank/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category blog {

   domainlist      “blog/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category celebrity {

   domainlist      “celebrity/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

category chat {

   domainlist      “chat/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category child {

   domainlist      “child/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category cleaning {

   domainlist      “cleaning/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category cooking {

   domainlist      “cooking/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category dangermat {

   domainlist      “dangermat/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category dating {

   domainlist      “dating/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category drugs {

   domainlist      “drugs/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category filehosting {

   domainlist      “filehosting/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category financial {

   domainlist      “financial/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category forums {

   domainlist      “forums/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category gambling {

   domainlist      “gambling/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category games {

   domainlist      “games/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category hacking {

   domainlist      “hacking/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category jobsearch {

   domainlist      “jobsearch/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category lingerie {

   domainlist      “lingerie/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category liste_bu {

   domainlist      “liste_bu/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category malware {

   domainlist      “malware/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category manga {

   domainlist      “manga/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category marketingware {

   domainlist      “marketingware/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category mixed_adult {

   domainlist      “mixed_adult/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category mobile-phone {

   domainlist      “mobile-phone/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category phishing {

   domainlist      “phishing/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category press {

   domainlist      “press/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category proxy {

   domainlist      “proxy/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category radio {

   domainlist      “radio/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category reaffected {

   domainlist      “reaffected/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category remote-control {

   domainlist      “remote-control/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category sect {

   domainlist      “sect/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category sex_ed {

   domainlist      “sex_ed/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category shopping {

   domainlist      “shopping/domains”

   redirect        “http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category social_networks {

   domainlist      “social_networks/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category sports {

   domainlist      “sports/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category strict_redir {

   domainlist      “strict_redir/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category strong_redir {

   domainlist      “strong_redir/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category tricheur {

   domainlist      “tricheur/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category warez {

   domainlist      “warez/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

category webmail {

   domainlist      “webmail/domains”

   redirect       
“http://192.168.8.2:1080/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

# define web content access rights, Put a questionmark in front of
catagories you want blocked

acl {

 

 

   AllSystems {

 

           pass safesearch-on alwaysallow !alwaysblock

           !ads !porn !arjel !astrology !celebrity !child

           !cooking !dangermat !dating !drugs !gambling games

           !hacking !jobsearch !lingerie !malware !manga !marketingware

           !mixed_adult !mobile-phone !phishing proxy !reaffected !social_networks

           !remote-control !sex_ed !sports !strict_redir !strong_redir
!tricheur !warez

           audiovideo bank blog chat cleaning filehosting financial
forums press sect shopping webmail radio liste_bu security any

}

 

 

### the next acl is a mandatory fallback for all other cases.

   ### do NOT remove this ACL.

 

 

 default {

           pass !ads !porn !arjel !astrology !celebrity !child

           !cooking !dangermat !dating !drugs !gambling !games

           !hacking !jobsearch !lingerie !malware !manga
!marketingware

           !mixed_adult !mobile-phone !phishing !proxy !reaffected

           !remote-control !sex_ed !sports !strict_redir

           !strong_redir !tricheur !warez

           audiovideo bank blog chat cleaning filehosting financial
forums press sect shopping webmail radio liste_bu social_networks any

           redirect
“http://cgibin.urlfilterdb.com/cgi-bin/URLblocked.cgi?admin=%A&color=orange&size=normal&clientaddr=%a&clientname=%n&clientuser=%i&clientgroup=%s&category=%t&url=%u”

}

 

}

Next up, we need to create our Exceptions directories and
files. First change directory – cd /usr/local/ufdbguard.These are
for any exceptions to the blacklists we’ll be using. So for example, facebook
is part of the social networks category, and we want to block that, but only
allow facebook, we’d put facebook.com (as typed there), in the
alwaysallow/domains file.

Next, create a new directory for 2 scripts we need to
create, you can create it anywhere.

The first script converts & imports our exception
blacklists to ufdbguard’s blacklist format, then restarts ufdbguard to apply
the changes.

Type out the above & save & exit

Then make the script executable.

The second script downloads our squidguard blacklists &
does the same for them.

Type out the above & save and exit.

Then make the script executable.

Then execute the script.

Next we need to enable ufdbguard during system startup.

And finally, we need to copy our block page CGI script to
the /var/www/cgi-bin directory. This is the page that is displayed when a
website is blocked.

Now reboot. At this point you can change your DHCP server
settings to dish out the Proxy server as your Default Gateway – instead of your
Firewall / Router.

And we’re done!
Now for some testing.