Advertisement
prazola

dnsmasq adblock for Alfie's DGND4000

Sep 7th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.13 KB | None | 0 0
  1. #!/bin/sh
  2. RED='\033[0;31m'
  3. GREEN='\033[0;32m'
  4. NC='\033[0m'
  5. LBLUE='\033[1;34m'
  6.  
  7. if /etc/amod/bin/cron check dnsmasq; then
  8.     echo "${GREEN}Cron    a posto!${NC}\n"
  9. else
  10.     /etc/amod/bin/cron add "30 13 * * * /mnt/shares/U/conf/dnsmasq_update_adblock.sh"
  11.     echo "${RED}Cron non era a posto: ${GREEN}sistemato!${NC}\n"
  12. fi
  13.  
  14. if amodfunc wanip >/dev/null 2>&1; then
  15.     echo "${GREEN}Online${NC}\n"
  16.     cd /mnt/shares/U/conf/
  17.  
  18.     echo "Downloading file from YoYo, SWC, MVPS${LBLUE}"
  19.     wget -O yoyo http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=0
  20.     wget -O swc http://someonewhocares.org/hosts/hosts
  21.     wget -O mvps http://winhelp2002.mvps.org/hosts.txt
  22.  
  23.     echo "${NC}Processing YoYo.org file"
  24.     cat yoyo | grep "127.0.0.1" | awk '{ print "127.0.0.1\t"$2 }' >> adblock
  25.     echo "Processing SomeoneWhoCares.org file"
  26.     cat swc | grep "127.0.0.1" | awk '{ print "127.0.0.1\t"$2 }' | grep -v "#" >> adblock
  27.     echo "Processing MVPS.org file"
  28.     cat mvps | grep 0.0.0.0 | grep -v "# 0.0.0.0" | awk '{ print "127.0.0.1\t"$2 }' >> adblock
  29.  
  30.     echo "Downloading file from Easylist${LBLUE}"
  31.     wget --no-check-certificate -O - https://easylist-downloads.adblockplus.org/easylistitaly+easylist.txt | grep ^\|\|[^\*]*\^$ | sed -e 's:||:127.0.0.1   :' -e 's:\^::' >> /mnt/shares/U/conf/adblock
  32.  
  33.     echo "${NC}Processing malicious sites list${LBLUE}"
  34.     wget --no-check-certificate -O - https://easylist-downloads.adblockplus.org/malwaredomains_full.txt | grep ^\|\|[^\*]*\^$ |sed -e 's:||:127.0.0.1   :' -e 's:\^::' >> /mnt/shares/U/conf/malware
  35.     sed -i "s/127.0.0.1/127.0.0.1 /g" malware
  36.  
  37.     [ -e mylist ] && {
  38.         echo "${NC}Merging mylist to adblock"
  39.     sed -i -e '$a\' adblock
  40.         cat mylist >> adblock
  41.     }
  42.     echo "${NC}Merging malwarelist to adblock"
  43.     sed -i -e '$a\' adblock
  44.     cat malware >> adblock
  45.  
  46.     echo "Writing changes to zone file"
  47.     tr '[A-Z]' '[a-z]' < adblock | sort -fu > adblock.uniq
  48.     rm yoyo swc mvps adblock malware
  49. else
  50.     echo "${RED}Offline"
  51. fi
  52.  
  53. killall -q -SIGHUP dnsmasq || {
  54.     echo "dnsmasq not running...${NC}"
  55.     /usr/etc/amod/init.d/dns start
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement