adblock: update 1.1.15 2751/head
authorDirk Brenken <dev@brenken.org>
Thu, 26 May 2016 15:40:32 +0000 (17:40 +0200)
committerDirk Brenken <dev@brenken.org>
Thu, 26 May 2016 15:43:34 +0000 (17:43 +0200)
* toggle to quickly switch adblocking 'on' or 'off' (/etc/init.d/adblock
toggle)
* new config option 'fetchttl' to set download timeouts (default: 5
seconds)
* better config check, distinct between major/minor changes
* documentation update

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

index b0fd19da2e33ad11cf6b29db8264c8aae966ac2a..3bc057cd866f5e82de82f3c7a6512251b9644606 100644 (file)
@@ -7,7 +7,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=adblock
-PKG_VERSION:=1.1.12
+PKG_VERSION:=1.1.15
 PKG_RELEASE:=1
 PKG_LICENSE:=GPL-3.0+
 PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
index 4831d27db87c45a30ffc1639ad1f9a469d5f76e3..7bdc729a38fc864b3399d0ccdf950eb24274fe77 100644 (file)
@@ -59,8 +59,9 @@ A lot of people already use adblocker plugins within their desktop browsers, but
 * status & error logging to stdout and syslog
 * use a dynamic uhttpd instance as an adblock pixel server
 * use dynamic iptables rulesets for adblock related redirects/rejects
-* openwrt init system support (start/stop/restart/reload)
+* init system support (start/stop/restart/reload/toggle)
 * hotplug support, the adblock start will be triggered by wan 'ifup' event
+* adblock toggle to quickly (temporary) switch adblocking 'on' or 'off'
 * optional: automatic adblock list backup/restore, backups will be (de-)compressed on the fly (disabled by default)
 * optional: add new adblock sources via uci config (see example below)
 
@@ -101,6 +102,8 @@ A lot of people already use adblocker plugins within their desktop browsers, but
 * **list updates:** for a scheduled call of the adblock service add an appropriate crontab entry (see example below)
 * **new list sources:** you could add new blocklist sources on your own via uci config, all you need is a source url and an awk one-liner (see example below)
 * **AP mode:** in AP mode adblock uses automatically the local router ip as nullip address. To make sure that your LuCI interface will be still accessible, please change the local uhttpd instance to ports <> 80/443 (see example below)
+* **adblock toggle:** to quickly switch adblocking 'on' or 'off', simply use _/etc/init.d/adblock toggle_
+* **outdated configuration:** if adblock detects an outdated config file, please copy the current version from '/etc/adblock/adblock.conf.default' to '/etc/config/adblock', make your individual changes and finally restart the adblock service
 * **debugging:** for script debugging please change the 'DEBUG' variable in the header of _/usr/bin/adblock-update.sh_ from '0' to '1' and start this script directly (without any parameters)
 * **disable active dns probing in windows:** to prevent a possible 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_
 
@@ -113,6 +116,7 @@ A lot of people already use adblocker plugins within their desktop browsers, but
     * adb\_nullipv4 => IPv4 blackhole ip address (default: '192.0.2.1', in AP mode: local router ip)
     * adb\_nullipv6 => IPv6 blackhole ip address (default: '::ffff:c000:0201', in AP mode: local router ip)
     * adb\_forcedns => redirect all DNS queries to local dnsmasq resolver (default: '1', enabled)
+    * adb\_fetchttl => set the timeout for list downloads (default: '5' seconds)
 
 ## Examples
 
index 50c68e4fbf8281defca7c0925fd283bb97b92315..15773efbef09acce0e4f4ba604973d211d63ee19 100644 (file)
@@ -38,6 +38,7 @@ f_envload()
     adb_whitelist="/etc/adblock/adblock.whitelist"
     adb_whitelist_rset="\$1 ~/^([A-Za-z0-9_-]+\.){1,}[A-Za-z]+/{print tolower(\$1)}"
     adb_forcedns=1
+    adb_fetchttl=5
 
     # function to parse global section by callback
     #
@@ -111,6 +112,7 @@ f_envload()
     adb_tmpfile="$(mktemp -tu)"
     adb_tmpdir="$(mktemp -p /tmp -d)"
     adb_dnsdir="/tmp/dnsmasq.d"
