Browse Source

adblock: update 4.1.0

* major source changes:
  * split oisd.nl in basic and full variant
  * add swedish regional list
  * made archive categories for shallalist and utcapitole selectable
    via LuCI
  * made all list variants of energized and stevenblack selectable
    via LuCI
* removed dns filereset mode

Signed-off-by: Dirk Brenken <dev@brenken.org>
lilik-openwrt-22.03
Dirk Brenken 4 years ago
parent
commit
215ffbe357
No known key found for this signature in database GPG Key ID: 9D71CD547BFAE684
7 changed files with 599 additions and 438 deletions
  1. +4
    -4
      net/adblock/Makefile
  2. +35
    -40
      net/adblock/files/README.md
  3. +145
    -0
      net/adblock/files/adblock.categories
  4. +183
    -70
      net/adblock/files/adblock.init
  5. +0
    -40
      net/adblock/files/adblock.monitor
  6. +203
    -201
      net/adblock/files/adblock.sh
  7. +29
    -83
      net/adblock/files/adblock.sources

+ 4
- 4
net/adblock/Makefile View File

@ -1,13 +1,13 @@
# #
# Copyright (c) 2015-2020 Dirk Brenken (dev@brenken.org)
# Copyright (c) 2015-2021 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3. # This is free software, licensed under the GNU General Public License v3.
# #
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=adblock PKG_NAME:=adblock
PKG_VERSION:=4.0.8
PKG_RELEASE:=3
PKG_VERSION:=4.1.0
PKG_RELEASE:=1
PKG_LICENSE:=GPL-3.0-or-later PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org> PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
@ -55,9 +55,9 @@ define Package/adblock/install
$(INSTALL_DIR) $(1)/etc/adblock $(INSTALL_DIR) $(1)/etc/adblock
$(INSTALL_BIN) ./files/adblock.mail $(1)/etc/adblock $(INSTALL_BIN) ./files/adblock.mail $(1)/etc/adblock
$(INSTALL_BIN) ./files/adblock.monitor $(1)/etc/adblock
$(INSTALL_CONF) ./files/adblock.blacklist $(1)/etc/adblock $(INSTALL_CONF) ./files/adblock.blacklist $(1)/etc/adblock
$(INSTALL_CONF) ./files/adblock.whitelist $(1)/etc/adblock $(INSTALL_CONF) ./files/adblock.whitelist $(1)/etc/adblock
$(INSTALL_CONF) ./files/adblock.categories $(1)/etc/adblock
$(INSTALL_CONF) ./files/adblock.sources $(1)/etc/adblock $(INSTALL_CONF) ./files/adblock.sources $(1)/etc/adblock
gzip -9 $(1)/etc/adblock/adblock.sources gzip -9 $(1)/etc/adblock/adblock.sources
endef endef


+ 35
- 40
net/adblock/files/README.md View File

