Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
101
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None
  1. #!/bin/sh
  2.  
  3. ### short script that downloads a list of ad servers for use with
  4. ### dnsmasq to block ads.
  5. ###
  6.  
  7. # the ipaddress where we want to send the requests to, instead of the
  8. # bannerservers
  9.  
  10. addcatcherip='192.168.1.1'
  11. configfile=/etc/dnsmasq.d/adblock
  12.  
  13. # the args to add to the request to the yoyo server, to tell it that we want
  14. # a hosts file and that we want to redirect to the addcatcher
  15. listurlargs="hostformat=nohtml&showintro=0&mimetype=plaintext"
  16.  
  17. # URL of the ad server list to download
  18. listurl="http://pgl.yoyo.org/adservers/serverlist.php?${listurlargs}"
  19.  
  20. # location of a file where hostnames not listed can be added
  21. extrasfile='/etc/banner_add_hosts.manual'
  22.  
  23. ## command to reload dnsmasq - change according to your system
  24. ## not sure if we need this for dnsmasq
  25. reloadcmd='/etc/init.d/dnsmasq restart'
  26.  
  27. # temp files to use
  28. tmpfile="/tmp/.adlist.$$"
  29. tmpconffile="/tmp/.dnsmasq.conf.$$"
  30.  
  31. # command to fetch the list (alternatives commented out)
  32. fetchcmd="/usr/bin/wget -q -O $tmpfile $listurl"
  33.  
  34. $fetchcmd
  35.  
  36. # add the extras
  37. [ -f "$extrasfile" ] && cat $extrasfile >> $tmpfile
  38.  
  39. # check the temp file exists OK before overwriting the existing list
  40. if [ ! -s $tmpfile ]
  41. then
  42. echo "temp file '$tmpfile' either doesn't exist or is empty; quitting"
  43. exit
  44. fi
  45.  
  46. # get a fresh list of ad server addresses for dnsmasq to refuse
  47. cat $configfile | grep -v "address=" > $tmpconffile
  48.  
  49. while read line; do
  50. ADDRESS="/${line}/${addcatcherip}"
  51. echo "address=\"${ADDRESS}\"" | grep -v linksynergy >> $tmpconffile
  52. done < $tmpfile
  53.  
  54. mv $tmpconffile $configfile
  55. $reloadcmd
  56. rm $tmpfile
  57. exit
Advertisement
RAW Paste Data Copied
Advertisement