Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # services-start by mark3748 August 30, 2015
- # original script by Todd Stein (toddbstein@gmail.com), Saturday, October 25, 2014 -- https://github.com/tablespoon/fun/blob/master/adblocker.sh
- # modified for use on ASUS-WRT routers running Merlin firmware
- # Periodically download lists of known ad and malware servers, and prevents traffic from being sent to them.
- # This is a complete rewrite of a script originally written by teffalump (https://gist.github.com/teffalump/7227752).
- HOST_LISTS="
- http://adaway.org/hosts.txt
- http://www.malwaredomainlist.com/hostslist/hosts.txt
- http://www.mvps.org/winhelp2002/hosts.txt
- http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&startdate%5Bday%5D=&startdate%5Bmonth%5D=&star
- "
- BLOCKLIST=/tmp/mnt/My_Passport/ADBLOCK/adblocker_hostlist
- BLACKLIST=/tmp/mnt/My_Passport/ADBLOCK/adblocker_blacklist
- WHITELIST=/tmp/mnt/My_Passport/ADBLOCK/adblocker_whitelist
- # get script's absolute path and escape spaces
- cd "${0%/*}"
- SCRIPT_NAME="$PWD/${0##*/}"
- SCRIPT_NAME="${SCRIPT_NAME// /' '}"
- cd "$OLDPWD"
- # await internet connectivity before proceeding (in case rc.local executes this script before connectivity is achieved)
- until ping -c1 -w3 google.com || ping -c1 -w3 yahoo.com; do
- sleep 5
- done &>/dev/null
- # initialize block list
- >"$BLOCKLIST"
- # grab blacklisted domains if any have been specified
- [ -s "$BLACKLIST" ] && awk '/^[^#]/ { print "0.0.0.0",$1 }' "$BLACKLIST" >>"$BLOCKLIST"
- # grab host lists from the internet
- wget -qO- $HOST_LISTS | grep -w ^0.0.0.0 | sed $'s/\r$//' | sort -u > "$BLOCKLIST"
- # remove any whitelisted domains from the block list
- if [ -s "$WHITELIST" ]; then
- # create a pipe-delimited list of all non-commented words in whitelist
- white_listed_regex=`echo \`grep -o '^[^#]\+' "$WHITELIST"\` | tr ' ' '|'`
- sed -ri "/$white_listed_regex/d" "$BLOCKLIST"
- fi
- # add IPv6 blocking
- sed -ri 's/([^ ]+)$/\1\n:: \1/' "$BLOCKLIST"
- # add block list to dnsmasq config
- cp $BLOCKLIST /jffs/dnsmasq.adblock.conf
- echo "#adblocking" > /tmp/mnt/My_Passport/ADBLOCK/dnsmasq.conf.add
- echo "address=/0.0.0.0/0.0.0.0" >> /jffs/configs/dnsmasq.conf.add
- echo "ptr-record=0.0.0.0.in-addr.arpa,0.0.0.0" >> /jffs/configs/dnsmasq.conf.add
- echo "addn-hosts=/tmp/mnt/My_Passport/ADBLOCK/dnsmasq.adblock.conf" >> /jffs/configs/dnsmasq.conf.add
- # restart dnsmasq service
- service restart_dnsmasq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement