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 ... , 17, 18, 19  Next
Author Message
goonx126
DD-WRT User


Joined: 13 Feb 2008
Posts: 59

PostPosted: Mon Dec 08, 2008 19:13    Post subject: Reply with quote
Hey Frater,

I was wondering if you would start a new thread with the script posted as the first post. It's getting hard to shuffle through 17 looking for the startup and command code.

Thanks
Sponsor
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Tue Dec 09, 2008 18:27    Post subject: Reply with quote
No Problem,

It's because you ask, but I was a bit anxious to do so.
Using the router's DNS-server to do this was NOT my idea. The reason why I was 'interfering' was because the previous poster were overwriting data (local hosts) that I was using in one of my projects (a reverse proxy). This was bad practice.

Furthermore the code was too complex and would still deliver unexpected results. No checking was done on the result and it would stay in memory infinitely with no real purpose whatsoever.

There was a little section with mazilo where he pointed out some superfluous code on my part, although his cut and paste job was not entirely at the right spot.

We had a discussion about \015 (^M), but he's wrong there. The filtering IS needed on many linux distributions. Although it is NOT needed on DD-WRT now, it doesn't mean this will stay this way in the future.

It "doesn't waste valuable CPU cycles" as he said it. This is not the place to do this. The code is supposed to run only once after startup and portability is more valuable than some neglectable CPU cycles (I did a test and sometimes the code even ran faster... not worth to investigate further anyhow)

I'll start a new thread after I get an answer from Brainslayer about the httpd server.

_________________
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: Wed Dec 10, 2008 21:55    Post subject: Reply with quote
frater wrote:
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.


Well..I was originally looking to check the http server on port 80 as it had died at random times..this looks to be checking the one on port 88 (or in my case port 8080)...however I just had the one on port 8080 die for no apparent reason (ssh still worked and the one on port 80 worked) so not sure what the deal is. Perhaps I'll end up needing to check BOTH every 5 mins.
mazilo
DD-WRT User


Joined: 10 Jun 2006
Posts: 385

PostPosted: Fri Dec 12, 2008 4:00    Post subject: Reply with quote
I believe one can use IPAlias on a DDWRT router; however, what I don't know is if it is possible to run another httpd instance on the IPAlias address. Anyone?
_________________
Mazi
UK non-geo DID #: +447031942574
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Fri Dec 12, 2008 6:23    Post subject: Reply with quote
I already investigated that, but alas, the httpd daemon binds to all addresses.

I also tried this:
Code:
httpd -p `nvram get lan_ipaddr`:80
but although the process runs afterwards it doesn't listen to the lan address. It isn't bound to any IP.

I think it's better to ask for a specific daemon that does the same as pixelserv. I installed perl on DD-WRT and ran pixelserv, but the resources needed are ludicrous for such a device. 20% of memory and perl needs about 20 MB.

I actually don't really need it myself. I have pixelserv running on Fedora core on an alternate IP, but I'm still investigating. Please write to Brainslayer to ask for a good solution....

It's a piece of cake in C

_________________
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)
gene
DD-WRT Guru


Joined: 28 Dec 2007
Posts: 619

PostPosted: Tue Jan 06, 2009 15:15    Post subject: Reply with quote
ok, guys, NOT everyone wants to use jffs or move the web gui to another port or have a custom hosts file that needs to be checked and merged into this new hosts file that gets down loaded. I see that the scripts are being perfected and updated and refined.... If you are going to tweak the scripts here, then please be considerate of other users who are not using custom hosts files or those who have no need to remember to type in the port address when trying to log into the router.... THIS MEANS if you are going to tweak this script, then include the basic script in your post along with your tweaked script AND the other code necessary to make it run ( like the dnsmask entry and the firewall script code) There are 18 pages of refined scripts here...the first page does not have the script I need, nor does the last page...we should NOT have to read every single script posted here in-order to figure out which script we need.

I don't mean to come across grumpy, but I see from reading that tweaks and refinements ARE being made to this script that enable the router to run more efficiently with this script. I have gathered that there is the basic script that anyone should be able to run, then there is the script that users using jffs want because they have custom hosts files, then there is a script that changes the port of the router web UI ..... some of us would like the tweaked basic script and NOT have to read 18 pages of posts to figure out which one we need ! the supporting code dnsmasq and firewall should also be posted as reminders as well as the start-up code.

So what is the newest tweaked script that does not change the port of the router and does not force me to start using jffs when I don't need it ?????

_________________
1 WRT160N v3 - remote AP WPA2 Personal Aes dd-wrt-mini-trailed CPU OC400,
2 wrt54G v3(BCM4712 chip rev 1, corerev=7)- AP WPA2 Personal Aes dd-wrt-mini-generic CPU OC228,
1 wrt54gs v6 - remote AP WPA2 Personal Aes dd-wrt-micro CPU OC228 ,
3 WAP54g v3 - repeater, client Bridge, repeater bridge dd-wrt-micro CPU OC225,
1 NetGear WNR2000 v3 AP Atheros AR7241 ver 1 rev 1.1 (0x0101) Trailed build CPU OC360
DD-WRT usually the most current BS builds and less frequently lately EKO builds(because of new BS rules that eliminated EKO builds I used).
redhawk0
DD-WRT Guru


Joined: 04 Jan 2007
Posts: 11563
Location: Wherever the wind blows- North America

PostPosted: Tue Jan 06, 2009 15:20    Post subject: Reply with quote
gene...here is what I use...included are my notes at the top. No jffs needed.

redhawk



[Notes] - To add the host file ad blocker to the router. At a command line (telnet or ssh) enter.
last line refreshes hosts file every friday at 23:45.


