adblock: release 2.4.0 4086/head
authorDirk Brenken <dev@brenken.org>
Mon, 27 Feb 2017 20:42:53 +0000 (21:42 +0100)
committerDirk Brenken <dev@brenken.org>
Tue, 28 Feb 2017 15:52:10 +0000 (16:52 +0100)
* add tld compression,
  this new "top level domain compression" removes up to 40 thousand
  needless host entries from the block lists and
  lowers the memory footprint for the dns backends by 8-10 MByte
* optimize restart behavior in case of an error
* cosmetics

Signed-off-by: Dirk Brenken <dev@brenken.org>
net/adblock/Makefile
net/adblock/files/README.md
net/adblock/files/adblock.init
net/adblock/files/adblock.sh

index dbed4f629fbe5b97c1c7faed74c29dd8f17b3c66..917c51425e17c78b7a494e8fc8d6a6e9569a4a9a 100644 (file)
@@ -6,7 +6,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=adblock
-PKG_VERSION:=2.3.2
+PKG_VERSION:=2.4.0
 PKG_RELEASE:=1
 PKG_LICENSE:=GPL-3.0+
 PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
index 62732e9075d0bf28888dbff583b94be094cc8b48..172551f5cdac76f0bbdf76818265c5ebae26aac4 100644 (file)
@@ -57,6 +57,7 @@ A lot of people already use adblocker plugins within their desktop browsers, but
 * automatically selects uclient-fetch or wget as download utility (other tools like curl or aria2c are supported as well)
 * automatically supports a wide range of router modes, even AP modes are supported
 * full IPv4 and IPv6 support
+* supports tld compression (top level domain compression), this feature removes thousands of needless host entries from the block lists and lowers the memory footprint for the dns backends
 * each block list source will be updated and processed separately
 * block list source parsing by fast & flexible regex rulesets
 * overall duplicate removal in separate block lists
@@ -120,6 +121,7 @@ A lot of people already use adblocker plugins within their desktop browsers, but
     * adb\_iface => restrict the procd interface trigger to a (list of) certain wan interface(s) or disable it at all (default: not set, disabled)
     * adb\_fetch => full path to a different download utility, see example below (default: not set, use wget)
     * adb\_fetchparm => options for the download utility, see example below (default: not set, use wget options)
+    * adb\_tldcomp => enable/disable tld compression (default: '1', enabled)
 
 ## Examples
 
@@ -136,19 +138,19 @@ If you use manual configuration for unbound, then just include the following lin
 <pre><code>
 wget (default):
   option adb_fetch="/usr/bin/wget"
-  option adb_fetchparm="--no-config --quiet --tries=1 --no-cache --no-cookies --max-redirect=0 --timeout=5 --no-check-certificate -O"
+  option adb_fetchparm="--no-config --quiet --no-cache --no-cookies --max-redirect=0 --timeout=10 --no-check-certificate -O"
 
 aria2c:
   option adb_fetch '/usr/bin/aria2c'
-  option adb_fetchparm '-q --max-tries=1 --timeout=5 --allow-overwrite=true --auto-file-renaming=false --check-certificate=false -o'
+  option adb_fetchparm '-q --timeout=10 --allow-overwrite=true --auto-file-renaming=false --check-certificate=false -o'
 
 uclient-fetch:
   option adb_fetch '/bin/uclient-fetch'
-  option adb_fetchparm '-q --timeout=5 --no-check-certificate -O'
+  option adb_fetchparm '-q --timeout=10 --no-check-certificate -O'
 
 curl:
   option adb_fetch '/usr/bin/curl'
-  option adb_fetchparm '-s --retry 1 --connect-timeout 5 --insecure -o'
+  option adb_fetchparm '-s --connect-timeout 10 --insecure -o'
 </code></pre>
   
 **receive adblock statistics via ubus:**
index 7c4a91c1c4a8e7f10e8ae883a95ebf5ce49836a4..cf8a57b1516ba2f9bd0327f97816fd508dd1c9e4 100755 (executable)
@@ -37,7 +37,6 @@ start_service()
     if [ $(/etc/init.d/adblock enabled; printf ${?}) -eq 0 ]
     then
         procd_open_instance "adblock"
-        procd_set_param env adb_procd="true"
         procd_set_param command "${adb_script}" "${@}"
         procd_set_param stdout 1
         procd_set_param stderr 1
@@ -52,7 +51,6 @@ reload_service()
 
 stop_service()
 {
-    export adb_procd="true"
     rc_procd "${adb_script}" stop
 }
 
@@ -73,7 +71,6 @@ resume()
 
 query()
 {
-    export adb_procd="true"
     rc_procd "${adb_script}" query "${1}"
 }
 
