-
-
Save markstinson/6008a152cdcc842cd15c2fc83956a697 to your computer and use it in GitHub Desktop.
adblock for OpenWrt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh /etc/rc.common | |
START=90 | |
H1='http://www.malwaredomainlist.com/hostslist/hosts.txt' | |
H2='http://winhelp2002.mvps.org/hosts.txt' | |
H3='http://sysctl.org/cameleon/hosts.win' | |
H4='http://pgl.yoyo.org/as/serverlist.php?hostformat=hosts&showintro=1&mimetype=plaintext' | |
WWW2=/var/www2 | |
GIF=blank.gif | |
LAN_IP=$(uci get network.lan.ipaddr) | |
LAN2=br-lan:1 | |
LAN2_IP=10.3.5.3 | |
H_TMP=/tmp/hosts.tmp | |
H=/var/hosts/hosts.bad | |
DM=/etc/init.d/dnsmasq | |
UH=/etc/init.d/uhttpd | |
UH_CONF=/etc/config/uhttpd | |
ssd=start-stop-daemon | |
UPID=/var/run/uhttpd_www2.pid | |
start() { | |
if ping -c 1 `wget -qO- http://ipecho.net/plain`; then | |
case $LAN_IP in 10.3.*) LAN2_IP=10.4.6.4 ;; esac | |
if ! ifconfig |grep $LAN2 > /dev/null 2>&1; then | |
ifconfig $LAN2 inet $LAN2_IP netmask 255.255.255.255 | |
fi | |
sed -i "s/0\.0\.0\.0/$LAN_IP/;s/$LAN2_IP/$LAN_IP/" $UH_CONF | |
if [ ! -d $WWW2 ]; then | |
mkdir -p $WWW2 | |
fi | |
if [ ! -f $WWW2/$GIF ]; then | |
echo -ne 'GIF89a1010\x8000\xff\xff\xff000!\xf9\x0400000,000010100\x02\x02D10;' | tr 01 '\000\001' > $WWW2/$GIF | |
fi | |
if ! ps |grep uhttpd |grep $WWW2 > /dev/null 2>&1; then | |
$ssd -Sqbmp $UPID -x uhttpd -- -f -h $WWW2 -E /$GIF -I $GIF -p $LAN2_IP:80 | |
if ! ps |grep uhttpd |grep $WWW2 > /dev/null 2>&1; then | |
$UH restart | |
$ssd -Sqbmp $UPID -x uhttpd -- -f -h $WWW2 -E /$GIF -I $GIF -p $LAN2_IP:80 | |
fi | |
fi | |
wget -qO- $H1 >> $H_TMP | |
wget -qO- $H2 >> $H_TMP | |
wget -qO- $H3 >> $H_TMP | |
wget -qO- $H4 >> $H_TMP | |
sed -i '/localhost/d;s/^0\.0\.0\.0.//;s/^127\.0\.0\.1.//;s/[[:cntrl:]]$//;s/[[:cntrl:]]$/ /;/^#/d;/^$/d;s/[[:space:]]*#.*$//;s/^ //;s/^ //;s|^|'$LAN2_IP' |' $H_TMP | |
rm -f $H | |
sort $H_TMP|uniq > $H | |
rm -f $H_TMP | |
$DM restart | |
sleep 6h && start | |
else | |
sleep 10 && start >> /dev/null 2>&1 & | |
fi >> /dev/null 2>&1 & | |
} | |
stop() { | |
if ps |grep uhttpd |grep $WWW2 > /dev/null 2>&1; then | |
$ssd -Kqs HUP -p $UPID | |
rm -f $UPID | |
rm -rf $WWW2 | |
fi | |
if ifconfig |grep $LAN2 > /dev/null 2>&1; then | |
ifconfig $LAN2 down | |
fi | |
if [ -f $H ]; then | |
rm -f $H | |
$DM restart | |
fi | |
for KILLPID in `ps | grep 'adblock' | awk ' { print $1;}'`; do | |
kill -9 $KILLPID; | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment