[solved]Adblock intermittent blocking

Folks would appreciate a little help on where to start my troubleshooting. Running 22.03.0 rc6, with adblock 4.1.3. It's enabled and triggered by the wan interface. I've just changed my mobile (not sure if relevant or not) everything running great as expected prior to this change. Wife's phone all sponsored results are blocked but on my phone they are not... Any thoughts please on what my next steps should be. Thanks

Step 1: Update to 22.03.2, to make sure your issue is not caused by the old rc6.

2 Likes

Thank you for the suggestion. Upgrade complete but still not blocked on my device unfortunately

Disabled DoT on the phone ?

1 Like

DoT ??????????? Not sure what that is

Or blocked it in the fw.

1 Like

Are you running a VPN on your phone?

I had installed my VPN app but not actually set it up so no mate

ssh to your router and provide the output of /etc/init.d/adblock status and the content of /etc/config/adblock.

If it's working on some clients, there's probably nothing wrong with adblock.

Saying it works on A, but not on B, without providing any additional details, isn't however useful.

root@OpenWrt:~# cat /etc/init.d/adblock
#!/bin/sh /etc/rc.common
# Copyright (c) 2015-2022 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.

# disable (s)hellcheck in release
# shellcheck disable=all

START=30
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" "[[<cli>|<mail>|<gen>|<json>] [<top_count>] [<res_count>] [<search>]] Print DNS statistics with an optional search parameter"
extra_command "list" "[<add>|<add_utc>|<add_eng>|<add_stb>|<remove>|<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"

adb_init="/etc/init.d/adblock"
adb_script="/usr/bin/adblock.sh"
adb_pidfile="/var/run/adblock.pid"

if [ -s "${adb_pidfile}" ] && { [ "${action}" = "start" ] || [ "${action}" = "stop" ] ||
	[ "${action}" = "restart" ] || [ "${action}" = "reload" ] || [ "${action}" = "report" ] ||
	[ "${action}" = "suspend" ] || [ "${action}" = "resume" ] || [ "${action}" = "query" ] ||
	{ [ "${action}" = "list" ] && [ -n "${1}" ]; }; }; then
	return 0
fi

boot() {
	[ -s "${adb_pidfile}" ] && : >"${adb_pidfile}"
	rc_procd start_service
}

start_service() {
	if "${adb_init}" enabled; then
		if [ "${action}" = "boot" ]; then
			[ -n "$(uci_get adblock global adb_trigger)" ] && return 0
		fi
		procd_open_instance "adblock"
		procd_set_param command "${adb_script}" "${@}"
		procd_set_param pidfile "${adb_pidfile}"
		procd_set_param nice "$(uci_get adblock global adb_nice "0")"
		procd_set_param stdout 1
		procd_set_param stderr 1
		procd_close_instance
	fi
}

reload_service() {
	rc_procd start_service reload
}

stop_service() {
	rc_procd "${adb_script}" stop
}

restart() {
	rc_procd start_service restart
}

suspend() {
	rc_procd start_service suspend
}

resume() {
	rc_procd start_service resume
}

query() {
	rc_procd "${adb_script}" query "${1}"
}

report() {
	rc_procd "${adb_script}" report "${1:-"cli"}" "${2}" "${3}" "${4}"
}