@@ -81,8 +78,6 @@ service_triggers()
 {
     local iface="$(uci -q get adblock.global.adb_iface)"
 
-    procd_open_trigger
-    procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
     if [ -z "${iface}" ]
     then
         procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/adblock start
@@ -92,5 +87,5 @@ service_triggers()
             procd_add_interface_trigger "interface.*.up" "${name}" /etc/init.d/adblock start
         done
     fi
-    procd_close_trigger
+    procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
 }
index 8dc464b62a7adc4da57af08639a77f982b5ee089..62d1a1c540376b339de3f052b771e8ae09e9c619 100755 (executable)
 #
 LC_ALL=C
 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-adb_ver="2.3.2"
+adb_ver="2.4.0"
 adb_enabled=1
 adb_debug=0
 adb_backup=0
+adb_tldcomp=1
 adb_backupdir="/mnt"
 adb_whitelist="/etc/adblock/adblock.whitelist"
 adb_whitelist_rset="\$1 ~/^([A-Za-z0-9_-]+\.){1,}[A-Za-z]+/{print tolower(\"^\"\$1\"\\\|[.]\"\$1)}"
@@ -324,7 +325,11 @@ f_log()
         then
             logger -t "adblock-[${adb_ver}] ${class}" "Please check the online documentation 'https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md'"
             f_rmtemp
-            f_rmdns
+            if [ "$(ls -dA "${adb_dnsdir}/${adb_dnsprefix}"* >/dev/null 2>&1)" ]
+            then
+                f_rmdns
+                f_dnsrestart
+            fi
             exit 255
         fi
     fi
@@ -389,13 +394,20 @@ f_main()
             adb_rc=${?}
         fi
 
-        # check download result and prepare domain output (incl. list backup/restore)
+        # check download result and prepare domain output (incl. tld compression, list backup & restore)
         #
         if [ ${adb_rc} -eq 0 ] && [ -s "${adb_tmpload}" ]
         then
             awk "${src_rset}" "${adb_tmpload}" > "${adb_tmpfile}"
             if [ -s "${adb_tmpfile}" ]
             then
+                if [ ${adb_tldcomp} -eq 1 ]
+                then
+                    awk -F "." '{for(f=NF;f > 1;f--) printf "%s.", $f;print $1}' "${adb_tmpfile}" | sort -u > "${adb_tmpload}"
+                    awk '{if(NR==1){tld=$NF};while(getline){if($NF !~ tld"\\."){print tld;tld=$NF}}print tld}' "${adb_tmpload}" > "${adb_tmpfile}"
+                    awk -F "." '{for(f=NF;f > 1;f--) printf "%s.", $f;print $1}' "${adb_tmpfile}" > "${adb_tmpload}"
+                    mv -f "${adb_tmpload}" "${adb_tmpfile}"
+                fi
                 f_list backup
             else
                 f_list restore
@@ -410,9 +422,9 @@ f_main()
         then
             if [ -s "${adb_tmpdir}/tmp.whitelist" ]
             then
-                grep -vf "${adb_tmpdir}/tmp.whitelist" "${adb_tmpfile}" | sort -u | eval "${adb_dnsformat}" > "${adb_dnsfile}"
+                grep -vf "${adb_tmpdir}/tmp.whitelist" "${adb_tmpfile}" | eval "${adb_dnsformat}" > "${adb_dnsfile}"
             else
-                sort -u "${adb_tmpfile}" | eval "${adb_dnsformat}" > "${adb_dnsfile}"
+                cat "${adb_tmpfile}" | eval "${adb_dnsformat}" > "${adb_dnsfile}"
             fi
             adb_rc=${?}
             if [ ${adb_rc} -ne 0 ]
@@ -472,34 +484,31 @@ f_main()
 
 # handle different adblock actions
 #
-if [ "${adb_procd}" = "true" ]
-then
-    f_envload
-    case "${1}" in
-        stop)
-            f_rmtemp
-            f_rmdns
-            f_dnsrestart
-            ;;
-        restart)
-            f_rmtemp
-            f_rmdns
-            f_envcheck
-            f_main
-            ;;
-        suspend)
-            f_switch suspend
-            ;;
-        resume)
-            f_switch resume
-            ;;
-        query)
-            f_query "${2}"
-            ;;
-        *)
-            f_envcheck
-            f_main
-            ;;
-    esac
-fi
+f_envload
+case "${1}" in
+    stop)
+        f_rmtemp
+        f_rmdns
+        f_dnsrestart
+        ;;
+    restart)
+        f_rmtemp
+        f_rmdns
+        f_envcheck
+        f_main
+        ;;
+    suspend)
+        f_switch suspend
+        ;;
+    resume)
+        f_switch resume
+        ;;
+    query)
+        f_query "${2}"
+        ;;
+    *)
+        f_envcheck
+        f_main
+        ;;
+esac
 exit 0