* => daily updates, approx. 1.500 entries
* [openphish](https://openphish.com)
* => numerous updates on the same day, approx. 1.800 entries
- * [palevo tracker](https://palevotracker.abuse.ch)
- * => daily updates, approx. 15 entries
* [ransomware tracker](https://ransomwaretracker.abuse.ch)
* => daily updates, approx. 150 entries
* [reg_cn](https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt)
* query function to quickly identify blocked (sub-)domains, e.g. for whitelisting
* optional: force dns requests to local resolver
* optional: force overall sort / duplicate removal for low memory devices (handle with care!)
-* optional: automatic block list backup & restore, backups will be (de-)compressed and restored on the fly in case of any runtime error
+* optional: 'manual mode' to re-use blocklist backups during startup, get fresh lists only via manual reload or restart action
+* optional: automatic block list backup & restore, they will be used in case of download errors or during startup in manual mode
* optional: add new adblock sources on your own via uci config
## Prerequisites
* adb\_triggerdelay => additional trigger delay in seconds before adblock processing starts (default: '2')
* 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\_manmode => do not automatically update blocklists during startup, use blocklist backups instead (default: '0', disabled)
## Examples
**change default dns backend to 'unbound':**
#
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-adb_ver="2.6.4"
+adb_ver="2.7.0"
adb_sysver="$(ubus -S call system board | jsonfilter -e '@.release.description')"
adb_enabled=1
adb_debug=0
+adb_minfree=2
+adb_manmode=0
adb_forcesrt=0
adb_forcedns=0
adb_backup=0
{
local services dns_up cnt=0
- # source in system library
+ # source in system libraries
#
if [ -r "/lib/functions.sh" ] && [ -r "/usr/share/libubox/jshn.sh" ]
then
#
f_dnsrestart()
{
- local cnt=0
+ local dns_up mem_free cnt=0
"/etc/init.d/${adb_dns}" restart >/dev/null 2>&1
while [ ${cnt} -le 10 ]
do
- adb_dnsup="$(ubus -S call service list "{\"name\":\"${adb_dns}\"}" | jsonfilter -l1 -e "@.${adb_dns}.instances.*.running")"
- if [ "${adb_dnsup}" = "true" ]
+ dns_up="$(ubus -S call service list "{\"name\":\"${adb_dns}\"}" | jsonfilter -l1 -e "@.${adb_dns}.instances.*.running")"
+ if [ "${dns_up}" = "true" ]
then
- break
+ mem_free="$(awk '/^MemFree/ {print int($2/1000)}' "/proc/meminfo")"
+ if [ ${mem_free} -ge ${adb_minfree} ]
+ then
+ return 0
+ fi
fi
cnt=$((cnt+1))
sleep 1
done
+ return 1
}
# f_list: backup/restore/remove block lists
fi
adb_rc=${?}
;;
+ format)
+ if [ -s "${adb_tmpdir}/tmp.whitelist" ]
+ then
+ grep -vf "${adb_tmpdir}/tmp.whitelist" "${adb_tmpfile}" | eval "${adb_dnsformat}" > "${adb_dnsfile}"
+ else
+ eval "${adb_dnsformat}" "${adb_tmpfile}" > "${adb_dnsfile}"
+ fi
+ adb_rc=${?}
+ ;;
esac
f_log "debug" "name: ${src_name}, mode: ${mode}, count: ${cnt}, in_rc: ${in_rc}, out_rc: ${adb_rc}"
}
f_rmdns
f_dnsrestart
fi
- exit 255
+ exit 1
fi
fi
}
#
f_main()
{
- local enabled url cnt sum_cnt=0 mem_total=0
- local src_name src_rset shalla_archive
- mem_total="$(awk '$1 ~ /^MemTotal/ {printf $2}' "/proc/meminfo" 2>/dev/null)"
+ local src_name src_rset shalla_archive enabled url cnt sum_cnt=0
+ local mem_total="$(awk '/^MemTotal/ {print int($2/1000)}' "/proc/meminfo")"
f_log "info " "start adblock processing ..."
- f_log "debug" "action: ${adb_action}, backup: ${adb_backup}, dns: ${adb_dns}, fetch: ${adb_fetchinfo}, memory: ${mem_total}, force srt/dns: ${adb_forcesrt}/${adb_forcedns}"
+ f_log "debug" "action: ${adb_action}, manual_mode:${adb_manmode}, backup: ${adb_backup}, dns: ${adb_dns}, fetch: ${adb_fetchinfo}, mem_total: ${mem_total}, force_srt/_dns: ${adb_forcesrt}/${adb_forcedns}"
> "${adb_rtfile}"
for src_name in ${adb_sources}
do
continue
fi
+ # manual mode
+ #
+ if [ ${adb_manmode} -eq 1 ] && [ -z "${adb_action}" ]
+ then
+ adb_rc=4
+ f_list restore
+ if [ ${adb_rc} -eq 0 ] && [ -s "${adb_tmpfile}" ]
+ then
+ f_list format
+ continue
+ fi
+ fi
+
# download block list
#
if [ "${src_name}" = "blacklist" ]
then
- cat "${url}" 2>/dev/null > "${adb_tmpload}"
+ cat "${url}" > "${adb_tmpload}"
adb_rc=${?}
elif [ "${src_name}" = "shalla" ]
then
shalla_archive="${adb_tmpdir}/shallalist.tar.gz"
- "${adb_fetch}" ${adb_fetchparm} "${shalla_archive}" "${url}" 2>/dev/null
+ "${adb_fetch}" ${adb_fetchparm} "${shalla_archive}" "${url}"
adb_rc=${?}
if [ ${adb_rc} -eq 0 ]
then
rm -f "${shalla_archive}"
rm -rf "${adb_tmpdir}/BL"
else
- "${adb_fetch}" ${adb_fetchparm} "${adb_tmpload}" "${url}" 2>/dev/null
+ "${adb_fetch}" ${adb_fetchparm} "${adb_tmpload}" "${url}"
adb_rc=${?}
fi
#
if [ ${adb_rc} -eq 0 ] && [ -s "${adb_tmpfile}" ]
then
- if [ -s "${adb_tmpdir}/tmp.whitelist" ]
- then
- grep -vf "${adb_tmpdir}/tmp.whitelist" "${adb_tmpfile}" 2>/dev/null | eval "${adb_dnsformat}" > "${adb_dnsfile}"
- else
- eval "${adb_dnsformat}" "${adb_tmpfile}" > "${adb_dnsfile}"
- fi
- adb_rc=${?}
+ f_list format
if [ ${adb_rc} -ne 0 ]
then
f_list remove
#
for src_name in $(ls -dASr "${adb_tmpdir}/${adb_dnsprefix}"* 2>/dev/null)
do
- if [ ${mem_total} -ge 64000 ] || [ ${adb_forcesrt} -eq 1 ]
+ if [ ${mem_total} -ge 64 ] || [ ${adb_forcesrt} -eq 1 ]
then
if [ -s "${adb_tmpdir}/blocklist.overall" ]
then
chown "${adb_dns}":"${adb_dns}" "${adb_dnsdir}/${adb_dnsprefix}"* 2>/dev/null
f_rmtemp
f_dnsrestart
- if [ "${adb_dnsup}" = "true" ]
+ if [ ${?} -eq 0 ]
then
json_init
json_add_object "data"