summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Grishin <stangri@melmac.ca>2023-09-26 22:46:55 +0000
committerStan Grishin <stangri@melmac.ca>2023-09-26 22:48:37 +0000
commitcfe85fbde3cdce2ab05e9cd888ebb3713c42299f (patch)
treee16400beb770c75116a7e636d3c92c6a6eadecb9
parentf9403708f38b37faf8c09cef50908d908e695c45 (diff)
adblock-fast: bugfix: better detect ABP lists
* bugfix: better detect ABP lists * update Makefile with BUSYBOX features dependencies * update the type of dnsmasq_instance setting * add error message when file type can't be detected * add reporting when file type can't be detected * bugfix: include URL on errors related to URL processing/parsing * rename resolver function to resolver_config to better reflect its use Signed-off-by: Stan Grishin <stangri@melmac.ca>
-rw-r--r--net/adblock-fast/Makefile6
-rw-r--r--net/adblock-fast/files/etc/config/adblock-fast2
-rwxr-xr-xnet/adblock-fast/files/etc/init.d/adblock-fast67
3 files changed, 51 insertions, 24 deletions
diff --git a/net/adblock-fast/Makefile b/net/adblock-fast/Makefile
index 317a3d1aa..72a3324ac 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.0.0
-PKG_RELEASE:=2
+PKG_RELEASE:=3
PKG_MAINTAINER:=Stan Grishin <stangri@melmac.ca>
PKG_LICENSE:=GPL-3.0-or-later
@@ -18,6 +18,10 @@ define Package/adblock-fast
TITLE:=AdBlock Fast Service
URL:=https://docs.openwrt.melmac.net/adblock-fast/
DEPENDS:=+jshn +curl
+ DEPENDS+=+!BUSYBOX_DEFAULT_AWK:gawk
+ DEPENDS+=+!BUSYBOX_DEFAULT_GREP:grep
+ DEPENDS+=+!BUSYBOX_DEFAULT_SED:sed
+ DEPENDS+=+!BUSYBOX_DEFAULT_SORT:coreutils-sort
CONFLICTS:=simple-adblock
PROVIDES:=simple-adblock
PKGARCH:=all
diff --git a/net/adblock-fast/files/etc/config/adblock-fast b/net/adblock-fast/files/etc/config/adblock-fast
index 10cdf5186..f459411f0 100644
--- a/net/adblock-fast/files/etc/config/adblock-fast
+++ b/net/adblock-fast/files/etc/config/adblock-fast
@@ -13,7 +13,7 @@ config adblock-fast 'config'
option curl_retry '3'
option debug '0'
option dns 'dnsmasq.servers'
- option dnsmasq_instance '*'
+ list dnsmasq_instance '*'
# option dnsmasq_config_file_url 'https://big.oisd.nl/dnsmasq2'
option download_timeout '10'
option force_dns '1'
diff --git a/net/adblock-fast/files/etc/init.d/adblock-fast b/net/adblock-fast/files/etc/init.d/adblock-fast
index 2a75e6938..6d0cade3f 100755
--- a/net/adblock-fast/files/etc/init.d/adblock-fast
+++ b/net/adblock-fast/files/etc/init.d/adblock-fast
@@ -151,6 +151,7 @@ get_text() {
errorParsingList) r="failed to parse";;
errorNoSSLSupport) r="no HTTPS/SSL support on device";;
errorCreatingDirectory) r="failed to create output/cache/gzip file directory";;
+ errorDetectingFileType) r="failed to detect format";;
statusNoInstall) r="$serviceName is not installed or not found";;
statusStopped) r="Stopped";;
@@ -268,20 +269,35 @@ append_url() {
fi
}
-detect_file_type() {
- local file="$1"
- if [ "$(head -1 "$file")" = '[Adblock Plus]' ]; then
- echo 'adBlockPlus'
- elif grep -q '^server=' "$file"; then
- echo 'dnsmasqFile'
- elif grep -q '^local=' "$file"; then
- echo 'dnsmasq2File'
- elif grep -q '^0.0.0.0' "$file" || grep -q '^127.0.0.1' "$file"; then
- echo 'hosts'
- else
- echo 'domains'
- fi
-}
+ detect_file_type() {
+ local file="$1"
+ if [ "$(head -1 "$file")" = '[Adblock Plus]' ] || \
+ grep -q '^||' "$file"; then
+ echo 'adBlockPlus'
+ elif grep -q '^server=' "$file"; then
+ echo 'dnsmasqFile'
+ elif grep -q '^local=' "$file"; then
+ echo 'dnsmasq2File'
+ elif grep -q '^0.0.0.0' "$file" || grep -q '^127.0.0.1' "$file"; then
+ echo 'hosts'
+ elif [ -n "$(sed "$domainsFilter" "$file" | head -1)" ]; then
+ echo 'domains'
+ fi
+ }
+# detect_file_type() {
+# local file="$1"
+# if [ -n "$(sed "$adBlockPlusFilter" "$file" | head -1)" ]; then
+# echo 'adBlockPlus'
+# elif [ -n "$(sed "$dnsmasqFileFilter" "$file" | head -1)" ]; then
+# echo 'dnsmasqFile'
+# elif [ -n "$(sed "$dnsmasq2FileFilter" "$file" | head -1)" ]; then
+# echo 'dnsmasq2File'
+# elif [ -n "$(sed "$hostsFilter" "$file" | head -1)" ]; then
+# echo 'hosts'
+# elif [ -n "$(sed "$domainsFilter" "$file" | head -1)" ]; then
+# echo 'domains'
+# fi
+# }
load_environment() {
local i j
@@ -543,7 +559,7 @@ get_local_filesize() {
echo -en "$size"
}
-resolver() {
+resolver_config() {
local cfg="$1" param="$2"
case "$param" in
dnsmasq.addnhosts)
@@ -580,10 +596,10 @@ dns() {
config_load 'dhcp'
if [ "$dnsmasq_instance" = "*" ]; then
- config_foreach resolver 'dnsmasq' "$dns"
+ config_foreach resolver_config 'dnsmasq' "$dns"
elif [ -n "$dnsmasq_instance" ]; then
for i in $dnsmasq_instance; do
- resolver "@dnsmasq[$i]" "$dns" || resolver "$i" "$dns"
+ resolver_config "@dnsmasq[$i]" "$dns" || resolver_config "$i" "$dns"
done
fi
@@ -849,16 +865,23 @@ process_file_url() {
format="$(detect_file_type "$R_TMP")"
case "$format" in
adBlockPlus) filter="$adBlockPlusFilter";;
-# dnsmasqFile) filter="$dnsmasqFileFilter";;
-# dnsmasq2File) filter="$dnsmasq2FileFilter";;
+ dnsmasqFile) filter="$dnsmasqFileFilter";;
+ dnsmasq2File) filter="$dnsmasq2FileFilter";;
domains) filter="$domainsFilter";;
hosts) filter="$hostsFilter";;
+ *)
+ output 1 "$_FAIL_"
+ output 2 "[DL] $type $label $__FAIL__\\n"
+ echo "errorDetectingFileType|${url}" >> "$sharedMemoryError"
+ rm -f "$R_TMP"
+ return 0
+ ;;
esac
- [ -n "$filter" ] && sed -i "$filter" "$R_TMP"
+ sed -i "$filter" "$R_TMP"
if [ ! -s "$R_TMP" ]; then
output 1 "$_FAIL_"
output 2 "[DL] $type $label ($format) $__FAIL__\\n"
- echo "errorParsingList|${1}" >> "$sharedMemoryError"
+ echo "errorParsingList|${url}" >> "$sharedMemoryError"
else
cat "${R_TMP}" >> "$D_TMP"
output 1 "$_OK_"
@@ -1596,7 +1619,7 @@ killcache() {
rm -f "$dnsmasqServersCache" "${compressed_cache_dir}/${dnsmasqServersGzip}"
rm -f "$unboundCache" "$unboundGzip"
config_load 'dhcp'
- config_foreach resolver 'dnsmasq' 'cleanup'
+ config_foreach resolver_config 'dnsmasq' 'cleanup'
uci_commit 'dhcp'
return 0
}