Difference between revisions of "Squid as ad blocker"
From LinuxMCE
(Created page with "This ad blocking is using [http://pgl.yoyo.org/adservers/] blocking lists. Install Squid as laid out in How to setup secure outbound web access Find the following line: # I...") |
m |
||
Line 36: | Line 36: | ||
# command to reload squid - change according to your system | # command to reload squid - change according to your system | ||
reloadcmd='restart squid' | reloadcmd='restart squid' | ||
− | + | ||
# temp file to use | # temp file to use | ||
tmpfile="/tmp/.adlist.$$" | tmpfile="/tmp/.adlist.$$" | ||
− | + | ||
# command to fetch the list (alternatives commented out) | # command to fetch the list (alternatives commented out) | ||
fetchcmd="wget -q $listurl -O $tmpfile" | fetchcmd="wget -q $listurl -O $tmpfile" | ||
Line 45: | Line 45: | ||
# log file | # log file | ||
logfile='/var/log/pluto/ad-blocker' | logfile='/var/log/pluto/ad-blocker' | ||
− | + | ||
## do things | ## do things | ||
## | ## | ||
Line 52: | Line 52: | ||
# get a fresh list of ad server addresses for squid to refuse | # get a fresh list of ad server addresses for squid to refuse | ||
$fetchcmd | $fetchcmd | ||
− | + | ||
# add the extras | # add the extras | ||
[ -f "$extrasfile" ] && cat $extrasfile >> $tmpfile | [ -f "$extrasfile" ] && cat $extrasfile >> $tmpfile | ||
− | + | ||
# check the temp file exists OK before overwriting the existing list | # check the temp file exists OK before overwriting the existing list | ||
if [ ! -s $tmpfile ] | if [ ! -s $tmpfile ] |
Revision as of 21:50, 22 December 2011
This ad blocking is using [1] blocking lists.
Install Squid as laid out in How to setup secure outbound web access
Find the following line: # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS Add these two lines below:
acl ads dstdom_regex -i "/etc/squid/squid.adservers.regex" http_access deny ads
Create a script file, e.g. nano /etc/cron.daily/getadblock.sh
#!/bin/sh ### short script that downloads a list of ad servers for use with squid to block ads. ### ### details on configuring squid itself can be found here: ### ### http://pgl.yoyo.org/adservers/#withsquid ### ### - originally by Stephen Patterson <steve@lexx.uklinux.net> ### - butchered by Peter Lowe <pgl@yoyo.org> ### - LMCE 10.04 adjustments by Joakim Lindbom ## set things # URL of the ad server list to download listurl='http://pgl.yoyo.org/adservers/serverlist.php?hostformat=squid-dstdom-regex;showintro=0&mimetype=plaintext' # location of the list of ad servers used by Squid targetfile='/etc/squid/squid.adservers.regex' # location of a file where hostnames not listed can be added extrasfile='/etc/squid/squid-extra.adservers' # command to reload squid - change according to your system reloadcmd='restart squid' # temp file to use tmpfile="/tmp/.adlist.$$" # command to fetch the list (alternatives commented out) fetchcmd="wget -q $listurl -O $tmpfile" # log file logfile='/var/log/pluto/ad-blocker' ## do things ## echo "$(date -R) Getting new refuse list" >> "$logfile" # get a fresh list of ad server addresses for squid to refuse $fetchcmd # add the extras [ -f "$extrasfile" ] && cat $extrasfile >> $tmpfile # check the temp file exists OK before overwriting the existing list if [ ! -s $tmpfile ] then echo "$(date -R) temp file '$tmpfile' either doesn't exist or is empty; quitting" >> "$logfile" exit fi cp $tmpfile $targetfile # clean up rm $tmpfile # restart Squid $reloadcmd
Make it executable:
chmod 755 /etc/cron.daily/getadblock.sh