Advertisement
Guest User

block ads with unbound

a guest
Nov 15th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.55 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ## Clean up any stale tempfile
  4. echo "Removing old files..."
  5. [ -f /tmp/hosts.working ] && rm -f /tmp/hosts.working
  6.  
  7. ## Awk regex to be inverse-matched as whitelist
  8. # - Project Wonderful does unobtrusive ads on a lot of webcomics
  9. # - SolveMedia is needed for captchas on some websites
  10. whitelist='/(api.solvemedia.com)/'
  11.  
  12. # All Blacklists
  13. blacklist='http://winhelp2002.mvps.org/hosts.txt http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext https://adaway.org/hosts.txt https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts https://mirror1.malwaredomains.com/files/justdomains http://sysctl.org/cameleon/hosts https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt https://hosts-file.net/ad_servers.txt'
  14.  
  15. ## Fetch all Blacklist Files
  16. echo "Fetching Blacklists..."
  17. for url in $blacklist; do
  18.     curl --silent $url >> "/tmp/hosts.working"
  19. done
  20.  
  21. ## Process Blacklist, Eliminiating Duplicates, Integrating Whitelist, and Converting to unbound format
  22. echo "Processing Blacklist..."
  23. awk -v whitelist="$whitelist" '$1 ~ /^127\.|^0\./ && $2 !~ whitelist {gsub("\r",""); print tolower($2)}' /tmp/hosts.working | sort | uniq | \
  24. awk '{printf "server:\n", $1; printf "local-data: \"%s A 0.0.0.0\"\n", $1}' > /var/unbound/ad-blacklist.conf
  25.  
  26. # Clean up tempfile
  27. echo "Cleaning Up..."
  28. rm -f '/tmp/hosts.working'
  29. echo "Done. Please Restart the DNS Resolver service from the WebUI."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement