Simple-adblock: fast, lean and fully uci/luci configurable AdBlocking

THIS HAS BEEN REPLACED BY adblock-fast, PLEASE USE THE NEW PACKAGE!

Here's the story -- I was impressed by the elegance and simplicity of bole5's (from OpenWrt forum) single-file adblocking script and started tinkering with it a long time ago. I kept working on it and now turned it into simple-adblock and luci-app-simple-adblock (with some help/suggestions from @hnyman and @dibdot).

There are a few things which differentiate this from another excellent adblocking solution by @dibdot:

  1. It's very fast.
  2. It understands hosts files and domains lists only (to keep it lean and fast).
  3. Everything is configurable from Web UI and uci commands.
  4. You can add your own domains to whitelist or blacklist.
  5. You can add URLs to your own blocked hosts or domains lists to block/whitelist.
  6. Requires no configuration for the download utility wherever you want to use wget/libopenssl or uclient-fetch/libustream-mbedtls.
  7. Installs dependencies automatically (DD/LEDE-default uclient-fetch libustream-mbedtls).

Just like @dibdot's solution:

  1. It uses dnsmasq to return "domain not found" (thanks @dibdot for the suggestion!) for blocked domains/hosts with no memory footprint for its own code .
  2. It defaults to DNS-hijacking, so if you have local devices on your network with hardcoded DNS servers, simple-adblock will force them to use your router DNS server (both IPv4 and IPv6) instead.

The actual speed will depend on your router model and connection speed, but because it uses simple sed substitutions to process the whole list in one go and because it backgrounds processing of already downloaded data while the next list is being downloaded, it's pretty quick.

Check out the README for more information/instructions.

Both packages are available from my repo: https://docs.openwrt.melmac.net/#on-your-router

I welcome any feedback!

23 Likes

Added the README link above.

1 Like

In 1.5.5 I've added an option to assign one of the router LEDs to indicate adblocking status (on/off).

Can be set in config file/uci command or Web UI.

3 Likes

Thanks for simple-adblock! I'm really impressed with how lean it is, while still being very functional!

1 Like

Now in official repo for trunk/snapshot images. For everything else -- there's my own repository.

1 Like

Hi @stangri!
Do you think I can use your ad blocking in this firmware TP-Link TL-WR841N(D), WA701N(D), WR740N(D), WR741N(D), WR743N(D), WR940N, WR941N(D) - LADUS / JULIA / Ultra Lite / VPN builds.
I've already tried with no success. But I'm willing to learn.
Thanks

Hard to say without knowing why you failed.

Hi can u help me with this...

