adblock: update 1.1.15

* 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>
This commit is contained in:
Dirk Brenken 2016-05-26 17:40:32 +02:00
parent bad84563dc
commit 4f3f239ff2
6 changed files with 75 additions and 15 deletions

View 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>

View 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

View 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

View File

@ -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 ${?})"

View 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'

View File

@ -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