2016-02-15 19:25:21 +08:00
|
|
|
#!/bin/sh /etc/rc.common
|
2025-04-11 05:39:08 +08:00
|
|
|
# Copyright (c) 2015-2025 Dirk Brenken (dev@brenken.org)
|
2020-03-28 03:26:39 +08:00
|
|
|
# This is free software, licensed under the GNU General Public License v3.
|
2016-02-15 19:25:21 +08:00
|
|
|
|
2024-06-27 13:47:10 +08:00
|
|
|
# (s)hellcheck exceptions
|
2022-09-11 00:42:14 +08:00
|
|
|
# shellcheck disable=all
|
2020-10-18 17:05:22 +08:00
|
|
|
|
2017-09-09 23:35:42 +08:00
|
|
|
START=30
|
2016-12-20 03:11:25 +08:00
|
|
|
USE_PROCD=1
|
2016-02-15 19:25:21 +08:00
|
|
|
|
2022-10-20 17:46:09 +08:00
|
|
|
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"
|
2025-04-11 05:39:08 +08:00
|
|
|
extra_command "report" "[<cli>|<mail>|<gen>|<json>] Print DNS statistics"
|
2016-02-15 19:25:21 +08:00
|
|
|
|
2017-03-26 04:49:44 +08:00
|
|
|
adb_init="/etc/init.d/adblock"
|
2016-12-20 03:11:25 +08:00
|
|
|
adb_script="/usr/bin/adblock.sh"
|
2018-01-11 02:33:42 +08:00
|
|
|
adb_pidfile="/var/run/adblock.pid"
|
2016-07-31 23:19:33 +08:00
|
|
|
|
2025-04-14 03:41:36 +08:00
|
|
|
if [ -z "${IPKG_INSTROOT}" ]; then
|
|
|
|
if [ "${action}" = "boot" ] && "${adb_init}" running; then
|
|
|
|
exit 0
|
|
|
|
elif [ -s "${adb_pidfile}" ] &&
|
|
|
|
{ [ "${action}" = "start" ] || [ "${action}" = "stop" ] || [ "${action}" = "restart" ] ||
|
|
|
|
[ "${action}" = "reload" ] || [ "${action}" = "report" ] || [ "${action}" = "suspend" ] ||
|
|
|
|
[ "${action}" = "resume" ] || [ "${action}" = "query" ]; }; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2019-10-31 19:34:48 +08:00
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
boot() {
|
2024-06-27 13:47:10 +08:00
|
|
|
: >"${adb_pidfile}"
|
2025-05-03 20:37:13 +08:00
|
|
|
rc_procd start_service boot
|
2016-02-15 19:25:21 +08:00
|
|
|
}
|
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
start_service() {
|
|
|
|
if "${adb_init}" enabled; then
|
|
|
|
if [ "${action}" = "boot" ]; then
|
|
|
|
[ -n "$(uci_get adblock global adb_trigger)" ] && return 0
|
2018-09-01 14:35:35 +08:00
|
|
|
fi
|
|
|
|
procd_open_instance "adblock"
|
2025-05-03 20:37:13 +08:00
|
|
|
procd_set_param command "${adb_script}" "${@:-"${action}"}"
|
2018-09-01 14:35:35 +08:00
|
|
|
procd_set_param pidfile "${adb_pidfile}"
|
2020-03-28 03:26:39 +08:00
|
|
|
procd_set_param nice "$(uci_get adblock global adb_nice "0")"
|
2024-11-24 05:15:00 +08:00
|
|
|
procd_set_param stdout 0
|
2025-03-04 04:50:01 +08:00
|
|
|
procd_set_param stderr 1
|
2018-09-01 14:35:35 +08:00
|
|
|
procd_close_instance
|
|
|
|
fi
|
2016-02-15 19:25:21 +08:00
|
|
|
}
|
|
|
|
|
2025-04-11 05:39:08 +08:00
|
|
|
restart() {
|
2025-05-03 20:37:13 +08:00
|
|
|
stop_service "restart"
|
2025-04-11 05:39:08 +08:00
|
|
|
rc_procd start_service restart
|
|
|
|
}
|
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
reload_service() {
|
2018-09-01 14:35:35 +08:00
|
|
|
rc_procd start_service reload
|
2017-05-08 17:19:57 +08:00
|
|
|
}
|
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
stop_service() {
|
2025-05-03 20:37:13 +08:00
|
|
|
[ -z "${1}" ] && rc_procd "${adb_script}" stop
|
2016-02-15 19:25:21 +08:00
|
|
|
}
|
2016-06-03 21:14:53 +08:00
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
suspend() {
|
2019-08-15 20:02:30 +08:00
|
|
|
rc_procd start_service suspend
|
2016-06-03 21:14:53 +08:00
|
|
|
}
|
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
resume() {
|
2019-08-15 20:02:30 +08:00
|
|
|
rc_procd start_service resume
|
2016-06-22 05:14:29 +08:00
|
|
|
}
|
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
query() {
|
2018-09-01 14:35:35 +08:00
|
|
|
rc_procd "${adb_script}" query "${1}"
|
2016-12-23 14:15:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
report() {
|
2022-10-18 18:44:31 +08:00
|
|
|
rc_procd "${adb_script}" report "${1:-"cli"}" "${2}" "${3}" "${4}"
|
2020-03-28 03:26:39 +08:00
|
|
|
}
|
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
status() {
|
2021-02-27 03:52:55 +08:00
|
|
|
status_service
|
|
|
|
}
|
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
status_service() {
|
2025-04-11 05:39:08 +08:00
|
|
|
local key keylist value values
|
2018-01-06 01:54:45 +08:00
|
|
|
|
2024-10-11 01:00:14 +08:00
|
|
|
json_init
|
2025-04-11 05:39:08 +08:00
|
|
|
json_load_file "/var/run/adb_runtime.json" >/dev/null 2>&1
|
2021-02-27 03:52:55 +08:00
|
|
|
json_get_keys keylist
|
2022-09-11 00:42:14 +08:00
|
|
|
if [ -n "${keylist}" ]; then
|
2021-02-27 03:52:55 +08:00
|
|
|
printf "%s\n" "::: adblock runtime information"
|
2022-09-11 00:42:14 +08:00
|
|
|
for key in ${keylist}; do
|
2021-02-27 03:52:55 +08:00
|
|
|
json_get_var value "${key}" >/dev/null 2>&1
|
2025-04-11 05:39:08 +08:00
|
|
|
if [ "${key}" = "active_feeds" ]; then
|
2024-10-11 01:00:14 +08:00
|
|
|
json_get_values values "${key}" >/dev/null 2>&1
|
|
|
|
value="${values// /, }"
|
2020-03-28 03:26:39 +08:00
|
|
|
fi
|
2024-10-11 01:00:14 +08:00
|
|
|
printf " + %-15s : %s\n" "${key}" "${value:-"-"}"
|
2018-09-01 14:35:35 +08:00
|
|
|
done
|
|
|
|
else
|
2021-02-27 03:52:55 +08:00
|
|
|
printf "%s\n" "::: no adblock runtime information available"
|
2018-09-01 14:35:35 +08:00
|
|
|
fi
|
2017-04-11 03:15:34 +08:00
|
|
|
}
|
|
|
|
|
2022-09-11 00:42:14 +08:00
|
|
|
service_triggers() {
|
2021-02-27 03:52:55 +08:00
|
|
|
local iface delay
|
2020-03-28 03:26:39 +08:00
|
|
|
|
2021-02-27 03:52:55 +08:00
|
|
|
delay="$(uci_get adblock global adb_triggerdelay "5")"
|
2025-05-03 20:37:13 +08:00
|
|
|
trigger="$(uci_get adblock global adb_trigger)"
|
2021-02-27 03:52:55 +08:00
|
|
|
|
2024-08-11 15:31:29 +08:00
|
|
|
PROCD_RELOAD_DELAY="$((delay * 1000))"
|
2025-05-03 20:37:13 +08:00
|
|
|
for iface in ${trigger}; do
|
|
|
|
procd_add_interface_trigger "interface.*.up" "${iface}" "${adb_init}" start
|
|
|
|
done
|
2016-10-08 01:00:44 +08:00
|
|
|
}
|