From 73b689f96ee4c93b97565630d69abfb1ad227419 Mon Sep 17 00:00:00 2001 From: Stan Grishin Date: Mon, 11 Dec 2023 00:54:17 +0000 Subject: [PATCH] adblock-fast: better allow-listing * improve allow-listing reliability by running sed from the script-file instead of the command-line * fix user for smartdns files ownership Signed-off-by: Stan Grishin (cherry picked from commit 693287e9610b379111b1c2a5a7589a576a8ce663) --- net/adblock-fast/Makefile | 2 +- .../files/etc/init.d/adblock-fast | 32 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/net/adblock-fast/Makefile b/net/adblock-fast/Makefile index 3be6d3c34c..4b22bfe2cb 100644 --- a/net/adblock-fast/Makefile +++ b/net/adblock-fast/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=adblock-fast PKG_VERSION:=1.1.0 -PKG_RELEASE:=5 +PKG_RELEASE:=7 PKG_MAINTAINER:=Stan Grishin PKG_LICENSE:=GPL-3.0-or-later diff --git a/net/adblock-fast/files/etc/init.d/adblock-fast b/net/adblock-fast/files/etc/init.d/adblock-fast index 12c32c5b0e..da9087767b 100755 --- a/net/adblock-fast/files/etc/init.d/adblock-fast +++ b/net/adblock-fast/files/etc/init.d/adblock-fast @@ -53,8 +53,9 @@ 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 A_TMP="/var/${packageName}.hosts.a.tmp" -readonly B_TMP="/var/${packageName}.hosts.b.tmp" +readonly A_TMP="/var/${packageName}.a.tmp" +readonly B_TMP="/var/${packageName}.b.tmp" +readonly SED_TMP="/var/${packageName}.sed.tmp" readonly jsonFile="/dev/shm/$packageName-status.json" readonly sharedMemoryError="/dev/shm/$packageName-error" 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;' @@ -875,7 +876,7 @@ resolver() { ;; smartdns.*) chmod 660 "$outputFile" "$outputConfig" - chown root:smartdns "$outputFile" "$outputConfig" + chown root:root "$outputFile" "$outputConfig" param='smartdns_restart' output_text='Restarting SmartDNS' ;; @@ -1084,12 +1085,10 @@ process_file_url() { } download_dnsmasq_file() { - local hf allow_filter j=0 R_TMP - json set message "$(get_text 'statusDownloading')..." json set status 'statusDownloading' - rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip" + rm -f "$A_TMP" "$B_TMP" "$SED_TMP" "$outputFile" "$outputCache" "$outputGzip" if [ "$(get_ram_free)" -lt 32 ]; then output 3 'Low free memory, restarting resolver ' if resolver 'quiet_restart'; then @@ -1098,7 +1097,7 @@ download_dnsmasq_file() { output_failn fi fi - touch $A_TMP; touch $B_TMP; + touch "$A_TMP" "$B_TMP" "$SED_TMP" output 1 'Downloading dnsmasq file ' rm -f "$sharedMemoryError" process_file_url '' "$dnsmasq_config_file_url" 'file' @@ -1147,14 +1146,14 @@ download_lists() { return 0 fi } - local hf allow_filter j=0 R_TMP + local hf j=0 R_TMP _ram_check || return 1 json set message "$(get_text 'statusDownloading')..." json set status 'statusDownloading' - rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip" + rm -f "$A_TMP" "$B_TMP" "$SED_TMP" "$outputFile" "$outputCache" "$outputGzip" if [ "$(get_ram_total)" -lt 33554432 ]; then output 3 'Low free memory, restarting resolver ' if resolver 'quiet_restart'; then @@ -1163,7 +1162,7 @@ download_lists() { output_failn fi fi - touch $A_TMP; touch $B_TMP; + touch "$A_TMP" "$B_TMP" "$SED_TMP" output 1 'Downloading lists ' rm -f "$sharedMemoryError" config_load "$packageName" @@ -1194,8 +1193,11 @@ download_lists() { printf "%s\n" "$(echo "$hf" | sed "$domainsFilter")" >> "$B_TMP" done allowed_domain="${allowed_domain} -$(cat $A_TMP)" - for hf in ${allowed_domain}; do hf="$(echo "$hf" | sed 's/\./\\./g')"; allow_filter="$allow_filter/(^|\.)${hf}$/d;"; done +$(sed '/^[[:space:]]*$/d' "$A_TMP")" + for hf in ${allowed_domain}; do + hf="$(echo "$hf" | sed 's/\./\\./g')" + echo "/(^|\.)${hf}$/d;" >> "$SED_TMP" + done sed -i '/^[[:space:]]*$/d' "$B_TMP" [ ! -s "$B_TMP" ] && return 1 @@ -1266,10 +1268,10 @@ $(cat $A_TMP)" mv "$A_TMP" "$B_TMP" fi - if [ -n "$allow_filter" ]; then + if [ -s "$SED_TMP" ]; then output 2 'Allowing domains ' json set message "$(get_text 'statusProcessing'): allowing domains" - if sed -i -E "$allow_filter" "$B_TMP"; then + if sed -i -E -f "$SED_TMP" "$B_TMP"; then output_ok else output_failn @@ -1358,7 +1360,7 @@ $(cat $A_TMP)" fi output 2 'Removing temporary files ' json set message "$(get_text '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" "$SED_TMP" "$outputCache" || j=1 if [ $j -eq 0 ]; then output_ok else -- 2.30.2