list() {
	local src_archive src_file src_enabled enabled name utc_list size focus descurl action="${1}"

	if [ "${action%_*}" = "add" ] || [ "${action%_*}" = "remove" ]; then
		shift
		for name in "${@}"; do
			case "${action}" in
				"add")
					if ! uci_get adblock global adb_sources | grep -q "${name}"; then
						uci_add_list adblock global adb_sources "${name}"
						printf "%s\n" "::: adblock source '${name}' added to config"
					fi
					;;
				"remove")
					if uci_get adblock global adb_sources | grep -q "${name}"; then
						uci_remove_list adblock global adb_sources "${name}"
						printf "%s\n" "::: adblock source '${name}' removed from config"
					fi
					;;
				"add_utc")
					if ! uci_get adblock global adb_utc_sources | grep -q "${name}"; then
						uci_add_list adblock global adb_utc_sources "${name}"
						printf "%s\n" "::: adblock utcapitole '${name}' added to config"
					fi
					;;
				"remove_utc")
					if uci_get adblock global adb_utc_sources | grep -q "${name}"; then
						uci_remove_list adblock global adb_utc_sources "${name}"
						printf "%s\n" "::: adblock utcapitole '${name}' removed from config"
					fi
					;;
				"add_eng")
					if ! uci_get adblock global adb_eng_sources | grep -q "${name}"; then
						uci_add_list adblock global adb_eng_sources "${name}"
						printf "%s\n" "::: adblock energized '${name}' added to config"
					fi
					;;
				"remove_eng")
					if uci_get adblock global adb_eng_sources | grep -q "${name}"; then
						uci_remove_list adblock global adb_eng_sources "${name}"
						printf "%s\n" "::: adblock energized '${name}' removed from config"
					fi
					;;
				"add_stb")
					if ! uci_get adblock global adb_stb_sources | grep -q "${name}"; then
						uci_add_list adblock global adb_stb_sources "${name}"
						printf "%s\n" "::: adblock stevenblack '${name}' added to config"
					fi
					;;
				"remove_stb")
					if uci_get adblock global adb_stb_sources | grep -q "${name}"; then
						uci_remove_list adblock global adb_stb_sources "${name}"
						printf "%s\n" "::: adblock stevenblack '${name}' removed from config"
					fi
					;;
			esac
		done
		[ -n "$(uci -q changes adblock)" ] && { uci_commit adblock; "${adb_init}" start; }
	else
		src_archive="$(uci_get adblock global adb_srcarc "/etc/adblock/adblock.sources.gz")"
		src_file="$(uci_get adblock global adb_srcfile "/tmp/adb_sources.json")"
		src_enabled="$(uci -q show adblock.global.adb_sources)"
		[ -r "${src_archive}" ] && zcat "${src_archive}" >"${src_file}" || printf "%s\n" "::: adblock source archive '${src_archive}' not found"

		if [ -r "${src_file}" ]; then
			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" "    -------------------------------------------------------------------"
			json_load_file "${src_file}"
			json_get_keys keylist
			for key in ${keylist}; do
				json_select "${key}"
				json_get_var size "size"
				json_get_var focus "focus"
				json_get_var descurl "descurl"
				json_get_var url "url"
				json_get_var rule "rule"
				if [ -n "${url}" ] && [ -n "${rule}" ]; then
					if printf "%s" "${src_enabled}" | grep -q "${key}"; then
						enabled="x"
					else
						enabled=" "
					fi
					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}"
				else
					src_enabled="${src_enabled} ${key}"
				fi
				json_select ..
			done
			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 utcapitole categories: ${utc_list// /, }"
			printf "  * %s\n" "Configured energized variants: ${eng_list// /, }"
			printf "  * %s\n" "Configured stevenblack variants: ${stb_list// /, }"

			if [ -n "${src_enabled// }" ]; then
				printf "%s\n" "    ---------------------------------------------------------------------------"
				printf "%s\n" "    Sources with invalid configuration"
				printf "%s\n" "    ---------------------------------------------------------------------------"
				for key in ${src_enabled}; do
					printf "  - %s\n" "${key:0:20}"
				done
			fi
		else
			printf "%s\n" "::: adblock source file '${src_file}' not found"
		fi
	fi
}

status() {
	status_service
}

status_service() {
	local key keylist value idxval values type rtfile

	rtfile="$(uci_get adblock global adb_rtfile "/tmp/adb_runtime.json")"

	json_load_file "${rtfile}" >/dev/null 2>&1
	json_get_keys keylist
	if [ -n "${keylist}" ]; then
		printf "%s\n" "::: adblock runtime information"
		for key in ${keylist}; do
			json_get_var value "${key}" >/dev/null 2>&1
			if [ "${key%_*}" = "active" ]; then
				printf "  + %-15s : " "${key}"
				json_select "${key}" >/dev/null 2>&1
				values=""
				index="1"
				while json_get_type type "${index}" && [ "${type}" = "object" ]; do
					json_get_values idxval "${index}" >/dev/null 2>&1
					if [ "${index}" = "1" ]; then
						values="${idxval}"
					else
						values="${values}, ${idxval}"
					fi
					index="$((index + 1))"
				done
				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 ".."
			else
				printf "  + %-15s : %s\n" "${key}" "${value:-"-"}"
			fi
		done
	else
		printf "%s\n" "::: no adblock runtime information available"
	fi
}

