blob: 0917288ea9e167c4515ed53eefd2d99657e3d4d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#!/bin/sh /etc/rc.common
#
START=30
USE_PROCD=1
EXTRA_COMMANDS="suspend resume query report status"
EXTRA_HELP=" suspend Suspend adblock processing
resume Resume adblock processing
query <DOMAIN> Query active blocklists for specific domains
report <SEARCH> Print dns query statistics with an optional search parameter
status Print runtime information"
adb_init="/etc/init.d/adblock"
adb_script="/usr/bin/adblock.sh"
adb_pidfile="/var/run/adblock.pid"
boot()
{
adb_boot=1
rc_procd start_service
}
start_service()
{
if [ "$("${adb_init}" enabled; printf "%u" ${?})" -eq 0 ]
then
if [ -n "${adb_boot}" ]
then
local trigger="$(uci_get adblock global adb_trigger)"
if [ "${trigger}" != "timed" ]
then
return 0
fi
fi
local nice="$(uci_get adblock extra adb_nice "0")"
procd_open_instance "adblock"
procd_set_param command "${adb_script}" "${@}"
procd_set_param pidfile "${adb_pidfile}"
procd_set_param nice "${nice}"
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()
{
[ -s "${adb_pidfile}" ] && return 1
rc_procd start_service suspend
}
resume()
{
[ -s "${adb_pidfile}" ] && return 1
rc_procd start_service resume
}
query()
{
[ -s "${adb_pidfile}" ] && return 1
rc_procd "${adb_script}" query "${1}"
}
report()
{
[ -s "${adb_pidfile}" ] && return 1
rc_procd "${adb_script}" report "${1:-"+"}" "${2:-"50"}" "${3:-"false"}" "${4:-"true"}"
}
status()
{
local key keylist value
local rtfile="$(uci_get adblock extra adb_rtfile "/tmp/adb_runtime.json")"
if [ -s "${rtfile}" ]
then
printf "%s\\n" "::: adblock runtime information"
json_load_file "${rtfile}"
json_select data
json_get_keys keylist
for key in ${keylist}
do
json_get_var value "${key}"
printf " + %-15s : %s\\n" "${key}" "${value}"
done
else
printf "%s\\n" "::: no adblock runtime information available"
fi
}
service_triggers()
{
local trigger="$(uci_get adblock global adb_trigger)"
local delay="$(uci_get adblock extra adb_triggerdelay "2")"
PROCD_RELOAD_DELAY=$((delay*1000))
if [ -n "${trigger}" ] && [ "${trigger}" != "none" ] && [ "${trigger}" != "timed" ]
then
procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" start
elif [ -z "${trigger}" ]
then
procd_add_raw_trigger "interface.*.up" ${PROCD_RELOAD_DELAY} "${adb_init}" start
fi
procd_add_reload_trigger "adblock"
}
|