Browse Source

Merge pull request #2049 from dibdot/adblock

adblock: maintenance update
Hannu Nyman 9 years ago
parent
commit
eeb2ccb860

+ 2
- 2
net/adblock/Makefile View File

7
 include $(TOPDIR)/rules.mk
7
 include $(TOPDIR)/rules.mk
8
 
8
 
9
 PKG_NAME:=adblock
9
 PKG_NAME:=adblock
10
-PKG_VERSION:=0.22.1
10
+PKG_VERSION:=0.22.2
11
 PKG_RELEASE:=1
11
 PKG_RELEASE:=1
12
 PKG_LICENSE:=GPL-3.0+
12
 PKG_LICENSE:=GPL-3.0+
13
 PKG_MAINTAINER:=Dirk Brenken <dirk@brenken.org>
13
 PKG_MAINTAINER:=Dirk Brenken <dirk@brenken.org>
17
 define Package/$(PKG_NAME)
17
 define Package/$(PKG_NAME)
18
 	SECTION:=net
18
 	SECTION:=net
19
 	CATEGORY:=Network
19
 	CATEGORY:=Network
20
-	TITLE:=powerful adblock script to block ad/abuse domains
20
+	TITLE:=Powerful adblock script to block ad/abuse domains
21
 	DEPENDS:=+curl +wget
21
 	DEPENDS:=+curl +wget
22
 	PKGARCH:=all
22
 	PKGARCH:=all
23
 endef
23
 endef

+ 27
- 25
net/adblock/files/README.md View File

12
 * support of the following domain blacklist sites (free for private usage, for commercial use please check their individual licenses):
12
 * support of the following domain blacklist sites (free for private usage, for commercial use please check their individual licenses):
13
     * [pgl.yoyo.org](http://pgl.yoyo.org/adservers), approx. 2.500 entries
13
     * [pgl.yoyo.org](http://pgl.yoyo.org/adservers), approx. 2.500 entries
14
     * [malwaredomains.com](http://malwaredomains.com), approx. 16.000 entries
14
     * [malwaredomains.com](http://malwaredomains.com), approx. 16.000 entries
15
-    * [zeustracker.abuse.ch](https://zeustracker.abuse.ch), currently down
15
+    * [zeustracker.abuse.ch](https://zeustracker.abuse.ch), approx. 420 entries
16
     * [feodotracker.abuse.ch](https://feodotracker.abuse.ch), approx. 10 entries
16
     * [feodotracker.abuse.ch](https://feodotracker.abuse.ch), approx. 10 entries
17
     * [palevotracker.abuse.ch](https://palevotracker.abuse.ch), approx. 10 entries
17
     * [palevotracker.abuse.ch](https://palevotracker.abuse.ch), approx. 10 entries
18
     * [dshield.org](http://dshield.org), approx. 4.500 entries
18
     * [dshield.org](http://dshield.org), approx. 4.500 entries
19
-    * [shallalist.de](http://www.shallalist.de) (tested with the categories "adv" "costtraps" "downloads" "spyware" "tracker" "warez"), approx. 37.000 entries
19
+    * [shallalist.de](http://www.shallalist.de) (categories "adv" "costtraps" "spyware" "tracker" "warez" enabled by default), approx. 32.000 entries
20
+    * a short description of all shallalist categories can be found [online](http://www.shallalist.de/categories.html)
20
     * [spam404.com](http://www.spam404.com), approx. 5.000 entries
21
     * [spam404.com](http://www.spam404.com), approx. 5.000 entries
21
     * [winhelp2002.mvps.org](http://winhelp2002.mvps.org), approx. 15.000 entries
22
     * [winhelp2002.mvps.org](http://winhelp2002.mvps.org), approx. 15.000 entries
22
 * blocklist parsing by fast & flexible regex rulesets
23
 * blocklist parsing by fast & flexible regex rulesets
23
 * additional white- and blacklist support for manual overrides
24
 * additional white- and blacklist support for manual overrides
24
 * separate dynamic adblock network interface
25
 * separate dynamic adblock network interface
25
 * separate dynamic uhttpd instance as pixel server
26
 * separate dynamic uhttpd instance as pixel server
26
-* optional: quality checks and a powerful backup/restore handling to ensure a reliable dnsmasq service
27
+* adblock quality checks after list update to ensure a reliable dnsmasq service
28
+* optional: powerful adblock list backup/restore handling
27
 * optional: adblock updates only on pre-defined wan interfaces (useful for (mobile) multiwan setups)
29
 * optional: adblock updates only on pre-defined wan interfaces (useful for (mobile) multiwan setups)
28
-* optional: domain query logging as a background service to easily identify free and already blocked domains
30
+* optional: domain query logging as a background service to easily identify free and already blocked domains (see example output below)
31
+* optional: status & error logging to separate file (req. ntp time sync)
29
 * optional: ntp time sync
32
 * optional: ntp time sync
30
-* optional: status & error logging (req. ntp time sync)
31
 
33
 
32
 ## Prerequisites
34
 ## Prerequisites
33
 * [openwrt](https://openwrt.org) (tested only with trunk > r47025), CC should also work
35
 * [openwrt](https://openwrt.org) (tested only with trunk > r47025), CC should also work
41
 
43
 
42
 ## Usage
44
 ## Usage
43
 * select & install adblock package (*opkg install adblock*)
45
 * select & install adblock package (*opkg install adblock*)
44
-* configure /etc/config/adblock to your needs, see additional comments in *adblock.conf.sample*
46
+* configure */etc/config/adblock* to your needs, see additional comments in *adblock.conf.sample*
45
 * at least configure the ip address of the local adblock interface/uhttpd instance, needs to be a different subnet from the normal LAN
47
 * at least configure the ip address of the local adblock interface/uhttpd instance, needs to be a different subnet from the normal LAN
48
+* optional: add additional domain white- or blacklist entries, one domain per line (wildcards & regex are not allowed!), both list are located in */etc/adblock*
46
 * by default openwrts main uhttpd instance is bind to all ports of your router. For a working adblock setup you have to bind uhttpd to the standard LAN port only, please change listen_http accordingly
49
 * by default openwrts main uhttpd instance is bind to all ports of your router. For a working adblock setup you have to bind uhttpd to the standard LAN port only, please change listen_http accordingly
47
 * start /usr/bin/adblock-update.sh and check console output or *logread -e "adblock"* for errors
50
 * start /usr/bin/adblock-update.sh and check console output or *logread -e "adblock"* for errors
48
 
51
 
59
 
62
 
60
   stdout excerpt for successful adblock run:  
63
   stdout excerpt for successful adblock run:  
61
     
64
     
62
-    root@pi2wrt:~# /usr/bin/adblock-update.sh  
63
-    adblock[17771] info : domain adblock processing started (0.21.0)  
64
-    adblock[17771] info : get wan/update interface (wlan1), after 0 loops  
65
-    adblock[17771] info : get ntp time sync (0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org 3.pool.ntp.org), after 0 loops  
66
-    adblock[17771] info : shallalist archive download finished  
67
-    adblock[17771] info : shallalist archive extraction finished  
68
-    adblock[17771] info : shallalist (pre-)processing finished (adv costtraps downloads spyware tracker warez)  
69
-    adblock[17771] info : source download finished (http://pgl.yoyo.org/adservers/serverlist.php?hostformat=one-line&showintro=0&mimetype=plaintext, 2426 entries)  
70
-    adblock[17771] info : source download finished (http://mirror1.malwaredomains.com/files/justdomains, 15275 entries)  
71
-    adblock[17771] info : source download finished (https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist, 3 entries)  
72
-    adblock[17771] info : source download finished (https://feodotracker.abuse.ch/blocklist/?download=domainblocklist, 0 entries)  
73
-    adblock[17771] info : source download finished (https://palevotracker.abuse.ch/blocklists.php?download=domainblocklist, 11 entries)  
74
-    adblock[17771] info : source download finished (http://www.dshield.org/feeds/suspiciousdomains_Low.txt, 4542 entries)  
75
-    adblock[17771] info : source download finished (http://spam404bl.com/spam404scamlist.txt, 5193 entries)  
76
-    adblock[17771] info : source download finished (http://winhelp2002.mvps.org/hosts.txt, 13852 entries)  
77
-    adblock[17771] info : source download finished (file:////tmp/tmp.emlDeH/shallalist.txt, 36961 entries)  
78
-    adblock[17771] info : source download finished (file:///etc/adblock/adblock.blacklist, 1 entries)  
79
-    adblock[17771] info : new adblock list with 73090 domains loaded, backup generated  
80
-    adblock[17771] info : domain adblock processing finished (0.21.0)  
65
+    adblock[11541] info : domain adblock processing started (0.22.2, r47665, 29.11.2015 14:58:11)  
66
+    adblock[11541] info : wan update check will be disabled  
67
+    adblock[11541] info : get ntp time sync (192.168.254.254), after 0 loops  
68
+    adblock[11541] info : shallalist (pre-)processing started ...  
69
+    adblock[11541] info : shallalist (pre-)processing finished (adv costtraps spyware tracker warez)  
70
+    adblock[11541] info : source download finished (http://pgl.yoyo.org/adservers/serverlist.php?hostformat=one-line&showintro=0&mimetype=plaintext, 2423 entries)  
71
+    adblock[11541] info : source download finished (http://mirror1.malwaredomains.com/files/justdomains, 16016 entries)  
72
+    adblock[11541] info : source download finished (https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist, 419 entries)  
73
+    adblock[11541] info : source download finished (https://feodotracker.abuse.ch/blocklist/?download=domainblocklist, 0 entries)  
74
+    adblock[11541] info : source download finished (https://palevotracker.abuse.ch/blocklists.php?download=domainblocklist, 12 entries)  
75
+    adblock[11541] info : source download finished (http://www.dshield.org/feeds/suspiciousdomains_Low.txt, 4542 entries)  
76
+    adblock[11541] info : source download finished (http://spam404bl.com/spam404scamlist.txt, 5193 entries)  
77
+    adblock[11541] info : source download finished (http://winhelp2002.mvps.org/hosts.txt, 13635 entries)  
78
+    adblock[11541] info : source download finished (file:////tmp/tmp.CgbMmO/shallalist.txt, 32446 entries)  
79
+    adblock[11541] info : empty source download finished (file:///etc/adblock/adblock.blacklist)  
80
+    adblock[11541] info : domain merging finished  
81
+    adblock[11541] info : new adblock list with 69646 domains loaded, backup generated  
82
+    adblock[11541] info : domain adblock processing finished (0.22.2, r47665, 29.11.2015 14:59:23)  
81
     
83
     
82
 
84
 
83
   generated domain blocklist for dnsmasq:  
85
   generated domain blocklist for dnsmasq:  

+ 17
- 16
net/adblock/files/adblock-helper.sh View File

195
 
195
 
196
     # check main uhttpd configuration
196
     # check main uhttpd configuration
197
     #
197
     #
198
-    check_uhttpd="$(uci get uhttpd.main.listen_http 2>/dev/null | grep -o "0.0.0.0")"
198
+    check_uhttpd="$(uci get uhttpd.main.listen_http 2>/dev/null | grep -Fo "0.0.0.0")"
199
     if [ -n "${check_uhttpd}" ]
199
     if [ -n "${check_uhttpd}" ]
200
     then
200
     then
201
         rc=530
201
         rc=530
287
     if [ -z "${check}" ]
287
     if [ -z "${check}" ]
288
     then
288
     then
289
         curl_parm="-q --insecure"
289
         curl_parm="-q --insecure"
290
-        wget_parm="--no-config --no-check-certificate"
290
+        wget_parm="--no-config --no-hsts --no-check-certificate"
291
     else
291
     else
292
         curl_parm="-q"
292
         curl_parm="-q"
293
-        wget_parm="--no-config"
293
+        wget_parm="--no-config --no-hsts"
294
     fi
294
     fi
295
 
295
 
296
     # check total and swap memory
296
     # check total and swap memory
297
     #
297
     #
298
-    mem_total="$(cat /proc/meminfo | grep "MemTotal" | grep -o "[0-9]*")"
299
-    mem_free="$(cat /proc/meminfo | grep "MemFree" | grep -o "[0-9]*")"
300
-    swap_total="$(cat /proc/meminfo | grep "SwapTotal" | grep -o "[0-9]*")"
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]*")"
301
     if [ $((mem_total)) -le 64000 ] && [ $((swap_total)) -eq 0 ]
301
     if [ $((mem_total)) -le 64000 ] && [ $((swap_total)) -eq 0 ]
302
     then
302
     then
303
-        f_log "please consider to add an external swap device to supersize your /tmp directory (total: ${mem_total}, free: ${mem_free}, swap: ${mem_swap})"
303
+        f_log "please consider adding an external swap device to supersize your /tmp directory (total: ${mem_total}, free: ${mem_free}, swap: ${mem_swap})"
304
     fi
304
     fi
305
 
305
 
306
     # check backup configuration
306
     # check backup configuration
323
     then
323
     then
324
         # check find capabilities
324
         # check find capabilities
325
         #
325
         #
326
-        check="$(find --help 2>&1 | grep "mtime")"
326
+        check="$(find --help 2>&1 | grep -F "mtime")"
327
         if [ -z "${check}" ]
327
         if [ -z "${check}" ]
328
         then
328
         then
329
             query_ok="false"
329
             query_ok="false"
340
         if [ -s "${adb_querypid}" ]
340
         if [ -s "${adb_querypid}" ]
341
         then
341
         then
342
             kill -9 "$(cat "${adb_querypid}")" >/dev/null 2>&1
342
             kill -9 "$(cat "${adb_querypid}")" >/dev/null 2>&1
343
-            f_log "remove old dns query log background process (pid: $(cat "${adb_querypid}"))"
343
+            f_log "remove old dns query log background process (pid: $(cat "${adb_querypid}" 2>/dev/null))"
344
             > "${adb_querypid}"
344
             > "${adb_querypid}"
345
         fi
345
         fi
346
     fi
346
     fi
442
         then
442
         then
443
             class="error"
443
             class="error"
444
             log_rc=", rc: ${log_rc}"
444
             log_rc=", rc: ${log_rc}"
445
+            log_msg="${log_msg}${log_rc}"
445
         fi
446
         fi
446
-        /usr/bin/logger -s -t "adblock[${pid}] ${class}" "${log_msg}${log_rc}"
447
+        /usr/bin/logger -s -t "adblock[${pid}] ${class}" "${log_msg}"
447
         if [ "${log_ok}" = "true" ] && [ "${ntp_ok}" = "true" ]
448
         if [ "${log_ok}" = "true" ] && [ "${ntp_ok}" = "true" ]
448
         then
449
         then
449
-            printf "%s\n" "$(/bin/date "+%d.%m.%Y %H:%M:%S") adblock[${pid}] ${class}: ${log_msg}${log_rc}" >> "${adb_logfile}"
450
+            printf "%s\n" "$(/bin/date "+%d.%m.%Y %H:%M:%S") adblock[${pid}] ${class}: ${log_msg}" >> "${adb_logfile}"
450
         fi
451
         fi
451
     fi
452
     fi
452
 }
453
 }
500
     then
501
     then
501
        rm -rf "${adb_tmpdir}" >/dev/null 2>&1
502
        rm -rf "${adb_tmpdir}" >/dev/null 2>&1
502
     fi
503
     fi
503
-    f_log "domain adblock processing finished (${adb_version}, ${openwrt_version})"
504
+    f_log "domain adblock processing finished (${adb_version}, ${openwrt_version}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
504
     exit ${rc}
505
     exit ${rc}
505
 }
506
 }
506
 
507
 
516
         then
517
         then
517
             kill -9 "$(cat "${adb_querypid}")" >/dev/null 2>&1
518
             kill -9 "$(cat "${adb_querypid}")" >/dev/null 2>&1
518
             find "${adb_backupdir}" -maxdepth 1 -type f -mtime +"${adb_queryhistory}" -name "${query_name}.*" -exec rm -f {} \; 2>/dev/null
519
             find "${adb_backupdir}" -maxdepth 1 -type f -mtime +"${adb_queryhistory}" -name "${query_name}.*" -exec rm -f {} \; 2>/dev/null
519
-            f_log "remove old dns query log background process (pid: $(cat "${adb_querypid}")) and do logfile housekeeping"
520
+            f_log "remove old domain query log background process (pid: $(cat "${adb_querypid}")) and do logfile housekeeping"
520
             > "${adb_querypid}"
521
             > "${adb_querypid}"
521
         fi
522
         fi
522
         if [ ! -s "${adb_querypid}" ]
523
         if [ ! -s "${adb_querypid}" ]
523
         then
524
         then
524
-            ( logread -f 2>/dev/null & printf ${!} > "${adb_querypid}" ) | egrep -o "(query\[A\].*)|([a-z0-9\.\-]* is ${query_ip}$)" >> "${adb_queryfile}.${query_date}" &
525
-            f_log "new domain query log background process started (pid: $(cat "${adb_querypid}"))"
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"
526
         fi
527
         fi
527
     fi
528
     fi
528
     f_deltemp
529
     f_deltemp
626
     rc=${?}
627
     rc=${?}
627
     if [ -z "${dns_status}" ]
628
     if [ -z "${dns_status}" ]
628
     then
629
     then
629
-        dns_status="$(nslookup "${adb_domain}" 2>/dev/null | grep "${adb_ip}")"
630
+        dns_status="$(nslookup "${adb_domain}" 2>/dev/null | grep -F "${adb_ip}")"
630
         rc=${?}
631
         rc=${?}
631
         if [ -z "${dns_status}" ]
632
         if [ -z "${dns_status}" ]
632
         then
633
         then

+ 15
- 15
net/adblock/files/adblock-update.sh View File

25
 
25
 
26
 # set script version
26
 # set script version
27
 #
27
 #
28
-adb_version="0.22.1"
28
+adb_version="0.22.2"
29
 
29
 
30
 # get current pid, script directory and openwrt version
30
 # get current pid, script directory and openwrt version
31
 #
31
 #
54
 
54
 
55
 # start logging
55
 # start logging
56
 #
56
 #
57
-f_log "domain adblock processing started (${adb_version}, ${openwrt_version})"
57
+f_log "domain adblock processing started (${adb_version}, ${openwrt_version}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
58
 
58
 
59
 # load environment
59
 # load environment
60
 #
60
 #
74
 then
74
 then
75
     # download shallalist archive
75
     # download shallalist archive
76
     #
76
     #
77
+    f_log "shallalist (pre-)processing started ..."
77
     shalla_archive="${adb_tmpdir}/shallalist.tar.gz"
78
     shalla_archive="${adb_tmpdir}/shallalist.tar.gz"
78
     shalla_file="${adb_tmpdir}/shallalist.txt"
79
     shalla_file="${adb_tmpdir}/shallalist.txt"
79
     curl ${curl_parm} --max-time "${adb_maxtime}" "${adb_arc_shalla}" --output "${shalla_archive}" 2>/dev/null
80
     curl ${curl_parm} --max-time "${adb_maxtime}" "${adb_arc_shalla}" --output "${shalla_archive}" 2>/dev/null
80
     rc=${?}
81
     rc=${?}
81
-    if [ $((rc)) -eq 0 ]
82
+    if [ $((rc)) -ne 0 ]
82
     then
83
     then
83
-        f_log "shallalist archive download finished"
84
-    else
85
         f_log "shallalist archive download failed (${adb_arc_shalla})" "${rc}"
84
         f_log "shallalist archive download failed (${adb_arc_shalla})" "${rc}"
86
         f_restore
85
         f_restore
87
     fi
86
     fi
91
     > "${shalla_file}"
90
     > "${shalla_file}"
92
     for category in ${adb_cat_shalla}
91
     for category in ${adb_cat_shalla}
93
     do
92
     do
94
-        tar -C "${adb_tmpdir}" -xzf "${shalla_archive}" BL/${category}/domains 2>/dev/null
93
+        tar -xOzf "${shalla_archive}" BL/${category}/domains 2>/dev/null >> "${shalla_file}"
95
         rc=${?}
94
         rc=${?}
96
-        if [ $((rc)) -eq 0 ]
95
+        if [ $((rc)) -ne 0 ]
97
         then
96
         then
98
-            if [ -r "${adb_tmpdir}/BL/${category}/domains" ]
99
-            then
100
-                cat "${adb_tmpdir}/BL/${category}/domains" 2>/dev/null >> "${shalla_file}"
101
-            fi
102
-        else
103
             f_log "shallalist archive extraction failed (${category})" "${rc}"
97
             f_log "shallalist archive extraction failed (${category})" "${rc}"
104
             f_restore
98
             f_restore
105
         fi
99
         fi
157
 # remove whitelist domains, sort domains and make them unique
151
 # remove whitelist domains, sort domains and make them unique
158
 # and finally rewrite ad/abuse domain information to dnsmasq file
152
 # and finally rewrite ad/abuse domain information to dnsmasq file
159
 #
153
 #
160
-> "${adb_dnsfile}"
161
-grep -vxf "${adb_whitelist}" < "${adb_tmpfile}" 2>/dev/null | sort -u 2>/dev/null | eval "${adb_dnsformat}" 2>/dev/null >> "${adb_dnsfile}"
162
-rc=${?}
154
+if [ -s "${adb_whitelist}" ]
155
+then
156
+    grep -Fvxf "${adb_whitelist}" "${adb_tmpfile}" 2>/dev/null | sort -u 2>/dev/null | eval "${adb_dnsformat}" 2>/dev/null > "${adb_dnsfile}"
157
+    rc=${?}
158
+else
159
+    sort -u "${adb_tmpfile}" 2>/dev/null | eval "${adb_dnsformat}" 2>/dev/null > "${adb_dnsfile}"
160
+    rc=${?}
161
+fi
162
+
163
 if [ $((rc)) -eq 0 ]
163
 if [ $((rc)) -eq 0 ]
164
 then
164
 then
165
     rm -f "${adb_tmpfile}" >/dev/null 2>&1
165
     rm -f "${adb_tmpfile}" >/dev/null 2>&1

+ 1
- 1
net/adblock/files/adblock.blacklist View File

1
-bild.de
1
+

+ 0
- 1
net/adblock/files/adblock.conf View File

63
 	option adb_arc_shalla "http://www.shallalist.de/Downloads/shallalist.tar.gz"
63
 	option adb_arc_shalla "http://www.shallalist.de/Downloads/shallalist.tar.gz"
64
 	list adb_catlist "adv"
64
 	list adb_catlist "adv"
65
 	list adb_catlist "costtraps"
65
 	list adb_catlist "costtraps"
66
-	list adb_catlist "downloads"
67
 	list adb_catlist "spyware"
66
 	list adb_catlist "spyware"
68
 	list adb_catlist "tracker"
67
 	list adb_catlist "tracker"
69
 	list adb_catlist "warez"
68
 	list adb_catlist "warez"

+ 1
- 4
net/adblock/files/adblock.whitelist View File

1
-downloads.openwrt.org
2
-ftp.de.debian.org
3
-download.eclipse.org
4
-dl.sourceforge.net
1
+