adblock: update 1.4.9
[feed/packages.git] / net / adblock / files / adblock.init
index 15c7d9ee7b9163cb3a9c1b5f3087c4f26a16fcda..f7b707a21bf48d588d61d5cd9bb9281ce1064bbe 100755 (executable)
@@ -2,10 +2,11 @@
 #
 
 START=99
-EXTRA_COMMANDS="toggle stats cfgup"
+EXTRA_COMMANDS="toggle stats cfgup query"
 EXTRA_HELP="   toggle  Toggle adblock 'on' or 'off'
        stats   Update adblock statistics
-       cfgup   Update adblock configuration file"
+       cfgup   Update adblock configuration file
+       query   <DOMAIN> Query active blocklists for specific domain"
 
 adb_debug=0
 adb_pid="${$}"
@@ -127,3 +128,34 @@ cfgup()
     fi
     return 0
 }
+
+query()
+{
+    domain="${1}"
+    tld="${domain#*.}"
+    list_dns="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
+    if [ -z "${list_dns}" ]
+    then
+        f_log "no active blocklists found, please start adblock first"
+    elif [ -z "${domain}" ] || [ "${domain}" = "${tld}" ]
+    then
+        f_log "invalid domain query 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_list"* | awk -F ':|/' '{print "   "$4"\t: "$6}')"
+            count="$(grep -hc "[/\.]${search}/" "${adb_dnsdir}/adb_list"* | awk '{sum += $1} END {printf sum}')"
+            printf "%s\n" "=> distinct results for domain '${domain}' (overall ${count})"
+            if [ -z "${result}" ]
+            then
+                printf "%s\n" "   no matches in active blocklists"
+            else
+                printf "%s\n" "${result}"
+            fi
+            domain="${tld}"
+            tld="${domain#*.}"
+        done
+    fi
+    return 0
+}