logger WAN UP Script Executing
sleep 5
test -s /tmp/dlhosts
if [ $? == 1 ] ; then
echo -e "#!/bin/sh\nwget -O - http://www.mvps.org/winhelp2002/hosts.txt | grep 127.0.0.1 | tr -d '\015\032' | sed -e '2,\$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//' > /etc/hosts\nlogger DOWNLOADED http://www.mvps.org/winhelp2002/hosts.txt\nkillall -1 dnsmasq" > /tmp/dlhosts
chmod 777 /tmp/dlhosts
/tmp/dlhosts
fi
echo "45 23 * * 5 root /tmp/dlhosts" >> /tmp/crontab

_________________
The only stupid question....is the unasked one.
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Wed Jan 21, 2009 19:42    Post subject: Reply with quote
Redhawk...
The script you are using is both inefficient and erroneous as it overwrites all the local hosts you have in your /etc/hosts

Downloading the host-file more than once without error-checking is close to useless. IMHO it is better to do it only once and then check it.

I have written the script so it doesn't need a cronjob and will only run once during startup and makes sure it downloads the file.

Later on I've added some functions so it can use the http-server on DD-WRT to respond to http-requests..
Well, if you don't want that, Gene... I will give you a stripped version...
/jffs is not needed. Not even with the 'enhanced' script. It's just an extra....

Code:
_rogue=0.0.0.0
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 /opt/dlhosts\` ] && break\n\t[ \$n -gt 5 ] && break\n\tlet n+=1\n\tsleep 60\ndone\nkillall -HUP dnsmasq" >>/tmp/write_dlhosts
chmod +x /tmp/write_dlhosts
/tmp/write_dlhosts &


Add this in services -> Additional DNSMasq Options
Code:
addn-hosts=/tmp/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)
lairdreed
DD-WRT Novice


Joined: 30 Jan 2009
Posts: 1

PostPosted: Fri Jan 30, 2009 22:57    Post subject: pixelserv on fedora Reply with quote
>> This pixelserv is a great idea so I'm now running it on my fedora on an extra IP. If someone wants to know how, I will write an howto..


I would love to know how to do this; I have added an IP and got pixelserv running OK - dd-wrt is redirecting OK as well using frater's script from pg 17 - but I'm having trouble getting httpd running at the same time on just one address. *.*.*.100 wityh pixelserv running on .99

Thoughts?
jimmydu3
DD-WRT Novice


Joined: 31 Jan 2009
Posts: 2

PostPosted: Sat Jan 31, 2009 18:41    Post subject: Reply with quote
Couple of questions..
1) I've got adblocking working at Frater has described using jffs. How much space should jffs be using?
2) Alot of ads are being blocked, but some of the ab boxes are saying "400 Bad Request
Cross Site Action detected!" Is there a way to change this error to a 1x1 pixel? Or am I currently doing something wrong?
3) How would pixelserv change things in this setup?


Thanks!
MKruer
DD-WRT Novice


Joined: 15 Feb 2009
Posts: 18

PostPosted: Mon Feb 16, 2009 8:47    Post subject: Reply with quote
Was this ever fully resolved? I have been though the thread about a dozen times and can’t get it to work for me. To cut the crap, I am doing the job manually and I can verify the host file does exist and is populated correctly. However it never works from my client system even when the dns has been flushed. Its blocked fine on the telnet sessions so I know the file is working at least that far.

DNSMasq is enabled
Additional DNSMasq Options addn-hosts=/etc/hosts
Enable DNSMasq is Enabled
Local DNS is Enabled
cron is enabled.

This page should be updated with the latest information as well
http://www.dd-wrt.com/wiki/index.php/Ad_blocking

Setup
Linksys wrt54gsv4 +dd-wrt 24-sp1 (standard)

Edit: I guess I should ask if there is a project out there the is working on adding a full ad blocker via the router. I like the host file, but lets face it is ver inefficient. something like the script blocker being used in fire fox is a much better way of handling it.
carbonize
DD-WRT Novice


Joined: 13 Feb 2009
Posts: 43
Location: Bristol, UK

PostPosted: Mon Feb 16, 2009 10:20    Post subject: Reply with quote
Personally I'd say doing it locally on the computer is a far better idea. As has already been stated you can use AdBlock+ for Firefox and IE7 Pro for IE7 to block the ads at the browser level.

My hosts file is already pretty full with all the malware and tracking sites that Spybot adds to it.
MKruer
DD-WRT Novice


Joined: 15 Feb 2009
Posts: 18

PostPosted: Mon Feb 16, 2009 18:10    Post subject: Reply with quote
The problem is that we are using a host file which is woefully inefficient case in point ADBlock plus blocks more, but also the definition size is only 80KB compared to the 500KB of the host file.

Edit:the Source for Adblock plus is avaiable, and appears to be very small. Smaller then the current host file.

Also another reason for doing this is that some sites are now adding exceptions where if it detects AD block it fails to go the proper page.

Edit2: This explains how it works in a nut shell ADBlock has been compromised
http://blog.taragana.com/index.php/archive/how-to-detect-adblock-plus/
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Mon Feb 16, 2009 18:41    Post subject: Reply with quote
If you want to use code that works go to this thread: http://www.dd-wrt.com/phpBB2/viewtopic.php?p=263581#263581
_________________
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)
MKruer
DD-WRT Novice


Joined: 15 Feb 2009
Posts: 18

PostPosted: Mon Feb 16, 2009 18:57    Post subject: Reply with quote
Thanks, that worked. I found my error too. I guess I was really tired.

If you are going to advance with with a proper/better system let me know if i can help.
Goto page Previous  1, 2, 3 ... , 17, 18, 19  Next Display posts from previous:    Page 18 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