Ad-blocking with DD-WRT

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page Previous  1, 2, 3 ... 16, 17, 18, 19  Next
Author Message
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Wed Nov 19, 2008 18:54    Post subject: Reply with quote
It seems there has been this variable all along:

Code:
nvram set http_lanport=8888


So, there's no need for killing httpd
You just need to start one....

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
Sponsor
mazilo
DD-WRT User


Joined: 10 Jun 2006
Posts: 385

PostPosted: Sun Nov 23, 2008 20:25    Post subject: Reply with quote
frater wrote:
I think this is even a bit more cleaner....

Code:
echo -e "#!/bin/sh\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | awk '{print \$1\"\\\t\"\$2}' | sed -e 's/127.0.0.1/0.0.0.0/g' | grep -v localhost >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\tif [ \"\`grep -c doubleclick /tmp/dlhosts\`\" -ne \"0\" ]; then\n\t\tbreak\n\tfi\n\tsleep 60\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

Instead of having awk to print $1 (127.0.0.1), why not just set awk to print 0.0.0.0 as shown below?
Code:
echo -e "#!/bin/sh\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | awk '{print \0.0.0.0\"\\\t\"\$2}' | grep -v localhost >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\tif [ \"\`grep -c doubleclick /tmp/dlhosts\`\" -ne \"0\" ]; then\n\t\tbreak\n\tfi\n\tsleep 60\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

_________________
Mazi
UK non-geo DID #: +447031942574
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Mon Nov 24, 2008 0:47    Post subject: Reply with quote
Yes, not needed.
But at that moment I wrote that I was in the process of rewriting someone else's code and already changed a lot of its concept.
That wasn't the latest anyhow

Removing of ^M is still needed to save space...

Code:
rogue=192.168.10.5
echo -e "#!/bin/sh\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"$rogue\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \"\`grep -c doubleclick /tmp/dlhosts\`\" -ne \"0\" ] && break\n\tsleep 60\ndone\n[ -e /jffs/hosts ] && cat /jffs/hosts >>/tmp/dlhosts\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
mazilo
DD-WRT User


Joined: 10 Jun 2006
Posts: 385

