Last active
September 7, 2016 18:04
-
-
Save aarmot/5730468 to your computer and use it in GitHub Desktop.
Adblock skript for OpenWrt. Tested on Attitude Adjustment 12.09
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 | |
# Copy this skript to /etc/init.d/adblock and enable: | |
# chmod +x /etc/init.d/adblock | |
# /etc/init.d/adblock enable | |
START=90 | |
ADS='http://pgl.yoyo.org/as/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext' | |
WWW2="/tmp/www2" | |
GIF1="1.gif" | |
DM_CONF=/var/etc/dnsmasq.conf | |
DM_BAD=/var/etc/dnsmasq.bad | |
ssd=start-stop-daemon | |
UPID1=/var/run/uhttpd_main.pid | |
UPID2=/var/run/uhttpd_www2.pid | |
UH=/usr/sbin/uhttpd | |
start() { | |
mkdir -p $WWW2 | |
echo -ne 'GIF89a1010\x8000\xff\xff\xff000!\xf9\x0400000,000010100\x02\x02D10;' | tr 01 '\000\001' > $WWW2/$GIF1 | |
# Choose an unused IP | |
ip=$(uci get network.lan.ipaddr) | |
ip2=10.3.5.3 | |
case $ip in 10.3.*) ip2=10.4.6.4 ;; esac | |
ifconfig br-lan:1 inet $ip2 netmask 255.255.255.255 | |
# Restart uhttpd to listen only LAN | |
if [ -f "$UPID1" ]; then | |
uargs="$(cat /proc/$(cat $UPID1)/cmdline | tr '\000' ' ' | cut -d ' ' -f 2- )" | |
if echo "$uargs" | grep -q '0.0.0.0'; then | |
uargs=$(echo $uargs | sed -e "s/0\.0\.0\.0/$ip/") | |
$ssd -Kqs HUP -p $UPID1 | |
sleep 1 | |
$ssd -Sqbmp $UPID1 -x $UH -- $uargs | |
fi | |
fi | |
# Start another uhttpd | |
$ssd -Sqbmp $UPID2 -x $UH -- -f -h $WWW2 -E /$GIF1 -I $GIF1 -p $ip2:80 | |
# Add rules to dnsmasq | |
wget -qO $DM_BAD "$ADS" && sed -i -e "s/127\.0\.0\.1/$ip2/" $DM_BAD | |
if [ -f $DM_CONF -a -f $DM_BAD ] && ! grep -q $DM_BAD $DM_CONF; then | |
$ssd -Kqn dnsmasq | |
sleep 1 | |
echo "conf-file=$DM_BAD" >> $DM_CONF | |
$ssd -Sqx dnsmasq -- -C $DM_CONF | |
fi | |
} | |
stop() { | |
$ssd -Kqs HUP -p $UPID2 | |
} |
Thanks for feedback! I tried specifically to be terse in comments, to keep the script small. In case you have questions about specific parts of the script I'm glad to answer them in OpenWRT thread you mentioned. Suggestions about good quality (but compact) blacklists are also welcome.
Thanks!
Here is my suggestion https://gist.github.com/someon/9609363
This script run in background and updates bad hosts list every 6 hours.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this have some more optional https://forum.openwrt.org/viewtopic.php?id=35023&p=2