Posted: Sat Jul 09, 2016 21:32 Post subject: Ad-Blocking Script (No longer developing)
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 )
- 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.....
- "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
- "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
- "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
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.....
-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
-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