Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ### short script that downloads a list of ad servers for use with
- ### dnsmasq to block ads.
- ###
- # the ipaddress where we want to send the requests to, instead of the
- # bannerservers
- addcatcherip='192.168.1.1'
- configfile=/etc/dnsmasq.d/adblock
- # the args to add to the request to the yoyo server, to tell it that we want
- # a hosts file and that we want to redirect to the addcatcher
- listurlargs="hostformat=nohtml&showintro=0&mimetype=plaintext"
- # URL of the ad server list to download
- listurl="http://pgl.yoyo.org/adservers/serverlist.php?${listurlargs}"
- # location of a file where hostnames not listed can be added
- extrasfile='/etc/banner_add_hosts.manual'
- ## command to reload dnsmasq - change according to your system
- ## not sure if we need this for dnsmasq
- reloadcmd='/etc/init.d/dnsmasq restart'
- # temp files to use
- tmpfile="/tmp/.adlist.$$"
- tmpconffile="/tmp/.dnsmasq.conf.$$"
- # command to fetch the list (alternatives commented out)
- fetchcmd="/usr/bin/wget -q -O $tmpfile $listurl"
- $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 "temp file '$tmpfile' either doesn't exist or is empty; quitting"
- exit
- fi
- # get a fresh list of ad server addresses for dnsmasq to refuse
- cat $configfile | grep -v "address=" > $tmpconffile
- while read line; do
- ADDRESS="/${line}/${addcatcherip}"
- echo "address=\"${ADDRESS}\"" | grep -v linksynergy >> $tmpconffile
- done < $tmpfile
- mv $tmpconffile $configfile
- $reloadcmd
- rm $tmpfile
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement