* zero-conf like automatic installation & setup, usually no manual changes needed
* simple but yet powerful adblock engine: adblock does not use error prone external iptables rulesets, http pixel server instances and things like that
* supports five different dns backends / blocklist formats: dnsmasq, unbound, named (bind), kresd and dnscrypt-proxy
-* automatically selects uclient-fetch or wget as download utility (other tools like curl or aria2c are supported as well)
+* supports six different download utilities: uclient-fetch, wget, curl, aria2c, wget-nossl, busybox-wget
* provides 'http only' mode without installed ssl library for all non-SSL blocklist sources
* supports a wide range of router modes, even AP modes are supported
* full IPv4 and IPv6 support
* **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_
## Further adblock config options
-* usually the pre-configured adblock setup works quite well and no manual config overrides are needed, all listed options apply to the 'global' config section:
+* usually the pre-configured adblock setup works quite well and no manual overrides are needed
+* the following options apply to the 'global' config section:
* adb\_enabled => main switch to enable/disable adblock service (default: '0', disabled)
* adb\_debug => enable/disable adblock debug output (default: '0', disabled)
+ * adb\_fetchutil => name of the used download utility: 'uclient-fetch', 'wget', 'curl', 'aria2c', 'wget-nossl'. 'busybox' (default: 'uclient-fetch')
+ * adb\_fetchparm => special config options for the download utility (default: not set)
* adb\_dns => select the dns backend for your environment: 'dnsmasq', 'unbound', 'named', 'kresd' or 'dnscrypt-proxy' (default: 'dnsmasq')
* adb\_dnsdir => target directory for the generated blocklist 'adb_list.overall' (default: not set, use dns backend default)
* adb\_trigger => set the startup trigger to a certain interface, to 'timed' or to 'none' (default: 'wan')
+
+* the following options apply to the 'extra' config section:
* adb\_triggerdelay => additional trigger delay in seconds before adblock processing begins (default: '1')
- * adb\_fetch => full path to a dedicated download utility, see example below (default: not set, use wget default)
- * adb\_fetchparm => options for the download utility, see example below (default: not set, use wget default options)
* adb\_forcedns => force dns requests to local resolver (default: '0', disabled)
* adb\_forcesrt => force overall sort on low memory devices with less than 64 MB RAM (default: '0', disabled)
* adb\_backup_mode => do not automatically update blocklists during startup, use backups instead (default: '0', disabled)
Edit the file '/etc/adblock/adblock.notify' and change at least the 'mail_receiver'.
Finally make this file executable via 'chmod' and test it directly. If no more errors come up you can comment 'mail_debug', too.
-**configuration for different download utilities:**
-
-<pre><code>
-wget (default):
- option adb_fetch '/usr/bin/wget'
- option adb_fetchparm '--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 --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=10 --no-check-certificate -O'
-
-curl:
- option adb_fetch '/usr/bin/curl'
- option adb_fetchparm '-s --connect-timeout 10 --insecure -o'
-</code></pre>
-
**receive adblock runtime information:**
<pre><code>
#
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-adb_ver="3.4.1"
+adb_ver="3.4.3"
adb_sysver="unknown"
adb_enabled=0
adb_debug=0
adb_triggerdelay=0
adb_backup=0
adb_backupdir="/mnt"
-adb_fetchutil="/usr/bin/wget"
-adb_fetchparm="--quiet --no-cache --no-cookies --max-redirect=0 --timeout=10 --no-check-certificate -O"
+adb_fetchutil="uclient-fetch"
adb_dns="dnsmasq"
adb_dnsprefix="adb_list"
adb_dnsfile="${adb_dnsprefix}.overall"
adb_cnt=0
adb_rc=0
adb_action="${1:-"start"}"
+adb_pidfile="/var/run/adblock.pid"
# load adblock environment
#
{
local dns_up sys_call sys_desc sys_model sys_ver cnt=0
- # create temp files and directories
- #
- adb_tmpload="$(mktemp -tu)"
- adb_tmpfile="$(mktemp -tu)"
- adb_tmpdir="$(mktemp -p /tmp -d)"
-
# get system information
#
sys_call="$(ubus -S call system board 2>/dev/null)"
if [ ${adb_enabled} -eq 0 ]
then
f_extconf
+ f_temp
f_rmdns
f_jsnup
f_log "info" "adblock is currently disabled, please set adb_enabled to '1' to use this service"
- f_rmtemp
exit 0
fi
printf '%s\n' "${adb_dnsheader}" > "${adb_dnsdir}/${adb_dnsfile}"
fi
- case "${adb_action}" in
- start|restart|reload)
- > "${adb_rtfile}"
- if [ "${adb_action}" = "start" ] && [ "${adb_trigger}" = "timed" ]
- then
- sleep ${adb_triggerdelay}
- fi
- ;;
- esac
+ if [ "${adb_action}" = "start" ] && [ "${adb_trigger}" = "timed" ]
+ then
+ sleep ${adb_triggerdelay}
+ fi
while [ ${cnt} -le 30 ]
do
{
local ssl_lib
- f_log "info" "start adblock processing (${adb_action})"
-
# check external uci config files
#
f_extconf
# check fetch utility
#
- if [ -x "${adb_fetchutil}" ]
- then
- if [ "$(readlink -fn "${adb_fetchutil}")" = "/usr/bin/wget-nossl" ]
- then
- adb_fetchparm="--quiet --no-cache --no-cookies --max-redirect=0 --timeout=10 -O"
- elif [ "$(readlink -fn "${adb_fetchutil}")" = "/bin/busybox" ] ||
- ([ "$(readlink -fn "/bin/wget")" = "/bin/busybox" ] && [ "$(readlink -fn "${adb_fetchutil}")" != "/usr/bin/wget" ])
- then
- adb_fetchutil="/bin/busybox"
- adb_fetchparm="-q -O"
- else
+ case "${adb_fetchutil}" in
+ uclient-fetch)
+ if [ -f "/lib/libustream-ssl.so" ]
+ then
+ adb_fetchparm="${adb_fetchparm:-"--timeout=10 --no-check-certificate -O"}"
+ ssl_lib="libustream-ssl"
+ else
+ adb_fetchparm="${adb_fetchparm:-"--timeout=10 -O"}"
+ fi
+ ;;
+ wget)
+ adb_fetchparm="${adb_fetchparm:-"--no-cache --no-cookies --max-redirect=0 --timeout=10 --no-check-certificate -O"}"
ssl_lib="built-in"
- fi
+ ;;
+ wget-nossl)
+ adb_fetchparm="${adb_fetchparm:-"--no-cache --no-cookies --max-redirect=0 --timeout=10 -O"}"
+ ;;
+ busybox)
+ adb_fetchparm="${adb_fetchparm:-"-O"}"
+ ;;
+ curl)
+ adb_fetchparm="${adb_fetchparm:-"--connect-timeout 10 --insecure -o"}"
+ ssl_lib="built-in"
+ ;;
+ aria2c)
+ adb_fetchparm="${adb_fetchparm:-"--timeout=10 --allow-overwrite=true --auto-file-renaming=false --check-certificate=false -o"}"
+ ssl_lib="built-in"
+ ;;
+ esac
+ adb_fetchutil="$(command -v "${adb_fetchutil}")"
+
+ if [ ! -x "${adb_fetchutil}" ] || [ -z "${adb_fetchutil}" ] || [ -z "${adb_fetchparm}" ]
+ then
+ f_log "err" "download utility not found, please install 'uclient-fetch' with 'libustream-mbedtls' or the full 'wget' package"
fi
- if [ ! -x "${adb_fetchutil}" ] && [ "$(readlink -fn "/bin/wget")" = "/bin/uclient-fetch" ]
+ adb_fetchinfo="${adb_fetchutil} (${ssl_lib:-"-"})"
+
+ f_temp
+ f_jsnup "running"
+ f_log "info" "start adblock processing (${adb_action})"
+}
+
+# create temporay files and directories
+#
+f_temp()
+{
+ if [ -z "${adb_tmpdir}" ]
then
- adb_fetchutil="/bin/uclient-fetch"
- if [ -f "/lib/libustream-ssl.so" ]
- then
- adb_fetchparm="-q --timeout=10 --no-check-certificate -O"
- ssl_lib="libustream-ssl"
- else
- adb_fetchparm="-q --timeout=10 -O"
- fi
+ adb_tmpdir="$(mktemp -p /tmp -d)"
+ adb_tmpload="$(mktemp -tu)"
+ adb_tmpfile="$(mktemp -tu)"
fi
- if [ ! -x "${adb_fetchutil}" ] || [ -z "${adb_fetchutil}" ] || [ -z "${adb_fetchparm}" ]
+ if [ ! -s "${adb_pidfile}" ]
then
- f_log "err" "no download utility found, please install 'uclient-fetch' with 'libustream-mbedtls' or the full 'wget' package"
+ printf '%s' "${$}" > "${adb_pidfile}"
fi
- adb_fetchinfo="${adb_fetchutil##*/} (${ssl_lib:-"-"})"
}
-# remove temp files and directories
+# remove temporay files and directories
#
f_rmtemp()
{
if [ -d "${adb_tmpdir}" ]
then
+ rm -rf "${adb_tmpdir}"
rm -f "${adb_tmpload}"
rm -f "${adb_tmpfile}"
- rm -rf "${adb_tmpdir}"
fi
+ > "${adb_pidfile}"
}
# remove dns related files and directories
then
f_dnsup
fi
+ f_rmtemp
fi
f_log "debug" "f_rmdns::: dns: ${adb_dns}, dns_dir: ${adb_dnsdir}, dns_prefix: ${adb_dnsprefix}, dns_file: ${adb_dnsfile}, rt_file: ${adb_rtfile}, backup_dir: ${adb_backupdir}"
}
;;
unbound)
cache_util="$(command -v unbound-control)"
- if [ -x "${cache_util}" ] && [ -f "${adb_dnsdir}"/unbound.conf ]
+ if [ -x "${cache_util}" ] && [ -d "${adb_tmpdir}" ] && [ -f "${adb_dnsdir}"/unbound.conf ]
then
"${cache_util}" -c "${adb_dnsdir}"/unbound.conf dump_cache > "${adb_tmpdir}"/adb_cache.dump 2>/dev/null
fi
case "${adb_dns}" in
unbound)
cache_util="$(command -v unbound-control)"
- if [ -x "${cache_util}" ] && [ -s "${adb_tmpdir}"/adb_cache.dump ]
+ if [ -x "${cache_util}" ] && [ -d "${adb_tmpdir}" ] && [ -s "${adb_tmpdir}"/adb_cache.dump ]
then
while [ ${cnt} -le 10 ]
do
cnt=$((cnt+1))
sleep 1
done
- f_log "debug" "f_dnsup::: cache_util: ${cache_util:-"-"}, cache_rc: ${cache_rc}, cache_flush: ${adb_dnsflush}, cache_cnt: ${cnt}, out_rc: ${adb_rc}"
+ f_log "debug" "f_dnsup::: cache_util: ${cache_util:-"-"}, cache_rc: ${cache_rc:-"-"}, cache_flush: ${adb_dnsflush}, cache_cnt: ${cnt}, out_rc: ${adb_rc}"
}
# backup/restore/remove blocklists
fi
if [ ${?} -eq 1 ]
then
+ f_temp
f_dnsup
f_jsnup
f_log "info" "${mode} adblock processing"
+ f_rmtemp
+ exit 0
fi
}
#
f_jsnup()
{
- local status bg_pid mode="normal mode" rundate="$(/bin/date "+%d.%m.%Y %H:%M:%S")"
+ local bg_pid rundate status="${1}" mode="normal mode"
- if [ ${adb_rc} -gt 0 ]
- then
- status="error"
- elif [ ${adb_enabled} -eq 0 ]
+ if [ -z "${status}" ]
then
- status="disabled"
- elif [ -s "${adb_dnsdir}/.${adb_dnsfile}" ]
- then
- status="paused"
- else
- status="enabled"
- f_count
+ rundate="$(/bin/date "+%d.%m.%Y %H:%M:%S")"
+ if [ ${adb_rc} -gt 0 ]
+ then
+ status="error"
+ elif [ ${adb_enabled} -eq 0 ]
+ then
+ status="disabled"
+ elif [ -s "${adb_dnsdir}/.${adb_dnsfile}" ]
+ then
+ status="paused"
+ else
+ status="enabled"
+ f_count
+ fi
fi
if [ ${adb_backup_mode} -eq 1 ]
json_add_string "overall_domains" "${adb_cnt} (${mode})"
json_add_string "fetch_utility" "${adb_fetchinfo:-"-"}"
json_add_string "dns_backend" "${adb_dns} (${adb_dnsdir})"
- json_add_string "last_rundate" "${rundate}"
+ json_add_string "last_rundate" "${rundate:-"-"}"
json_add_string "system_release" "${adb_sysver}"
json_close_object
json_dump > "${adb_rtfile}"
then
f_rmdns
f_jsnup
- f_rmtemp
logger -p "${class}" -t "adblock-[${adb_ver}]" "Please also check 'https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md' (${adb_sysver})"
exit 1
fi
#
f_main()
{
- local src_name src_rset shalla_archive enabled url mem_total="$(awk '/^MemTotal/ {print int($2/1000)}' "/proc/meminfo")"
+ local src_name src_rset src_log src_arc enabled url mem_total="$(awk '/^MemTotal/ {print int($2/1000)}' "/proc/meminfo")"
f_log "debug" "f_main ::: dns: ${adb_dns}, fetch_util: ${adb_fetchinfo}, backup: ${adb_backup}, backup_mode: ${adb_backup_mode}, whitelist_mode: ${adb_whitelist_mode}, force_srt: ${adb_forcesrt}, force_dns: ${adb_forcedns}, mem_total: ${mem_total}"
- > "${adb_rtfile}"
> "${adb_dnsdir}/.${adb_dnsfile}"
> "${adb_tmpdir}/tmp.whitelist"
fi
elif [ "${src_name}" = "shalla" ]
then
- shalla_archive="${adb_tmpdir}/shallalist.tar.gz"
- "${adb_fetchutil}" ${adb_fetchparm} "${shalla_archive}" "${url}" 2>/dev/null
+ src_arc="${adb_tmpdir}/shallalist.tar.gz"
+ src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${src_arc}" "${url}" 2>&1)"
adb_rc=${?}
if [ ${adb_rc} -eq 0 ]
then
for category in ${adb_src_cat_shalla}
do
- tar -xOzf "${shalla_archive}" "BL/${category}/domains" >> "${adb_tmpload}"
+ tar -xOzf "${src_arc}" "BL/${category}/domains" >> "${adb_tmpload}"
adb_rc=${?}
if [ ${adb_rc} -ne 0 ]
then
fi
done
fi
- rm -f "${shalla_archive}"
+ rm -f "${src_arc}"
rm -rf "${adb_tmpdir}/BL"
else
- "${adb_fetchutil}" ${adb_fetchparm} "${adb_tmpload}" "${url}" 2>/dev/null
+ src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${adb_tmpload}" "${url}" 2>&1)"
adb_rc=${?}
fi
+ if [ ${adb_rc} -ne 0 ] && [ "${src_name}" != "blacklist" ]
+ then
+ f_log "debug" "f_main ::: url: ${url}, rc: ${adb_rc}, src_log: ${src_log:-"-"}"
+ fi
# check download result and prepare list output
#
else
f_log "err" "dns backend restart with active blocklist failed"
fi
+ f_rmtemp
+ exit ${adb_rc}
}
# handle different adblock actions
f_main
;;
esac
-
-f_rmtemp
-exit ${adb_rc}