+    adb_dnshidedir="${adb_dnsdir}/.adb_hidden"
     adb_dnsprefix="adb_list"
     adb_uci="$(which uci)"
     adb_iptv4="$(which iptables)"
@@ -120,11 +122,14 @@ f_envload()
 
     # check 'enabled' & 'version' config options
     #
-    if [ -z "${adb_enabled}" ] || [ -z "${adb_cfgver}" ] || [ "${adb_cfgver}" != "${adb_mincfgver}" ]
+    if [ -z "${adb_enabled}" ] || [ -z "${adb_cfgver}" ] || [ "${adb_cfgver%%.*}" != "${adb_mincfgver%%.*}" ]
     then
         rc=-1
-        f_log "outdated adblock configuration found, please copy latest version from '/etc/adblock/adblock.conf.default' to '/etc/config/adblock'"
+        f_log "outdated adblock config (${adb_mincfgver} vs. ${adb_cfgver}), please use latest version from '/etc/adblock/adblock.conf.default'"
         f_exit
+    elif [ "${adb_cfgver#*.}" != "${adb_mincfgver#*.}" ]
+    then
+        outdate_ok="true"
     fi
     if [ $((adb_enabled)) -ne 1 ]
     then
@@ -202,6 +207,11 @@ f_envcheck()
 {
     local check
 
+    if [ "${outdate_ok}" = "true" ]
+    then
+        f_log "partially outdated adblock config (${adb_mincfgver} vs. ${adb_cfgver}), please use latest version from '/etc/adblock/adblock.conf.default'"
+    fi
+
     if [ "${apmode_ok}" = "true" ]
     then
         f_log "AP mode enabled"
@@ -235,9 +245,18 @@ f_envcheck()
         fi
     fi
 
+    # check dns hideout directory
+    #
+    if [ -d "${adb_dnshidedir}" ]
+    then
+        mv_done="$(find "${adb_dnshidedir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print -exec mv -f "{}" "${adb_dnsdir}" \;)"
+    else
+        mkdir -p -m 660 "${adb_dnshidedir}"
+    fi
+
     # check ca-certificates package and set fetch parms accordingly
     #
-    fetch_parm="--no-config --quiet --tries=1 --no-cache --no-cookies --max-redirect=0 --dns-timeout=5 --connect-timeout=5 --read-timeout=5"
+    fetch_parm="--no-config --quiet --tries=1 --no-cache --no-cookies --max-redirect=0 --dns-timeout=${adb_fetchttl} --connect-timeout=${adb_fetchttl} --read-timeout=${adb_fetchttl}"
     check="$(printf "${pkg_list}" | grep "^ca-certificates -")"
     if [ -z "${check}" ]
     then
index 883a0f5803b221ed70c0f01b39cdbfd5635e7427..222e41247bed745dafc517e0460f9095f169d42c 100755 (executable)
@@ -37,8 +37,8 @@ fi
 # get current directory and set script/config version
 #
 adb_scriptdir="${0%/*}"
-adb_scriptver="1.1.12"
-adb_mincfgver="1.3"
+adb_scriptver="1.1.15"
+adb_mincfgver="2.0"
 
 # source in adblock function library
 #
@@ -298,8 +298,9 @@ fi
 #
 f_cntconfig
 adb_count="$(${adb_uci} -q get "adblock.global.adb_overall_count")"
-if [ -n "${adb_revsrclist}" ] || [ -n "${rm_done}" ] || [ -n "${restore_done}" ]
+if [ -n "${adb_revsrclist}" ] || [ -n "${rm_done}" ] || [ -n "${restore_done}" ] || [ -n "${mv_done}" ]
 then
+    "${adb_uci}" -q set "adblock.global.adb_dnstoggle=on"
     /etc/init.d/dnsmasq restart
     sleep 1
     rc="$(ps | grep -q "[d]nsmasq"; printf ${?})"
index 199fa247334abe1ba3294f3c241df215cf078785..c3a0845961533f35096680520d1ac2af6012a73d 100644 (file)
@@ -3,10 +3,11 @@
 
 config adblock 'global'
        option adb_enabled '1'
-       option adb_cfgver '1.3'
+       option adb_cfgver '2.0'
        option adb_whitelist '/etc/adblock/adblock.whitelist'
        option adb_whitelist_rset '\$1 ~/^([A-Za-z0-9_-]+\.){1,}[A-Za-z]+/{print tolower(\$1)}'
        option adb_forcedns '1'
+       option adb_dnstoggle 'on'
 
 config service 'backup'
        option enabled '0'
index 754355333988a2c29dffa0432dd864fc8435425a..edd29a1101f605046eb24127b629fbef43899b17 100755 (executable)
@@ -2,13 +2,18 @@
 #
 
 START=99
+EXTRA_COMMANDS="toggle"
+EXTRA_HELP="        toggle  Toggle adblocking 'on' or 'off'"
 
 exec 2>/dev/null
 adb_pid="${$}"
 adb_script="/usr/bin/adblock-update.sh"
+adb_dnsdir="/tmp/dnsmasq.d"
+adb_dnshidedir="${adb_dnsdir}/.adb_hidden"
+adb_dnsprefix="adb_list"
 adb_pidfile="/var/run/adblock.pid"
-adb_logger="/usr/bin/logger"
-adb_uci="/sbin/uci"
+adb_logger="$(which logger)"
+adb_uci="$(which uci)"
 
 if [ -t 1 ]
 then
@@ -30,7 +35,7 @@ remove_config()
     local value opt section="${1}" options="adb_src_timestamp adb_src_count"
     for opt in ${options}
     do
-        ${adb_uci} -q delete "adblock.${section}.${opt}"
+        "${adb_uci}" -q delete "adblock.${section}.${opt}"
     done
 }
 