@ -18,17 +18,13 @@ A lot of people already use adblocker plugins within their desktop browsers, but
| anudeep | | M | compilation | [Link](https://github.com/anudeepND/blacklist) | | anudeep | | M | compilation | [Link](https://github.com/anudeepND/blacklist) |
| bitcoin | | S | mining | [Link](https://github.com/hoshsadiq/adblock-nocoin-list) | | bitcoin | | S | mining | [Link](https://github.com/hoshsadiq/adblock-nocoin-list) |
| disconnect | x | S | general | [Link](https://disconnect.me) | | disconnect | x | S | general | [Link](https://disconnect.me) |
| energized_blugo | | XL | compilation | [Link](https://energized.pro) |
| energized_blu | | XL | compilation | [Link](https://energized.pro) |
| energized_porn | | XXL | compilation+porn | [Link](https://energized.pro) |
| energized_ultimate | | XXL | compilation | [Link](https://energized.pro) |
| energized_unified | | XXL | compilation | [Link](https://energized.pro) |
| energized | | VAR | compilation | [Link](https://energized.pro) |
| firetv_tracking | | S | tracking | [Link](https://github.com/Perflyst/PiHoleBlocklist) | | firetv_tracking | | S | tracking | [Link](https://github.com/Perflyst/PiHoleBlocklist) |
| games_tracking | | S | tracking | [Link](https://www.gameindustry.eu) | | games_tracking | | S | tracking | [Link](https://www.gameindustry.eu) |
| gaming | | S | gaming | [Link](https://github.com/abyssin/pihole-blocklist) | | gaming | | S | gaming | [Link](https://github.com/abyssin/pihole-blocklist) |
| malwaredomains | | M | malware | [Link](https://malwaredomains.com) |
| notracking | | XL | tracking | [Link](https://github.com/notracking/hosts-blocklists) | | notracking | | XL | tracking | [Link](https://github.com/notracking/hosts-blocklists) |
| oisd_nl | | XXL | general | [Link](https://oisd.nl) |
| oisd_basic | | L | general | [Link](https://oisd.nl) |
| oisd_full | | XXL | general | [Link](https://oisd.nl) |
| openphish | | S | phishing | [Link](https://openphish.com) | | openphish | | S | phishing | [Link](https://openphish.com) |
| phishing_army | | S | phishing | [Link](https://phishing.army) | | phishing_army | | S | phishing | [Link](https://phishing.army) |
| reg_cn | | M | reg_china | [Link](https://easylist.to) | | reg_cn | | M | reg_china | [Link](https://easylist.to) |
@ -45,16 +41,14 @@ A lot of people already use adblocker plugins within their desktop browsers, but
| reg_pl2 | | S | reg_poland | [Link](https://www.certyficate.it) | | reg_pl2 | | S | reg_poland | [Link](https://www.certyficate.it) |
| reg_ro | | M | reg_romania | [Link](https://easylist.to) | | reg_ro | | M | reg_romania | [Link](https://easylist.to) |
| reg_ru | | M | reg_russia | [Link](https://easylist.to) | | reg_ru | | M | reg_russia | [Link](https://easylist.to) |
| reg_se | | M | reg_sweden | [Link](https://github.com/lassekongo83/Frellwits-filter-lists) |
| reg_vn | | S | reg_vietnam | [Link](https://bigdargon.github.io/hostsVN) | | reg_vn | | S | reg_vietnam | [Link](https://bigdargon.github.io/hostsVN) |
| shallalist | | L | general | [Link](https://www.shallalist.de) |
| shallalist_porn | | XXL | general+porn | [Link](https://www.shallalist.de) |
| shallalist | | VAR | general | [Link](https://www.shallalist.de) |
| smarttv_tracking | | S | tracking | [Link](https://github.com/Perflyst/PiHoleBlocklist) | | smarttv_tracking | | S | tracking | [Link](https://github.com/Perflyst/PiHoleBlocklist) |
| spam404 | | S | general | [Link](https://github.com/Dawsey21) | | spam404 | | S | general | [Link](https://github.com/Dawsey21) |
| stevenblack | | L | compilation | [Link](https://github.com/StevenBlack/hosts) |
| stevenblack_porn | | L | compilation+porn | [Link](https://github.com/StevenBlack/hosts) |
| stevenblack | | VAR | compilation | [Link](https://github.com/StevenBlack/hosts) |
| stopforumspam | | S | spam | [Link](https://www.stopforumspam.com) | | stopforumspam | | S | spam | [Link](https://www.stopforumspam.com) |
| utcapitole | | L | general | [Link](https://dsi.ut-capitole.fr/blacklists/index_en.php) |
| utcapitole_porn | | XXL | general+porn | [Link](https://dsi.ut-capitole.fr/blacklists/index_en.php) |
| utcapitole | | VAR | general | [Link](https://dsi.ut-capitole.fr/blacklists/index_en.php) |
| wally3k | | S | compilation | [Link](https://firebog.net/about) | | wally3k | | S | compilation | [Link](https://firebog.net/about) |
| whocares | | M | general | [Link](https://someonewhocares.org) | | whocares | | M | general | [Link](https://someonewhocares.org) |
| winhelp | | S | general | [Link](https://winhelp2002.mvps.org) | | winhelp | | S | general | [Link](https://winhelp2002.mvps.org) |
@ -117,26 +111,28 @@ A lot of people already use adblocker plugins within their desktop browsers, but
## Adblock CLI Options ## Adblock CLI Options
* All important adblock functions are accessible via CLI as well. * All important adblock functions are accessible via CLI as well.
<b>Please note:</b> The 'status' command in 19.07.x and TurrisOS is only available via 'status_service'
<pre><code> <pre><code>
/etc/init.d/adblock
~# /etc/init.d/adblock
Syntax: /etc/init.d/adblock [command] Syntax: /etc/init.d/adblock [command]
Available commands: Available commands:
start Start the service
stop Stop the service
restart Restart the service
reload Reload configuration files (or restart if service does not implement reload)
enable Enable service autostart
disable Disable service autostart
running Check if service is running
status Service status
suspend Suspend adblock processing
resume Resume adblock processing
query &lt;domain&gt; Query active blocklists and backups for a specific domain
report [&lt;search&gt;] Print DNS statistics with an optional search parameter
list [[&lt;add&gt;|&lt;remove&gt;] [source(s)]] List available adblock sources or add/remove them from config
timer &lt;action&gt; &lt;hour&gt; [&lt;minute&gt;] [&lt;weekday&gt;] Set a cron based update interval
start Start the service
stop Stop the service
restart Restart the service
reload Reload configuration files (or restart if service does not implement reload)
enable Enable service autostart
disable Disable service autostart
enabled Check if service is started on boot
suspend Suspend adblock processing
resume Resume adblock processing
query &lt;domain&gt; Query active blocklists and backups for a specific domain
report [&lt;search&gt;] Print DNS statistics with an optional search parameter
list [&lt;add&gt;|&lt;add_sha&gt;|&lt;add_utc&gt;|&lt;add_eng&gt;|&lt;add_stb&gt;|&lt;remove&gt;|&lt;remove_sha&gt;|&lt;remove_utc&gt;|&lt;remove_eng&gt;|&lt;remove_stb&gt;] &lt;source(s)&gt; List/Edit available sources
timer [&lt;add&gt; &lt;tasks&gt; &lt;hour&gt; [&lt;minute&gt;] [&lt;weekday&gt;]]|[&lt;remove&gt; &lt;line no.&gt;] List/Edit cron update intervals
version Print version information
running Check if service is running
status Service status
trace Start with syscall trace
</code></pre> </code></pre>
## Adblock Config Options ## Adblock Config Options
@ -159,7 +155,6 @@ Available commands:
| adb_dnsdir | -, auto-detected | path for the generated blocklist file 'adb_list.overall' | | adb_dnsdir | -, auto-detected | path for the generated blocklist file 'adb_list.overall' |
| adb_dnstimeout | 10 | timeout in seconds to wait for a successful DNS backend restart | | adb_dnstimeout | 10 | timeout in seconds to wait for a successful DNS backend restart |
| adb_dnsinstance | 0, first instance | set to the relevant dns backend instance used by adblock (dnsmasq only) | | adb_dnsinstance | 0, first instance | set to the relevant dns backend instance used by adblock (dnsmasq only) |
| adb_dnsfilereset | 0, disabled | set to 1 to purge the final DNS blocklist file after DNS backend loading |
| adb_dnsflush | 0, disabled | set to 1 to flush the DNS Cache before & after adblock processing | | adb_dnsflush | 0, disabled | set to 1 to flush the DNS Cache before & after adblock processing |
| adb_dnsinotify | -, not set | set to 1 to prevent adblock triggered restarts for DNS backends with autoload functions | | adb_dnsinotify | -, not set | set to 1 to prevent adblock triggered restarts for DNS backends with autoload functions |
| adb_dnsallow | -, not set | set to 1 to disable selective DNS whitelisting (RPZ pass through) | | adb_dnsallow | -, not set | set to 1 to disable selective DNS whitelisting (RPZ pass through) |
@ -236,19 +231,19 @@ Finally enable E-Mail support and add a valid E-Mail receiver address in LuCI.
In LuCI you'll see the realtime status in the 'Runtime' section on the overview page. In LuCI you'll see the realtime status in the 'Runtime' section on the overview page.
To get the status in the CLI, just call _/etc/init.d/adblock status_ or _/etc/init.d/adblock status\_service_ (in 19.07 and TurrisOS): To get the status in the CLI, just call _/etc/init.d/adblock status_ or _/etc/init.d/adblock status\_service_ (in 19.07 and TurrisOS):
<pre><code> <pre><code>
/etc/init.d/adblock status_service
~# /etc/init.d/adblock status
::: adblock runtime information ::: adblock runtime information
+ adblock_status : enabled + adblock_status : enabled
+ adblock_version : 4.0.2
+ blocked_domains : 52420
+ active_sources : adaway adguard andryou bitcoin disconnect winspy yoyo
+ dns_backend : kresd, /etc/kresd
+ run_utils : /usr/bin/curl, /bin/awk
+ adblock_version : 4.1.0
+ blocked_domains : 32658
+ active_sources : android_tracking, disconnect, shallalist
+ dns_backend : dnsmasq, /tmp/dnsmasq.d
+ run_utils : /usr/bin/curl, /usr/bin/gawk
+ run_ifaces : trigger: trm_wwan, report: br-lan + run_ifaces : trigger: trm_wwan, report: br-lan
+ run_directories : base: /tmp, backup: /tmp, report: /tmp, jail: /tmp
+ run_flags : backup: 1, reset: 0, flush: 0, force: 1, search: 0, report: 1, mail: 0, jail: 0
+ last_run : start, 0m 17s, 496/198/218, 03.04.2020 08:55:14
+ system : CZ.NIC Turris Mox Board, TurrisOS 5.1.0 81264ebb51991aa2d17489852854e3b5ec3f514d
+ run_directories : base: /tmp, backup: /tmp/adblock-Backup, report: /tmp/adblock-Report, jail: /tmp
+ run_flags : backup: 1, flush: 0, force: 1, search: 1, report: 1, mail: 0, jail: 0
+ last_run : reload, 0m 25s, 252/177/167, 26.02.2021 18:31:41
+ system : GL.iNet GL-MT1300, OpenWrt SNAPSHOT r15875-1bf6d70e60
</code></pre> </code></pre>
The 'last\_run' line includes the used start type, the run duration, the memory footprint after DNS backend loading (total/free/available) and the date/time of the last run. The 'last\_run' line includes the used start type, the run duration, the memory footprint after DNS backend loading (total/free/available) and the date/time of the last run.


+ 145
- 0
net/adblock/files/adblock.categories View File

@ -0,0 +1,145 @@
eng;basic;basic/formats/domains.txt
eng;blu;blu/formats/domains.txt
eng;blugo;bluGo/formats/domains.txt
eng;ext-extreme;extensions/xtreme/formats/domains.txt
eng;ext-pornlite;extensions/porn-lite/formats/domains.txt
eng;ext-regional;extensions/regional/formats/domains.txt
eng;ext-social;extensions/social/formats/domains.txt
eng;porn;porn/formats/domains.txt
eng;spark;spark/formats/domains.txt
eng;ultimate;ultimate/formats/domains.txt
eng;unified;unified/formats/domains.txt
sha;adv
sha;aggressive
sha;alcohol
sha;anonvpn
sha;automobile
sha;chat
sha;costtraps
sha;dating
sha;downloads
sha;drugs
sha;dynamic
sha;education
sha;finance
sha;fortunetelling
sha;forum
sha;gamble
sha;government
sha;hacking
sha;hobby
sha;homestyle
sha;hospitals
sha;imagehosting
sha;isp
sha;jobsearch
sha;library
sha;military
sha;models
sha;movies
sha;music
sha;news
sha;podcasts
sha;politics
sha;porn
sha;radiotv
sha;recreation
sha;redirector
sha;religion
sha;remotecontrol
sha;ringtones
sha;science
sha;searchengines
sha;sex
sha;shopping
sha;socialnet
sha;spyware
sha;tracker
sha;updatesites
sha;urlshortener
sha;violence
sha;warez
sha;weapons
sha;webmail
sha;webphone
sha;webradio
sha;webtv
stb;fakenews;alternates/fakenews/hosts
stb;fakenews-gambling;alternates/fakenews-gambling/hosts
stb;fakenews-gambling-porn;alternates/fakenews-gambling-porn/hosts
stb;fakenews-gambling-porn-social;alternates/fakenews-porn-social/hosts
stb;fakenews-gambling-social;alternates/fakenews-gambling-social/hosts
stb;fakenews-porn;alternates/fakenews-porn/hosts
stb;fakenews-porn-social;alternates/fakenews-porn-social/hosts
stb;fakenews-social;alternates/fakenews-social/hosts
stb;gambling;alternates/gambling/hosts
stb;gambling-porn;alternates/gambling-porn/hosts
stb;gambling-porn-social;alternates/gambling-porn-social/hosts
stb;gambling-social;alternates/gambling-social/hosts
stb;porn;alternates/porn/hosts
stb;porn-social;alternates/porn-social/hosts
stb;social;alternates/social/hosts
stb;standard;hosts
utc;adult
utc;agressif
utc;arjel
utc;associations_religieuses
utc;astrology
utc;audio-video
utc;bank
utc;bitcoin
utc;blog
utc;celebrity
utc;chat
utc;child
utc;cleaning
utc;cooking
utc;cryptojacking
utc;dangerous_material
utc;dating
utc;ddos
utc;dialer
utc;doh
utc;download
utc;drogue
utc;educational_games
utc;examen_pix
utc;exceptions_liste_bu
utc;filehosting
utc;financial
utc;forums
utc;gambling
utc;games
utc;hacking
utc;jobsearch
utc;lingerie
utc;liste_blanche
utc;liste_bu
utc;malware
utc;manga
utc;marketingware
utc;mixed_adult
utc;mobile-phone
utc;phishing
utc;press
utc;publicite
utc;radio
utc;reaffected
utc;redirector
utc;remote-control
utc;sect
utc;sexual_education
utc;shopping
utc;shortener
utc;social_networks
utc;special
utc;sports
utc;stalkerware
utc;strict_redirector
utc;strong_redirector
utc;translation
utc;tricheur
utc;update
utc;vpn
utc;warez
utc;webmail

+ 183
- 70
net/adblock/files/adblock.init View File

@ -1,5 +1,5 @@
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
# Copyright (c) 2015-2020 Dirk Brenken (dev@brenken.org)
# Copyright (c) 2015-2021 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3. # This is free software, licensed under the GNU General Public License v3.
# set (s)hellcheck exceptions # set (s)hellcheck exceptions
@ -8,13 +8,26 @@
START=30 START=30
USE_PROCD=1 USE_PROCD=1
extra_command "suspend" "Suspend adblock processing"
extra_command "resume" "Resume adblock processing"
extra_command "query" "<domain> Query active blocklists and backups for a specific domain"
extra_command "report" "[<search>] Print DNS statistics with an optional search parameter"
extra_command "list" "[[<add>|<remove>] [source(s)]] List available adblock sources or add/remove them from config"
extra_command "timer" "<action> <hour> [<minute>] [<weekday>] Set a cron based update interval"
extra_command "version" "Print version information"
if [ -n "$(type -t extra_command)" ]
then
extra_command "suspend" "Suspend adblock processing"
extra_command "resume" "Resume adblock processing"
extra_command "query" "<domain> Query active blocklists and backups for a specific domain"
extra_command "report" "[<search>] Print DNS statistics with an optional search parameter"
extra_command "list" "[<add>|<add_sha>|<add_utc>|<add_eng>|<add_stb>|<remove>|<remove_sha>|<remove_utc>|<remove_eng>|<remove_stb>] <source(s)> List/Edit available sources"
extra_command "timer" "[<add> <tasks> <hour> [<minute>] [<weekday>]]|[<remove> <line no.>] List/Edit cron update intervals"
extra_command "version" "Print version information"
else
EXTRA_COMMANDS="status suspend resume query report list timer version"
EXTRA_HELP=" status Service status
suspend Suspend adblock processing
resume Resume adblock processing
query <domain> Query active blocklists and backups for a specific domain
report [<search>] Print DNS statistics with an optional search parameter
list [<add>|<add_sha>|<add_utc>|<add_eng>|<add_stb>|<remove>|<remove_sha>|<remove_utc>|<remove_eng>|<remove_stb>] <source(s)> List/Edit available sources
timer [<add> <tasks> <hour> [<minute>] [<weekday>]]|[<remove> <line no.>] List/Edit cron update intervals
version Print version information"
fi
adb_init="/etc/init.d/adblock" adb_init="/etc/init.d/adblock"
adb_script="/usr/bin/adblock.sh" adb_script="/usr/bin/adblock.sh"
@ -97,27 +110,85 @@ report()
list() list()
{ {
local src_archive src_file src_enabled enabled name action="${1}"
local src_archive src_file src_enabled enabled name sha_list utc_list action="${1}"
if [ "${action}" = "add" ] || [ "${action}" = "remove" ]
if [ "${action%_*}" = "add" ] || [ "${action%_*}" = "remove" ]
then then
shift shift
for name in "${@}" for name in "${@}"
do do
if [ "${action}" = "add" ]
then
if [ -z "$(uci_get adblock global adb_sources | grep -Fo "${name}")" ]
then
uci_add_list adblock global adb_sources "${name}"
printf "%s\\n" "::: adblock source '${name}' added to config"
fi
else
if [ -n "$(uci_get adblock global adb_sources | grep -Fo "${name}")" ]
then
uci_remove_list adblock global adb_sources "${name}"
printf "%s\\n" "::: adblock source '${name}' removed from config"
fi
fi
case "${action}" in
"add")
if [ -z "$(uci_get adblock global adb_sources | grep -Fo "${name}")" ]
then
uci_add_list adblock global adb_sources "${name}"
printf "%s\n" "::: adblock source '${name}' added to config"
fi
;;
"remove")
if [ -n "$(uci_get adblock global adb_sources | grep -Fo "${name}")" ]
then
uci_remove_list adblock global adb_sources "${name}"
printf "%s\n" "::: adblock source '${name}' removed from config"
fi
;;
"add_sha")
if [ -z "$(uci_get adblock global adb_sha_sources | grep -Fo "${name}")" ]
then
uci_add_list adblock global adb_sha_sources "${name}"
printf "%s\n" "::: adblock shallalist '${name}' added to config"
fi
;;
"remove_sha")
if [ -n "$(uci_get adblock global adb_sha_sources | grep -Fo "${name}")" ]
then
uci_remove_list adblock global adb_sha_sources "${name}"
printf "%s\n" "::: adblock shallalist '${name}' removed from config"
fi
;;
"add_utc")
if [ -z "$(uci_get adblock global adb_utc_sources | grep -Fo "${name}")" ]
then
uci_add_list adblock global adb_utc_sources "${name}"
printf "%s\n" "::: adblock utcapitole '${name}' added to config"
fi
;;
"remove_utc")
if [ -n "$(uci_get adblock global adb_utc_sources | grep -Fo "${name}")" ]
then
uci_remove_list adblock global adb_utc_sources "${name}"
printf "%s\n" "::: adblock utcapitole '${name}' removed from config"
fi
;;
"add_eng")
if [ -z "$(uci_get adblock global adb_eng_sources | grep -Fo "${name}")" ]
then
uci_add_list adblock global adb_eng_sources "${name}"
printf "%s\n" "::: adblock energized '${name}' added to config"
fi
;;
"remove_eng")
if [ -n "$(uci_get adblock global adb_eng_sources | grep -Fo "${name}")" ]
then
uci_remove_list adblock global adb_eng_sources "${name}"
printf "%s\n" "::: adblock energized '${name}' removed from config"
fi
;;
"add_stb")
if [ -z "$(uci_get adblock global adb_stb_sources | grep -Fo "${name}")" ]
then
uci_add_list adblock global adb_stb_sources "${name}"
printf "%s\n" "::: adblock stevenblack '${name}' added to config"
fi
;;
"remove_stb")
if [ -n "$(uci_get adblock global adb_stb_sources | grep -Fo "${name}")" ]
then
uci_remove_list adblock global adb_stb_sources "${name}"
printf "%s\n" "::: adblock stevenblack '${name}' removed from config"
fi
;;
esac
done done
if [ -n "$(uci -q changes adblock)" ] if [ -n "$(uci -q changes adblock)" ]
then then
@ -132,16 +203,16 @@ list()
then then
zcat "${src_archive}" > "${src_file}" zcat "${src_archive}" > "${src_file}"
else else
printf "%s\\n" "::: adblock source archive '${src_archive}' not found"
printf "%s\n" "::: adblock source archive '${src_archive}' not found"
fi fi
if [ -r "${src_file}" ] if [ -r "${src_file}" ]
then then
src_enabled="${src_enabled#*=}" src_enabled="${src_enabled#*=}"
src_enabled="${src_enabled//\'}" src_enabled="${src_enabled//\'}"
printf "%s\\n" "::: Available adblock sources"
printf "%s\\n" ":::"
printf "%-25s%-10s%-7s%-21s%s\\n" " Name" "Enabled" "Size" "Focus" "Info URL"
printf "%s\\n" " -------------------------------------------------------------------"
printf "%s\n" "::: Available adblock sources"
printf "%s\n" ":::"
printf "%-25s%-10s%-7s%-21s%s\n" " Name" "Enabled" "Size" "Focus" "Info URL"
printf "%s\n" " -------------------------------------------------------------------"
json_load_file "${src_file}" json_load_file "${src_file}"
json_get_keys keylist json_get_keys keylist
for key in ${keylist} for key in ${keylist}
@ -161,98 +232,140 @@ list()
enabled=" " enabled=" "
fi fi
src_enabled="${src_enabled/${key}}" src_enabled="${src_enabled/${key}}"
printf " + %-21s%-10s%-7s%-21s%s\\n" "${key:0:20}" "${enabled}" "${size:0:3}" "${focus:0:20}" "${descurl:0:50}"
printf " + %-21s%-10s%-7s%-21s%s\n" "${key:0:20}" "${enabled}" "${size:0:3}" "${focus:0:20}" "${descurl:0:50}"
else else
src_enabled="${src_enabled} ${key}" src_enabled="${src_enabled} ${key}"
fi fi
json_select .. json_select ..
done done
sha_list="$(uci_get adblock global adb_sha_sources "-")"
utc_list="$(uci_get adblock global adb_utc_sources "-")"
eng_list="$(uci_get adblock global adb_eng_sources "-")"
stb_list="$(uci_get adblock global adb_stb_sources "-")"
printf "%s\n" " ---------------------------------------------------------------------------"
printf " * %s\n" "Configured shallalist categories: ${sha_list// /, }"
printf " * %s\n" "Configured utcapitole categories: ${utc_list// /, }"
printf " * %s\n" "Configured energized variants: ${eng_list// /, }"
printf " * %s\n" "Configured stevenblack variants: ${stb_list// /, }"
if [ -n "${src_enabled// }" ] if [ -n "${src_enabled// }" ]
then then
printf "%s\\n" " ----------------------------------------------"
printf "%s\\n" " Sources without valid configuration"
printf "%s\\n" " ----------------------------------------------"
printf "%s\n" " ---------------------------------------------------------------------------"
printf "%s\n" " Sources without valid configuration"
printf "%s\n" " ---------------------------------------------------------------------------"
for key in ${src_enabled} for key in ${src_enabled}
do do
printf " - %s\\n" "${key:0:20}"
printf " - %s\n" "${key:0:20}"
done done
fi fi
else else
printf "%s\\n" "::: adblock source file '${src_file}' not found"
printf "%s\n" "::: adblock source file '${src_file}' not found"
fi fi
fi fi
} }
status()
{
status_service
}
status_service() status_service()
{ {
local key keylist value rtfile
local key keylist value idxval values rtfile
rtfile="$(uci_get adblock global adb_rtfile "/tmp/adb_runtime.json")" rtfile="$(uci_get adblock global adb_rtfile "/tmp/adb_runtime.json")"
if [ -s "${rtfile}" ]
json_load_file "${rtfile}" >/dev/null 2>&1
json_get_keys keylist
if [ -n "${keylist}" ]
then then
printf "%s\\n" "::: adblock runtime information"
json_load_file "${rtfile}"
json_select data
json_get_keys keylist
printf "%s\n" "::: adblock runtime information"
for key in ${keylist} for key in ${keylist}
do do
json_get_var value "${key}"
if [ "${key}" = "active_sources" ]
json_get_var value "${key}" >/dev/null 2>&1
if [ "${key%_*}" = "active" ]
then then
printf " + %-15s : " "${key}" printf " + %-15s : " "${key}"
json_select "${key}"
json_select "${key}" >/dev/null 2>&1
values=""
index=1 index=1
while json_get_type status "${index}" && [ "${status}" = "object" ]
while json_get_type type "${index}" && [ "${type}" = "object" ]
do do
json_get_values source "${index}"
printf "%s " "${source}"
json_get_values idxval "${index}" >/dev/null 2>&1
if [ "${index}" = "1" ]
then
values="${idxval}"
else
values="${values}, ${idxval}"
fi
index=$((index+1)) index=$((index+1))
done done
printf "\\n"
values="$(printf "%s" "${values}" | awk '{NR=1;max=98;if(length($0)>max+1)while($0){if(NR==1){print substr($0,1,max)}else{printf"%-22s%s\n","",substr($0,1,max)}{$0=substr($0,max+1);NR=NR+1}}else print}')"
printf "%s\n" "${values:-"-"}"
json_select ".." json_select ".."
else else
printf " + %-15s : %s\\n" "${key}" "${value}"
printf " + %-15s : %s\n" "${key}" "${value:-"-"}"
fi fi
done done
else else
printf "%s\\n" "::: no adblock runtime information available"
printf "%s\n" "::: no adblock runtime information available"
fi fi
} }
timer() timer()
{ {
local action="${1}" hour="${2}" minute="${3:-0}" weekday="${4:-"*"}"
local cron_file cron_content cron_lineno action="${1:-"list"}" cron_tasks="${2}" hour="${3}" minute="${4:-0}" weekday="${5:-"*"}"
cron_file="/etc/crontabs/root"
hour="${hour//[[:alpha:]]/}"
minute="${minute//[[:alpha:]]/}"
if [ -n "${action}" ] && [ -n "${hour}" ] && [ -n "${minute}" ] && [ -n "${weekday}" ] && \
[ "${hour}" -ge 0 ] && [ "${hour}" -le 23 ] && \
[ "${minute}" -ge 0 ] && [ "${minute}" -le 59 ]
if [ -s "${cron_file}" ] && [ "${action}" = "list" ]
then
awk '{print NR "> " $0}' "${cron_file}"
elif [ "${action}" = "add" ]
then then
if [ -r "/etc/crontabs/root" ]
hour="${hour//[[:alpha:]]/}"
minute="${minute//[[:alpha:]]/}"
if [ -n "${cron_tasks}" ] && [ -n "${hour}" ] && [ -n "${minute}" ] && [ -n "${weekday}" ] && \
[ "${hour}" -ge 0 ] && [ "${hour}" -le 23 ] && \
[ "${minute}" -ge 0 ] && [ "${minute}" -le 59 ]
then then
search="${adb_init//\//\\/}"
search="${search//./\\.}"
sed -i "/${search}/d" "/etc/crontabs/root"
printf "%02d %02d %s\n" "${minute}" "${hour}" "* * ${weekday} ${adb_init} ${cron_tasks}" >> "${cron_file}"
/etc/init.d/cron restart
fi
elif [ -s "${cron_file}" ] && [ "${action}" = "remove" ]
then
cron_tasks="${cron_tasks//[[:alpha:]]/}"
cron_lineno="$(awk 'END{print NR}' "${cron_file}")"
cron_content="$(awk '{print $0}' "${cron_file}")"
if [ "${cron_tasks:-"0"}" -le "${cron_lineno:-"1"}" ] && [ -n "${cron_content}" ]
then
printf "%s\n" "${cron_content}" | awk "NR!~/^${cron_tasks}$/" > "${cron_file}"
/etc/init.d/cron restart
fi fi
printf "%02d %02d %s\\n" "${minute}" "${hour}" "* * ${weekday} ${adb_init} ${action}" >> "/etc/crontabs/root"
/etc/init.d/cron restart
else
printf "%s\\n" "::: the refresh timer could not been updated"
fi fi
} }
service_triggers() service_triggers()
{ {
local trigger delay type
local iface delay
trigger="$(uci_get adblock global adb_trigger)"
delay="$(uci_get adblock global adb_triggerdelay "2")"
type="$(uci_get adblock global adb_starttype "start")"
iface="$(uci_get adblock global adb_trigger)"
delay="$(uci_get adblock global adb_triggerdelay "5")"
PROCD_RELOAD_DELAY=$((delay*1000)) PROCD_RELOAD_DELAY=$((delay*1000))
if [ -n "${trigger}" ]
if [ -z "${iface}" ]
then
. "/lib/functions/network.sh"
network_find_wan iface
if [ -n "${iface}" ]
then
uci_set adblock global adb_trigger "${iface}"
uci_commit "adblock"
fi
fi
if [ -n "${iface}" ]
then then
procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" "${type}"
procd_add_interface_trigger "interface.*.up" "${iface}" "${adb_init}" "start"
fi fi
procd_add_reload_trigger "adblock" procd_add_reload_trigger "adblock"
} }

+ 0
- 40
net/adblock/files/adblock.monitor View File

@ -1,40 +0,0 @@
#!/bin/sh
# ubus monitor to trace dns backend events and conditionally restart adblock
# Copyright (c) 2015-2020 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.
# set (s)hellcheck exceptions
# shellcheck disable=1091,2010,2016,2034,2039,2059,2086,2091,2129,2143,2154,2181,2183,2188
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
if [ -r "/lib/functions.sh" ]
then
. "/lib/functions.sh"
adb_dns="$(uci_get adblock global adb_dns)"
fi
adb_ver="${1}"
adb_ubus="$(command -v ubus)"
adb_logger="$(command -v logger)"
f_log()
{
local class="${1}" log_msg="${2}"
if [ -x "${adb_logger}" ]
then
"${adb_logger}" -p "${class}" -t "adblock-${adb_ver}[${$}]" "${log_msg}"
else
printf "%s %s %s\\n" "${class}" "adblock-${adb_ver}[${$}]" "${log_msg}"
fi
}
if [ -x "${adb_ubus}" ] && [ -n "${adb_dns}" ]
then
f_log "info" "ubus/adblock monitor started"
"${adb_ubus}" -S -M r -m invoke monitor | \
{ grep -qE "\"method\":\"(set|signal)\",\"data\":\{\"name\":\"${adb_dns}\""; [ $? -eq 0 ] && /etc/init.d/adblock start; }
else
f_log "err" "can't start ubus/adblock monitor"
fi

+ 203
- 201
net/adblock/files/adblock.sh View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# dns based ad/abuse domain blocking # dns based ad/abuse domain blocking
# Copyright (c) 2015-2020 Dirk Brenken (dev@brenken.org)
# Copyright (c) 2015-2021 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3. # This is free software, licensed under the GNU General Public License v3.
# set (s)hellcheck exceptions # set (s)hellcheck exceptions
@ -11,12 +11,11 @@
export LC_ALL=C export LC_ALL=C
export PATH="/usr/sbin:/usr/bin:/sbin:/bin" export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
set -o pipefail set -o pipefail
adb_ver="4.0.8"
adb_ver="4.1.0"
adb_enabled=0 adb_enabled=0
adb_debug=0 adb_debug=0
adb_forcedns=0 adb_forcedns=0
adb_maxqueue=4 adb_maxqueue=4
adb_dnsfilereset=0
adb_dnsflush=0 adb_dnsflush=0
adb_dnstimeout=20 adb_dnstimeout=20
adb_safesearch=0 adb_safesearch=0
@ -33,13 +32,12 @@ adb_dns=""
adb_dnsprefix="adb_list" adb_dnsprefix="adb_list"
adb_locallist="blacklist whitelist" adb_locallist="blacklist whitelist"
adb_tmpbase="/tmp" adb_tmpbase="/tmp"
adb_backupdir="/tmp"
adb_reportdir="/tmp"
adb_backupdir="${adb_tmpbase}/adblock-Backup"
adb_reportdir="${adb_tmpbase}/adblock-Report"
adb_jaildir="/tmp" adb_jaildir="/tmp"
adb_pidfile="/var/run/adblock.pid" adb_pidfile="/var/run/adblock.pid"
adb_blacklist="/etc/adblock/adblock.blacklist" adb_blacklist="/etc/adblock/adblock.blacklist"
adb_whitelist="/etc/adblock/adblock.whitelist" adb_whitelist="/etc/adblock/adblock.whitelist"
adb_ubusservice="/etc/adblock/adblock.monitor"
adb_mailservice="/etc/adblock/adblock.mail" adb_mailservice="/etc/adblock/adblock.mail"
adb_dnsfile="${adb_dnsprefix}.overall" adb_dnsfile="${adb_dnsprefix}.overall"
adb_dnsjail="${adb_dnsprefix}.jail" adb_dnsjail="${adb_dnsprefix}.jail"
@ -75,12 +73,11 @@ f_load()
f_fetch f_fetch
fi fi
if [ "${adb_enabled}" -eq 0 ]
if [ "${adb_enabled}" = "0" ]
then then
f_extconf f_extconf
f_temp f_temp
f_rmdns f_rmdns
f_bgserv "stop"
f_jsnup "disabled" f_jsnup "disabled"
f_log "info" "adblock is currently disabled, please set the config option 'adb_enabled' to '1' to use this service" f_log "info" "adblock is currently disabled, please set the config option 'adb_enabled' to '1' to use this service"
exit 0 exit 0
@ -97,7 +94,7 @@ f_env()
f_extconf f_extconf
f_temp f_temp
if [ "${adb_dnsflush}" -eq 1 ]
if [ "${adb_dnsflush}" = "1" ]
then then
printf "${adb_dnsheader}" > "${adb_dnsdir}/${adb_dnsfile}" printf "${adb_dnsheader}" > "${adb_dnsdir}/${adb_dnsfile}"
f_dnsup f_dnsup
@ -146,6 +143,18 @@ f_conf()
if [ "${option}" = "adb_sources" ] if [ "${option}" = "adb_sources" ]
then then
eval "${option}=\"$(printf "%s" "${adb_sources}") ${value}\"" eval "${option}=\"$(printf "%s" "${adb_sources}") ${value}\""
elif [ "${option}" = "adb_eng_sources" ]
then
eval "${option}=\"$(printf "%s" "${adb_eng_sources}") ${value}\""
elif [ "${option}" = "adb_sha_sources" ]
then
eval "${option}=\"$(printf "%s" "${adb_sha_sources}") ${value}\""
elif [ "${option}" = "adb_stb_sources" ]
then
eval "${option}=\"$(printf "%s" "${adb_stb_sources}") ${value}\""
elif [ "${option}" = "adb_utc_sources" ]
then
eval "${option}=\"$(printf "%s" "${adb_utc_sources}") ${value}\""
elif [ "${option}" = "adb_safesearchlist" ] elif [ "${option}" = "adb_safesearchlist" ]
then then
eval "${option}=\"$(printf "%s" "${adb_safesearchlist}") ${value}\"" eval "${option}=\"$(printf "%s" "${adb_safesearchlist}") ${value}\""
@ -299,7 +308,7 @@ f_dns()
if [ -n "${adb_dnsdir}" ] && [ ! -d "${adb_dnsdir}" ] if [ -n "${adb_dnsdir}" ] && [ ! -d "${adb_dnsdir}" ]
then then
mkdir -p "${adb_dnsdir}" mkdir -p "${adb_dnsdir}"
if [ "${?}" -eq 0 ]
if [ "${?}" = "0" ]
then then
f_log "info" "dns backend directory '${adb_dnsdir}' created" f_log "info" "dns backend directory '${adb_dnsdir}' created"
else else
@ -315,27 +324,27 @@ f_dns()
if [ "${dns_up}" != "true" ] if [ "${dns_up}" != "true" ]
then then
f_dnsup 4 f_dnsup 4
if [ "${?}" -ne 0 ]
if [ "${?}" != "0" ]
then then
f_log "err" "dns backend '${adb_dns}' not running or executable" f_log "err" "dns backend '${adb_dns}' not running or executable"
fi fi
fi fi
if [ "${adb_backup}" -eq 1 ] && [ -n "${adb_backupdir}" ] && [ ! -d "${adb_backupdir}" ]
if [ "${adb_backup}" = "1" ] && [ -n "${adb_backupdir}" ] && [ ! -d "${adb_backupdir}" ]
then then
mkdir -p "${adb_backupdir}" mkdir -p "${adb_backupdir}"
if [ "${?}" -eq 0 ]
if [ "${?}" = "0" ]
then then
f_log "info" "backup directory '${adb_backupdir}' created" f_log "info" "backup directory '${adb_backupdir}' created"
else else
f_log "err" "backup backend directory '${adb_backupdir}' could not be created"
f_log "err" "backup directory '${adb_backupdir}' could not be created"
fi fi
fi fi
if [ -n "${adb_jaildir}" ] && [ ! -d "${adb_jaildir}" ] if [ -n "${adb_jaildir}" ] && [ ! -d "${adb_jaildir}" ]
then then
mkdir -p "${adb_jaildir}" mkdir -p "${adb_jaildir}"
if [ "${?}" -eq 0 ]
if [ "${?}" = "0" ]
then then
f_log "info" "jail directory '${adb_jaildir}' created" f_log "info" "jail directory '${adb_jaildir}' created"
else else
@ -405,11 +414,11 @@ f_temp()
cpu="$(grep -c '^processor' /proc/cpuinfo 2>/dev/null)" cpu="$(grep -c '^processor' /proc/cpuinfo 2>/dev/null)"
core="$(grep -cm1 '^core id' /proc/cpuinfo 2>/dev/null)" core="$(grep -cm1 '^core id' /proc/cpuinfo 2>/dev/null)"
if [ "${cpu}" -eq 0 ]
if [ "${cpu}" = "0" ]
then then
cpu=1 cpu=1
fi fi
if [ "${core}" -eq 0 ]
if [ "${core}" = "0" ]
then then
core=1 core=1
fi fi
@ -454,7 +463,7 @@ f_rmdns()
if [ "${adb_dns}" = "raw" ] || { [ -n "${adb_dns}" ] && [ -n "${status}" ]; } if [ "${adb_dns}" = "raw" ] || { [ -n "${adb_dns}" ] && [ -n "${status}" ]; }
then then
> "${adb_rtfile}" > "${adb_rtfile}"
if [ "${adb_backup}" -eq 1 ]
if [ "${adb_backup}" = "1" ]
then then
rm -f "${adb_backupdir}/${adb_dnsprefix}".*.gz rm -f "${adb_backupdir}/${adb_dnsprefix}".*.gz
fi fi
@ -566,7 +575,7 @@ f_extconf()
"dnsmasq") "dnsmasq")
config="dhcp" config="dhcp"
config_dir="$(uci_get dhcp "@dnsmasq[${adb_dnsinstance}]" confdir | grep -Fo "${adb_dnsdir}")" config_dir="$(uci_get dhcp "@dnsmasq[${adb_dnsinstance}]" confdir | grep -Fo "${adb_dnsdir}")"
if [ "${adb_enabled}" -eq 1 ] && [ -z "${config_dir}" ]
if [ "${adb_enabled}" = "1" ] && [ -z "${config_dir}" ]
then then
uci_set dhcp "@dnsmasq[${adb_dnsinstance}]" confdir "${adb_dnsdir}" 2>/dev/null uci_set dhcp "@dnsmasq[${adb_dnsinstance}]" confdir "${adb_dnsdir}" 2>/dev/null
fi fi
@ -574,10 +583,10 @@ f_extconf()
"kresd") "kresd")
config="resolver" config="resolver"
config_file="$(uci_get resolver kresd rpz_file | grep -Fo "${adb_dnsdir}/${adb_dnsfile}")" config_file="$(uci_get resolver kresd rpz_file | grep -Fo "${adb_dnsdir}/${adb_dnsfile}")"
if [ "${adb_enabled}" -eq 1 ] && [ -z "${config_file}" ]
if [ "${adb_enabled}" = "1" ] && [ -z "${config_file}" ]
then then
uci -q add_list resolver.kresd.rpz_file="${adb_dnsdir}/${adb_dnsfile}" uci -q add_list resolver.kresd.rpz_file="${adb_dnsdir}/${adb_dnsfile}"
elif [ "${adb_enabled}" -eq 0 ] && [ -n "${config_file}" ]
elif [ "${adb_enabled}" = "0" ] && [ -n "${config_file}" ]
then then
uci -q del_list resolver.kresd.rpz_file="${adb_dnsdir}/${adb_dnsfile}" uci -q del_list resolver.kresd.rpz_file="${adb_dnsdir}/${adb_dnsfile}"
fi fi
@ -587,8 +596,8 @@ f_extconf()
config="firewall" config="firewall"
fwcfg="$(uci -qNX show "${config}" | "${adb_awk}" 'BEGIN{FS="[.=]"};/adblock_/{if(zone==$2){next}else{ORS=" ";zone=$2;print zone}}')" fwcfg="$(uci -qNX show "${config}" | "${adb_awk}" 'BEGIN{FS="[.=]"};/adblock_/{if(zone==$2){next}else{ORS=" ";zone=$2;print zone}}')"
if [ "${adb_enabled}" -eq 1 ] && [ "${adb_forcedns}" -eq 1 ] && \
[ "$(/etc/init.d/firewall enabled; printf "%u" ${?})" -eq 0 ]
if [ "${adb_enabled}" = "1" ] && [ "${adb_forcedns}" = "1" ] && \
[ "$(/etc/init.d/firewall enabled; printf "%u" ${?})" = "0" ]
then then
for zone in ${adb_zonelist} for zone in ${adb_zonelist}
do do
@ -612,7 +621,7 @@ f_extconf()
fwcfg="${fwcfg#"${fwcfg%%[![:space:]]*}"}" fwcfg="${fwcfg#"${fwcfg%%[![:space:]]*}"}"
fwcfg="${fwcfg%"${fwcfg##*[![:space:]]}"}" fwcfg="${fwcfg%"${fwcfg##*[![:space:]]}"}"
fi fi
if [ "${adb_enabled}" -eq 0 ] || [ "${adb_forcedns}" -eq 0 ] || [ -n "${fwcfg}" ]
if [ "${adb_enabled}" = "0" ] || [ "${adb_forcedns}" = "0" ] || [ -n "${fwcfg}" ]
then then
for section in ${fwcfg} for section in ${fwcfg}
do do
@ -628,7 +637,7 @@ f_dnsup()
{ {
local dns_service dns_up dns_pid dns_procfile restart_rc cnt=0 out_rc=4 in_rc="${1:-0}" local dns_service dns_up dns_pid dns_procfile restart_rc cnt=0 out_rc=4 in_rc="${1:-0}"
if [ "${adb_dns}" = "raw" ] || { [ "${in_rc}" -eq 0 ] && [ "${adb_dnsinotify}" -eq 1 ]; }
if [ "${adb_dns}" = "raw" ] || { [ "${in_rc}" = "0" ] && [ "${adb_dnsinotify}" = "1" ]; }
then then
out_rc=0 out_rc=0
else else
@ -648,7 +657,7 @@ f_dnsup()
if [ -x "${adb_lookupcmd}" ] && [ "${adb_lookupdomain}" != "false" ] if [ -x "${adb_lookupcmd}" ] && [ "${adb_lookupdomain}" != "false" ]
then then
"${adb_lookupcmd}" "${adb_lookupdomain}" >/dev/null 2>&1 "${adb_lookupcmd}" "${adb_lookupdomain}" >/dev/null 2>&1
if [ "${?}" -eq 0 ]
if [ "${?}" = "0" ]
then then
out_rc=0 out_rc=0
break break
@ -690,16 +699,16 @@ f_list()
rset="/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower(\$1)}" rset="/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower(\$1)}"
"${adb_awk}" "${rset}" "${adb_whitelist}" > "${adb_tmpdir}/tmp.raw.${src_name}" "${adb_awk}" "${rset}" "${adb_whitelist}" > "${adb_tmpdir}/tmp.raw.${src_name}"
out_rc="${?}" out_rc="${?}"
if [ "${out_rc}" -eq 0 ]
if [ "${out_rc}" = "0" ]
then then
rset="/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{gsub(\"\\\\.\",\"\\\\.\",\$1);print tolower(\"^(|.*\\\\.)\"\$1\"$\")}" rset="/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{gsub(\"\\\\.\",\"\\\\.\",\$1);print tolower(\"^(|.*\\\\.)\"\$1\"$\")}"
"${adb_awk}" "${rset}" "${adb_tmpdir}/tmp.raw.${src_name}" > "${adb_tmpdir}/tmp.rem.${src_name}" "${adb_awk}" "${rset}" "${adb_tmpdir}/tmp.raw.${src_name}" > "${adb_tmpdir}/tmp.rem.${src_name}"
out_rc="${?}" out_rc="${?}"
if [ "${out_rc}" -eq 0 ] && [ "${adb_dnsallow}" != "1" ]
if [ "${out_rc}" = "0" ] && [ "${adb_dnsallow}" != "1" ]
then then
eval "${adb_dnsallow}" "${adb_tmpdir}/tmp.raw.${src_name}" > "${adb_tmpdir}/tmp.add.${src_name}" eval "${adb_dnsallow}" "${adb_tmpdir}/tmp.raw.${src_name}" > "${adb_tmpdir}/tmp.add.${src_name}"
out_rc="${?}" out_rc="${?}"
if [ "${out_rc}" -eq 0 ] && [ "${adb_jail}" = "1" ] && [ "${adb_dnsstop}" != "0" ]
if [ "${out_rc}" = "0" ] && [ "${adb_jail}" = "1" ] && [ "${adb_dnsstop}" != "0" ]
then then
> "${adb_jaildir}/${adb_dnsjail}" > "${adb_jaildir}/${adb_dnsjail}"
if [ -n "${adb_dnsheader}" ] if [ -n "${adb_dnsheader}" ]
@ -720,19 +729,19 @@ f_list()
safe_url="https://www.google.com/supported_domains" safe_url="https://www.google.com/supported_domains"
safe_cname="forcesafesearch.google.com" safe_cname="forcesafesearch.google.com"
safe_domains="${adb_tmpdir}/tmp.load.safesearch.${src_name}" safe_domains="${adb_tmpdir}/tmp.load.safesearch.${src_name}"
if [ "${adb_backup}" -eq 1 ] && [ -s "${adb_backupdir}/safesearch.${src_name}.gz" ]
if [ "${adb_backup}" = "1" ] && [ -s "${adb_backupdir}/safesearch.${src_name}.gz" ]
then then
zcat "${adb_backupdir}/safesearch.${src_name}.gz" > "${safe_domains}" zcat "${adb_backupdir}/safesearch.${src_name}.gz" > "${safe_domains}"
out_rc="${?}" out_rc="${?}"
else else
"${adb_fetchutil}" ${adb_fetchparm} "${safe_domains}" "${safe_url}" 2>/dev/null "${adb_fetchutil}" ${adb_fetchparm} "${safe_domains}" "${safe_url}" 2>/dev/null
out_rc="${?}" out_rc="${?}"
if [ "${adb_backup}" -eq 1 ] && [ "${out_rc}" -eq 0 ]
if [ "${adb_backup}" = "1" ] && [ "${out_rc}" = "0" ]
then then
gzip -cf "${safe_domains}" > "${adb_backupdir}/safesearch.${src_name}.gz" gzip -cf "${safe_domains}" > "${adb_backupdir}/safesearch.${src_name}.gz"
fi fi
fi fi
if [ "${out_rc}" -eq 0 ]
if [ "${out_rc}" = "0" ]
then then
if [ -x "${adb_lookupcmd}" ] if [ -x "${adb_lookupcmd}" ]
then then
@ -786,7 +795,7 @@ f_list()
;; ;;
"yandex") "yandex")
safe_cname="familysearch.yandex.ru" safe_cname="familysearch.yandex.ru"
safe_domains="ya.ru yandex.ru yandex.com yandex.com.tr yandex.ua yandex.by yandex.ee yandex.lt yandex.lv yandex.md yandex.uz yandex.tm yandex.tj yandex.az"
safe_domains="ya.ru yandex.ru yandex.com yandex.com.tr yandex.ua yandex.by yandex.ee yandex.lt yandex.lv yandex.md yandex.uz yandex.tm yandex.tj yandex.az yandex.kz"
if [ -x "${adb_lookupcmd}" ] if [ -x "${adb_lookupcmd}" ]
then then
safe_ips="$("${adb_lookupcmd}" "${safe_cname}" 2>/dev/null | "${adb_awk}" '/^Address[ 0-9]*: /{ORS=" ";print $NF}')" safe_ips="$("${adb_lookupcmd}" "${safe_cname}" 2>/dev/null | "${adb_awk}" '/^Address[ 0-9]*: /{ORS=" ";print $NF}')"
@ -798,7 +807,7 @@ f_list()
out_rc="${?}" out_rc="${?}"
;; ;;
"youtube") "youtube")
if [ "${adb_safesearchmod}" -eq 0 ]
if [ "${adb_safesearchmod}" = "0" ]
then then
safe_cname="restrict.youtube.com" safe_cname="restrict.youtube.com"
else else
@ -816,7 +825,7 @@ f_list()
out_rc="${?}" out_rc="${?}"
;; ;;
esac esac
if [ "${out_rc}" -eq 0 ] && [ -s "${adb_tmpdir}/tmp.raw.safesearch.${src_name}" ]
if [ "${out_rc}" = "0" ] && [ -s "${adb_tmpdir}/tmp.raw.safesearch.${src_name}" ]
then then
> "${adb_tmpdir}/tmp.safesearch.${src_name}" > "${adb_tmpdir}/tmp.safesearch.${src_name}"
if [ "${adb_dns}" = "named" ] if [ "${adb_dns}" = "named" ]
@ -828,7 +837,7 @@ f_list()
for item in ${array} for item in ${array}
do do
eval "${adb_dnssafesearch}" "${adb_tmpdir}/tmp.raw.safesearch.${src_name}" >> "${adb_tmpdir}/tmp.safesearch.${src_name}" eval "${adb_dnssafesearch}" "${adb_tmpdir}/tmp.raw.safesearch.${src_name}" >> "${adb_tmpdir}/tmp.safesearch.${src_name}"
if [ "${?}" -ne 0 ]
if [ "${?}" != "0" ]
then then
rm -f "${adb_tmpdir}/tmp.safesearch.${src_name}" rm -f "${adb_tmpdir}/tmp.safesearch.${src_name}"
break break
@ -859,7 +868,7 @@ f_list()
name="${name%.*}" name="${name%.*}"
zcat "${file}" > "${adb_tmpfile}.${name}" & zcat "${file}" > "${adb_tmpfile}.${name}" &
hold=$((cnt%adb_maxqueue)) hold=$((cnt%adb_maxqueue))
if [ "${hold}" -eq 0 ]
if [ "${hold}" = "0" ]
then then
wait wait
fi fi
@ -871,13 +880,13 @@ f_list()
else else
out_rc=4 out_rc=4
fi fi
if [ "${adb_action}" != "start" ] && [ "${adb_action}" != "resume" ] && [ -n "${src_name}" ] && [ "${out_rc}" -ne 0 ]
if [ "${adb_action}" != "start" ] && [ "${adb_action}" != "resume" ] && [ -n "${src_name}" ] && [ "${out_rc}" != "0" ]
then then
adb_sources="${adb_sources/${src_name}}" adb_sources="${adb_sources/${src_name}}"
fi fi
;; ;;
"remove") "remove")
if [ "${adb_backup}" -eq 1 ]
if [ "${adb_backup}" = "1" ]
then then
rm "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" 2>/dev/null rm "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" 2>/dev/null
fi fi
@ -885,13 +894,13 @@ f_list()
adb_sources="${adb_sources/${src_name}}" adb_sources="${adb_sources/${src_name}}"
;; ;;
"merge") "merge")
if [ "${adb_backup}" -eq 1 ]
if [ "${adb_backup}" = "1" ]
then then
for src_name in ${adb_sources} for src_name in ${adb_sources}
do do
ffiles="${ffiles} -a ! -name ${adb_dnsprefix}.${src_name}.gz" ffiles="${ffiles} -a ! -name ${adb_dnsprefix}.${src_name}.gz"
done done
if [ "${adb_safesearch}" -eq 1 ] && [ "${adb_dnssafesearch}" != "0" ]
if [ "${adb_safesearch}" = "1" ] && [ "${adb_dnssafesearch}" != "0" ]
then then
ffiles="${ffiles} -a ! -name safesearch.google.gz" ffiles="${ffiles} -a ! -name safesearch.google.gz"
fi fi
@ -944,7 +953,7 @@ f_tld()
"${adb_awk}" '{if(NR==1){tld=$NF};while(getline){if(index($NF,tld".")==0){print tld;tld=$NF}}print tld}' "${source}" | \ "${adb_awk}" '{if(NR==1){tld=$NF};while(getline){if(index($NF,tld".")==0){print tld;tld=$NF}}print tld}' "${source}" | \
"${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > "${temp_tld}" "${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > "${temp_tld}"
if [ "${?}" -eq 0 ]
if [ "${?}" = "0" ]
then then
mv -f "${temp_tld}" "${source}" mv -f "${temp_tld}" "${source}"
cnt_tld="$(wc -l 2>/dev/null < "${source}")" cnt_tld="$(wc -l 2>/dev/null < "${source}")"
@ -979,13 +988,8 @@ f_switch()
then then
if [ "${mode}" = "suspend" ] if [ "${mode}" = "suspend" ]
then then
f_bgserv "stop"
f_dnsup f_dnsup
fi fi
if [ "${mode}" = "resume" ]
then
f_bgserv "start"
fi
f_jsnup "${mode}" f_jsnup "${mode}"
f_log "info" "${mode} adblock processing" f_log "info" "${mode} adblock processing"
fi fi
@ -1000,7 +1004,7 @@ f_query()
if [ -z "${domain}" ] || [ "${domain}" = "${tld}" ] if [ -z "${domain}" ] || [ "${domain}" = "${tld}" ]
then then
printf "%s\\n" "::: invalid input, please submit a single (sub-)domain :::"
printf "%s\n" "::: invalid input, please submit a single (sub-)domain :::"
else else
case "${adb_dns}" in case "${adb_dns}" in
"dnsmasq") "dnsmasq")
@ -1030,48 +1034,45 @@ f_query()
;; ;;
esac esac
query_start="$(date "+%s")" query_start="$(date "+%s")"
if [ "${adb_dnsfilereset}" -eq 0 ]
then
while [ "${domain}" != "${tld}" ]
do
search="${domain//[+*~%\$&\"\']/}"
search="${search//./\\.}"
result="$("${adb_awk}" -F '/|\"|\t| ' "/^(${search}|${prefix}+${search}.*${suffix})$/{i++;if(i<=9){printf \" + %s\\n\",\$${field}}else if(i==10){printf \" + %s\\n\",\"[...]\";exit}}" "${adb_dnsdir}/${adb_dnsfile}")"
printf "%s\\n%s\\n%s\\n" ":::" "::: domain '${domain}' in active blocklist" ":::"
printf "%s\\n\\n" "${result:-" - no match"}"
domain="${tld}"
tld="${domain#*.}"
done
fi
if [ "${adb_backup}" -eq 1 ] && [ -d "${adb_backupdir}" ]
while [ "${domain}" != "${tld}" ]
do
search="${domain//[+*~%\$&\"\']/}"
search="${search//./\\.}"
result="$("${adb_awk}" -F '/|\"|\t| ' "/^(${search}|${prefix}+${search}.*${suffix})$/{i++;if(i<=9){printf \" + %s\n\",\$${field}}else if(i==10){printf \" + %s\n\",\"[...]\";exit}}" "${adb_dnsdir}/${adb_dnsfile}")"
printf "%s\n%s\n%s\n" ":::" "::: domain '${domain}' in active blocklist" ":::"
printf "%s\n\n" "${result:-" - no match"}"
domain="${tld}"
tld="${domain#*.}"
done
if [ "${adb_backup}" = "1" ] && [ -d "${adb_backupdir}" ]
then then
search="${1//[+*~%\$&\"\']/}" search="${1//[+*~%\$&\"\']/}"
search="${search//./\\.}" search="${search//./\\.}"
printf "%s\\n%s\\n%s\\n" ":::" "::: domain '${1}' in backups and black-/whitelist" ":::"
printf "%s\n%s\n%s\n" ":::" "::: domain '${1}' in backups and black-/whitelist" ":::"
for file in "${adb_backupdir}/${adb_dnsprefix}".*.gz "${adb_blacklist}" "${adb_whitelist}" for file in "${adb_backupdir}/${adb_dnsprefix}".*.gz "${adb_blacklist}" "${adb_whitelist}"
do do
suffix="${file##*.}" suffix="${file##*.}"
if [ "${suffix}" = "gz" ] if [ "${suffix}" = "gz" ]
then then
zcat "${file}" 2>/dev/null | \ zcat "${file}" 2>/dev/null | \
"${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' | "${adb_awk}" -v f="${file##*/}" "BEGIN{rc=1};/^($search|.*\\.${search})$/{i++;if(i<=3){printf \" + %-30s%s\\n\",f,\$1;rc=0}else if(i==4){printf \" + %-30s%s\\n\",f,\"[...]\"}};END{exit rc}"
"${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' | "${adb_awk}" -v f="${file##*/}" "BEGIN{rc=1};/^($search|.*\\.${search})$/{i++;if(i<=3){printf \" + %-30s%s\n\",f,\$1;rc=0}else if(i==4){printf \" + %-30s%s\n\",f,\"[...]\"}};END{exit rc}"
else else
"${adb_awk}" -v f="${file##*/}" "BEGIN{rc=1};/^($search|.*\\.${search})$/{i++;if(i<=3){printf \" + %-30s%s\\n\",f,\$1;rc=0}else if(i==4){printf \" + %-30s%s\\n\",f,\"[...]\"}};END{exit rc}" "${file}"
"${adb_awk}" -v f="${file##*/}" "BEGIN{rc=1};/^($search|.*\\.${search})$/{i++;if(i<=3){printf \" + %-30s%s\n\",f,\$1;rc=0}else if(i==4){printf \" + %-30s%s\n\",f,\"[...]\"}};END{exit rc}" "${file}"
fi fi
if [ "${?}" -eq 0 ]
if [ "${?}" = "0" ]
then then
result="true" result="true"
query_end="$(date "+%s")" query_end="$(date "+%s")"
if [ "$((query_end-query_start))" -gt "${query_timeout}" ] if [ "$((query_end-query_start))" -gt "${query_timeout}" ]
then then
printf "%s\\n\\n" " - [...]"
printf "%s\n\n" " - [...]"
break break
fi fi
fi fi
done done
if [ "${result}" != "true" ] if [ "${result}" != "true" ]
then then
printf "%s\\n\\n" " - no match"
printf "%s\n\n" " - no match"
fi fi
fi fi
fi fi
@ -1106,8 +1107,7 @@ f_jsnup()
;; ;;
esac esac
json_load_file "${adb_rtfile}" >/dev/null 2>&1 json_load_file "${adb_rtfile}" >/dev/null 2>&1
json_select "data" >/dev/null 2>&1
if [ "${?}" -eq 0 ]
if [ "${?}" = "0" ]
then then
if [ -z "${adb_fetchutil}" ] || [ -z "${adb_awk}" ] if [ -z "${adb_fetchutil}" ] || [ -z "${adb_awk}" ]
then then
@ -1128,7 +1128,6 @@ f_jsnup()
> "${adb_rtfile}" > "${adb_rtfile}"
json_load_file "${adb_rtfile}" >/dev/null 2>&1 json_load_file "${adb_rtfile}" >/dev/null 2>&1
json_init json_init
json_add_object "data"
json_add_string "adblock_status" "${status:-"enabled"}" json_add_string "adblock_status" "${status:-"enabled"}"
json_add_string "adblock_version" "${adb_ver}" json_add_string "adblock_version" "${adb_ver}"
json_add_string "blocked_domains" "${adb_cnt:-0}" json_add_string "blocked_domains" "${adb_cnt:-0}"
@ -1144,13 +1143,12 @@ f_jsnup()
json_add_string "run_utils" "${utils:-"-"}" json_add_string "run_utils" "${utils:-"-"}"
json_add_string "run_ifaces" "trigger: ${adb_trigger:-"-"}, report: ${adb_repiface:-"-"}" json_add_string "run_ifaces" "trigger: ${adb_trigger:-"-"}, report: ${adb_repiface:-"-"}"
json_add_string "run_directories" "base: ${adb_tmpbase}, backup: ${adb_backupdir}, report: ${adb_reportdir}, jail: ${adb_jaildir}" json_add_string "run_directories" "base: ${adb_tmpbase}, backup: ${adb_backupdir}, report: ${adb_reportdir}, jail: ${adb_jaildir}"
json_add_string "run_flags" "backup: ${adb_backup}, reset: ${adb_dnsfilereset}, flush: ${adb_dnsflush}, force: ${adb_forcedns}, search: ${adb_safesearch}, report: ${adb_report}, mail: ${adb_mail}, jail: ${adb_jail}"
json_add_string "run_flags" "backup: ${adb_backup}, flush: ${adb_dnsflush}, force: ${adb_forcedns}, search: ${adb_safesearch}, report: ${adb_report}, mail: ${adb_mail}, jail: ${adb_jail}"
json_add_string "last_run" "${runtime:-"-"}" json_add_string "last_run" "${runtime:-"-"}"
json_add_string "system" "${adb_sysver}" json_add_string "system" "${adb_sysver}"
json_close_object
json_dump > "${adb_rtfile}" json_dump > "${adb_rtfile}"
if [ "${adb_mail}" -eq 1 ] && [ -x "${adb_mailservice}" ] && \
if [ "${adb_mail}" = "1" ] && [ -x "${adb_mailservice}" ] && \
{ [ "${status}" = "error" ] || { [ "${status}" = "enabled" ] && [ "${adb_cnt}" -le "${adb_mailcnt}" ]; } } { [ "${status}" = "error" ] || { [ "${status}" = "enabled" ] && [ "${adb_cnt}" -le "${adb_mailcnt}" ]; } }
then then
( "${adb_mailservice}" "${adb_ver}" >/dev/null 2>&1 )& ( "${adb_mailservice}" "${adb_ver}" >/dev/null 2>&1 )&
@ -1165,42 +1163,23 @@ f_log()
{ {
local class="${1}" log_msg="${2}" local class="${1}" log_msg="${2}"
if [ -n "${log_msg}" ] && { [ "${class}" != "debug" ] || [ "${adb_debug}" -eq 1 ]; }
if [ -n "${log_msg}" ] && { [ "${class}" != "debug" ] || [ "${adb_debug}" = "1" ]; }
then then
if [ -x "${adb_loggercmd}" ] if [ -x "${adb_loggercmd}" ]
then then
"${adb_loggercmd}" -p "${class}" -t "adblock-${adb_ver}[${$}]" "${log_msg}" "${adb_loggercmd}" -p "${class}" -t "adblock-${adb_ver}[${$}]" "${log_msg}"
else else
printf "%s %s %s\\n" "${class}" "adblock-${adb_ver}[${$}]" "${log_msg}"
printf "%s %s %s\n" "${class}" "adblock-${adb_ver}[${$}]" "${log_msg}"
fi fi
if [ "${class}" = "err" ] if [ "${class}" = "err" ]
then then
f_rmdns f_rmdns
f_bgserv "stop"
f_jsnup "error" f_jsnup "error"
exit 1 exit 1
fi fi
fi fi
} }
# start ubus monitor service to trace dns backend events
#
f_bgserv()
{
local bg_pid status="${1}"
bg_pid="$(pgrep -f "^/bin/sh ${adb_ubusservice}.*|^/bin/ubus -S -M r -m invoke monitor|^grep -qF \"method\":\"set\",\"data\":\\{\"name\":\"${adb_dns}\"" | "${adb_awk}" '{ORS=" "; print $1}')"
if [ "${adb_dns}" != "raw" ] && [ -z "${bg_pid}" ] && [ "${status}" = "start" ] \
&& [ -x "${adb_ubusservice}" ] && [ "${adb_dnsfilereset}" -eq 1 ]
then
( "${adb_ubusservice}" "${adb_ver}" & )
elif [ -n "${bg_pid}" ] && [ "${status}" = "stop" ]
then
kill -HUP "${bg_pid}" 2>/dev/null
fi
f_log "debug" "f_bgserv ::: status: ${status:-"-"}, bg_pid: ${bg_pid:-"-"}, dns_filereset: ${adb_dnsfilereset:-"-"}, ubus_service: ${adb_ubusservice:-"-"}"
}
# main function for blocklist processing # main function for blocklist processing
# #
f_main() f_main()
@ -1219,7 +1198,7 @@ f_main()
# safe search preparation # safe search preparation
# #
if [ "${adb_safesearch}" -eq 1 ] && [ "${adb_dnssafesearch}" != "0" ]
if [ "${adb_safesearch}" = "1" ] && [ "${adb_dnssafesearch}" != "0" ]
then then
if [ -z "${adb_safesearchlist}" ] if [ -z "${adb_safesearchlist}" ]
then then
@ -1237,15 +1216,15 @@ f_main()
for src_name in ${adb_sources} for src_name in ${adb_sources}
do do
json_select "${src_name}" >/dev/null 2>&1 json_select "${src_name}" >/dev/null 2>&1
if [ "${?}" -ne 0 ]
if [ "${?}" != "0" ]
then then
adb_sources="${adb_sources/${src_name}}" adb_sources="${adb_sources/${src_name}}"
continue continue
fi fi
json_get_var src_url "url" >/dev/null 2>&1 json_get_var src_url "url" >/dev/null 2>&1
json_get_var src_rset "rule" >/dev/null 2>&1 json_get_var src_rset "rule" >/dev/null 2>&1
json_get_values src_cat "categories" >/dev/null 2>&1
json_select .. json_select ..
src_tmpcat="${adb_tmpload}.${src_name}.cat"
src_tmpload="${adb_tmpload}.${src_name}.load" src_tmpload="${adb_tmpload}.${src_name}.load"
src_tmpsort="${adb_tmpload}.${src_name}.sort" src_tmpsort="${adb_tmpload}.${src_name}.sort"
src_tmpfile="${adb_tmpfile}.${src_name}" src_tmpfile="${adb_tmpfile}.${src_name}"
@ -1261,10 +1240,10 @@ f_main()
# backup mode # backup mode
# #
if [ "${adb_backup}" -eq 1 ] && { [ "${adb_action}" = "start" ] || [ "${adb_action}" = "resume" ]; }
if [ "${adb_backup}" = "1" ] && { [ "${adb_action}" = "start" ] || [ "${adb_action}" = "resume" ]; }
then then
f_list restore f_list restore
if [ "${?}" -eq 0 ] && [ -s "${src_tmpfile}" ]
if [ "${?}" = "0" ] && [ -s "${src_tmpfile}" ]
then then
continue continue
fi fi
@ -1272,70 +1251,104 @@ f_main()
# download queue processing # download queue processing
# #
if [ -n "${src_cat}" ]
unset src_cat src_entries
if [ "${src_name}" = "shallalist" ] || [ "${src_name}" = "utcapitole" ]
then then
(
src_arc="${adb_tmpdir}/${src_url##*/}"
src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${src_arc}" "${src_url}" 2>&1)"
src_rc="${?}"
if [ "${src_rc}" -eq 0 ] && [ -s "${src_arc}" ]
then
unset src_entries
src_suffix="$(eval printf "%s" \"\$\{adb_src_suffix_${src_name}:-\"domains\"\}\")"
src_list="$(tar -tzf "${src_arc}" 2>/dev/null)"
for src_item in ${src_cat}
do
src_entries="${src_entries} $(printf "%s" "${src_list}" | grep -E "${src_item}/${src_suffix}$")"
done
if [ -n "${src_entries}" ]
then
tar -xOzf "${src_arc}" ${src_entries} 2>/dev/null > "${src_tmpload}"
src_rc="${?}"
fi
rm -f "${src_arc}"
else
src_log="$(printf "%s" "${src_log}" | "${adb_awk}" '{ORS=" ";print $0}')"
f_log "info" "download of '${src_name}' failed, url: ${src_url}, rule: ${src_rset:-"-"}, categories: ${src_cat:-"-"}, rc: ${src_rc}, log: ${src_log:-"-"}"
fi
if [ "${src_rc}" -eq 0 ] && [ -s "${src_tmpload}" ]
then
if [ -s "${adb_tmpdir}/tmp.rem.whitelist" ]
if [ "${src_name}" = "shallalist" ] && [ -n "${adb_sha_sources}" ]
then
src_cat="${adb_sha_sources}"
elif [ "${src_name}" = "utcapitole" ] && [ -n "${adb_utc_sources}" ]
then
src_cat="${adb_utc_sources}"
fi
if [ -n "${src_cat}" ]
then
(
src_arc="${adb_tmpdir}/${src_url##*/}"
src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${src_arc}" "${src_url}" 2>&1)"
src_rc="${?}"
if [ "${src_rc}" = "0" ] && [ -s "${src_arc}" ]
then then
"${adb_awk}" "${src_rset}" "${src_tmpload}" | sed "s/\r//g" | \
grep -Evf "${adb_tmpdir}/tmp.rem.whitelist" | "${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > "${src_tmpsort}"
src_suffix="$(eval printf "%s" \"\$\{adb_src_suffix_${src_name}:-\"domains\"\}\")"
src_list="$(tar -tzf "${src_arc}" 2>/dev/null)"
for src_item in ${src_cat}
do
src_entries="${src_entries} $(printf "%s" "${src_list}" | grep -E "${src_item}/${src_suffix}$")"
done
if [ -n "${src_entries}" ]
then
tar -xOzf "${src_arc}" ${src_entries} 2>/dev/null > "${src_tmpload}"
src_rc="${?}"
fi
> "${src_arc}"
else else
"${adb_awk}" "${src_rset}" "${src_tmpload}" | sed "s/\r//g" | \
"${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > "${src_tmpsort}"
src_log="$(printf "%s" "${src_log}" | "${adb_awk}" '{ORS=" ";print $0}')"
f_log "info" "download of '${src_name}' failed, url: ${src_url}, rule: ${src_rset:-"-"}, categories: ${src_cat:-"-"}, rc: ${src_rc}, log: ${src_log:-"-"}"
fi fi
rm -f "${src_tmpload}"
"${adb_sort}" ${adb_srtopts} -u "${src_tmpsort}" 2>/dev/null > "${src_tmpfile}"
src_rc="${?}"
rm -f "${src_tmpsort}"
if [ "${src_rc}" -eq 0 ] && [ -s "${src_tmpfile}" ]
if [ "${src_rc}" = "0" ] && [ -s "${src_tmpload}" ]
then then
f_list download
if [ "${adb_backup}" -eq 1 ]
if [ -s "${adb_tmpdir}/tmp.rem.whitelist" ]
then then
f_list backup
"${adb_awk}" "${src_rset}" "${src_tmpload}" | sed "s/\r//g" | \
grep -Evf "${adb_tmpdir}/tmp.rem.whitelist" | "${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > "${src_tmpsort}"
else
"${adb_awk}" "${src_rset}" "${src_tmpload}" | sed "s/\r//g" | \
"${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > "${src_tmpsort}"
fi fi
elif [ "${adb_backup}" -eq 1 ] && [ "${adb_action}" != "start" ]
> "${src_tmpload}"
"${adb_sort}" ${adb_srtopts} -u "${src_tmpsort}" 2>/dev/null > "${src_tmpfile}"
src_rc="${?}"
> "${src_tmpsort}"
if [ "${src_rc}" = "0" ] && [ -s "${src_tmpfile}" ]
then
f_list download
if [ "${adb_backup}" = "1" ]
then
f_list backup
fi
elif [ "${adb_backup}" = "1" ] && [ "${adb_action}" != "start" ]
then
f_log "info" "archive preparation of '${src_name}' failed, categories: ${src_cat:-"-"}, entries: ${src_entries}, rc: ${src_rc}"
f_list restore
rm -f "${src_tmpfile}"
fi
elif [ "${adb_backup}" = "1" ] && [ "${adb_action}" != "start" ]
then then
f_log "info" "archive preparation of '${src_name}' failed, categories: ${src_cat:-"-"}, entries: ${src_entries}, rc: ${src_rc}"
f_log "info" "archive extraction of '${src_name}' failed, categories: ${src_cat:-"-"}, entries: ${src_entries}, rc: ${src_rc}"
f_list restore f_list restore
rm -f "${src_tmpfile}"
fi fi
elif [ "${adb_backup}" -eq 1 ] && [ "${adb_action}" != "start" ]
then
f_log "info" "archive extraction of '${src_name}' failed, categories: ${src_cat:-"-"}, entries: ${src_entries}, rc: ${src_rc}"
f_list restore
fi
)&
continue
)&
fi
else else
if [ "${src_name}" = "energized" ] && [ -n "${adb_eng_sources}" ]
then
src_cat="${adb_eng_sources}"
elif [ "${src_name}" = "stevenblack" ] && [ -n "${adb_stb_sources}" ]
then
src_cat="${adb_stb_sources}"
elif { [ "${src_name}" = "energized" ] && [ -z "${adb_eng_sources}" ]; } || \
{ [ "${src_name}" = "stevenblack" ] && [ -z "${adb_stb_sources}" ]; }
then
continue
fi
( (
src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${src_tmpload}" "${src_url}" 2>&1)"
src_rc="${?}"
if [ "${src_rc}" -eq 0 ] && [ -s "${src_tmpload}" ]
for suffix in ${src_cat:-${src_url}}
do
if [ "${src_url}" != "${suffix}" ]
then
src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${src_tmpcat}" "${src_url}${suffix}" 2>&1)"
src_rc="${?}"
if [ "${src_rc}" = "0" ] && [ -s "${src_tmpcat}" ]
then
cat "${src_tmpcat}" >> "${src_tmpload}"
> "${src_tmpcat}"
fi
else
src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${src_tmpload}" "${src_url}" 2>&1)"
src_rc="${?}"
fi
done
if [ "${src_rc}" = "0" ] && [ -s "${src_tmpload}" ]
then then
if [ -s "${adb_tmpdir}/tmp.rem.whitelist" ] if [ -s "${adb_tmpdir}/tmp.rem.whitelist" ]
then then
@ -1345,18 +1358,18 @@ f_main()
"${adb_awk}" "${src_rset}" "${src_tmpload}" | sed "s/\r//g" | \ "${adb_awk}" "${src_rset}" "${src_tmpload}" | sed "s/\r//g" | \
"${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > "${src_tmpsort}" "${adb_awk}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' > "${src_tmpsort}"
fi fi
rm -f "${src_tmpload}"
> "${src_tmpload}"
"${adb_sort}" ${adb_srtopts} -u "${src_tmpsort}" 2>/dev/null > "${src_tmpfile}" "${adb_sort}" ${adb_srtopts} -u "${src_tmpsort}" 2>/dev/null > "${src_tmpfile}"
src_rc="${?}" src_rc="${?}"
rm -f "${src_tmpsort}"
if [ "${src_rc}" -eq 0 ] && [ -s "${src_tmpfile}" ]
> "${src_tmpsort}"
if [ "${src_rc}" = "0" ] && [ -s "${src_tmpfile}" ]
then then
f_list download f_list download
if [ "${adb_backup}" -eq 1 ]
if [ "${adb_backup}" = "1" ]
then then
f_list backup f_list backup
fi fi
elif [ "${adb_backup}" -eq 1 ] && [ "${adb_action}" != "start" ]
elif [ "${adb_backup}" = "1" ] && [ "${adb_action}" != "start" ]
then then
f_log "info" "preparation of '${src_name}' failed, rc: ${src_rc}" f_log "info" "preparation of '${src_name}' failed, rc: ${src_rc}"
f_list restore f_list restore
@ -1365,7 +1378,7 @@ f_main()
else else
src_log="$(printf "%s" "${src_log}" | "${adb_awk}" '{ORS=" ";print $0}')" src_log="$(printf "%s" "${src_log}" | "${adb_awk}" '{ORS=" ";print $0}')"
f_log "info" "download of '${src_name}' failed, url: ${src_url}, rule: ${src_rset:-"-"}, categories: ${src_cat:-"-"}, rc: ${src_rc}, log: ${src_log:-"-"}" f_log "info" "download of '${src_name}' failed, url: ${src_url}, rule: ${src_rset:-"-"}, categories: ${src_cat:-"-"}, rc: ${src_rc}, log: ${src_log:-"-"}"
if [ "${adb_backup}" -eq 1 ] && [ "${adb_action}" != "start" ]
if [ "${adb_backup}" = "1" ] && [ "${adb_action}" != "start" ]
then then
f_list restore f_list restore
fi fi
@ -1373,7 +1386,7 @@ f_main()
)& )&
fi fi
hold=$((cnt%adb_maxqueue)) hold=$((cnt%adb_maxqueue))
if [ "${hold}" -eq 0 ]
if [ "${hold}" = "0" ]
then then
wait wait
fi fi
@ -1384,7 +1397,7 @@ f_main()
# tld compression and dns restart # tld compression and dns restart
# #
if [ "${?}" -eq 0 ] && [ -s "${adb_tmpdir}/${adb_dnsfile}" ]
if [ "${?}" = "0" ] && [ -s "${adb_tmpdir}/${adb_dnsfile}" ]
then then
f_tld "${adb_tmpdir}/${adb_dnsfile}" f_tld "${adb_tmpdir}/${adb_dnsfile}"
f_list final f_list final
@ -1393,20 +1406,13 @@ f_main()
fi fi
chown "${adb_dnsuser}" "${adb_dnsdir}/${adb_dnsfile}" 2>/dev/null chown "${adb_dnsuser}" "${adb_dnsdir}/${adb_dnsfile}" 2>/dev/null
f_dnsup f_dnsup
if [ "${?}" -eq 0 ]
if [ "${?}" = "0" ]
then then
if [ "${adb_action}" != "resume" ] if [ "${adb_action}" != "resume" ]
then then
f_jsnup "enabled" f_jsnup "enabled"
fi fi
if [ "${adb_dns}" != "raw" ] && [ "${adb_dnsfilereset}" -eq 1 ]
then
printf "${adb_dnsheader}" > "${adb_dnsdir}/${adb_dnsfile}"
f_log "info" "blocklist with overall ${adb_cnt} blocked domains loaded successfully and reset afterwards (${adb_sysver})"
f_bgserv "start"
else
f_log "info" "blocklist with overall ${adb_cnt} blocked domains loaded successfully (${adb_sysver})"
fi
f_log "info" "blocklist with overall ${adb_cnt} blocked domains loaded successfully (${adb_sysver})"
else else
f_log "err" "dns backend restart with adblock blocklist failed" f_log "err" "dns backend restart with adblock blocklist failed"
fi fi
@ -1419,10 +1425,10 @@ f_report()
{ {
local iface bg_pid status total start end blocked percent top_list top array item index hold ports cnt=0 search="${1}" count="${2}" process="${3}" print="${4}" local iface bg_pid status total start end blocked percent top_list top array item index hold ports cnt=0 search="${1}" count="${2}" process="${3}" print="${4}"
if [ "${adb_report}" -eq 1 ] && [ ! -x "${adb_dumpcmd}" ]
if [ "${adb_report}" = "1" ] && [ ! -x "${adb_dumpcmd}" ]
then then
f_log "info" "Please install the package 'tcpdump' or 'tcpdump-mini' to use the reporting feature" f_log "info" "Please install the package 'tcpdump' or 'tcpdump-mini' to use the reporting feature"
elif [ "${adb_report}" -eq 0 ] && [ "${adb_action}" = "report" ]
elif [ "${adb_report}" = "0" ] && [ "${adb_action}" = "report" ]
then then
f_log "info" "Please enable the 'DNS Report' option to use the reporting feature" f_log "info" "Please enable the 'DNS Report' option to use the reporting feature"
fi fi
@ -1430,7 +1436,7 @@ f_report()
if [ -x "${adb_dumpcmd}" ] if [ -x "${adb_dumpcmd}" ]
then then
bg_pid="$(pgrep -f "^${adb_dumpcmd}.*adb_report\\.pcap$" | "${adb_awk}" '{ORS=" "; print $1}')" bg_pid="$(pgrep -f "^${adb_dumpcmd}.*adb_report\\.pcap$" | "${adb_awk}" '{ORS=" "; print $1}')"
if [ "${adb_report}" -eq 0 ] || { [ -n "${bg_pid}" ] && { [ "${adb_action}" = "stop" ] || [ "${adb_action}" = "restart" ]; } }
if [ "${adb_report}" = "0" ] || { [ -n "${bg_pid}" ] && { [ "${adb_action}" = "stop" ] || [ "${adb_action}" = "restart" ]; } }
then then
if [ -n "${bg_pid}" ] if [ -n "${bg_pid}" ]
then then
@ -1444,7 +1450,7 @@ f_report()
fi fi
fi fi
if [ -x "${adb_dumpcmd}" ] && [ "${adb_report}" -eq 1 ]
if [ -x "${adb_dumpcmd}" ] && [ "${adb_report}" = "1" ]
then then
if [ -z "${bg_pid}" ] && [ "${adb_action}" != "report" ] && [ "${adb_action}" != "stop" ] if [ -z "${bg_pid}" ] && [ "${adb_action}" != "report" ] && [ "${adb_action}" != "stop" ]
then then
@ -1501,7 +1507,7 @@ f_report()
e=$(NF-1);sub(/[0-9]\/[0-9]\/[0-9]|0\.0\.0\.0/,"NX",e);sub(/\.$/,"",e);sub(/([0-9]{1,3}\.){3}[0-9]{1,3}/,"OK",e);gsub(/[^[:alnum:]\.-]/,"",e);if(e==""){e="err"};printf "%s\t%s\t%s\t%s\t%s\n",d,e,a,b,c}' >> "${adb_reportdir}/adb_report.raw" e=$(NF-1);sub(/[0-9]\/[0-9]\/[0-9]|0\.0\.0\.0/,"NX",e);sub(/\.$/,"",e);sub(/([0-9]{1,3}\.){3}[0-9]{1,3}/,"OK",e);gsub(/[^[:alnum:]\.-]/,"",e);if(e==""){e="err"};printf "%s\t%s\t%s\t%s\t%s\n",d,e,a,b,c}' >> "${adb_reportdir}/adb_report.raw"
)& )&
hold=$((cnt%adb_maxqueue)) hold=$((cnt%adb_maxqueue))
if [ "${hold}" -eq 0 ]
if [ "${hold}" = "0" ]
then then
wait wait
fi fi
@ -1524,38 +1530,38 @@ f_report()
blocked="$("${adb_awk}" '{if($5=="NX")cnt++}END{printf "%s",cnt}' "${adb_reportdir}/adb_report.srt")" blocked="$("${adb_awk}" '{if($5=="NX")cnt++}END{printf "%s",cnt}' "${adb_reportdir}/adb_report.srt")"
percent="$("${adb_awk}" -v t="${total}" -v b="${blocked}" 'BEGIN{printf "%.2f%s",b/t*100,"%"}')" percent="$("${adb_awk}" -v t="${total}" -v b="${blocked}" 'BEGIN{printf "%.2f%s",b/t*100,"%"}')"
> "${adb_reportdir}/adb_report.json" > "${adb_reportdir}/adb_report.json"
printf "%s" "{ \"data\": { " >> "${adb_reportdir}/adb_report.json"
printf "%s" "\"start_date\": \"${start%_*}\", " >> "${adb_reportdir}/adb_report.json"
printf "%s" "\"start_time\": \"${start#*_}\", " >> "${adb_reportdir}/adb_report.json"
printf "%s" "\"end_date\": \"${end%_*}\", " >> "${adb_reportdir}/adb_report.json"
printf "%s" "\"end_time\": \"${end#*_}\", " >> "${adb_reportdir}/adb_report.json"
printf "%s" "\"total\": \"${total}\", " >> "${adb_reportdir}/adb_report.json"
printf "%s" "\"blocked\": \"${blocked}\", " >> "${adb_reportdir}/adb_report.json"
printf "%s" "\"percent\": \"${percent}\", " >> "${adb_reportdir}/adb_report.json"
printf "%s\n" "{ " >> "${adb_reportdir}/adb_report.json"
printf "\t%s\n" "\"start_date\": \"${start%_*}\", " >> "${adb_reportdir}/adb_report.json"
printf "\t%s\n" "\"start_time\": \"${start#*_}\", " >> "${adb_reportdir}/adb_report.json"
printf "\t%s\n" "\"end_date\": \"${end%_*}\", " >> "${adb_reportdir}/adb_report.json"
printf "\t%s\n" "\"end_time\": \"${end#*_}\", " >> "${adb_reportdir}/adb_report.json"
printf "\t%s\n" "\"total\": \"${total}\", " >> "${adb_reportdir}/adb_report.json"
printf "\t%s\n" "\"blocked\": \"${blocked}\", " >> "${adb_reportdir}/adb_report.json"
printf "\t%s\n" "\"percent\": \"${percent}\", " >> "${adb_reportdir}/adb_report.json"
top_list="top_clients top_domains top_blocked" top_list="top_clients top_domains top_blocked"
for top in ${top_list} for top in ${top_list}
do do
printf "%s" " \"${top}\": [ " >> "${adb_reportdir}/adb_report.json"
printf "\t%s" "\"${top}\": [ " >> "${adb_reportdir}/adb_report.json"
case "${top}" in case "${top}" in
"top_clients") "top_clients")
"${adb_awk}" '{print $3}' "${adb_reportdir}/adb_report.srt" | "${adb_sort}" ${adb_srtopts} | uniq -c | \ "${adb_awk}" '{print $3}' "${adb_reportdir}/adb_report.srt" | "${adb_sort}" ${adb_srtopts} | uniq -c | \
"${adb_sort}" ${adb_srtopts} -nr | "${adb_awk}" '{ORS=" ";if(NR==1)printf "{ \"count\": \"%s\", \"address\": \"%s\" }",$1,$2; else if(NR<10)printf ", { \"count\": \"%s\", \"address\": \"%s\" }",$1,$2}' >> "${adb_reportdir}/adb_report.json"
"${adb_sort}" ${adb_srtopts} -nr | "${adb_awk}" '{ORS=" ";if(NR==1)printf "\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t}",$1,$2; else if(NR<10)printf ",\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t}",$1,$2}' >> "${adb_reportdir}/adb_report.json"
;; ;;
"top_domains") "top_domains")
"${adb_awk}" '{if($5!="NX")print $4}' "${adb_reportdir}/adb_report.srt" | "${adb_sort}" ${adb_srtopts} | uniq -c | \ "${adb_awk}" '{if($5!="NX")print $4}' "${adb_reportdir}/adb_report.srt" | "${adb_sort}" ${adb_srtopts} | uniq -c | \
"${adb_sort}" ${adb_srtopts} -nr | "${adb_awk}" '{ORS=" ";if(NR==1)printf "{ \"count\": \"%s\", \"address\": \"%s\" }",$1,$2; else if(NR<10)printf ", { \"count\": \"%s\", \"address\": \"%s\" }",$1,$2}' >> "${adb_reportdir}/adb_report.json"
"${adb_sort}" ${adb_srtopts} -nr | "${adb_awk}" '{ORS=" ";if(NR==1)printf "\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t}",$1,$2; else if(NR<10)printf ",\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t}",$1,$2}' >> "${adb_reportdir}/adb_report.json"
;; ;;
"top_blocked") "top_blocked")
"${adb_awk}" '{if($5=="NX")print $4}' "${adb_reportdir}/adb_report.srt" | "${adb_sort}" ${adb_srtopts} | uniq -c | \ "${adb_awk}" '{if($5=="NX")print $4}' "${adb_reportdir}/adb_report.srt" | "${adb_sort}" ${adb_srtopts} | uniq -c | \
"${adb_sort}" ${adb_srtopts} -nr | "${adb_awk}" '{ORS=" ";if(NR==1)printf "{ \"count\": \"%s\", \"address\": \"%s\" }",$1,$2; else if(NR<10)printf ", { \"count\": \"%s\", \"address\": \"%s\" }",$1,$2}' >> "${adb_reportdir}/adb_report.json"
"${adb_sort}" ${adb_srtopts} -nr | "${adb_awk}" '{ORS=" ";if(NR==1)printf "\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t}",$1,$2; else if(NR<10)printf ",\n\t\t{\n\t\t\t\"count\": \"%s\",\n\t\t\t\"address\": \"%s\"\n\t\t}",$1,$2}' >> "${adb_reportdir}/adb_report.json"
;; ;;
esac esac
printf "%s" " ], " >> "${adb_reportdir}/adb_report.json"
printf "\n\t%s\n" "]," >> "${adb_reportdir}/adb_report.json"
done done
search="${search//./\\.}" search="${search//./\\.}"
search="${search//[+*~%\$&\"\' ]/}" search="${search//[+*~%\$&\"\' ]/}"
"${adb_awk}" "BEGIN{i=0;printf \"\\\"requests\\\": [ \" }/(${search})/{i++;if(i==1)printf \"{ \\\"date\\\": \\\"%s\\\", \\\"time\\\": \\\"%s\\\", \\\"client\\\": \\\"%s\\\", \\\"domain\\\": \\\"%s\\\", \\\"rc\\\": \\\"%s\\\" }\",\$1,\$2,\$3,\$4,\$5;else if(i<=${count})printf \", { \\\"date\\\": \\\"%s\\\", \\\"time\\\": \\\"%s\\\", \\\"client\\\": \\\"%s\\\", \\\"domain\\\": \\\"%s\\\", \\\"rc\\\": \\\"%s\\\" }\",\$1,\$2,\$3,\$4,\$5}END{printf \" ] } }\n\"}" "${adb_reportdir}/adb_report.srt" >> "${adb_reportdir}/adb_report.json"
"${adb_awk}" "BEGIN{i=0;printf \"\t\\\"requests\\\": [\n\"}/(${search})/{i++;if(i==1)printf \"\n\t\t{\n\t\t\t\\\"date\\\": \\\"%s\\\",\n\t\t\t\\\"time\\\": \\\"%s\\\",\n\t\t\t\\\"client\\\": \\\"%s\\\",\n\t\t\t\\\"domain\\\": \\\"%s\\\",\n\t\t\t\\\"rc\\\": \\\"%s\\\"\n\t\t}\",\$1,\$2,\$3,\$4,\$5;else if(i<=${count})printf \",\n\t\t{\n\t\t\t\\\"date\\\": \\\"%s\\\",\n\t\t\t\\\"time\\\": \\\"%s\\\",\n\t\t\t\\\"client\\\": \\\"%s\\\",\n\t\t\t\\\"domain\\\": \\\"%s\\\",\n\t\t\t\\\"rc\\\": \\\"%s\\\"\n\t\t}\",\$1,\$2,\$3,\$4,\$5}END{printf \"\n\t]\n}\n\"}" "${adb_reportdir}/adb_report.srt" >> "${adb_reportdir}/adb_report.json"
rm -f "${adb_reportdir}/adb_report.srt" rm -f "${adb_reportdir}/adb_report.srt"
fi fi
fi fi
@ -1564,17 +1570,16 @@ f_report()
then then
if [ "${print}" = "cli" ] if [ "${print}" = "cli" ]
then then
printf "%s\\n%s\\n%s\\n" ":::" "::: Adblock DNS-Query Report" ":::"
printf "%s\n%s\n%s\n" ":::" "::: Adblock DNS-Query Report" ":::"
json_load_file "${adb_reportdir}/adb_report.json" json_load_file "${adb_reportdir}/adb_report.json"
json_select "data"
json_get_keys keylist json_get_keys keylist
for key in ${keylist} for key in ${keylist}
do do
json_get_var value "${key}" json_get_var value "${key}"
eval "${key}=\"${value}\"" eval "${key}=\"${value}\""
done done
printf " + %s\\n + %s\\n" "Start ::: ${start_date}, ${start_time}" "End ::: ${end_date}, ${end_time}"
printf " + %s\\n + %s %s\\n" "Total ::: ${total}" "Blocked ::: ${blocked}" "(${percent})"
printf " + %s\n + %s\n" "Start ::: ${start_date}, ${start_time}" "End ::: ${end_date}, ${end_time}"
printf " + %s\n + %s %s\n" "Total ::: ${total}" "Blocked ::: ${blocked}" "(${percent})"
top_list="top_clients top_domains top_blocked requests" top_list="top_clients top_domains top_blocked requests"
for top in ${top_list} for top in ${top_list}
@ -1592,25 +1597,25 @@ f_report()
esac esac
if json_get_type status "${top}" && [ "${top}" != "requests" ] && [ "${status}" = "array" ] if json_get_type status "${top}" && [ "${top}" != "requests" ] && [ "${status}" = "array" ]
then then
printf "%s\\n%s\\n%s\\n" ":::" "${item}" ":::"
printf "%s\n%s\n%s\n" ":::" "${item}" ":::"
json_select "${top}" json_select "${top}"
index=1 index=1
while json_get_type status "${index}" && [ "${status}" = "object" ] while json_get_type status "${index}" && [ "${status}" = "object" ]
do do
json_get_values item "${index}" json_get_values item "${index}"
printf " + %-9s::: %s\\n" ${item}
printf " + %-9s::: %s\n" ${item}
index=$((index+1)) index=$((index+1))
done done
elif json_get_type status "${top}" && [ "${top}" = "requests" ] && [ "${status}" = "array" ] elif json_get_type status "${top}" && [ "${top}" = "requests" ] && [ "${status}" = "array" ]
then then
printf "%s\\n%s\\n%s\\n" ":::" "::: Latest DNS Queries" ":::"
printf "%-15s%-15s%-45s%-80s%s\\n" "Date" "Time" "Client" "Domain" "Answer"
printf "%s\n%s\n%s\n" ":::" "::: Latest DNS Queries" ":::"
printf "%-15s%-15s%-45s%-80s%s\n" "Date" "Time" "Client" "Domain" "Answer"
json_select "${top}" json_select "${top}"
index=1 index=1
while json_get_type status "${index}" && [ "${status}" = "object" ] while json_get_type status "${index}" && [ "${status}" = "object" ]
do do
json_get_values item "${index}" json_get_values item "${index}"
printf "%-15s%-15s%-45s%-80s%s\\n" ${item}
printf "%-15s%-15s%-45s%-80s%s\n" ${item}
index=$((index+1)) index=$((index+1))
done done
fi fi
@ -1650,7 +1655,7 @@ fi
# sort selection # sort selection
# #
adb_sort="$(command -v gnu-sort)"
adb_sort="$(command -v /usr/libexec/sort-coreutils)"
if [ -z "${adb_sort}" ] if [ -z "${adb_sort}" ]
then then
adb_sort="$(command -v sort)" adb_sort="$(command -v sort)"
@ -1673,12 +1678,10 @@ fi
f_load f_load
case "${adb_action}" in case "${adb_action}" in
"stop") "stop")
f_bgserv "stop"
f_report "+" "50" "false" "false" f_report "+" "50" "false" "false"
f_rmdns f_rmdns
;; ;;
"restart") "restart")
f_bgserv "stop"
f_report "+" "50" "false" "false" f_report "+" "50" "false" "false"
f_rmdns f_rmdns
f_env f_env
@ -1703,7 +1706,6 @@ case "${adb_action}" in
f_query "${2}" f_query "${2}"
;; ;;
"start"|"reload") "start"|"reload")
f_bgserv "stop"
f_report "+" "50" "false" "false" f_report "+" "50" "false" "false"
f_env f_env
f_main f_main


+ 29
- 83
net/adblock/files/adblock.sources View File

@ -7,7 +7,7 @@
"descurl": "https://github.com/AdAway/adaway.github.io" "descurl": "https://github.com/AdAway/adaway.github.io"
}, },
"adguard": { "adguard": {
"url": "https://filters.adtidy.org/windows/filters/15.txt",
"url": "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt",
"rule": "BEGIN{FS=\"[\/|^|\\r]\"}/^\\|\\|([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+[\\/\\^\\r]+$/{print tolower($3)}", "rule": "BEGIN{FS=\"[\/|^|\\r]\"}/^\\|\\|([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+[\\/\\^\\r]+$/{print tolower($3)}",
"size": "L", "size": "L",
"focus": "general", "focus": "general",
@ -55,38 +55,10 @@
"focus": "general", "focus": "general",
"descurl": "https://disconnect.me" "descurl": "https://disconnect.me"
}, },
"energized_blugo": {
"url": "https://block.energized.pro/bluGo/formats/domains.txt",
"energized": {
"url": "https://block.energized.pro/",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}", "rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"size": "XL",
"focus": "compilation",
"descurl": "https://energized.pro"
},
"energized_blu": {
"url": "https://block.energized.pro/blu/formats/domains.txt",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"size": "XL",
"focus": "compilation",
"descurl": "https://energized.pro"
},
"energized_porn": {
"url": "https://block.energized.pro/porn/formats/domains.txt",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"size": "XXL",
"focus": "compilation+porn",
"descurl": "https://energized.pro"
},
"energized_ultimate": {
"url": "https://block.energized.pro/ultimate/formats/domains.txt",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"size": "XXL",
"focus": "compilation",
"descurl": "https://energized.pro"
},
"energized_unified": {
"url": "https://block.energized.pro/unified/formats/domains.txt",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"size": "XXL",
"size": "VAR",
"focus": "compilation", "focus": "compilation",
"descurl": "https://energized.pro" "descurl": "https://energized.pro"
}, },
@ -111,13 +83,6 @@
"focus": "gaming", "focus": "gaming",
"descurl": "https://github.com/abyssin/pihole-blocklist" "descurl": "https://github.com/abyssin/pihole-blocklist"
}, },
"malwaredomains": {
"url": "https://mirror.cedia.org.ec/malwaredomains/justdomains",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"size": "M",
"focus": "malware",
"descurl": "https://www.malwaredomains.com"
},
"notracking": { "notracking": {
"url": "https://raw.githubusercontent.com/notracking/hosts-blocklists/master/dnscrypt-proxy/dnscrypt-proxy.blacklist.txt", "url": "https://raw.githubusercontent.com/notracking/hosts-blocklists/master/dnscrypt-proxy/dnscrypt-proxy.blacklist.txt",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}", "rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
@ -125,9 +90,16 @@
"focus": "tracking", "focus": "tracking",
"descurl": "https://github.com/notracking/hosts-blocklists" "descurl": "https://github.com/notracking/hosts-blocklists"
}, },
"oisd_nl": {
"url": "https://abp.oisd.nl/",
"rule": "BEGIN{FS=\"[|^]\"}/^\\|\\|([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+\\^(\\$third-party)?$/{print tolower($3)}",
"oisd_basic": {
"url": "https://dbl.oisd.nl/basic",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"size": "L",
"focus": "general",
"descurl": "https://oisd.nl"
},
"oisd_full": {
"url": "https://dbl.oisd.nl",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"size": "XXL", "size": "XXL",
"focus": "general", "focus": "general",
"descurl": "https://oisd.nl" "descurl": "https://oisd.nl"
@ -217,11 +189,11 @@
"descurl": "https://easylist.to" "descurl": "https://easylist.to"
}, },
"reg_pl1": { "reg_pl1": {
"url": "https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts_without_controversies.txt",
"url": "https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt",
"rule": "/^0\\.0\\.0\\.0[[:space:]]+([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($2)}", "rule": "/^0\\.0\\.0\\.0[[:space:]]+([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($2)}",
"size": "S", "size": "S",
"focus": "reg_poland", "focus": "reg_poland",
"descurl": "https://kadantiscam.netlify.com"
"descurl": "https://kadantiscam.netlify.app"
}, },
"reg_pl2": { "reg_pl2": {
"url": "https://raw.githubusercontent.com/MajkiIT/polish-ads-filter/master/polish-pihole-filters/hostfile.txt", "url": "https://raw.githubusercontent.com/MajkiIT/polish-ads-filter/master/polish-pihole-filters/hostfile.txt",
@ -237,6 +209,13 @@
"focus": "reg_romania", "focus": "reg_romania",
"descurl": "https://easylist.to" "descurl": "https://easylist.to"
}, },
"reg_se": {
"url": "https://raw.githubusercontent.com/lassekongo83/Frellwits-filter-lists/master/Frellwits-Swedish-Hosts-File.txt",
"rule": "/^127\\.0\\.0\\.1[[:space:]]+([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($2)}",
"size": "s",
"focus": "reg_sweden",
"descurl": "https://github.com/lassekongo83/Frellwits-filter-lists"
},
"reg_ru": { "reg_ru": {
"url": "https://easylist-downloads.adblockplus.org/ruadlist+easylist.txt", "url": "https://easylist-downloads.adblockplus.org/ruadlist+easylist.txt",
"rule": "BEGIN{FS=\"[|^]\"}/^\\|\\|([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+\\^(\\$third-party)?$/{print tolower($3)}", "rule": "BEGIN{FS=\"[|^]\"}/^\\|\\|([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+\\^(\\$third-party)?$/{print tolower($3)}",
@ -254,22 +233,9 @@
"shallalist": { "shallalist": {
"url": "https://www.shallalist.de/Downloads/shallalist.tar.gz", "url": "https://www.shallalist.de/Downloads/shallalist.tar.gz",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}", "rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"categories": [
"adv", "costtraps", "spyware", "tracker", "warez"
],
"size": "L",
"size": "VAR",
"focus": "general", "focus": "general",
"descurl": "https://www.shallalist.de"
},
"shallalist_porn": {
"url": "https://www.shallalist.de/Downloads/shallalist.tar.gz",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"categories": [
"adv", "costtraps", "porn", "spyware", "tracker", "warez"
],
"size": "XXL",
"focus": "general+porn",
"descurl": "https://www.shallalist.de"
"descurl": "https://www.shallalist.de",
}, },
"smarttv_tracking": { "smarttv_tracking": {
"url": "https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV.txt", "url": "https://raw.githubusercontent.com/Perflyst/PiHoleBlocklist/master/SmartTV.txt",
@ -286,16 +252,9 @@
"descurl": "https://github.com/Dawsey21" "descurl": "https://github.com/Dawsey21"
}, },
"stevenblack": { "stevenblack": {
"url": "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts",
"rule": "/^0\\.0\\.0\\.0[[:space:]]+([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($2)}",
"size": "L",
"focus": "compilation",
"descurl": "https://github.com/StevenBlack/hosts"
},
"stevenblack_porn": {
"url": "https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts",
"url": "https://raw.githubusercontent.com/StevenBlack/hosts/master/",
"rule": "/^0\\.0\\.0\\.0[[:space:]]+([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($2)}", "rule": "/^0\\.0\\.0\\.0[[:space:]]+([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($2)}",
"size": "L",
"size": "VAR",
"focus": "compilation", "focus": "compilation",
"descurl": "https://github.com/StevenBlack/hosts" "descurl": "https://github.com/StevenBlack/hosts"
}, },
@ -309,22 +268,9 @@
"utcapitole": { "utcapitole": {
"url": "https://dsi.ut-capitole.fr/blacklists/download/blacklists.tar.gz", "url": "https://dsi.ut-capitole.fr/blacklists/download/blacklists.tar.gz",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}", "rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"categories": [
"publicite", "bitcoin", "cryptojacking", "ddos", "malware", "phishing", "warez"
],
"size": "L",
"size": "VAR",
"focus": "general", "focus": "general",
"descurl": "https://dsi.ut-capitole.fr/blacklists/index_en.php"
},
"utcapitole_porn": {
"url": "https://dsi.ut-capitole.fr/blacklists/download/blacklists.tar.gz",
"rule": "/^([[:alnum:]_-]{1,63}\\.)+[[:alpha:]]+([[:space:]]|$)/{print tolower($1)}",
"categories": [
"adult", "publicite", "bitcoin", "cryptojacking", "ddos", "malware", "phishing", "warez"
],
"size": "XXL",
"focus": "general+porn",
"descurl": "https://dsi.ut-capitole.fr/blacklists/index_en.php"
"descurl": "https://dsi.ut-capitole.fr/blacklists/index_en.php",
}, },
"wally3k": { "wally3k": {
"url": "https://v.firebog.net/hosts/static/w3kbl.txt", "url": "https://v.firebog.net/hosts/static/w3kbl.txt",


Loading…
Cancel
Save