Sat Apr 1 12:26:05 2017 daemon.info odhcpd[1793]: Using a RA lifetime of 0 seconds on br-lan
Sat Apr 1 12:27:23 2017 user.notice simple-adblock [6586]: No longer forcing local DNS server.
Sat Apr 1 12:27:23 2017 daemon.info dnsmasq[2536]: exiting on receipt of SIGTERM
Sat Apr 1 12:27:24 2017 user.notice simple-adblock [6586]: Restarting dnsmasq [✓]
Sat Apr 1 12:27:24 2017 user.notice simple-adblock [6586]: service stopped.
Sat Apr 1 12:27:24 2017 daemon.err uhttpd[2450]: Command failed: Not found
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: started, version 2.77test4 cachesize 150
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: DNS service limited to local subnets
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP no-DHCPv6 no-Lua TFTP no-conntrack no-ipset no-auth no-DNSSEC no-ID loop-detect inotify
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using local addresses only for domain test
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using local addresses only for domain onion
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using local addresses only for domain localhost
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using local addresses only for domain local
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using local addresses only for domain invalid
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using local addresses only for domain example.net
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using local addresses only for domain example.org
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using local addresses only for domain example.com
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using nameserver 8.8.8.8#53 for domain pool.ntp.org
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using nameserver 127.0.0.1#5353
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: using 3 more local addresses
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: read /etc/hosts - 4 addresses
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: read /tmp/hosts/dhcp.cfg02411c - 0 addresses
Sat Apr 1 12:27:24 2017 daemon.info dnsmasq[6655]: read /tmp/hosts/odhcpd - 2 addresses
Sat Apr 1 12:27:24 2017 user.notice simple-adblock [6586]: Forcing local DNS server: 192.168.2.101/fd7c:3a31:2ed4::1.
Sat Apr 1 12:27:29 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:27:30 2017 user.notice simple-adblock [6586]: [DL] Blocked Hosts: www.mvps.org [✗]
Sat Apr 1 12:27:30 2017 daemon.err uhttpd[2450]: tr: write error: Broken pipe
Sat Apr 1 12:27:30 2017 daemon.err uhttpd[2450]: head: standard output: Broken pipe
Sat Apr 1 12:27:35 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:27:35 2017 user.notice simple-adblock [6586]: [DL] Blocked Hosts: pgl.yoyo.org [✗]
Sat Apr 1 12:27:35 2017 daemon.err uhttpd[2450]: tr: write error: Broken pipe
Sat Apr 1 12:27:35 2017 daemon.err uhttpd[2450]: head: standard output: Broken pipe
Sat Apr 1 12:27:40 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:27:40 2017 user.notice simple-adblock [6586]: [DL] Blocked Hosts: www.malwaredomainlist.com [✗]
Sat Apr 1 12:27:45 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:27:45 2017 user.notice simple-adblock [6586]: [DL] Blocked Hosts: adaway.org [✗]
Sat Apr 1 12:27:50 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:27:50 2017 user.notice simple-adblock [6586]: [DL] Blocked Hosts: someonewhocares.org [✗]
Sat Apr 1 12:27:55 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:27:55 2017 user.notice simple-adblock [6586]: [DL] Blocked Hosts: easylist.to [✗]
Sat Apr 1 12:28:00 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:28:00 2017 user.notice simple-adblock [6586]: [DL] Blocked Hosts: zeustracker.abuse.ch [✗]
Sat Apr 1 12:28:05 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:28:05 2017 user.notice simple-adblock [6586]: [DL] Blocked Domains: mirror1.malwaredomains.com [✗]
Sat Apr 1 12:28:10 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:28:10 2017 user.notice simple-adblock [6586]: [DL] Blocked Domains: s3.amazonaws.com [✗]
Sat Apr 1 12:28:10 2017 daemon.err uhttpd[2450]: tr: write error: Broken pipe
Sat Apr 1 12:28:10 2017 daemon.err uhttpd[2450]: head: standard output: Broken pipe
Sat Apr 1 12:28:15 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:28:15 2017 user.notice simple-adblock [6586]: [DL] Blocked Domains: s3.amazonaws.com [✗]
Sat Apr 1 12:28:20 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:28:20 2017 user.notice simple-adblock [6586]: [DL] Blocked Domains: s3.amazonaws.com [✗]
Sat Apr 1 12:28:25 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:28:25 2017 user.notice simple-adblock [6586]: [DL] Blocked Domains: ransomwaretracker.abuse.ch [✗]
Sat Apr 1 12:28:31 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:28:31 2017 user.notice simple-adblock [6586]: [DL] Blocked Domains: gitlab.com [✗]
Sat Apr 1 12:28:36 2017 daemon.err uhttpd[2450]: Failed to establish connection
Sat Apr 1 12:28:36 2017 user.notice simple-adblock [6586]: [DL] Blocked Domains: dshield.org [✗]
Sat Apr 1 12:28:36 2017 user.notice simple-adblock [6586]: Waiting for background processes [✓]
Sat Apr 1 12:28:36 2017 user.notice simple-adblock [6586]: ERROR: service failed to create its data file!

Which device/OS is it happening on? Does it still happen on a freshly rebooted device?

Hey stangri! Thanks for your hard work! I'm still kind of new to the whole LEDE and what it has to offer and I'm very impressed with the sheer amount of work everyone in this community has put into it. And I just wanted to say thank you everybody! But I wanted to know, do I just run your simple ad block and disable the ad block in luci? Or do I run both? Just curious that's all

tried new build ([GCC 7.2 BUILD] Optimized TP-Link Archer C7 V2 AC1750 LEDE Firmware)
but still the same???

Uhm, is the LEDE 17.01.0 release available for your router? Can you try that? Thanks for posting the link to the thread on the image you're running, I'll try to reach out to the image builder to figure out what could be going wrong over the course of next week.

@Hemperror -- Daniel, if you don't mind doing a bit more testing, I'd appreciate it.

First, please add my repo to your LEDE install. Then do:

/etc/init.d/simple-adblock stop
opkg upgrade simple-adblock
uci set simple-adblock.config.debug=1; uci commit
/etc/init.d/simple-adblock reload

The new simple-adblock (1.5.6-9) should then create the debug log file at /var/simple-adblock.log -- please PM me this file.

I've published 1.5.7-1 to my repository, please upgrade to this version. It has a much stricter garbage removal filters.

Any chance you could start pushing your updates to the LEDE snapshots packages system rather than having to add another repo to a std LEDE system? It'd also ensure that the snapshot package is upto date.

This adblock is working great !

1 Like

I agree that the push to official repo is long overdue I'll try to send PR this (or next) weekend.

Good job mate. It's working well.

EDIT:
required an '/etc/init.d/simple-adblock stop' and
'/etc/init.d/simple-adblock start' to get it going.

Maybe I'm not configuring correctly, but the following site does not ever load with this package installed on default settings:

Chrome always says DNS server not resolved as the error for loading this website

Here is the whitelist code I've put in /etc/simple-adblock (which still doesn't allow it to load):

list whitelist_domain 'http://www.phonearena.com'

Chrome always says DNS server not resolved as the error for loading this website

@rajsris -- there's a trigger so that service reloads if there're any changes to config file.

@hnyman -- could you please confirm that the code below should cause service reload (and not restart) to be executed on the config changes?

service_triggers () {
    procd_add_reload_trigger 'simple-adblock'
}