adblock: update 2.0.2
authorDirk Brenken <redacted>
Fri, 23 Dec 2016 06:15:11 +0000 (07:15 +0100)
committerDirk Brenken <redacted>
Fri, 23 Dec 2016 06:18:57 +0000 (07:18 +0100)
* fixed dnsmasq check if multiple instances are present
* bring back query function on highly demand
* documentation update

Signed-off-by: Dirk Brenken <redacted>
net/adblock/Makefile
net/adblock/files/README.md
net/adblock/files/adblock.init
net/adblock/files/adblock.sh

index c52acf0bf7461cea33d791a14a74ba5a66d132b3..8ec995808458a66b370b89d73cb132b9ba598d81 100644 (file)
@@ -6,7 +6,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=adblock
-PKG_VERSION:=2.0.1
+PKG_VERSION:=2.0.2
 PKG_RELEASE:=1
 PKG_LICENSE:=GPL-3.0+
 PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
index 2d4a2c80331207010c866323189f4257a0e2f96f..a5ecd8a13dd37a130d1b5368a3f55ae50bcdf6e4 100644 (file)
@@ -63,6 +63,7 @@ A lot of people already use adblocker plugins within their desktop browsers, but
 * procd based hotplug support, the adblock start will be triggered by interface triggers
 * suspend & resume adblock actions temporarily without block list reloading
 * runtime statistics via ubus service call
+* query function to quickly identify blocked (sub-)domains, i.e. for whitelisting
 * automatic block list backup & restore, backups will be (de-)compressed and restored on the fly
 * add new adblock sources on your own via uci config
 
@@ -100,6 +101,7 @@ A lot of people already use adblocker plugins within their desktop browsers, but
 * **scheduled list updates:** for a scheduled call of the adblock service add an appropriate crontab entry (see example below)
 * **restrict/disable procd interface trigger:** to restrict the procd interface trigger to a (list of) certain wan interface(s) or to disable it at all, set 'adb\_iface' to an existing interface like 'wan' or to a non-existing like 'false'
 * **suspend & resume adblocking:** to quickly switch the adblock service 'on' or 'off', simply use _/etc/init.d/adblock [suspend|resume]_
+* **domain query:** to query the active block lists for a specific domain, please run _/etc/init.d/adblock query `<DOMAIN>`_ (see example below)
 * **divert dns requests:** to force dns requests to your local dns resolver add an appropriate firewall rule (see example below)
 * **add new list sources:** you could add new block list sources on your own via uci config, all you need is a source url and an awk one-liner (see example below)
 * **disable active dns probing in windows 10:** to prevent a yellow exclamation mark on your internet connection icon (which wrongly means connected, but no internet), please change the following registry key/value from "1" to "0" _HKLM\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\EnableActiveProbing_
@@ -178,6 +180,22 @@ This entry does not remove:
   www.adwhere.com
 </code></pre>
   
+**example to query active block lists for a certain (sub-)domain, i.e. for whitelisting:**
+<pre><code>
+/etc/init.d/adblock query "example.www.doubleclick.net"
+:: distinct results for domain 'example.www.doubleclick.net' (overall 0)
+   no matches in active block lists
+:: distinct results for domain 'www.doubleclick.net' (overall 1)
+   adb_list.securemecca : www.doubleclick.net
+:: distinct results for domain 'doubleclick.net' (overall 127)
+   adb_list.adaway      : ad-g.doubleclick.net
+   adb_list.securemecca : 1168945.fls.doubleclick.net
+
+The query function checks against the submitted (sub-)domain and recurses automatically to the upper top level domain(s).
+For every domain it returns the overall count plus a distinct list of active block lists with the first relevant result.
+In the example above whitelist "www.doubleclick.net" to free the submitted domain.
+</code></pre>
+  
 **example to divert dns requests to local dns resolver (/etc/config/firewall):**
 <pre><code>
 config redirect
index 2ed89cdc5776bd0907f79614a24d069763256c89..354c7d9692a7cc9a503eb631408cffe4eb08aeca 100755 (executable)
@@ -4,9 +4,10 @@
 START=90
 USE_PROCD=1
 
-EXTRA_COMMANDS="suspend resume"
+EXTRA_COMMANDS="suspend resume query"
 EXTRA_HELP="   suspend Suspend adblock processing
-       resume  Resume adblock processing"
+       resume  Resume adblock processing
+       query   <DOMAIN> Query active blocklists for specific domain"
 
 exec 2>/dev/null
 adb_script="/usr/bin/adblock.sh"
@@ -65,6 +66,12 @@ resume()
     rc_procd start_service resume
 }
 
+query()
+{
+    export adb_procd="true"
+    rc_procd "${adb_script}" query "${1}"
+}
+
 service_triggers()
 {
     local iface
index 3ec2aed5402d34a8635ae75aa44e8e42148a4162..9bd31f7e7ecc1dff1a7893a30944952b4955dae7 100755 (executable)
@@ -10,7 +10,7 @@
 #
 LC_ALL=C
 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-adb_ver="2.0.1"
+adb_ver="2.0.2"
 adb_enabled=1
 adb_debug=0
 adb_whitelist="/etc/adblock/adblock.whitelist"
@@ -161,18 +161,16 @@ f_dnsrestart()
     killall -q -TERM "${adb_dns}"
     while [ ${cnt} -le 10 ]
     do
-        dns_running="$(ubus -S call service list '{"name":"dnsmasq"}' | jsonfilter -e '@.dnsmasq.instances.*.running')"
+        dns_running="$(ubus -S call service list '{"name":"dnsmasq"}' | jsonfilter -l 1 -e '@.dnsmasq.instances.*.running')"
         if [ "${dns_running}" = "true" ]
         then
-            break
+            return 0
         fi
         cnt=$((cnt+1))
         sleep 1
     done
-    if [ "${dns_running}" = "false" ]
-    then
-        /etc/init.d/"${adb_dns}" restart
-    fi
+    /etc/init.d/"${adb_dns}" restart
+    sleep 1
 }
 
 # f_list: backup/restore/remove block lists
@@ -235,6 +233,40 @@ f_switch()
     fi
 }
 
+# f_query: query block lists for certain (sub-)domains
+#
+f_query()
+{
+    local search result cnt
+    local domain="${1}"
+    local tld="${domain#*.}"
+    local dns_active="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
+
+    if [ -z "${dns_active}" ]
+    then
+         printf "%s\n" ":: no active block lists found, please start adblock first"
+    elif [ -z "${domain}" ] || [ "${domain}" = "${tld}" ]
+    then
+        printf "%s\n" ":: invalid domain input, please submit a specific (sub-)domain, i.e. 'www.abc.xyz'"
+    else
+        while [ "${domain}" != "${tld}" ]
+        do
+            search="${domain//./\.}"
+            result="$(grep -Hm 1 "[/\.]${search}/" "${adb_dnsdir}/${adb_dnsprefix}"* | awk -F ':|/' '{print "   "$4"\t: "$6}')"
+            cnt="$(grep -hc "[/\.]${search}/" "${adb_dnsdir}/${adb_dnsprefix}"* | awk '{sum += $1} END {printf sum}')"
+            printf "%s\n" ":: distinct results for domain '${domain}' (overall ${cnt})"
+            if [ -z "${result}" ]
+            then
+                printf "%s\n" "   no matches in active block lists"
+            else
+                printf "%s\n" "${result}"
+            fi
+            domain="${tld}"
+            tld="${domain#*.}"
+        done
+    fi
+}
+
 # f_log: write to syslog, exit on error
 #
 f_log()
@@ -284,9 +316,8 @@ f_debug()
 #
 f_main()
 {
-    local rc cnt sum_cnt=0
-    local enabled url src_name src_rset
-    local shalla_file shalla_archive list
+    local enabled url rc cnt sum_cnt=0
+    local src_name src_rset shalla_file shalla_archive
 
     f_debug
     f_log "debug" "main   ::: tool: ${adb_fetch}, parm: ${adb_fetchparm}"
@@ -419,6 +450,9 @@ then
         resume)
             f_switch resume
             ;;
+        query)
+            f_query "${2}"
+            ;;
         *)
             f_envcheck
             f_main
git clone https://git.99rst.org/PROJECT