USE_PROCD=1
LC_ALL=C
-readonly PKG_VERSION='dev-test'
+if type extra_command 1>/dev/null 2>&1; then
+ extra_command 'allow' 'Allows domain in current block-list and config'
+ extra_command 'check' 'Checks if specified domain is found in current block-list'
+ extra_command 'check_lists' 'Checks if specified domain is found in enabled block-lists'
+ extra_command 'dl' 'Force-downloads all enabled block-list'
+ extra_command 'killcache' 'Delete all cached files'
+ extra_command 'pause' 'Pauses AdBlocking for specified number of seconds (default: 60)'
+ extra_command 'show_blocklist' 'List currently blocked domains'
+ extra_command 'sizes' 'Displays the file-sizes of enabled block-lists'
+ extra_command 'version' 'Show version information'
+else
+# shellcheck disable=SC2034
+ EXTRA_COMMANDS='allow check dl killcache pause sizes status_service version'
+# shellcheck disable=SC2034
+ EXTRA_HELP=' allow Allows domain(s) in current block-list and config
+ check Checks if specified domain is found in current block-list
+ check_lists Checks if specified domain is found in enabled block-lists
+ dl Force-downloads all enabled block-list
+ pause Pauses AdBlocking for specified number of seconds (default: 60)
+ show_blocklist List currently blocked domains
+ sizes Displays the file-sizes of enabled block-lists
+ version Show version information'
+fi
+
readonly packageName='adblock-fast'
+readonly PKG_VERSION='dev-test'
+readonly packageCompat='1'
readonly serviceName="$packageName $PKG_VERSION"
readonly packageConfigFile="/etc/config/${packageName}"
readonly dnsmasqAddnhostsFile="/var/run/${packageName}/dnsmasq.addnhosts"
readonly dnsmasqAddnhostsGzip="${packageName}.dnsmasq.addnhosts.gz"
readonly dnsmasqAddnhostsFilter='s|^|127.0.0.1 |;s|$||'
readonly dnsmasqAddnhostsFilterIPv6='s|^|:: |;s|$||'
+readonly dnsmasqAddnhostsOutputFilter='s|^127.0.0.1 ||;s|^:: ||;'
readonly dnsmasqConfFile="/tmp/dnsmasq.d/${packageName}"
readonly dnsmasqConfCache="/var/run/${packageName}/dnsmasq.conf.cache"
readonly dnsmasqConfGzip="${packageName}.dnsmasq.conf.gz"
readonly dnsmasqConfFilter='s|^|local=/|;s|$|/|'
+readonly dnsmasqConfOutputFilter='s|local=/||;s|/$||;'
readonly dnsmasqIpsetFile="/tmp/dnsmasq.d/${packageName}.ipset"
readonly dnsmasqIpsetCache="/var/run/${packageName}/dnsmasq.ipset.cache"
readonly dnsmasqIpsetGzip="${packageName}.dnsmasq.ipset.gz"
readonly dnsmasqIpsetFilter='s|^|ipset=/|;s|$|/adb|'
+readonly dnsmasqIpsetOutputFilter='s|ipset=/||;s|/adb$||;'
readonly dnsmasqNftsetFile="/tmp/dnsmasq.d/${packageName}.nftset"
readonly dnsmasqNftsetCache="/var/run/${packageName}/dnsmasq.nftset.cache"
readonly dnsmasqNftsetGzip="${packageName}.dnsmasq.nftset.gz"
readonly dnsmasqNftsetFilter='s|^|nftset=/|;s|$|/4#inet#fw4#adb4|'
readonly dnsmasqNftsetFilterIPv6='s|^|nftset=/|;s|$|/4#inet#fw4#adb4,6#inet#fw4#adb6|'
+readonly dnsmasqNftsetOutputFilter='s|nftset=/||;s|/4#inet#adb#adb4||;'
readonly dnsmasqServersFile="/var/run/${packageName}/dnsmasq.servers"
readonly dnsmasqServersCache="/var/run/${packageName}/dnsmasq.servers.cache"
readonly dnsmasqServersGzip="${packageName}.dnsmasq.servers.gz"
readonly dnsmasqServersFilter='s|^|server=/|;s|$|/|'
+readonly dnsmasqServersOutputFilter='s|server=/||;s|/$||;'
readonly smartdnsDomainSetFile="/var/run/${packageName}/smartdns.domainset"
readonly smartdnsDomainSetCache="/var/run/${packageName}/smartdns.domainset.cache"
readonly smartdnsDomainSetConfig="/var/run/${packageName}/smartdns.domainset.conf"
readonly smartdnsDomainSetGzip="${packageName}.smartdns.domainset.gz"
-readonly smartdnsDomainSetFilter=';'
+readonly smartdnsDomainSetFilter=''
+readonly smartdnsDomainSetOutputFilter=''
readonly smartdnsIpsetFile="/var/run/${packageName}/smartdns.ipset"
readonly smartdnsIpsetCache="/var/run/${packageName}/smartdns.ipset.cache"
readonly smartdnsIpsetConfig="/var/run/${packageName}/smartdns.ipset.conf"
readonly smartdnsIpsetGzip="${packageName}.smartdns.ipset.gz"
-readonly smartdnsIpsetFilter=';'
+readonly smartdnsIpsetFilter=''
+readonly smartdnsIpsetOutputFilter=''
readonly smartdnsNftsetFile="/var/run/${packageName}/smartdns.nftset"
readonly smartdnsNftsetCache="/var/run/${packageName}/smartdns.nftset.cache"
readonly smartdnsNftsetConfig="/var/run/${packageName}/smartdns.nftset.conf"
readonly smartdnsNftsetGzip="${packageName}.smartdns.nftset.gz"
-readonly smartdnsNftsetFilter=';'
+readonly smartdnsNftsetFilter=''
+readonly smartdnsNftsetOutputFilter=''
readonly unboundFile="/var/lib/unbound/adb_list.${packageName}"
readonly unboundCache="/var/run/${packageName}/unbound.cache"
readonly unboundGzip="${packageName}.unbound.gz"
-readonly unboundFilter='s|^|local-zone: "|;s|$|" static|'
+readonly unboundFilter='s|^|local-zone: "|;s|$|." always_nxdomain|'
+readonly unboundOutputFilter='s|^local-zone: "||;s|." always_nxdomain$||;'
readonly A_TMP="/var/${packageName}.a.tmp"
readonly B_TMP="/var/${packageName}.b.tmp"
readonly SED_TMP="/var/${packageName}.sed.tmp"
+readonly uciConfigFile="/etc/config/${packageName}"
readonly runningConfigFile="/dev/shm/${packageName}.config"
readonly runningErrorFile="/dev/shm/${packageName}.error"
readonly runningStatusFile="/dev/shm/${packageName}.status"
readonly hostsFilter='/localhost/d;/^#/d;/^[^0-9]/d;s/^0\.0\.0\.0.//;s/^127\.0\.0\.1.//;s/[[:space:]]*#.*$//;s/[[:cntrl:]]$//;s/[[:space:]]//g;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;'
-readonly domainsFilter='/^#/d;s/[[:space:]]*#.*$//;s/[[:space:]]*$//;s/[[:cntrl:]]$//;/[[:space:]]/d;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;'
+readonly domainsFilter='/^#/d;s/[[:space:]]*#.*$//;s/[[:space:]]*$//;s/[[:cntrl:]]$//;/[[:space:]]/d;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/^$/d;/[^[:alnum:]_.-]/d;'
readonly adBlockPlusFilter='/^#/d;/^!/d;s/[[:space:]]*#.*$//;s/^||//;s/\^$//;s/[[:space:]]*$//;s/[[:cntrl:]]$//;/[[:space:]]/d;/[`~!@#\$%\^&\*()=+;:"'\'',<>?/\|[{}]/d;/]/d;/\./!d;/^$/d;/[^[:alnum:]_.-]/d;'
readonly dnsmasqFileFilter='\|^server=/[[:alnum:]_.-].*/|!d;s|server=/||;s|/.*$||'
readonly dnsmasq2FileFilter='\|^local=/[[:alnum:]_.-].*/|!d;s|local=/||;s|/.*$||'
outputFile=
outputGzip=
outputCache=
+outputOutputFilter=
awk='awk'
load_environment_flag=
allowed_url=
local i ret
case "$param" in
create|set)
- cp -f "/etc/config/${packageName}" "$runningConfigFile"
+ cp -f "$uciConfigFile" "$runningConfigFile"
;;
get)
case "$var" in
local old_allowed_url old_blocked_url
if [ ! -s "$runningConfigFile" ]; then
ret='on_boot'
+ elif cmp -s "$uciConfigFile" "$runningConfigFile"; then
+ ret='restart'
else
for i in $_reload; do
local val_current val_old UCI_CONFIG_DIR
;;
esac
}
-debug() { local i j; for i in "$@"; do eval "j=\$$i"; echo "${i}: ${j} "; done; }
+debug() { local __i __j; for __i in "$@"; do eval "__j=\$$__i"; echo "${__i}: ${__j} "; done; }
dns_set_output_values() {
case "$1" in
dnsmasq.addnhosts)
outputFile="$dnsmasqAddnhostsFile"
outputCache="$dnsmasqAddnhostsCache"
outputGzip="${compressed_cache_dir}/${dnsmasqAddnhostsGzip}"
+ outputOutputFilter="$dnsmasqAddnhostsOutputFilter"
if [ "$ipv6_enabled" -ne '0' ]; then
outputFilterIPv6="$dnsmasqAddnhostsFilterIPv6"
fi
outputFile="$dnsmasqConfFile"
outputCache="$dnsmasqConfCache"
outputGzip="${compressed_cache_dir}/${dnsmasqConfGzip}"
+ outputOutputFilter="$dnsmasqConfOutputFilter"
;;
dnsmasq.ipset)
outputFilter="$dnsmasqIpsetFilter"
outputFile="$dnsmasqIpsetFile"
outputCache="$dnsmasqIpsetCache"
outputGzip="${compressed_cache_dir}/${dnsmasqIpsetGzip}"
+ outputOutputFilter="$dnsmasqIpsetOutputFilter"
;;
dnsmasq.nftset)
if [ "$ipv6_enabled" -ne '0' ]; then
outputFile="$dnsmasqNftsetFile"
outputCache="$dnsmasqNftsetCache"
outputGzip="${compressed_cache_dir}/${dnsmasqNftsetGzip}"
+ outputOutputFilter="$dnsmasqNftsetOutputFilter"
;;
dnsmasq.servers)
outputFilter="$dnsmasqServersFilter"
outputFile="$dnsmasqServersFile"
outputCache="$dnsmasqServersCache"
outputGzip="${compressed_cache_dir}/${dnsmasqServersGzip}"
+ outputOutputFilter="$dnsmasqServersOutputFilter"
;;
smartdns.domainset)
outputFilter="$smartdnsDomainSetFilter"
outputCache="$smartdnsDomainSetCache"
outputGzip="${compressed_cache_dir}/${smartdnsDomainSetGzip}"
outputConfig="$smartdnsDomainSetConfig"
+ outputOutputFilter="$smartdnsDomainSetOutputFilter"
;;
smartdns.ipset)
outputFilter="$smartdnsIpsetFilter"
outputCache="$smartdnsIpsetCache"
outputGzip="${compressed_cache_dir}/${smartdnsIpsetGzip}"
outputConfig="$smartdnsIpsetConfig"
+ outputOutputFilter="$smartdnsIpsetOutputFilter"
;;
smartdns.nftset)
outputFilter="$smartdnsNftsetFilter"
outputCache="$smartdnsNftsetCache"
outputGzip="${compressed_cache_dir}/${smartdnsNftsetGzip}"
outputConfig="$smartdnsNftsetConfig"
+ outputOutputFilter="$smartdnsNftsetOutputFilter"
;;
unbound.adb_list)
outputFilter="$unboundFilter"
outputFile="$unboundFile"
outputCache="$unboundCache"
- outputGzip="$unboundGzip"
+ outputGzip="${compressed_cache_dir}/${unboundGzip}"
+ outputOutputFilter="$unboundOutputFilter"
;;
esac
}
fi
}
ipset() { "$ipset" "$@" >/dev/null 2>&1; }
-get_version() { grep -m1 -A2 -w "^Package: $1$" /usr/lib/opkg/status | sed -n 's/Version: //p'; }
get_ram_free() { ubus call system info | jsonfilter -e '@.memory.free'; }
get_ram_total() { ubus call system info | jsonfilter -e '@.memory.total'; }
led_on(){ if [ -n "${1}" ] && [ -e "${1}/trigger" ]; then echo 'default-on' > "${1}/trigger" 2>&1; fi; }
print_json_int() { json_init; json_add_int "$1" "$2"; json_dump; json_cleanup; }
print_json_string() { json_init; json_add_string "$1" "$2"; json_dump; json_cleanup; }
sanitize_dir() { [ -d "$(readlink -fn "$1")" ] && readlink -fn "$1"; }
+smartdns_restart() { /etc/init.d/smartdns restart >/dev/null 2>&1; }
str_contains() { test "$1" != "$(str_replace "$1" "$2" '')"; }
str_contains_word() { echo "$1" | grep -q -w "$2"; }
# shellcheck disable=SC2018,SC2019
str_replace() { printf "%b" "$1" | sed -e "s/$(printf "%b" "$2")/$(printf "%b" "$3")/g"; }
ubus_get_data() { ubus call service list "{ 'name': '$packageName' }" | jsonfilter -e "@['${packageName}'].instances.main.data.${1}"; }
ubus_get_ports() { ubus call service list "{ 'name': '$packageName' }" | jsonfilter -e "@['${packageName}'].instances.main.data.firewall.*.dest_port"; }
+uci_get_protocol() { uci_get 'network' "$1" 'proto'; }
unbound_restart() { /etc/init.d/unbound restart >/dev/null 2>&1; }
json() {
local msg memmsg logmsg text
local sharedMemoryOutput="/dev/shm/$packageName-output"
if [ -z "$verbosity" ] && [ -n "$packageName" ]; then
- verbosity="$(uci -q get "$packageName.config.verbosity")"
+ verbosity="$(uci_get "$packageName" 'config' 'verbosity' '2')"
fi
- verbosity="${verbosity:-2}"
if [ $# -ne 1 ] && is_integer "$1"; then
if [ $((verbosity & $1)) -gt 0 ] || [ "$verbosity" = "$1" ]; then shift; text="$*"; else return 0; fi
fi
fi
}
-if type extra_command 1>/dev/null 2>&1; then
- extra_command 'allow' 'Allows domain in current block-list and config'
- extra_command 'check' 'Checks if specified domain is found in current block-list'
- extra_command 'check_lists' 'Checks if specified domain is found in enabled block-lists'
- extra_command 'dl' 'Force-downloads all enabled block-list'
- extra_command 'killcache' 'Delete all cached files'
- extra_command 'pause' 'Pauses AdBlocking for specified number of seconds (default: 60)'
- extra_command 'sizes' 'Displays the file-sizes of enabled block-lists'
- extra_command 'version' 'Show version information'
-else
-# shellcheck disable=SC2034
- EXTRA_COMMANDS='allow check dl killcache pause sizes status_service version'
-# shellcheck disable=SC2034
- EXTRA_HELP=' allow Allows domain(s) in current block-list and config
- check Checks if specified domain is found in current block-list
- dl Force-downloads all enabled block-list
- pause Pauses AdBlocking for specified number of seconds (default: 60)
- sizes Displays the file-sizes of enabled block-lists'
-fi
-
get_text() {
local r
case "$1" in
load_network() {
local param="$1"
- local i j wan_if wan_gw wan_proto
+ local i j wan_if wan_gw
local counter wan_if_timeout="$procd_boot_wan_timeout" wan_gw_timeout='5'
counter=0
while [ -z "$wan_if" ]; do
done
counter=0
- wan_proto="$(uci -q get "network.${wan_if}.proto")"
- if [ "$wan_proto" = 'pppoe' ]; then
+ if [ "$(uci_get_protocol "$wan_if")" = 'pppoe' ]; then
wan_gw_timeout=$((wan_gw_timeout+10))
fi
while [ "$counter" -le "$wan_gw_timeout" ]; do
[ "$dns" = 'smartdns.domainset' ] || rm -f "$smartdnsDomainSetFile" "$smartdnsDomainSetCache" "${compressed_cache_dir}/${smartdnsDomainSetGzip}" "$smartdnsDomainSetConfig"
[ "$dns" = 'smartdns.ipset' ] || rm -f "$smartdnsIpsetFile" "$smartdnsIpsetCache" "${compressed_cache_dir}/${smartdnsIpsetGzip}" "$smartdnsIpsetConfig"
[ "$dns" = 'smartdns.nftset' ] || rm -f "$smartdnsNftsetFile" "$smartdnsNftsetCache" "${compressed_cache_dir}/${smartdnsNftsetGzip}" "$smartdnsNftsetConfig"
- [ "$dns" = 'unbound.adb_list' ] || rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
+ [ "$dns" = 'unbound.adb_list' ] || rm -f "$unboundFile" "$unboundCache" "${compressed_cache_dir}/${unboundGzip}"
for i in "$runningConfigFile" "$runningErrorFile" "$runningStatusFile" "$outputFile" "$outputCache" "$outputGzip" "$outputConfig"; do
[ -n "$i" ] || continue
dl_flag="-O"
fi
led="${led:+/sys/class/leds/$led}"
- if curl --version 2>/dev/null | grep -q "https" \
- || wget --version 2>/dev/null | grep -q "+https" \
- || grep -q "libustream-mbedtls" /usr/lib/opkg/status \
- || grep -q "libustream-openssl" /usr/lib/opkg/status \
- || grep -q "libustream-wolfssl" /usr/lib/opkg/status; then
+ if curl --version 2>/dev/null | grep -q "Protocols: .*https.*" \
+ || wget --version 2>/dev/null | grep -q "+ssl"; then
isSSLSupported=1
else
unset isSSLSupported
}
resolver() {
- _resolver_config() {
+ _dnsmasq_instance_config() {
local cfg="$1" param="$2"
[ -s "/etc/config/dhcp" ] || return 0
case "$param" in
rm -f "$smartdnsDomainSetFile" "$smartdnsDomainSetCache" "${compressed_cache_dir}/${smartdnsDomainSetGzip}" "$smartdnsDomainSetConfig"
rm -f "$smartdnsIpsetFile" "$smartdnsIpsetCache" "${compressed_cache_dir}/${smartdnsIpsetGzip}" "$smartdnsIpsetConfig"
rm -f "$smartdnsNftsetFile" "$smartdnsNftsetCache" "${compressed_cache_dir}/${smartdnsNftsetGzip}" "$smartdnsNftsetConfig"
- rm -f "$unboundFile" "$unboundCache" "$unboundGzip"
+ rm -f "$unboundFile" "$unboundCache" "${compressed_cache_dir}/${unboundGzip}"
if [ -s "/etc/config/dhcp" ]; then
config_load 'dhcp'
config_foreach _dnsmasq_instance_config 'dnsmasq' 'cleanup'
config_load 'dhcp'
if [ "$dnsmasq_instance" = "*" ]; then
- config_foreach _resolver_config 'dnsmasq' "$dns"
+ config_foreach _dnsmasq_instance_config 'dnsmasq' "$dns"
elif [ -n "$dnsmasq_instance" ]; then
for i in $dnsmasq_instance; do
- _resolver_config "@dnsmasq[$i]" "$dns" || _resolver_config "$i" "$dns"
+ _dnsmasq_instance_config "@dnsmasq[$i]" "$dns" || _dnsmasq_instance_config "$i" "$dns"
+ done
+ fi
+ config_load 'smartdns'
+ if [ "$smartdns_instance" = "*" ]; then
+ config_foreach _smartdns_instance_config 'smartdns' "$dns"
+ elif [ -n "$smartdns_instance" ]; then
+ for i in $smartdns_instance; do
+ _smartdns_instance_config "@smartdns[$i]" "$dns" || _smartdns_instance_config "$i" "$dns"
done
fi
case "$dns" in
dnsmasq.*)
chmod 660 "$outputFile"
- chown root:dnsmasq "$outputFile"
- param=dnsmasq_restart
+ chown root:dnsmasq "$outputFile" >/dev/null 2>/dev/null
+ param='dnsmasq_restart'
output_text='Restarting dnsmasq'
;;
smartdns.*)
chmod 660 "$outputFile" "$outputConfig"
- chown root:root "$outputFile" "$outputConfig"
+ chown root:root "$outputFile" "$outputConfig" >/dev/null 2>/dev/null
param='smartdns_restart'
output_text='Restarting SmartDNS'
;;
unbound.*)
chmod 660 "$outputFile"
- chown root:unbound "$outputFile"
+ chown root:unbound "$outputFile" >/dev/null 2>/dev/null
param='unbound_restart'
output_text='Restarting Unbound'
;;
esac
- if [ -n "$(uci_changes dhcp)" ]; then
- uci_commit dhcp
- if [ "$param" = 'unbound_restart' ]; then
- param='dnsmasq_restart; unbound_restart;'
- output_text='Restarting Unbound/dnsmasq'
- else
- param=dnsmasq_restart
- output_text='Restarting dnsmasq'
+ if [ -n "$(uci_changes dhcp)" ]; then
+ uci_commit 'dhcp'
+ if ! str_contains "$param" 'dnsmasq_restart'; then
+ param="${param:+"$param; dnsmasq_restart"}"
+ output_text="${output_text}/dnsmasq"
+ fi
+ fi
+ if [ -n "$(uci_changes smartdns)" ]; then
+ uci_commit 'smartdns'
+ if ! str_contains "$param" 'smartdns_restart'; then
+ param="${param:+"$param; "}smartdns_restart"
+ output_text="${output_text}/smartDNS"
fi
fi
output 1 "$output_text "
;;
esac
if [ -n "$(uci_changes dhcp)" ]; then
- uci_commit dhcp
- if [ "$param" = 'unbound_restart' ]; then
- param='dnsmasq_restart; unbound_restart;'
- else
- param=dnsmasq_restart
- fi
+ uci_commit 'dhcp'
+ str_contains "$param" 'dnsmasq_restart' || param="${param:+"$param; dnsmasq_restart"}"
+ fi
+ if [ -n "$(uci_changes smartdns)" ]; then
+ uci_commit 'smartdns'
+ str_contains "$param" 'smartdns_restart' || param="${param:+"$param; "}smartdns_restart"
fi
eval "$param"
return $?
return $?
;;
test_gzip)
- [ -s "$outputGzip" ] && gzip -t -c "$outputGzip"
+ [ -s "$outputGzip" ] && gzip -t -c "$outputGzip" >/dev/null 2>/dev/null
return $?
;;
create_gzip)
append_newline "$R_TMP"
[ -n "$cfg" ] && new_size="$(get_local_filesize "$R_TMP")"
if [ -n "$new_size" ] && [ "$size" != "$new_size" ]; then
- uci set "${packageName}.${cfg}.size=$size"
+ uci_set "$packageName" "$cfg" 'size' "$size"
fi
format="$(detect_file_type "$R_TMP")"
case "$format" in
config_load "$packageName"
config_foreach load_validate_file_url_section 'file_url' process_file_url_wrapper
wait
- if [ -n "$(uci changes "$packageName")" ]; then
+ if [ -n "$(uci_changes "$packageName")" ]; then
output 2 "Saving updated file size(s) "
- if uci commit "$packageName"; then output_okn; else output_failn; fi
+ if uci_commit "$packageName"; then output_okn; else output_failn; fi
fi
output 1 '\n'
output_failn
json add error 'errorMovingDataFile'
fi
+ case "$dns" in
+ unbound.adb_list)
+ sed -i '1 i\server:' "$outputFile"
+ ;;
+ esac
if [ "$compressed_cache" -gt 0 ]; then
output 2 'Creating compressed cache '
json set message "$(get_text 'statusProcessing'): creating compressed cache"
output "Found $c matches for '$string' in '$outputFile'.\\n"
fi
if [ "$c" -le 20 ]; then
- case "$dns" in
- dnsmasq.addnhosts)
- grep "$string" "$outputFile" | sed 's|^127.0.0.1 ||;s|^:: ||;';;
- dnsmasq.conf)
- grep "$string" "$outputFile" | sed 's|local=/||;s|/$||;';;
- dnsmasq.ipset)
- grep "$string" "$outputFile" | sed 's|ipset=/||;s|/adb$||;';;
- dnsmasq.nftset)
- grep "$string" "$outputFile" | sed 's|nftset=/||;s|/4#inet#adb#adb4||;';;
- dnsmasq.servers)
- grep "$string" "$outputFile" | sed 's|server=/||;s|/$||;';;
- smartdns.*)
- grep "$string" "$outputFile";;
- unbound.adb_list)
- grep "$string" "$outputFile" | sed 's|^local-zone: "||;s|" static$||;';;
- esac
+ grep "$string" "$outputFile" | sed "$outputOutputFilter"
fi
else
output "The '$string' is not found in current block-list ('$outputFile').\\n"
return 0
}
+adb_show_blocklist() {
+ local validation_result="$3"
+ load_environment "$validation_result" 'quiet' || return 1
+ sed "$outputOutputFilter" "$outputFile"
+}
+
adb_sizes() {
_config_add_url_size() {
local cfg="$1" url size
size="$(get_url_filesize "$url")"
output "$url${size:+: $size} "
if [ -n "$size" ]; then
- uci set "${packageName}.${cfg}.size=$size"
+ uci_set "$packageName" "$cfg" 'size' "$size"
output_okn
else
output_failn
load_environment "$validation_result" 'quiet' || return 1
config_load "$packageName"
config_foreach _config_add_url_size 'file_url'
- uci commit "$packageName"
+ uci_commit "$packageName"
}
# shellcheck disable=SC2120
adb_start() {
- local action status error message stats c
+ local action status error message stats c iface
local param="$1" validation_result="$3"
load_environment "$validation_result" "$param" || return 1
action="$(config_cache get 'trigger_service')"
fw4_restart_flag="$(config_cache get 'trigger_fw4')"
- if [ "$action" = 'on_boot' ] || [ "$param" = 'on_boot' ]; then
+ if [ "$action" = 'on_boot' ] || [ "$param" = 'on_boot' ] || [ "$param" = 'on_pause' ]; then
if cache 'test_gzip' || cache 'test'; then
action='restore'
else
# shellcheck disable=SC3060
for c in ${force_dns_port/,/ }; do
if netstat -tuln | grep LISTEN | grep ":${c}" >/dev/null 2>&1; then
- json_add_object ""
- json_add_string type redirect
- json_add_string target DNAT
- json_add_string src lan
- json_add_string proto "tcp udp"
- json_add_string src_dport "$c"
- json_add_string dest_port "$c"
- json_add_string family any
- json_add_boolean reflection 0
- json_close_object
+ for iface in $force_dns_interface; do
+ json_add_object ""
+ json_add_string type redirect
+ json_add_string target DNAT
+ json_add_string src "$iface"
+ json_add_string proto "tcp udp"
+ json_add_string src_dport "$c"
+ json_add_string dest_port "$c"
+ json_add_string family any
+ json_add_boolean reflection 0
+ json_close_object
+ done
else
- json_add_object ""
- json_add_string type rule
- json_add_string src lan
- json_add_string dest "*"
- json_add_string proto "tcp udp"
- json_add_string dest_port "$c"
- json_add_string target REJECT
- json_close_object
+ for iface in $force_dns_interface; do
+ json_add_object ""
+ json_add_string type rule
+ json_add_string src "$iface"
+ json_add_string dest "*"
+ json_add_string proto "tcp udp"
+ json_add_string dest_port "$c"
+ json_add_string target REJECT
+ json_close_object
+ done
fi
done
fi
json_add_string match dest_net
json_add_string storage hash
json_close_object
- json_add_object ""
- json_add_string type rule
- json_add_string ipset adb
- json_add_string src lan
- json_add_string dest "*"
- json_add_string proto "tcp udp"
- json_add_string target REJECT
- json_close_object
+ for iface in $force_dns_interface; do
+ json_add_object ""
+ json_add_string type rule
+ json_add_string ipset adb
+ json_add_string src "$iface"
+ json_add_string dest "*"
+ json_add_string proto "tcp udp"
+ json_add_string target REJECT
+ json_close_object
+ done
;;
dnsmasq.nftset|smartdns.nftset)
json_add_object ""
json_add_string family 4
json_add_string match dest_net
json_close_object
- json_add_object ""
- json_add_string type rule
- json_add_string ipset adb4
- json_add_string src lan
- json_add_string dest "*"
- json_add_string proto "tcp udp"
- json_add_string target REJECT
- json_close_object
+ for iface in $force_dns_interface; do
+ json_add_object ""
+ json_add_string type rule
+ json_add_string ipset adb4
+ json_add_string src "$iface"
+ json_add_string dest "*"
+ json_add_string proto "tcp udp"
+ json_add_string target REJECT
+ json_close_object
+ done
if [ "$ipv6_enabled" -ne '0' ]; then
json_add_object ""
json_add_string type ipset
json_add_string family 6
json_add_string match dest_net
json_close_object
- json_add_object ""
- json_add_string type rule
- json_add_string ipset adb6
- json_add_string src lan
- json_add_string dest "*"
- json_add_string proto "tcp udp"
- json_add_string target REJECT
- json_close_object
+ for iface in $force_dns_interface; do
+ json_add_object ""
+ json_add_string type rule
+ json_add_string ipset adb6
+ json_add_string src "$iface"
+ json_add_string dest "*"
+ json_add_string proto "tcp udp"
+ json_add_string target REJECT
+ json_close_object
+ done
fi
;;
esac
resolver 'cleanup'
return 0
}
+show_blocklist() { load_validate_config 'config' adb_show_blocklist "'$*'"; }
reload_service() { rc_procd start_service 'restart'; }
restart_service() { rc_procd start_service 'restart'; }
service_started() { is_fw4_restart_needed && procd_set_config_changed firewall; }
load_validate_config() {
local enabled
local force_dns
+ local force_dns_interface
local force_dns_port
local parallel_downloads
local debug
local verbosity
local procd_trigger_wan6
local procd_boot_wan_timeout
+ local procd_lan_interface_name
local led
local dns
local dnsmasq_instance
uci_load_validate "$packageName" "$packageName" "$1" "${2}${3:+ $3}" \
'enabled:bool:0' \
'force_dns:bool:1' \
+ 'force_dns_interface:list(network):lan' \
'force_dns_port:list(integer):53,853' \
'parallel_downloads:bool:1' \
'debug:bool:0' \
'led:or("", "none", file, device, string)' \
'dns:or("dnsmasq.addnhosts", "dnsmasq.conf", "dnsmasq.ipset", "dnsmasq.nftset", "dnsmasq.servers", "smartdns.domainset", "smartdns.ipset", "smartdns.nftset", "unbound.adb_list"):dnsmasq.servers' \
'dnsmasq_instance:list(or(integer, string)):*' \
+ 'smartdns_instance:list(or(integer, string)):*' \
'allowed_domain:list(string)' \
'blocked_domain:list(string)' \
'dnsmasq_config_file_url:string'