timer() {
	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"

	if [ -s "${cron_file}" ] && [ "${action}" = "list" ]; then
		awk '{print NR ">  " $0}' "${cron_file}"
	elif [ -x "/etc/init.d/cron" ] && [ "${action}" = "add" ]; then
		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
			printf "%02d %02d %s\n" "${minute}" "${hour}" "* * ${weekday} ${adb_init} ${cron_tasks}" >>"${cron_file}"
			/etc/init.d/cron restart
		fi
	elif [ -x "/etc/init.d/cron" ] && [ -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
}

service_triggers() {
	local iface delay

	iface="$(uci_get adblock global adb_trigger)"
	delay="$(uci_get adblock global adb_triggerdelay "5")"
	PROCD_RELOAD_DELAY="$((delay * 1000))"

	[ -n "${iface}" ] && procd_add_interface_trigger "interface.*.up" "${iface}" "${adb_init}" "start"
	procd_add_reload_trigger "adblock"
}
root@OpenWrt:~# cat /etc/config/adblock

config adblock 'global'
	option adb_debug '0'
	option adb_forcedns '0'
	option adb_safesearch '0'
	option adb_dnsfilereset '0'
	option adb_mail '0'
	option adb_report '0'
	option adb_backup '1'
	option adb_maxqueue '4'
	list adb_sources 'adaway'
	list adb_sources 'adguard'
	list adb_sources 'disconnect'
	list adb_sources 'yoyo'
	option adb_dns 'dnsmasq'
	option adb_fetchutil 'uclient-fetch'
	option adb_trigger 'wan'
	option adb_dnsinstance '0'
	option adb_enabled '1'

I appreciate your comments. I am more than willing to provide any useful details as required. As a newbie the purpose of my post was to acertain exactly what details may be useful in the attempting to diagnose why I am experiencing the lack of blocking on my mobile. As you say I too now believe adblock to be doing its job as it is blocking ads on my laptop too. Just my mobile now doing my nut in..

Still no info about the phone...

Sorry, the first one was a command - I know the content of the init file ... :slight_smile: ... please execute the above command and provide the output - thanks.

Anyway, derived from your config you could enable "Force DNS" in adblocks LuCI frontend for ports 53 and 853 (under General Settings tab) and enable the blocklist 'doh_blocklist' under the Blocklist Sources tab. Save & Apply and check if the effect disappeared.

root@OpenWrt:~# /etc/init.d/adblock status
::: adblock runtime information
  + adblock_status  : enabled
  + adblock_version : 4.1.5
  + blocked_domains : 55483
  + active_sources  : adaway, adguard, disconnect, doh_blocklist, yoyo
  + dns_backend     : dnsmasq (-), /tmp/dnsmasq.d
  + run_utils       : download: /bin/uclient-fetch, sort: /usr/libexec/sort-coreutils, awk: /bin/busybox
  + run_ifaces      : trigger: wan, report: -
  + run_directories : base: /tmp, backup: /tmp/adblock-Backup, report: /tmp/adblock-Report, jail: /tmp
  + run_flags       : backup: ✔, flush: ✘, force: ✔, search: ✘, report: ✘, mail: ✘, jail: ✘
  + last_run        : start, 0m 31s, 475/387/371, 2022-11-19T16:40:24+00:00
  + system          : Netgear Nighthawk X4S R7800, OpenWrt 22.03.2 r19803-9a599fee93

Phone is a OnePlus 9 Pro running Android v12.
I have disabled the data connection to force use of wifi.

Android, DoT on OS level.
Disable it, or block it in the fw.

1 Like

Is it working now? Maybe you have to restart your mobile phone to reset DNS caches etc.

He has already set adblock to block DoT ports and DoH server, see above.

1 Like

Rebooted all devices.. Still not working, cant thank you enough for trying to help folks.Also tested on both Chrome and FF on the OnePlus