@@ -57,17 +62,47 @@ reload()
     start
 }
 
+toggle()
+{
+if [ -d "${adb_dnshidedir}" ]
+then
+    list_dns="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
+    list_dnshide="$(find "${adb_dnshidedir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print)"
+    if [ -n "${list_dns}" ]
+    then
+        mv -f "${adb_dnsdir}/${adb_dnsprefix}"* "${adb_dnshidedir}"
+        "${adb_uci}" -q set "adblock.global.adb_dnstoggle=off"
+        "${adb_uci}" -q commit "adblock"
+        /etc/init.d/dnsmasq restart
+        "${adb_logger}" ${log_parm} -t "adblock[${adb_pid}] info " "toggle for adblocking switched 'off'" 2>&1
+    elif [ -n "${list_dnshide}" ]
+    then
+        mv -f "${adb_dnshidedir}/${adb_dnsprefix}"* "${adb_dnsdir}"
+        "${adb_uci}" -q set "adblock.global.adb_dnstoggle=on"
+        "${adb_uci}" -q commit "adblock"
+        /etc/init.d/dnsmasq restart
+        "${adb_logger}" ${log_parm} -t "adblock[${adb_pid}] info " "toggle for adblocking switched 'on'" 2>&1
+    fi
+fi
+}
+
 stop()
 {
-    rm_done="$(find "/tmp/dnsmasq.d" -maxdepth 1 -type f -name "adb_list.*" -print -exec rm -f "{}" \;)"
+    if [ -d "${adb_dnshidedir}" ]
+    then
+        find "${adb_dnshidedir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -exec mv -f "{}" "${adb_dnsdir}" \;
+    fi
+    rm_done="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}*" -print -exec rm -f "{}" \;)"
     rc=${?}
     if [ $((rc)) -eq 0 ] && [ -n "${rm_done}" ]
     then
         . "/lib/functions.sh"
         config_load adblock
         config_foreach remove_config source
-        ${adb_uci} -q delete "adblock.global.adb_overall_count"
-        ${adb_uci} -q commit "adblock"
+        "${adb_uci}" -q set "adblock.global.adb_dnstoggle=on"
+        "${adb_uci}" -q delete "adblock.global.adb_overall_count"
+        "${adb_uci}" -q commit "adblock"
+        rm -rf "${adb_dnshidedir}"
         /etc/init.d/dnsmasq restart
         /etc/init.d/firewall restart
     fi