PostPosted: Mon Nov 24, 2008 1:01    Post subject: Reply with quote
Hnestly, you don't even need to waste CPU resources to get rid off the trailing ^M. The awk '{print \0.0.0.0\"\\\t\"\$2}' I showed you on my post above automatically takes care of this mainly because this ^M isn't part of variable $2.
_________________
Mazi
UK non-geo DID #: +447031942574
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Mon Nov 24, 2008 1:35    Post subject: Reply with quote
Although ^M is not part of that variable, it will get added because it's part of the carriage return line feed combo

[edit]
Before putting it on my router, I'm testing it on my Fedora-system. These ^M appear there, but not on my router. I guess the awk of busybox already translates them. I'm keeping it in for the sake of portability and it might change in the future.

Do not only look at the script, but inspect the result as well. (and you have a missing double quote)

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Mon Nov 24, 2008 2:30    Post subject: Reply with quote
A minor change in the test for doubleclick (cleaner code)
Code:

rogue=192.168.10.5
echo -e "#!/bin/sh\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"$rogue\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\tif [ \`grep -il doubleclick /tmp/dlhosts\` ]; then\n\t\tbreak\n\tfi\n\tsleep 60\ndone\n[ -e /jffs/hosts ] && cat /jffs/hosts >>/tmp/dlhosts\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &


I have pixelserv running on 192.168.10.5 (on another server).
You can use DD-WRT as well if you are willing to change the port of DD-WRT's webinterface.
You should do the following:

Code:
nvram set http_lanport=88
nvram commit
reboot


Go to the webinterface (http://192.168.1.1:88)
Administration -> Commands

and replace rogue=192.168.10.5 with these 2 lines:

Code:
rogue=192.168.1.1
httpd -h /usr/tmp/www

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
mazilo
DD-WRT User


Joined: 10 Jun 2006
Posts: 385

PostPosted: Mon Nov 24, 2008 3:03    Post subject: Reply with quote
frater wrote:
Although ^M is not part of that variable, it will get added because it's part of the carriage return line feed combo

When you instruct awk to print with the variable $2 (hostname), it will ONLY print that variable (hostname) without the ^M character or the comments after the variable $2 (hostname) and so forth. It is as simple as that and nothing is hidden with such a print statement.

Quote:
I guess the awk of busybox already translates them.

No. Unless instructed to do so, awk never translates such a character (see my explanation above). In your code, you didn't ask awk to translate any characters. As a matter of fact, you just instructed awk to print variables $1, a \t (tab), and $2.

_________________
Mazi
UK non-geo DID #: +447031942574
mazilo
DD-WRT User


Joined: 10 Jun 2006
Posts: 385

PostPosted: Mon Nov 24, 2008 17:01    Post subject: Reply with quote
I suppose /etc/hosts hack won't be able to stop the ads from flash, will it? How about pop-up ads?
_________________
Mazi
UK non-geo DID #: +447031942574
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Mon Nov 24, 2008 21:36    Post subject: Reply with quote
mazilo wrote:

Quote:
I guess the awk of busybox already translates them.

No. Unless instructed to do so, awk never translates such a character (see my explanation above). In your code, you didn't ask awk to translate any characters. As a matter of fact, you just instructed awk to print variables $1, a \t (tab), and $2.

Maybe you should "explain" less and read more.

You are looking at the old code. I'm not using print $1 anymore and I wouldn't have used it if I would have written the initial code.

I'm now instructing awk to only print this:
Code:
awk '{print \"$rogue\\\t\"\$2}'

rogue will be translated in the script (it's a script writing a script), so it's the same as your code (only yours is missing a double quote.

My latest script will give this script as output:
Code:
#!/bin/sh
while true
do
        wget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep "^127.0.0.1" | grep -v localhost | awk '{print "192.168.10.5\t"$2}' | tr -d '\015' >/tmp/dlhosts

        [ `grep -il doubleclick /tmp/dlhosts` ] && break
        sleep 60
done
[ -e /jffs/hosts ] && cat /jffs/hosts >>/tmp/dlhosts
killall -HUP dnsmasq


Your script gives this:

Code:
#!/bin/sh
while true
do
        wget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep "^127.0.0.1" | awk '{print .0.0.0"\t"$2}' | grep -v localhost >/tmp/dlhosts

        if [ "`grep -c doubleclick /tmp/dlhosts`" -ne "0" ]; then
                break
        fi
        sleep 60
done
killall -HUP dnsmasq


As you can see it misses the double quote before the 0.0.0.0
I corrected this syntax error and this will be the output on my fedora system:
Code:
0.0.0.0 ad.a8.net^M
0.0.0.0 asy.a8ww.net^M
0.0.0.0 a9rhiwa.cn
0.0.0.0 www.a9rhiwa.cn^M
0.0.0.0 acezip.net
0.0.0.0 www.acezip.net
0.0.0.0 phpadsnew.abac.com^M

To my surprise this wasn't the case on the DD-WRT router.

Your remark about the print $1 was good.

I've tested your script. You apparently didn't.

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Wed Nov 26, 2008 20:07    Post subject: Reply with quote
famewolf wrote:
While pixelserv is ok I prefer to keep all functionality just on the router and not dependent on another pc I need to keep running (and yes I have multiple linux box's available)...so the change to use the router's IP was most appreciated


Not everyone is able to run pixelserv and if you don't care that your router's webserver runs on port 88 instead of port 80, you can use the following code.

Put this in your startup code.

B E W A R E your router will only be accessible on port 88

Code:

if [ `nvram get http_lanport` == 80 ]; then
 nvram set http_lanport=88
 nvram commit
 stopservice httpd
 startservice httpd
 stopservice firewall
 startservice firewall
fi
httpd -h /usr/tmp/www
rogue=`nvram get lan_ipaddr`
echo -e "#!/bin/sh\nn=1\nwhile true\ndo\n\twget -q -O - http://www.mvps.org/winhelp2002/hosts.txt | grep \"^127.0.0.1\" | grep -v localhost | awk '{print \"$rogue\\\t\"\$2}' | tr -d '\\\015' >/tmp/dlhosts\n" >/tmp/write_dlhosts
echo -e "\t[ \`grep -il doubleclick /tmp/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\n\tsleep 60\ndone\n[ -e /jffs/hosts ] && cat /jffs/hosts >>/tmp/dlhosts\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
famewolf
DD-WRT Novice


Joined: 01 Oct 2008
Posts: 31

PostPosted: Fri Dec 05, 2008 1:47    Post subject: Reply with quote
Thanks for the updated script frater. It worked like a champ. Question...since we already have the script checking every xx seconds to see if the hosts need updating could it also check if httpd is running on port 80 and restart it if necessary? I've had some isolated cases where it appears to have died with no warning.
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Fri Dec 05, 2008 6:41    Post subject: Reply with quote
famewolf wrote:
Question...since we already have the script checking every xx seconds to see if the hosts need updating.


I'm sorry to tell you that it doesn't. There is a loop, but this one is only there to be sure the file is actually downloaded.

After the download succeeds it will tell DNSMASQ to reload its settings and stop.

This is all deliberate...

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
mazilo
DD-WRT User


Joined: 10 Jun 2006
Posts: 385

PostPosted: Fri Dec 05, 2008 16:47    Post subject: Reply with quote
frater wrote:
mazilo wrote:

Quote:
I guess the awk of busybox already translates them.

No. Unless instructed to do so, awk never translates such a character (see my explanation above). In your code, you didn't ask awk to translate any characters. As a matter of fact, you just instructed awk to print variables $1, a \t (tab), and $2.

Maybe you should "explain" less and read more.

Outch! Perhaps, you should test more before you post here! My reference above pointed to your comments on ^M and not about $1. Although I didn't have to be specific (unless I deal with mentally challenge and/or under-achieve folks), I posted to tell you that printing variable $2 on a DDWRT router, not on a Linux computer, will automatically get rid off the control ^M character! This very statement of yours Maybe you should "explain" less and read more will apply to you better, in this case. ;)

BTW, your latest scripts still show the use of tr -d '\015' to get rid off the control ^M characters that only wastes your router CPU resources. Very Happy

_________________
Mazi
UK non-geo DID #: +447031942574
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Fri Dec 05, 2008 23:36    Post subject: Reply with quote
If there ever was a waste of CPU-cycles it was the script staying in memory and reloading every time. I There is little to no impact whatsoever...

I wrote and tested the script on my linux-box and there I needed to kill the ^M. Because of your statement that it was not needed, I checked it again and also tested it on the router with that filter. Indeed, it is not necessary on the router, but I want the script to be portable and if somehow the behaviour of busybox changes I don't want to suddenly end up with a waste of space with superfluous ^M and maybe erratic behaviour.

BTW... I said this already in a previous post.

In your copy paste sequence you ended up with a syntax error which you never corrected, so your line became:
Code:
awk '{print .0.0.0"\t"$2}'

instead of
Code:
awk '{print "0.0.0.0\t"$2}'

Why are you avoiding that?
Too specific perhaps?

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Sat Dec 06, 2008 0:05    Post subject: Reply with quote
frater wrote:
famewolf wrote:
Question...since we already have the script checking every xx seconds to see if the hosts need updating.


I'm sorry to tell you that it doesn't. There is a loop, but this one is only there to be sure the file is actually downloaded.

After the download succeeds it will tell DNSMASQ to reload its settings and stop.

This is all deliberate...


If you put this in /jffs/check_http
Code:
#!/bin/sh

cd /tmp
while true
do
 sleep 300
 wget -q http://`nvram get lan_ipaddr`:`nvram get http_lanport`
 if [ ! -e index.html ]; then
  stopservice httpd
  startservice httpd
 else
  rm index.html
 fi
done

and this in startup:
Code:
/jffs/check_http &


Your webserver will be checked every 5 minutes and restarted if it has crashed.

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
Goto page Previous  1, 2, 3 ... 16, 17, 18, 19  Next Display posts from previous:    Page 17 of 19
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum