|
@@ -13,9 +13,9 @@ f_envload()
|
13
|
13
|
#
|
14
|
14
|
if [ -r "/lib/functions.sh" ]
|
15
|
15
|
then
|
16
|
|
- . /lib/functions.sh
|
|
16
|
+ . "/lib/functions.sh" 2>/dev/null
|
17
|
17
|
else
|
18
|
|
- rc=510
|
|
18
|
+ rc=500
|
19
|
19
|
f_log "openwrt function library not found" "${rc}"
|
20
|
20
|
f_deltemp
|
21
|
21
|
fi
|
|
@@ -24,9 +24,9 @@ f_envload()
|
24
|
24
|
#
|
25
|
25
|
if [ -r "/usr/share/libubox/jshn.sh" ]
|
26
|
26
|
then
|
27
|
|
- . "/usr/share/libubox/jshn.sh"
|
|
27
|
+ . "/usr/share/libubox/jshn.sh" 2>/dev/null
|
28
|
28
|
else
|
29
|
|
- rc=515
|
|
29
|
+ rc=505
|
30
|
30
|
f_log "openwrt json helpers library not found" "${rc}"
|
31
|
31
|
f_deltemp
|
32
|
32
|
fi
|
|
@@ -36,7 +36,7 @@ f_envload()
|
36
|
36
|
pkg_list="$(opkg list-installed 2>/dev/null)"
|
37
|
37
|
if [ -z "${pkg_list}" ]
|
38
|
38
|
then
|
39
|
|
- rc=520
|
|
39
|
+ rc=510
|
40
|
40
|
f_log "empty openwrt package list" "${rc}"
|
41
|
41
|
f_deltemp
|
42
|
42
|
fi
|
|
@@ -48,16 +48,19 @@ f_envload()
|
48
|
48
|
f_envparse()
|
49
|
49
|
{
|
50
|
50
|
# set the C locale, characters are single bytes, the charset is ASCII
|
51
|
|
- # speeds up sort, grep etc., guarantees unique domains
|
|
51
|
+ # speeds up sort, grep etc.
|
52
|
52
|
#
|
53
|
53
|
LC_ALL=C
|
54
|
54
|
|
55
|
|
- # set initial defaults (may be overwritten by adblock config options)
|
|
55
|
+ # set initial defaults (may be overwritten by setting appropriate adblock config options)
|
56
|
56
|
#
|
57
|
57
|
adb_if="adblock"
|
58
|
58
|
adb_minspace="20000"
|
59
|
59
|
adb_maxtime="60"
|
60
|
60
|
adb_maxloop="5"
|
|
61
|
+ adb_unique="1"
|
|
62
|
+ adb_blacklist="/etc/adblock/adblock.blacklist"
|
|
63
|
+ adb_whitelist="/etc/adblock/adblock.whitelist"
|
61
|
64
|
|
62
|
65
|
# adblock device name auto detection
|
63
|
66
|
# derived from first entry in openwrt lan ifname config
|
|
@@ -90,7 +93,7 @@ f_envparse()
|
90
|
93
|
{
|
91
|
94
|
local option="${1}"
|
92
|
95
|
local value="${2}"
|
93
|
|
- local opt_out="$(printf "${option}" | sed -n '/.*_ITEM[0-9]$/p; /.*_LENGTH$/p; /enabled/p')"
|
|
96
|
+ local opt_out="$(printf "${option}" | sed -n '/.*_ITEM[0-9]$/p; /.*_LENGTH$/p; /enabled/p' 2>/dev/null)"
|
94
|
97
|
if [ -z "${opt_out}" ]
|
95
|
98
|
then
|
96
|
99
|
all_options="${all_options} ${option}"
|
|
@@ -127,7 +130,7 @@ f_envparse()
|
127
|
130
|
config_get value "${config}" "${option}"
|
128
|
131
|
if [ -n "${value}" ]
|
129
|
132
|
then
|
130
|
|
- local opt_src="$(printf "${option}" | sed -n '/^adb_src_[a-z0-9]*$/p')"
|
|
133
|
+ local opt_src="$(printf "${option}" | sed -n '/^adb_src_[a-z0-9]*$/p' 2>/dev/null)"
|
131
|
134
|
if [ -n "${opt_src}" ]
|
132
|
135
|
then
|
133
|
136
|
adb_sources="${adb_sources} ${value}"
|
|
@@ -138,13 +141,13 @@ f_envparse()
|
138
|
141
|
done
|
139
|
142
|
elif [ "${config}" = "wancheck" ]
|
140
|
143
|
then
|
141
|
|
- unset adb_wandev 2>/dev/null
|
|
144
|
+ unset adb_wandev
|
142
|
145
|
elif [ "${config}" = "ntpcheck" ]
|
143
|
146
|
then
|
144
|
|
- unset adb_ntpsrv 2>/dev/null
|
|
147
|
+ unset adb_ntpsrv
|
145
|
148
|
elif [ "${config}" = "shalla" ]
|
146
|
149
|
then
|
147
|
|
- unset adb_cat_shalla 2>/dev/null
|
|
150
|
+ unset adb_cat_shalla
|
148
|
151
|
fi
|
149
|
152
|
}
|
150
|
153
|
|
|
@@ -154,25 +157,35 @@ f_envparse()
|
154
|
157
|
config_foreach parse_config service
|
155
|
158
|
config_foreach parse_config source
|
156
|
159
|
|
157
|
|
- # set temp variables and counter
|
|
160
|
+ # set temp variables and defaults
|
158
|
161
|
#
|
159
|
162
|
adb_tmpfile="$(mktemp -tu 2>/dev/null)"
|
160
|
163
|
adb_tmpdir="$(mktemp -p /tmp -d 2>/dev/null)"
|
|
164
|
+ unset adb_srcfind
|
|
165
|
+ unset adb_revsrcfind
|
161
|
166
|
|
162
|
167
|
# set adblock source ruleset definitions
|
163
|
168
|
#
|
164
|
169
|
rset_start="sed -r 's/[[:space:]]|[\[!#/:;_].*|[0-9\.]*localhost//g; s/[\^#/:;_\.\t ]*$//g'"
|
165
|
170
|
rset_end="sed '/^[#/:;_\s]*$/d'"
|
166
|
|
- rset_default="${rset_start} | ${rset_end}"
|
167
|
|
- rset_yoyo="${rset_start} | sed 's/,/\n/g' | ${rset_end}"
|
|
171
|
+ rset_adaway="${rset_start} | sed 's/\([0-9]\{1,3\}\.\)\{3\}[0-1]\{1,1\}//g' | ${rset_end}"
|
|
172
|
+ rset_blacklist="${rset_start} | ${rset_end}"
|
|
173
|
+ rset_disconnect="${rset_start} | ${rset_end}"
|
|
174
|
+ rset_dshield="${rset_start} | ${rset_end}"
|
|
175
|
+ rset_feodo="${rset_start} | ${rset_end}"
|
|
176
|
+ rset_malware="${rset_start} | ${rset_end}"
|
|
177
|
+ rset_palevo="${rset_start} | ${rset_end}"
|
168
|
178
|
rset_shalla="${rset_start} | sed 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}$//g' | ${rset_end}"
|
169
|
179
|
rset_spam404="${rset_start} | sed 's/^\|\|//g' | ${rset_end}"
|
170
|
180
|
rset_winhelp="${rset_start} | sed 's/\([0-9]\{1,3\}\.\)\{3\}[0-1]\{1,1\}//g' | ${rset_end}"
|
|
181
|
+ rset_yoyo="${rset_start} | sed 's/,/\n/g' | ${rset_end}"
|
|
182
|
+ rset_zeus="${rset_start} | ${rset_end}"
|
171
|
183
|
|
172
|
|
- # set adblock/dnsmasq destination file and format
|
|
184
|
+ # set dnsmasq defaults
|
173
|
185
|
#
|
174
|
|
- adb_dnsfile="/tmp/dnsmasq.d/adlist.conf"
|
|
186
|
+ adb_dnsdir="/tmp/dnsmasq.d"
|
175
|
187
|
adb_dnsformat="sed 's/^/address=\//;s/$/\/'${adb_ip}'/'"
|
|
188
|
+ adb_dnsprefix="adb_list"
|
176
|
189
|
}
|
177
|
190
|
|
178
|
191
|
#############################################
|
|
@@ -180,14 +193,25 @@ f_envparse()
|
180
|
193
|
#
|
181
|
194
|
f_envcheck()
|
182
|
195
|
{
|
183
|
|
- # check required config variables
|
|
196
|
+ # check adblock config file
|
|
197
|
+ #
|
|
198
|
+ check_config="$(grep -F "ruleset=rset_default" /etc/config/adblock 2>/dev/null)"
|
|
199
|
+ if [ -n "${check_config}" ]
|
|
200
|
+ then
|
|
201
|
+ rc=515
|
|
202
|
+ grep -Fv "#" "/etc/adblock/samples/adblock.conf.sample" > /etc/config/adblock
|
|
203
|
+ f_log "new default adblock config applied, please check your configuration settings in /etc/config/adblock" "${rc}"
|
|
204
|
+ f_deltemp
|
|
205
|
+ fi
|
|
206
|
+
|
|
207
|
+ # check required config options
|
184
|
208
|
#
|
185
|
|
- adb_varlist="adb_ip adb_dev adb_if adb_domain adb_minspace adb_maxloop adb_maxtime adb_blacklist adb_whitelist"
|
|
209
|
+ adb_varlist="adb_ip adb_dev adb_domain"
|
186
|
210
|
for var in ${adb_varlist}
|
187
|
211
|
do
|
188
|
212
|
if [ -z "$(eval printf \"\$"${var}"\")" ]
|
189
|
213
|
then
|
190
|
|
- rc=525
|
|
214
|
+ rc=520
|
191
|
215
|
f_log "missing adblock config option (${var})" "${rc}"
|
192
|
216
|
f_deltemp
|
193
|
217
|
fi
|
|
@@ -195,12 +219,12 @@ f_envcheck()
|
195
|
219
|
|
196
|
220
|
# check main uhttpd configuration
|
197
|
221
|
#
|
198
|
|
- check_uhttpd="$(uci get uhttpd.main.listen_http 2>/dev/null | grep -Fo "0.0.0.0")"
|
|
222
|
+ check_uhttpd="$(uci get uhttpd.main.listen_http 2>/dev/null | grep -Fo "0.0.0.0" 2>/dev/null)"
|
199
|
223
|
if [ -n "${check_uhttpd}" ]
|
200
|
224
|
then
|
201
|
|
- rc=530
|
|
225
|
+ rc=525
|
202
|
226
|
lan_ip="$(uci get network.lan.ipaddr 2>/dev/null)"
|
203
|
|
- f_log "main uhttpd instance listens to all network interfaces, please bind uhttpd to LAN only (${lan_ip})" "${rc}"
|
|
227
|
+ f_log "please bind main uhttpd instance to LAN only (lan ip: ${lan_ip})" "${rc}"
|
204
|
228
|
f_deltemp
|
205
|
229
|
fi
|
206
|
230
|
|
|
@@ -208,30 +232,36 @@ f_envcheck()
|
208
|
232
|
#
|
209
|
233
|
if [ ! -d "/sys/class/net/${adb_dev}" ]
|
210
|
234
|
then
|
211
|
|
- rc=535
|
|
235
|
+ rc=530
|
212
|
236
|
f_log "invalid adblock network device input (${adb_dev})" "${rc}"
|
213
|
237
|
f_deltemp
|
214
|
238
|
fi
|
215
|
239
|
|
216
|
240
|
# check adblock network interface configuration
|
217
|
241
|
#
|
218
|
|
- check_if="$(printf "${adb_if}" | sed -n '/[^._0-9A-Za-z]/p')"
|
219
|
|
- banned_if="$(printf "${adb_if}" | sed -n '/.*lan.*\|.*wan.*\|.*switch.*\|main\|globals\|loopback\|px5g/p')"
|
|
242
|
+ check_if="$(printf "${adb_if}" | sed -n '/[^._0-9A-Za-z]/p' 2>/dev/null)"
|
|
243
|
+ banned_if="$(printf "${adb_if}" | sed -n '/.*lan.*\|.*wan.*\|.*switch.*\|main\|globals\|loopback\|px5g/p' 2>/dev/null)"
|
220
|
244
|
if [ -n "${check_if}" ] || [ -n "${banned_if}" ]
|
221
|
245
|
then
|
222
|
|
- rc=540
|
|
246
|
+ rc=535
|
223
|
247
|
f_log "invalid adblock network interface input (${adb_if})" "${rc}"
|
224
|
248
|
f_deltemp
|
225
|
249
|
fi
|
226
|
250
|
|
227
|
251
|
# check adblock ip address configuration
|
228
|
252
|
#
|
229
|
|
- check_ip="$(printf "${adb_ip}" | sed -n '/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/p')"
|
|
253
|
+ check_ip="$(printf "${adb_ip}" | sed -n '/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/p' 2>/dev/null)"
|
|
254
|
+ lan_ip="$(uci get network.lan.ipaddr 2>/dev/null)"
|
230
|
255
|
if [ -z "${check_ip}" ]
|
231
|
256
|
then
|
232
|
|
- rc=545
|
|
257
|
+ rc=540
|
233
|
258
|
f_log "invalid adblock ip address input (${adb_ip})" "${rc}"
|
234
|
259
|
f_deltemp
|
|
260
|
+ elif [ "${adb_ip}" = "${lan_ip}" ]
|
|
261
|
+ then
|
|
262
|
+ rc=545
|
|
263
|
+ f_log "adblock ip needs to be a different subnet from the normal LAN (adblock ip: ${adb_ip})" "${rc}"
|
|
264
|
+ f_deltemp
|
235
|
265
|
fi
|
236
|
266
|
|
237
|
267
|
# check adblock blacklist/whitelist configuration
|
|
@@ -263,7 +293,7 @@ f_envcheck()
|
263
|
293
|
|
264
|
294
|
# check curl package dependency
|
265
|
295
|
#
|
266
|
|
- check="$(printf "${pkg_list}" | grep "^curl -")"
|
|
296
|
+ check="$(printf "${pkg_list}" | grep "^curl -" 2>/dev/null)"
|
267
|
297
|
if [ -z "${check}" ]
|
268
|
298
|
then
|
269
|
299
|
rc=565
|
|
@@ -273,7 +303,7 @@ f_envcheck()
|
273
|
303
|
|
274
|
304
|
# check wget package dependency
|
275
|
305
|
#
|
276
|
|
- check="$(printf "${pkg_list}" | grep "^wget -")"
|
|
306
|
+ check="$(printf "${pkg_list}" | grep "^wget -" 2>/dev/null)"
|
277
|
307
|
if [ -z "${check}" ]
|
278
|
308
|
then
|
279
|
309
|
rc=570
|
|
@@ -281,31 +311,32 @@ f_envcheck()
|
281
|
311
|
f_deltemp
|
282
|
312
|
fi
|
283
|
313
|
|
284
|
|
- # check ca-certificates package and set wget/curl parms accordingly
|
|
314
|
+ # check ca-certificates package and set wget/curl options accordingly
|
285
|
315
|
#
|
286
|
|
- check="$(printf "${pkg_list}" | grep "^ca-certificates -")"
|
|
316
|
+ check="$(printf "${pkg_list}" | grep "^ca-certificates -" 2>/dev/null)"
|
287
|
317
|
if [ -z "${check}" ]
|
288
|
318
|
then
|
289
|
|
- curl_parm="-q --insecure"
|
290
|
|
- wget_parm="--no-config --no-hsts --no-check-certificate"
|
|
319
|
+ curl_parm="-q --insecure --silent"
|
|
320
|
+ wget_parm="--no-config --no-hsts --no-check-certificate --quiet"
|
291
|
321
|
else
|
292
|
|
- curl_parm="-q"
|
293
|
|
- wget_parm="--no-config --no-hsts"
|
|
322
|
+ curl_parm="-q --silent"
|
|
323
|
+ wget_parm="--no-config --no-hsts --quiet"
|
294
|
324
|
fi
|
295
|
325
|
|
296
|
326
|
# check total and swap memory
|
297
|
327
|
#
|
298
|
|
- mem_total="$(cat /proc/meminfo | grep -F "MemTotal" | grep -o "[0-9]*")"
|
299
|
|
- mem_free="$(cat /proc/meminfo | grep -F "MemFree" | grep -o "[0-9]*")"
|
300
|
|
- swap_total="$(cat /proc/meminfo | grep -F "SwapTotal" | grep -o "[0-9]*")"
|
|
328
|
+ mem_total="$(grep -F "MemTotal" "/proc/meminfo" 2>/dev/null | grep -o "[0-9]*" 2>/dev/null)"
|
|
329
|
+ mem_free="$(grep -F "MemFree" "/proc/meminfo" 2>/dev/null | grep -o "[0-9]*" 2>/dev/null)"
|
|
330
|
+ swap_total="$(grep -F "SwapTotal" "/proc/meminfo" 2>/dev/null | grep -o "[0-9]*" 2>/dev/null)"
|
301
|
331
|
if [ $((mem_total)) -le 64000 ] && [ $((swap_total)) -eq 0 ]
|
302
|
332
|
then
|
|
333
|
+ adb_unique=0
|
|
334
|
+ f_log "overall sort/unique processing will be disabled,"
|
303
|
335
|
f_log "please consider adding an external swap device to supersize your /tmp directory (total: ${mem_total}, free: ${mem_free}, swap: ${mem_swap})"
|
304
|
336
|
fi
|
305
|
337
|
|
306
|
338
|
# check backup configuration
|
307
|
339
|
#
|
308
|
|
- adb_backupdir="${adb_backupfile%/*}"
|
309
|
340
|
if [ -n "${adb_backupdir}" ] && [ -d "${adb_backupdir}" ]
|
310
|
341
|
then
|
311
|
342
|
f_space "${adb_backupdir}"
|
|
@@ -323,7 +354,7 @@ f_envcheck()
|
323
|
354
|
then
|
324
|
355
|
# check find capabilities
|
325
|
356
|
#
|
326
|
|
- check="$(find --help 2>&1 | grep -F "mtime")"
|
|
357
|
+ check="$(find --help 2>&1 | grep -F "mtime" 2>/dev/null)"
|
327
|
358
|
if [ -z "${check}" ]
|
328
|
359
|
then
|
329
|
360
|
query_ok="false"
|
|
@@ -417,15 +448,9 @@ f_envcheck()
|
417
|
448
|
fi
|
418
|
449
|
fi
|
419
|
450
|
|
420
|
|
- # remove no longer used environment variables
|
|
451
|
+ # remove no longer used package list
|
421
|
452
|
#
|
422
|
|
- env_list="$(set | grep -o "CONFIG_[A-Za-z0-9_]*")"
|
423
|
|
- for var in ${env_list}
|
424
|
|
- do
|
425
|
|
- unset "${var}" 2>/dev/null
|
426
|
|
- done
|
427
|
|
- unset env_list 2>/dev/null
|
428
|
|
- unset pkg_list 2>/dev/null
|
|
453
|
+ unset pkg_list
|
429
|
454
|
}
|
430
|
455
|
|
431
|
456
|
################################################
|
|
@@ -461,7 +486,7 @@ f_space()
|
461
|
486
|
if [ -d "${mp}" ]
|
462
|
487
|
then
|
463
|
488
|
df "${mp}" 2>/dev/null |\
|
464
|
|
- tail -n1 |\
|
|
489
|
+ tail -n1 2>/dev/null |\
|
465
|
490
|
while read filesystem overall used available scrap
|
466
|
491
|
do
|
467
|
492
|
av_space="${available}"
|
|
@@ -516,14 +541,31 @@ f_remove()
|
516
|
541
|
if [ -s "${adb_querypid}" ] && [ ! -f "${adb_queryfile}.${query_date}" ]
|
517
|
542
|
then
|
518
|
543
|
kill -9 "$(cat "${adb_querypid}")" >/dev/null 2>&1
|
519
|
|
- find "${adb_backupdir}" -maxdepth 1 -type f -mtime +"${adb_queryhistory}" -name "${query_name}.*" -exec rm -f {} \; 2>/dev/null
|
520
|
|
- f_log "remove old domain query log background process (pid: $(cat "${adb_querypid}")) and do logfile housekeeping"
|
|
544
|
+ rc=${?}
|
|
545
|
+ if [ $((rc)) -eq 0 ]
|
|
546
|
+ then
|
|
547
|
+ find "${adb_backupdir}" -maxdepth 1 -type f -mtime +"${adb_queryhistory}" -name "${query_name}.*" -exec rm -f "{}" \; 2>/dev/null
|
|
548
|
+ rc=${?}
|
|
549
|
+ fi
|
|
550
|
+ if [ $((rc)) -eq 0 ]
|
|
551
|
+ then
|
|
552
|
+ f_log "remove old domain query log background process (pid: $(cat "${adb_querypid}")) and do logfile housekeeping"
|
|
553
|
+ else
|
|
554
|
+ f_log "error during domain query removal/housekeeping (pid: $(cat "${adb_querypid}"))"
|
|
555
|
+ fi
|
521
|
556
|
> "${adb_querypid}"
|
522
|
557
|
fi
|
523
|
558
|
if [ ! -s "${adb_querypid}" ]
|
524
|
559
|
then
|
525
|
|
- (logread -f 2>/dev/null & printf ${!} > "${adb_querypid}") | grep -Eo "(query\[A\].*)|([a-z0-9\.\-]* is ${query_ip}$)" >> "${adb_queryfile}.${query_date}" &
|
526
|
|
- f_log "new domain query log background process started"
|
|
560
|
+ (logread -f 2>/dev/null & printf ${!} > "${adb_querypid}") | grep -Eo "(query\[A\].*)|([a-z0-9\.\-]* is ${query_ip}$)" 2>/dev/null >> "${adb_queryfile}.${query_date}" &
|
|
561
|
+ rc=${?}
|
|
562
|
+ if [ $((rc)) -eq 0 ]
|
|
563
|
+ then
|
|
564
|
+ sleep 1
|
|
565
|
+ f_log "new domain query log background process started (pid: $(cat "${adb_querypid}"))"
|
|
566
|
+ else
|
|
567
|
+ f_log "error during domain query start"
|
|
568
|
+ fi
|
527
|
569
|
fi
|
528
|
570
|
fi
|
529
|
571
|
f_deltemp
|
|
@@ -534,13 +576,33 @@ f_remove()
|
534
|
576
|
#
|
535
|
577
|
f_restore()
|
536
|
578
|
{
|
537
|
|
- if [ "${backup_ok}" = "true" ] && [ -f "${adb_backupfile}" ]
|
|
579
|
+ # remove bogus adblocklists
|
|
580
|
+ #
|
|
581
|
+ if [ -n "${adb_revsrclist}" ]
|
538
|
582
|
then
|
539
|
|
- cp -f "${adb_backupfile}" "${adb_dnsfile}" >/dev/null 2>&1
|
540
|
|
- f_log "adblocklist backup restored"
|
541
|
|
- else
|
542
|
|
- > "${adb_dnsfile}"
|
543
|
|
- f_log="empty adblocklist generated"
|
|
583
|
+ find "${adb_dnsdir}" -maxdepth 1 -type f \( ${adb_revsrcfind} \) -exec rm -f "{}" \; 2>/dev/null
|
|
584
|
+ if [ $((rc)) -eq 0 ]
|
|
585
|
+ then
|
|
586
|
+ f_log "bogus adblocklists removed"
|
|
587
|
+ else
|
|
588
|
+ f_log "error during removal of bogus adblocklists" "${rc}"
|
|
589
|
+ f_remove
|
|
590
|
+ fi
|
|
591
|
+ fi
|
|
592
|
+
|
|
593
|
+ # restore backups
|
|
594
|
+ #
|
|
595
|
+ if [ "${backup_ok}" = "true" ] && [ -d "${adb_backupdir}" ] && [ "$(printf "${adb_backupdir}/${adb_dnsprefix}."*)" != "${adb_backupdir}/${adb_dnsprefix}.*" ]
|
|
596
|
+ then
|
|
597
|
+ cp -f "${adb_backupdir}/${adb_dnsprefix}."* "${adb_dnsdir}" >/dev/null 2>&1
|
|
598
|
+ rc=${?}
|
|
599
|
+ if [ $((rc)) -eq 0 ]
|
|
600
|
+ then
|
|
601
|
+ f_log "all available backups restored"
|
|
602
|
+ else
|
|
603
|
+ f_log "error during restore" "${rc}"
|
|
604
|
+ f_remove
|
|
605
|
+ fi
|
544
|
606
|
fi
|
545
|
607
|
/etc/init.d/dnsmasq restart >/dev/null 2>&1
|
546
|
608
|
f_remove
|
|
@@ -616,55 +678,3 @@ f_ntpcheck()
|
616
|
678
|
f_restore
|
617
|
679
|
fi
|
618
|
680
|
}
|
619
|
|
-
|
620
|
|
-####################################################################
|
621
|
|
-# f_dnscheck: dnsmasq health check with newly generated adblock list
|
622
|
|
-#
|
623
|
|
-f_dnscheck()
|
624
|
|
-{
|
625
|
|
- local dns_status
|
626
|
|
- dns_status="$(logread -l 20 -e "dnsmasq" -e "FAILED to start up")"
|
627
|
|
- rc=${?}
|
628
|
|
- if [ -z "${dns_status}" ]
|
629
|
|
- then
|
630
|
|
- dns_status="$(nslookup "${adb_domain}" 2>/dev/null | grep -F "${adb_ip}")"
|
631
|
|
- rc=${?}
|
632
|
|
- if [ -z "${dns_status}" ]
|
633
|
|
- then
|
634
|
|
- if [ "${backup_ok}" = "true" ]
|
635
|
|
- then
|
636
|
|
- cp -f "${adb_dnsfile}" "${adb_backupfile}" >/dev/null 2>&1
|
637
|
|
- f_log "new adblock list with ${adb_count} domains loaded, backup generated"
|
638
|
|
- else
|
639
|
|
- f_log "new adblock list with ${adb_count} domains loaded, no backup"
|
640
|
|
- fi
|
641
|
|
- else
|
642
|
|
- f_log "nslookup probe failed" "${rc}"
|
643
|
|
- f_restore
|
644
|
|
- fi
|
645
|
|
- else
|
646
|
|
- f_log "dnsmasq probe failed" "${rc}"
|
647
|
|
- f_restore
|
648
|
|
- fi
|
649
|
|
-}
|
650
|
|
-
|
651
|
|
-##########################################################
|
652
|
|
-# f_footer: write footer with a few statistics to dns file
|
653
|
|
-#
|
654
|
|
-f_footer()
|
655
|
|
-{
|
656
|
|
- local url
|
657
|
|
- adb_count="$(wc -l < "${adb_dnsfile}")"
|
658
|
|
- printf "%s\n" "####################################################" >> "${adb_dnsfile}"
|
659
|
|
- printf "%s\n" "# last adblock list update: $(date +"%d.%m.%Y - %T")" >> "${adb_dnsfile}"
|
660
|
|
- printf "%s\n" "# ${0##*/} (${adb_version}) - ${adb_count} ad/abuse domains blocked" >> "${adb_dnsfile}"
|
661
|
|
- printf "%s\n" "# domain blacklist sources:" >> "${adb_dnsfile}"
|
662
|
|
- for src in ${adb_sources}
|
663
|
|
- do
|
664
|
|
- url="${src//\&ruleset=*/}"
|
665
|
|
- printf "%s\n" "# ${url}" >> "${adb_dnsfile}"
|
666
|
|
- done
|
667
|
|
- printf "%s\n" "#####" >> "${adb_dnsfile}"
|
668
|
|
- printf "%s\n" "# ${adb_whitelist}" >> "${adb_dnsfile}"
|
669
|
|
- printf "%s\n" "####################################################" >> "${adb_dnsfile}"
|
670
|
|
-}
|