#!/bin/sh ## router IP address router_ip_address=192.168.1.1 ## black-listed domains blacklist=~/blocked-domains ## ~/blocked-domains is a list of domains to block, one per line ## after a space or tab, comments can be used: ## adserver.com all ads, all the time ## adblock-wrt54g ## (c) atom@smasher.org, 5 Sep 2006 ## PGP = 762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808 ## distributed under GPL - http://www.gnu.org/copyleft/gpl.html ## some builds of DD-WRT v24-sp1 have a bug that starts multiple ## dnsmasq processes, and causes blocked sites to only be blocked ## for a minute or two. if that happens, it's probably easiest to ## install a different DD-WRT build. ## the black-list is in "~/blocked-domains" ## format the list into a dnsmasq.conf file and write to the temp file #awk '{print "address=/"$1"/127.0.0.1"}' < ~/blocked-domains > /tmp/${tmp} ## make a backup copy of the original dnsmasq.conf, if a backup doesn't exist ## append the formatted block list to dnsmasq.conf ## kill and restart dnsmasq awk '$1 ~ /./ {print "address=/"$1"/127.0.0.1"}' < ${blacklist} | \ ssh root@${router_ip_address} '[ -f /tmp/dnsmasq.conf.orig ] && \ cp /tmp/dnsmasq.conf.orig /tmp/dnsmasq.conf || \ cp /tmp/dnsmasq.conf /tmp/dnsmasq.conf.orig cat - >> /tmp/dnsmasq.conf && \ killall dnsmasq dnsmasq --conf-file=/tmp/dnsmasq.conf'