Ad-Blocking Script (No longer developing)

Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload
Author Message
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Sat Jul 09, 2016 21:32    Post subject: Ad-Blocking Script (No longer developing) Reply with quote
This is a script I put together writing most myself, however, I also borrowed from google and existing scripts here in the wiki as well as smallnetbuilder.

It works off the same principle as most of the others, by using DNS poisoning with dnsmasq.

The Basics:

- All seems to be working as intended (The most important Razz )
- has a whitelist which we can process ourselves (or let it update on a schedule)
- has a blacklist which we can process ourselves (or let it update on a schedule)
- ipv4 functionality works for blocking ads, only ipv4 is enabled by default (since file is half the size and I don't use ipv6).
- All functions are logged in /tmp/var/log/messages, pre-faced with "adblocker" - granted you have syslogd enabled in webif.
- Basic health checks to cleanup old .tmp files, KEEP existing whitelist.adblocker / blacklist.adblocker file, and verify /jffs/adblocker/* is a true path prior to continuing.
- Has sanity checks using a lock file, as well as a sleep timer to allow startup processes to finish before it runs, as well as preventing duplicate updates from running at one time.
- Adds it's own entry in cron to update every Sunday at midnight.

To Install:

- Enable "DNSMasq" and "Local DNS" in Services tab; no Additional DNSMasq options necessary.
- Ensure cron is enabled.
- Mount a USB drive as "/jffs" (recommended).
- Enable "system log" in the services tab to enable system logging in "/tmp/var/log/messages".
- download and run on OS layer.....

Code:
https://www.dropbox.com/s/ag4lz9agcvyhzsh/DD-WRT_Ad-Blocker_10.21.2016_SA.sh?dl=0





<-- ENABLE


How to use:

- "adblocker" script that lives in "/tmp". This is what gets executed on a schedule to update our host files (as well as process our white/black lists if we choose to not update them manually)

- "whitelist.adblocker" file created in "/jffs/adblocker/allowed", this where you add whitelisted entries following the example I have given you inside the file already Wink

- "blacklist.adblocker" file created in "/jffs/adblocker/blocked", this where you add additional blacklisted entries following the example I have given you inside the file already Wink

- "processwhitelist.adblocker" script in "/jffs/adblocker" and is used to allow entries you have manually added into the "/jffs/adblocker/allowed/whitelist.adblocker" file.
Execute:
Code:
sh /jffs/adblocker/processwhitelist.adblocker


- "processblacklist.adblocker" script in "/jffs/adblocker" and is used to block entries you have manually added into the "/jffs/adblocker/blocked/blacklist.adblocker" file.
Execute:
Code:
sh /jffs/adblocker/processblacklist.adblocker


- "dnsmasqwatchdog.adblocker" script in "/jffs/adblocker" and is used as a watchdog to make sure dnsmasq is using our additional blocked hosts. (Cron runs this every 5 min)

- "dnsmasqwatchdog.log" created in "/jffs/adblocker". Will be created ONLY in the event that dnsmasq had to be restarted to add our blocked list.

- "failed2download.log" created in "/jffs/adblocker". Will be created ONLY in the event there is a failed update/download of one (or all) of the hosts files, specifying which URL failed.


I am not a coder by trade, so please be kind if there is a better way to do what I have. If you have constructive criticism, please share so we can all benefit.

I have tested and it works fine with IPv4


Last edited by cybrnook on Sat May 06, 2017 20:43; edited 29 times in total
Sponsor
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Mon Jul 11, 2016 17:57    Post subject: Reply with quote
If there is interest, I have revised the original and now have a version that also adds blacklist functionality, as well as a spot check during initial install that checks for and creates the required folder(s). So no longer have to manually create the "adblocker" folder in /jffs.

Though that's not the end of the world as it only has to be done once, so the only new addition as far as functionality would be black list.....
James Greystone
DD-WRT User


Joined: 20 Nov 2011
Posts: 194

PostPosted: Sat Jul 16, 2016 17:56    Post subject: Reply with quote
I am interested in this, if you could post the new script that would be great.

Cheers.
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Sat Jul 16, 2016 22:52    Post subject: Reply with quote
Sure thing, give me a little time though. I will have to do a complete walk through as I have added quite a few things.

Trying to figure out the best way to make a tutorial.
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Tue Jul 19, 2016 21:15    Post subject: Reply with quote
Okay I have updated the OP.

If you have installed it prior to now, I would ask you delete what it made previously, and start fresh.
James Greystone
DD-WRT User


Joined: 20 Nov 2011
Posts: 194

PostPosted: Fri Jul 22, 2016 22:03    Post subject: Reply with quote
cybrnook wrote:
Okay I have updated the OP.

If you have installed it prior to now, I would ask you delete what it made previously, and start fresh.


Great thanks.... Will give it a try.
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Wed Nov 30, 2016 16:45    Post subject: Reply with quote
New version almost complete.

-full error checking
-creates/checks all required folders during install
-verbose installation
-watchdogs to keep an eye on dnsmasq
-sets nvram for you
-ipv4/ipv6
-now installed locally, independent of precious nvram space
-logging with date+time stamp
-ability to watch "blocked" entries, to help in identifying white list candidates
-more, more , more Smile
doggmanthe
DD-WRT Novice


Joined: 12 Apr 2013
Posts: 1

PostPosted: Mon Dec 05, 2016 6:22    Post subject: Reply with quote
cybrnook wrote:
New version almost complete.

-full error checking
-creates/checks all required folders during install
-verbose installation
-watchdogs to keep an eye on dnsmasq
-sets nvram for you
-ipv4/ipv6
-now installed locally, independent of precious nvram space
-logging with date+time stamp
-ability to watch "blocked" entries, to help in identifying white list candidates
-more, more , more Smile



Outstanding!!!

Can't wait!
Special Man
DD-WRT Novice


Joined: 18 Feb 2013
Posts: 16

PostPosted: Thu Jan 12, 2017 0:02    Post subject: Reply with quote
Is this still in the works?
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Sat May 06, 2017 20:38    Post subject: Reply with quote
Special Man wrote:
Is this still in the works?


I abandoned it in favor of a pi-hole. However you are free to use what I have, works great for IPV4.

https://www.dropbox.com/s/ag4lz9agcvyhzsh/DD-WRT_Ad-Blocker_10.21.2016_SA.sh?dl=0

Just mount a drive as /jffs and execute the script, that's it....
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload 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 cannot attach files in this forum
You cannot download files in this forum