simple-adblock: jsonOps-related bugfixes
Signed-off-by: Stan Grishin <stangri@melmac.net>
This commit is contained in:
parent
b164a3aa32
commit
e695cc26b0
|
@ -5,7 +5,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=simple-adblock
|
PKG_NAME:=simple-adblock
|
||||||
PKG_VERSION:=1.8.5
|
PKG_VERSION:=1.8.7
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_MAINTAINER:=Stan Grishin <stangri@melmac.net>
|
PKG_MAINTAINER:=Stan Grishin <stangri@melmac.net>
|
||||||
PKG_LICENSE:=GPL-3.0-or-later
|
PKG_LICENSE:=GPL-3.0-or-later
|
||||||
|
@ -38,15 +38,11 @@ define Build/Compile
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/simple-adblock/install
|
define Package/simple-adblock/install
|
||||||
$(INSTALL_DIR) $(1)/etc/init.d
|
$(INSTALL_DIR) $(1)/etc/init.d $(1)/etc/config $(1)/tmp
|
||||||
$(INSTALL_BIN) ./files/simple-adblock.init $(1)/etc/init.d/simple-adblock
|
$(INSTALL_BIN) ./files/simple-adblock.init $(1)/etc/init.d/simple-adblock
|
||||||
$(SED) "s|^\(PKG_VERSION\).*|\1='$(PKG_VERSION)-$(PKG_RELEASE)'|" $(1)/etc/init.d/simple-adblock
|
$(SED) "s|^\(PKG_VERSION\).*|\1='$(PKG_VERSION)-$(PKG_RELEASE)'|" $(1)/etc/init.d/simple-adblock
|
||||||
$(INSTALL_DIR) $(1)/etc/config
|
|
||||||
$(INSTALL_CONF) ./files/simple-adblock.conf $(1)/etc/config/simple-adblock
|
$(INSTALL_CONF) ./files/simple-adblock.conf $(1)/etc/config/simple-adblock
|
||||||
$(INSTALL_DIR) $(1)/tmp
|
|
||||||
$(INSTALL_CONF) ./files/simple-adblock.conf.update $(1)/tmp/simple-adblock.conf.update
|
$(INSTALL_CONF) ./files/simple-adblock.conf.update $(1)/tmp/simple-adblock.conf.update
|
||||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
|
|
||||||
$(INSTALL_BIN) ./files/simple-adblock.hotplug $(1)/etc/hotplug.d/iface/80-simple-adblock
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/simple-adblock/postinst
|
define Package/simple-adblock/postinst
|
||||||
|
|
|
@ -6,6 +6,16 @@ config simple-adblock 'config'
|
||||||
option dns_instance '0'
|
option dns_instance '0'
|
||||||
option verbosity '2'
|
option verbosity '2'
|
||||||
option force_dns '1'
|
option force_dns '1'
|
||||||
|
list force_dns_port '53'
|
||||||
|
list force_dns_port '853'
|
||||||
|
# ports listed below are used by some
|
||||||
|
# of the dnscrypt-proxy v1 resolvers
|
||||||
|
# list force_dns_port '553'
|
||||||
|
# list force_dns_port '1443'
|
||||||
|
# list force_dns_port '4343'
|
||||||
|
# list force_dns_port '4434'
|
||||||
|
# list force_dns_port '5443'
|
||||||
|
# list force_dns_port '8443'
|
||||||
option led 'none'
|
option led 'none'
|
||||||
option boot_delay '120'
|
option boot_delay '120'
|
||||||
option download_timeout '10'
|
option download_timeout '10'
|
||||||
|
|
|
@ -41,7 +41,6 @@ readonly unboundGzip="/etc/${packageName}.unbound.gz"
|
||||||
readonly unboundOutputFilter='s|^|local-zone: "|;s|$|" static|'
|
readonly unboundOutputFilter='s|^|local-zone: "|;s|$|" static|'
|
||||||
readonly A_TMP="/var/${packageName}.hosts.a.tmp"
|
readonly A_TMP="/var/${packageName}.hosts.a.tmp"
|
||||||
readonly B_TMP="/var/${packageName}.hosts.b.tmp"
|
readonly B_TMP="/var/${packageName}.hosts.b.tmp"
|
||||||
readonly PIDFile="/var/run/${packageName}.pid"
|
|
||||||
readonly jsonFile="/var/run/${packageName}.json"
|
readonly jsonFile="/var/run/${packageName}.json"
|
||||||
readonly sharedMemoryError="/dev/shm/$packageName-error"
|
readonly sharedMemoryError="/dev/shm/$packageName-error"
|
||||||
readonly sharedMemoryOutput="/dev/shm/$packageName-output"
|
readonly sharedMemoryOutput="/dev/shm/$packageName-output"
|
||||||
|
@ -99,9 +98,6 @@ getErrorText() {
|
||||||
printf "%b" "$_ret"
|
printf "%b" "$_ret"
|
||||||
}
|
}
|
||||||
|
|
||||||
create_lock() { [ -e "$PIDFile" ] && return 1; touch "$PIDFile"; }
|
|
||||||
remove_lock() { [ -e "$PIDFile" ] && rm -f "$PIDFile"; }
|
|
||||||
trap remove_lock EXIT
|
|
||||||
output_ok() { output 1 "$_OK_"; output 2 "$__OK__\\n"; }
|
output_ok() { output 1 "$_OK_"; output 2 "$__OK__\\n"; }
|
||||||
output_okn() { output 1 "$_OK_\\n"; output 2 "$__OK__\\n"; }
|
output_okn() { output 1 "$_OK_\\n"; output 2 "$__OK__\\n"; }
|
||||||
output_fail() { output 1 "$_FAIL_"; output 2 "$__FAIL__\\n"; }
|
output_fail() { output 1 "$_FAIL_"; output 2 "$__FAIL__\\n"; }
|
||||||
|
@ -138,9 +134,10 @@ output() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceEnabled=''; forceDNS=''; parallelDL=''; debug=''; compressedCache='';
|
serviceEnabled=''; forceDNS=''; forceDNSPorts=''; parallelDL=''; debug='';
|
||||||
ipv6Enabled=''; configUpdateEnabled=''; configUpdateURL=''; bootDelay='';
|
compressedCache=''; ipv6Enabled=''; configUpdateEnabled=''; configUpdateURL='';
|
||||||
dlTimeout=''; curlRetry=''; verbosity=''; led=''; targetDNS=''; dnsInstance='';
|
bootDelay=''; dlTimeout=''; curlRetry=''; verbosity=''; led='';
|
||||||
|
targetDNS=''; dnsInstance='';
|
||||||
allowed_domains=''; allowed_domains_urls='';
|
allowed_domains=''; allowed_domains_urls='';
|
||||||
blocked_domains=''; blocked_domains_urls=''; blocked_hosts_urls='';
|
blocked_domains=''; blocked_domains_urls=''; blocked_hosts_urls='';
|
||||||
dl_command=''; dl_flag=''; isSSLSupported=''; allowIDN='';
|
dl_command=''; dl_flag=''; isSSLSupported=''; allowIDN='';
|
||||||
|
@ -156,11 +153,12 @@ load_package_config() {
|
||||||
config_get_bool compressedCache 'config' 'compressed_cache' 0
|
config_get_bool compressedCache 'config' 'compressed_cache' 0
|
||||||
config_get_bool ipv6Enabled 'config' 'ipv6_enabled' 0
|
config_get_bool ipv6Enabled 'config' 'ipv6_enabled' 0
|
||||||
config_get_bool configUpdateEnabled 'config' 'config_update_enabled' 0
|
config_get_bool configUpdateEnabled 'config' 'config_update_enabled' 0
|
||||||
|
config_get forceDNSPorts 'config' 'force_dns_port' '53 853'
|
||||||
config_get bootDelay 'config' 'boot_delay' '120'
|
config_get bootDelay 'config' 'boot_delay' '120'
|
||||||
config_get dlTimeout 'config' 'download_timeout' '20'
|
config_get dlTimeout 'config' 'download_timeout' '20'
|
||||||
config_get curlRetry 'config' 'curl_retry' '3'
|
config_get curlRetry 'config' 'curl_retry' '3'
|
||||||
config_get verbosity 'config' 'verbosity' '2'
|
config_get verbosity 'config' 'verbosity' '2'
|
||||||
config_get led 'config' 'led'
|
config_get led 'config' 'led'
|
||||||
config_get targetDNS 'config' 'dns' 'dnsmasq.servers'
|
config_get targetDNS 'config' 'dns' 'dnsmasq.servers'
|
||||||
config_get dnsInstance 'config' 'dns_instance' '0'
|
config_get dnsInstance 'config' 'dns_instance' '0'
|
||||||
config_get allowed_domains 'config' 'allowed_domain'
|
config_get allowed_domains 'config' 'allowed_domain'
|
||||||
|
@ -354,8 +352,8 @@ dnsOps() {
|
||||||
case $1 in
|
case $1 in
|
||||||
on_start)
|
on_start)
|
||||||
if [ ! -s "$outputFile" ]; then
|
if [ ! -s "$outputFile" ]; then
|
||||||
tmpfs set status "statusFail"
|
jsonOps set status "statusFail"
|
||||||
tmpfs add error "errorOutputFileCreate"
|
jsonOps add error "errorOutputFileCreate"
|
||||||
output "$_ERROR_: $(getErrorText 'errorOutputFileCreate')!\\n"
|
output "$_ERROR_: $(getErrorText 'errorOutputFileCreate')!\\n"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -396,15 +394,15 @@ dnsOps() {
|
||||||
fi
|
fi
|
||||||
output 1 "$output_text "
|
output 1 "$output_text "
|
||||||
output 2 "$output_text "
|
output 2 "$output_text "
|
||||||
tmpfs set message "$output_text"
|
jsonOps set message "$output_text"
|
||||||
if eval "$param"; then
|
if eval "$param"; then
|
||||||
tmpfs set status "statusSuccess"
|
jsonOps set status "statusSuccess"
|
||||||
led_on "$led"
|
led_on "$led"
|
||||||
output_okn
|
output_okn
|
||||||
else
|
else
|
||||||
output_fail
|
output_fail
|
||||||
tmpfs set status "statusFail"
|
jsonOps set status "statusFail"
|
||||||
tmpfs add error "errorDNSReload"
|
jsonOps add error "errorDNSReload"
|
||||||
output "$_ERROR_: $(getErrorText 'errorDNSReload')!\\n"
|
output "$_ERROR_: $(getErrorText 'errorDNSReload')!\\n"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -447,7 +445,7 @@ dnsOps() {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpfs() {
|
jsonOps() {
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
local action="$1" param="$2" value="$3"
|
local action="$1" param="$2" value="$3"
|
||||||
local status message error stats
|
local status message error stats
|
||||||
|
@ -463,8 +461,8 @@ tmpfs() {
|
||||||
get)
|
get)
|
||||||
case "$param" in
|
case "$param" in
|
||||||
triggers)
|
triggers)
|
||||||
curReload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS"
|
curReload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS $configUpdateEnabled $configUpdateURL"
|
||||||
curRestart="$compressedCache $forceDNS $led"
|
curRestart="$compressedCache $forceDNS $led $forceDNSPorts"
|
||||||
if [ ! -s "$jsonFile" ]; then
|
if [ ! -s "$jsonFile" ]; then
|
||||||
ret='on_boot'
|
ret='on_boot'
|
||||||
elif [ "$curReload" != "$reload" ]; then
|
elif [ "$curReload" != "$reload" ]; then
|
||||||
|
@ -479,7 +477,11 @@ tmpfs() {
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
add)
|
add)
|
||||||
eval "$param"='$(eval echo "\$$param")${value} ';;
|
if [ -n "$(eval echo "\$$param")" ]; then
|
||||||
|
value="$(eval echo "\$$param") ${value}"
|
||||||
|
fi
|
||||||
|
eval "$param"='${value}'
|
||||||
|
;;
|
||||||
del)
|
del)
|
||||||
case "$param" in
|
case "$param" in
|
||||||
all)
|
all)
|
||||||
|
@ -493,8 +495,8 @@ tmpfs() {
|
||||||
set)
|
set)
|
||||||
case "$param" in
|
case "$param" in
|
||||||
triggers)
|
triggers)
|
||||||
reload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS"
|
reload="$parallelDL $debug $dlTimeout $allowed_domains $blocked_domains $allowed_domains_urls $blocked_domains_urls $blocked_hosts_urls $targetDNS $configUpdateEnabled $configUpdateURL"
|
||||||
restart="$compressedCache $forceDNS $led"
|
restart="$compressedCache $forceDNS $led $forceDNSPorts"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
eval "$param"='$value';;
|
eval "$param"='$value';;
|
||||||
|
@ -608,15 +610,15 @@ process_config_update() {
|
||||||
if ! $dl_command "$1" $dl_flag "$R_TMP" 2>/dev/null || [ ! -s "$R_TMP" ]; then
|
if ! $dl_command "$1" $dl_flag "$R_TMP" 2>/dev/null || [ ! -s "$R_TMP" ]; then
|
||||||
output 1 "$_FAIL_"
|
output 1 "$_FAIL_"
|
||||||
output 2 "[DL] Config Update: $label $__FAIL__\\n"
|
output 2 "[DL] Config Update: $label $__FAIL__\\n"
|
||||||
tmpfs add error "errorDownloadingConfigUpdate"
|
jsonOps add error "errorDownloadingConfigUpdate"
|
||||||
else
|
else
|
||||||
if [ -s "$R_TMP" ] && sed -f "$R_TMP" -i /etc/config/simple-adblock; then
|
if [ -s "$R_TMP" ] && sed -f "$R_TMP" -i /etc/config/simple-adblock 2>/dev/null; then
|
||||||
output 1 "$_OK_"
|
output 1 "$_OK_"
|
||||||
output 2 "[DL] Config Update: $label $__OK__\\n"
|
output 2 "[DL] Config Update: $label $__OK__\\n"
|
||||||
else
|
else
|
||||||
output 1 "$_FAIL_"
|
output 1 "$_FAIL_"
|
||||||
output 2 "[DL] Config Update: $label $__FAIL__\\n"
|
output 2 "[DL] Config Update: $label $__FAIL__\\n"
|
||||||
tmpfs add error "errorParsingConfigUpdate"
|
jsonOps add error "errorParsingConfigUpdate"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
rm -f "$R_TMP"
|
rm -f "$R_TMP"
|
||||||
|
@ -626,8 +628,8 @@ process_config_update() {
|
||||||
download_lists() {
|
download_lists() {
|
||||||
local hf w_filter j=0 R_TMP
|
local hf w_filter j=0 R_TMP
|
||||||
|
|
||||||
tmpfs set message "$(getStatusText "statusDownloading")..."
|
jsonOps set message "$(getStatusText "statusDownloading")..."
|
||||||
tmpfs set status "statusDownloading"
|
jsonOps set status "statusDownloading"
|
||||||
|
|
||||||
rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip"
|
rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip"
|
||||||
if [ "$($awk '/^MemFree/ {print int($2/1000)}' "/proc/meminfo")" -lt 32 ]; then
|
if [ "$($awk '/^MemFree/ {print int($2/1000)}' "/proc/meminfo")" -lt 32 ]; then
|
||||||
|
@ -673,7 +675,7 @@ download_lists() {
|
||||||
output 1 '\n'
|
output 1 '\n'
|
||||||
if [ -s "$sharedMemoryError" ]; then
|
if [ -s "$sharedMemoryError" ]; then
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
tmpfs add error "$line"
|
jsonOps add error "$line"
|
||||||
done < "$sharedMemoryError"
|
done < "$sharedMemoryError"
|
||||||
rm -f "$sharedMemoryError"
|
rm -f "$sharedMemoryError"
|
||||||
fi
|
fi
|
||||||
|
@ -687,20 +689,20 @@ $(cat $A_TMP)"
|
||||||
|
|
||||||
output 1 'Processing downloads '
|
output 1 'Processing downloads '
|
||||||
output 2 'Sorting combined list '
|
output 2 'Sorting combined list '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): sorting combined list"
|
jsonOps set message "$(getStatusText "statusProcessing"): sorting combined list"
|
||||||
if [ "$allowIDN" -gt 0 ]; then
|
if [ "$allowIDN" -gt 0 ]; then
|
||||||
if sort -u "$B_TMP" > "$A_TMP"; then
|
if sort -u "$B_TMP" > "$A_TMP"; then
|
||||||
output_ok
|
output_ok
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorSorting"
|
jsonOps add error "errorSorting"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if sort -u "$B_TMP" | grep -E -v '[^a-zA-Z0-9=/.-]' > "$A_TMP"; then
|
if sort -u "$B_TMP" | grep -E -v '[^a-zA-Z0-9=/.-]' > "$A_TMP"; then
|
||||||
output_ok
|
output_ok
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorSorting"
|
jsonOps add error "errorSorting"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -710,7 +712,7 @@ $(cat $A_TMP)"
|
||||||
[ "$targetDNS" = 'unbound.adb_list' ]; then
|
[ "$targetDNS" = 'unbound.adb_list' ]; then
|
||||||
# TLD optimization written by Dirk Brenken (dev@brenken.org)
|
# TLD optimization written by Dirk Brenken (dev@brenken.org)
|
||||||
output 2 'Optimizing combined list '
|
output 2 'Optimizing combined list '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): optimizing combined list"
|
jsonOps set message "$(getStatusText "statusProcessing"): optimizing combined list"
|
||||||
# sed -E 'G;:t;s/(.*)(\.)(.*)(\n)(.*)/\1\4\5\2\3/;tt;s/(.*)\n(\.)(.*)/\3\2\1/' is actually slower than command below
|
# sed -E 'G;:t;s/(.*)(\.)(.*)(\n)(.*)/\1\4\5\2\3/;tt;s/(.*)\n(\.)(.*)/\3\2\1/' is actually slower than command below
|
||||||
if $awk -F "." '{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "$A_TMP" > "$B_TMP"; then
|
if $awk -F "." '{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "$A_TMP" > "$B_TMP"; then
|
||||||
if sort "$B_TMP" > "$A_TMP"; then
|
if sort "$B_TMP" > "$A_TMP"; then
|
||||||
|
@ -720,25 +722,25 @@ $(cat $A_TMP)"
|
||||||
output_ok
|
output_ok
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorOptimization"
|
jsonOps add error "errorOptimization"
|
||||||
mv "$A_TMP" "$B_TMP"
|
mv "$A_TMP" "$B_TMP"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorOptimization"
|
jsonOps add error "errorOptimization"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorOptimization"
|
jsonOps add error "errorOptimization"
|
||||||
mv "$A_TMP" "$B_TMP"
|
mv "$A_TMP" "$B_TMP"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorOptimization"
|
jsonOps add error "errorOptimization"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorOptimization"
|
jsonOps add error "errorOptimization"
|
||||||
mv "$A_TMP" "$B_TMP"
|
mv "$A_TMP" "$B_TMP"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
@ -746,22 +748,22 @@ $(cat $A_TMP)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
output 2 'Allowing domains '
|
output 2 'Allowing domains '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): allowing domains"
|
jsonOps set message "$(getStatusText "statusProcessing"): allowing domains"
|
||||||
if sed -i "$w_filter" "$B_TMP"; then
|
if sed -i "$w_filter" "$B_TMP"; then
|
||||||
output_ok
|
output_ok
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorAllowListProcessing"
|
jsonOps add error "errorAllowListProcessing"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
output 2 'Formatting merged file '
|
output 2 'Formatting merged file '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): formatting merged file"
|
jsonOps set message "$(getStatusText "statusProcessing"): formatting merged file"
|
||||||
if [ -z "$outputFilterIPv6" ]; then
|
if [ -z "$outputFilterIPv6" ]; then
|
||||||
if sed "$outputFilter" "$B_TMP" > "$A_TMP"; then
|
if sed "$outputFilter" "$B_TMP" > "$A_TMP"; then
|
||||||
output_ok
|
output_ok
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorDataFileFormatting"
|
jsonOps add error "errorDataFileFormatting"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
case "$targetDNS" in
|
case "$targetDNS" in
|
||||||
|
@ -771,7 +773,7 @@ $(cat $A_TMP)"
|
||||||
output_ok
|
output_ok
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorDataFileFormatting"
|
jsonOps add error "errorDataFileFormatting"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -780,77 +782,70 @@ $(cat $A_TMP)"
|
||||||
case "$targetDNS" in
|
case "$targetDNS" in
|
||||||
dnsmasq.addnhosts)
|
dnsmasq.addnhosts)
|
||||||
output 2 'Creating DNSMASQ addnhosts file '
|
output 2 'Creating DNSMASQ addnhosts file '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ addnhosts file"
|
jsonOps set message "$(getStatusText "statusProcessing"): creating DNSMASQ addnhosts file"
|
||||||
;;
|
;;
|
||||||
dnsmasq.conf)
|
dnsmasq.conf)
|
||||||
output 2 'Creating DNSMASQ config file '
|
output 2 'Creating DNSMASQ config file '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ config file"
|
jsonOps set message "$(getStatusText "statusProcessing"): creating DNSMASQ config file"
|
||||||
;;
|
;;
|
||||||
dnsmasq.ipset)
|
dnsmasq.ipset)
|
||||||
output 2 'Creating DNSMASQ ipset file '
|
output 2 'Creating DNSMASQ ipset file '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ ipset file"
|
jsonOps set message "$(getStatusText "statusProcessing"): creating DNSMASQ ipset file"
|
||||||
;;
|
;;
|
||||||
dnsmasq.servers)
|
dnsmasq.servers)
|
||||||
output 2 'Creating DNSMASQ servers file '
|
output 2 'Creating DNSMASQ servers file '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): creating DNSMASQ servers file"
|
jsonOps set message "$(getStatusText "statusProcessing"): creating DNSMASQ servers file"
|
||||||
;;
|
;;
|
||||||
unbound.adb_list)
|
unbound.adb_list)
|
||||||
output 2 'Creating Unbound adb_list file '
|
output 2 'Creating Unbound adb_list file '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): creating Unbound adb_list file"
|
jsonOps set message "$(getStatusText "statusProcessing"): creating Unbound adb_list file"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
if mv "$A_TMP" "$outputFile"; then
|
if mv "$A_TMP" "$outputFile"; then
|
||||||
output_ok
|
output_ok
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorMovingDataFile"
|
jsonOps add error "errorMovingDataFile"
|
||||||
fi
|
fi
|
||||||
if [ "$compressedCache" -gt 0 ]; then
|
if [ "$compressedCache" -gt 0 ]; then
|
||||||
output 2 'Creating compressed cache '
|
output 2 'Creating compressed cache '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): creating compressed cache"
|
jsonOps set message "$(getStatusText "statusProcessing"): creating compressed cache"
|
||||||
if cacheOps 'createGzip'; then
|
if cacheOps 'createGzip'; then
|
||||||
output_ok
|
output_ok
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorCreatingCompressedCache"
|
jsonOps add error "errorCreatingCompressedCache"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
rm -f "$outputGzip"
|
rm -f "$outputGzip"
|
||||||
fi
|
fi
|
||||||
output 2 'Removing temporary files '
|
output 2 'Removing temporary files '
|
||||||
tmpfs set message "$(getStatusText "statusProcessing"): removing temporary files"
|
jsonOps set message "$(getStatusText "statusProcessing"): removing temporary files"
|
||||||
rm -f "/tmp/${packageName}_tmp.*" "$A_TMP" "$B_TMP" "$outputCache" || j=1
|
rm -f "/tmp/${packageName}_tmp.*" "$A_TMP" "$B_TMP" "$outputCache" || j=1
|
||||||
if [ $j -eq 0 ]; then
|
if [ $j -eq 0 ]; then
|
||||||
output_ok
|
output_ok
|
||||||
else
|
else
|
||||||
output_failn
|
output_failn
|
||||||
tmpfs add error "errorRemovingTempFiles"
|
jsonOps add error "errorRemovingTempFiles"
|
||||||
fi
|
fi
|
||||||
output 1 '\n'
|
output 1 '\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
boot() {
|
boot() {
|
||||||
load_package_config
|
load_package_config
|
||||||
if create_lock; then
|
sleep "$bootDelay"
|
||||||
sleep "$bootDelay"
|
rc_procd start_service 'on_boot' && rc_procd service_triggers
|
||||||
remove_lock
|
|
||||||
rc_procd start_service 'on_boot' && rc_procd service_triggers
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
is_enabled 'on_start' || return 1
|
is_enabled 'on_start' || return 1
|
||||||
local action status error message stats c
|
local action status error message stats c
|
||||||
if ! create_lock; then
|
|
||||||
output 3 "$serviceName: another instance is starting up "; output_fail
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
status="$(tmpfs get status)"
|
status="$(jsonOps get status)"
|
||||||
error="$(tmpfs get error)"
|
error="$(jsonOps get error)"
|
||||||
message="$(tmpfs get message)"
|
message="$(jsonOps get message)"
|
||||||
stats="$(tmpfs get stats)"
|
stats="$(jsonOps get stats)"
|
||||||
action="$(tmpfs get triggers)"
|
action="$(jsonOps get triggers)"
|
||||||
|
|
||||||
if [ "$action" = 'on_boot' ] || [ "$1" = 'on_boot' ]; then
|
if [ "$action" = 'on_boot' ] || [ "$1" = 'on_boot' ]; then
|
||||||
if cacheOps 'testGzip' || cacheOps 'test'; then
|
if cacheOps 'testGzip' || cacheOps 'test'; then
|
||||||
|
@ -869,14 +864,14 @@ start_service() {
|
||||||
elif [ "$action" = 'restart' ] || [ "$1" = 'restart' ]; then
|
elif [ "$action" = 'restart' ] || [ "$1" = 'restart' ]; then
|
||||||
action='restart'
|
action='restart'
|
||||||
elif [ -s "$outputFile" ] && [ "$status" = "statusSuccess" ] && [ -z "$error" ]; then
|
elif [ -s "$outputFile" ] && [ "$status" = "statusSuccess" ] && [ -z "$error" ]; then
|
||||||
[ "$1" != 'hotplug' ] && showstatus
|
showstatus
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
action='download'
|
action='download'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tmpfs del all
|
jsonOps del all
|
||||||
tmpfs set triggers
|
jsonOps set triggers
|
||||||
|
|
||||||
procd_open_instance 'main'
|
procd_open_instance 'main'
|
||||||
procd_set_param command /bin/true
|
procd_set_param command /bin/true
|
||||||
|
@ -885,34 +880,43 @@ start_service() {
|
||||||
procd_open_data
|
procd_open_data
|
||||||
json_add_array firewall
|
json_add_array firewall
|
||||||
if [ "$forceDNS" -ne 0 ]; then
|
if [ "$forceDNS" -ne 0 ]; then
|
||||||
json_add_object ''
|
for c in $forceDNSPorts; do
|
||||||
json_add_string type redirect
|
if netstat -tuln | grep LISTEN | grep ":${c}" >/dev/null 2>&1; then
|
||||||
json_add_string name simple_adblock_dns_redirect
|
json_add_object ''
|
||||||
json_add_string target DNAT
|
json_add_string type 'redirect'
|
||||||
json_add_string src lan
|
json_add_string target 'DNAT'
|
||||||
json_add_string proto tcpudp
|
json_add_string src 'lan'
|
||||||
json_add_string src_dport 53
|
json_add_string proto 'tcp udp'
|
||||||
json_add_string dest_port 53
|
json_add_string src_dport "$c"
|
||||||
json_add_string reflection 0
|
json_add_string dest_port "$c"
|
||||||
json_close_object
|
json_add_string reflection '0'
|
||||||
|
json_close_object
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
if [ "$targetDNS" = 'dnsmasq.ipset' ]; then
|
if [ "$targetDNS" = 'dnsmasq.ipset' ]; then
|
||||||
json_add_object ''
|
json_add_object ''
|
||||||
json_add_string type ipset
|
json_add_string type 'ipset'
|
||||||
json_add_string name adb
|
json_add_string name 'adb'
|
||||||
json_add_string match dest_net
|
json_add_string match 'dest_net'
|
||||||
json_add_string storage hash
|
json_add_string storage 'hash'
|
||||||
json_add_string enabled 1
|
|
||||||
json_close_object
|
json_close_object
|
||||||
json_add_object ''
|
json_add_object ''
|
||||||
json_add_string type rule
|
json_add_string type 'rule'
|
||||||
json_add_string name simple_adblock_ipset_rule
|
json_add_string ipset 'adb'
|
||||||
json_add_string ipset adb
|
json_add_string src 'lan'
|
||||||
json_add_string src lan
|
|
||||||
json_add_string dest '*'
|
json_add_string dest '*'
|
||||||
json_add_string proto tcpudp
|
json_add_string proto 'tcp udp'
|
||||||
json_add_string target REJECT
|
json_add_string target 'REJECT'
|
||||||
json_add_string enabled 1
|
|
||||||
json_close_object
|
json_close_object
|
||||||
fi
|
fi
|
||||||
json_close_array
|
json_close_array
|
||||||
|
@ -922,74 +926,70 @@ start_service() {
|
||||||
if [ "$action" = 'restore' ]; then
|
if [ "$action" = 'restore' ]; then
|
||||||
output 0 "Starting $serviceName... "
|
output 0 "Starting $serviceName... "
|
||||||
output 3 "Starting $serviceName...\\n"
|
output 3 "Starting $serviceName...\\n"
|
||||||
tmpfs set status "statusStarting"
|
jsonOps set status "statusStarting"
|
||||||
if cacheOps 'testGzip' && ! cacheOps 'test' && [ ! -s "$outputFile" ]; then
|
if cacheOps 'testGzip' && ! cacheOps 'test' && [ ! -s "$outputFile" ]; then
|
||||||
output 3 'Found compressed cache file, unpacking it '
|
output 3 'Found compressed cache file, unpacking it '
|
||||||
tmpfs set message 'found compressed cache file, unpacking it.'
|
jsonOps set message 'found compressed cache file, unpacking it.'
|
||||||
if cacheOps 'unpackGzip'; then
|
if cacheOps 'unpackGzip'; then
|
||||||
output_okn
|
output_okn
|
||||||
else
|
else
|
||||||
output_fail
|
output_fail
|
||||||
tmpfs add error "errorRestoreCompressedCache"
|
jsonOps add error "errorRestoreCompressedCache"
|
||||||
output "$_ERROR_: $(getErrorText 'errorRestoreCompressedCache')!\\n"
|
output "$_ERROR_: $(getErrorText 'errorRestoreCompressedCache')!\\n"
|
||||||
action='download'
|
action='download'
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if cacheOps 'test' && [ ! -s "$outputFile" ]; then
|
if cacheOps 'test' && [ ! -s "$outputFile" ]; then
|
||||||
output 3 'Found cache file, reusing it '
|
output 3 'Found cache file, reusing it '
|
||||||
tmpfs set message 'found cache file, reusing it.'
|
jsonOps set message 'found cache file, reusing it.'
|
||||||
if cacheOps 'restore'; then
|
if cacheOps 'restore'; then
|
||||||
output_okn
|
output_okn
|
||||||
dnsOps 'on_start'
|
dnsOps 'on_start'
|
||||||
else
|
else
|
||||||
output_fail
|
output_fail
|
||||||
tmpfs add error "errorRestoreCache"
|
jsonOps add error "errorRestoreCache"
|
||||||
output "$_ERROR_: $(getErrorText 'errorRestoreCache')!\\n"
|
output "$_ERROR_: $(getErrorText 'errorRestoreCache')!\\n"
|
||||||
action='download'
|
action='download'
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
case "$action" in
|
if [ "$action" = 'download' ]; then
|
||||||
download)
|
if [ -s "$outputFile" ] || cacheOps 'test' || cacheOps 'testGzip'; then
|
||||||
if [ -s "$outputFile" ] || cacheOps 'test' || cacheOps 'testGzip'; then
|
output 0 "Force-reloading $serviceName... "
|
||||||
output 0 "Force-reloading $serviceName... "
|
output 3 "Force-reloading $serviceName...\\n"
|
||||||
output 3 "Force-reloading $serviceName...\\n"
|
jsonOps set status "statusForceReloading"
|
||||||
tmpfs set status "statusForceReloading"
|
else
|
||||||
else
|
|
||||||
output 0 "Starting $serviceName... "
|
|
||||||
output 3 "Starting $serviceName...\\n"
|
|
||||||
tmpfs set status "statusStarting"
|
|
||||||
fi
|
|
||||||
download_lists
|
|
||||||
dnsOps 'on_start'
|
|
||||||
;;
|
|
||||||
restart)
|
|
||||||
output 0 "Restarting $serviceName... "
|
|
||||||
output 3 "Restarting $serviceName...\\n"
|
|
||||||
tmpfs set status "statusRestarting"
|
|
||||||
dnsOps 'on_start'
|
|
||||||
;;
|
|
||||||
start)
|
|
||||||
output 0 "Starting $serviceName... "
|
output 0 "Starting $serviceName... "
|
||||||
output 3 "Starting $serviceName...\\n"
|
output 3 "Starting $serviceName...\\n"
|
||||||
tmpfs set status "statusStarting"
|
jsonOps set status "statusStarting"
|
||||||
dnsOps 'on_start'
|
fi
|
||||||
;;
|
download_lists
|
||||||
esac
|
dnsOps 'on_start'
|
||||||
if [ -s "$outputFile" ] && [ "$(tmpfs get status)" != "statusFail" ]; then
|
fi
|
||||||
|
if [ "$action" = 'restart' ]; then
|
||||||
|
output 0 "Restarting $serviceName... "
|
||||||
|
output 3 "Restarting $serviceName...\\n"
|
||||||
|
jsonOps set status "statusRestarting"
|
||||||
|
dnsOps 'on_start'
|
||||||
|
fi
|
||||||
|
if [ "$action" = 'start' ]; then
|
||||||
|
output 0 "Starting $serviceName... "
|
||||||
|
output 3 "Starting $serviceName...\\n"
|
||||||
|
jsonOps set status "statusStarting"
|
||||||
|
dnsOps 'on_start'
|
||||||
|
fi
|
||||||
|
if [ -s "$outputFile" ] && [ "$(jsonOps get status)" != "statusFail" ]; then
|
||||||
output 0 "$__OK__\\n";
|
output 0 "$__OK__\\n";
|
||||||
tmpfs del message
|
jsonOps del message
|
||||||
tmpfs set status "statusSuccess"
|
jsonOps set status "statusSuccess"
|
||||||
c="$(wc -l < "$outputFile")"
|
jsonOps set stats "$serviceName is blocking $(wc -l < "$outputFile") domains (with ${targetDNS})"
|
||||||
tmpfs set stats "$serviceName is blocking $c domains (with ${targetDNS})"
|
|
||||||
showstatus
|
showstatus
|
||||||
else
|
else
|
||||||
output 0 "$__FAIL__\\n";
|
output 0 "$__FAIL__\\n";
|
||||||
tmpfs set status "statusFail"
|
jsonOps set status "statusFail"
|
||||||
tmpfs add error "errorOhSnap"
|
jsonOps add error "errorOhSnap"
|
||||||
showstatus
|
showstatus
|
||||||
fi
|
fi
|
||||||
remove_lock
|
|
||||||
}
|
}
|
||||||
|
|
||||||
service_started() { procd_set_config_changed firewall; }
|
service_started() { procd_set_config_changed firewall; }
|
||||||
|
@ -1015,10 +1015,10 @@ show() { showstatus; }
|
||||||
status_service() { showstatus; }
|
status_service() { showstatus; }
|
||||||
showstatus() {
|
showstatus() {
|
||||||
local c url status message error stats
|
local c url status message error stats
|
||||||
status="$(tmpfs get status)"
|
status="$(jsonOps get status)"
|
||||||
message="$(tmpfs get message)"
|
message="$(jsonOps get message)"
|
||||||
error="$(tmpfs get error)"
|
error="$(jsonOps get error)"
|
||||||
stats="$(tmpfs get stats)"
|
stats="$(jsonOps get stats)"
|
||||||
if [ "$status" = "statusSuccess" ]; then
|
if [ "$status" = "statusSuccess" ]; then
|
||||||
output "$stats "; output_okn;
|
output "$stats "; output_okn;
|
||||||
else
|
else
|
||||||
|
@ -1051,12 +1051,12 @@ stop_service() {
|
||||||
if dnsOps 'on_stop'; then
|
if dnsOps 'on_stop'; then
|
||||||
led_off "$led"
|
led_off "$led"
|
||||||
output 0 "$__OK__\\n"; output_okn;
|
output 0 "$__OK__\\n"; output_okn;
|
||||||
tmpfs set status "statusStopped"
|
jsonOps set status "statusStopped"
|
||||||
tmpfs del message
|
jsonOps del message
|
||||||
else
|
else
|
||||||
output 0 "$__FAIL__\\n"; output_fail;
|
output 0 "$__FAIL__\\n"; output_fail;
|
||||||
tmpfs set status "statusFail"
|
jsonOps set status "statusFail"
|
||||||
tmpfs add error "errorStopping"
|
jsonOps add error "errorStopping"
|
||||||
output "$_ERROR_: $(getErrorText 'errorStopping')!\\n"
|
output "$_ERROR_: $(getErrorText 'errorStopping')!\\n"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -1064,7 +1064,9 @@ stop_service() {
|
||||||
|
|
||||||
service_triggers() {
|
service_triggers() {
|
||||||
procd_open_trigger
|
procd_open_trigger
|
||||||
procd_add_config_trigger "config.change" "${packageName}" /etc/init.d/${packageName} reload
|
procd_add_config_trigger 'config.change' "${packageName}" /etc/init.d/${packageName} reload
|
||||||
|
procd_add_reload_interface_trigger 'wan'
|
||||||
|
procd_add_interface_trigger 'interface.*.up' 'wan' /etc/init.d/${packageName} reload
|
||||||
procd_close_trigger
|
procd_close_trigger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue