adblock: release 3.6.3
authorDirk Brenken <dev@brenken.org>
Mon, 14 Jan 2019 14:58:13 +0000 (15:58 +0100)
committerDirk Brenken <dev@brenken.org>
Mon, 14 Jan 2019 14:58:13 +0000 (15:58 +0100)
* the DNS Report now displays the hostname, MAC-Address or
  client IP (CLI & LuCI)
* Filter the DNS Query result set for a particular domain, client or
  time frame (CLI & LuCI)
* remove needless XHR.Poll-Events from Reporting page in LuCI
* remove needless 'force sort' option in LuCI

Signed-off-by: Dirk Brenken <dev@brenken.org>
net/adblock/Makefile
net/adblock/files/adblock.init
net/adblock/files/adblock.sh

index d05c9c51b2b10c8b064200505a8d0b1b3c009ec5..fb807feaf2828ebb325fa5bad1ff5c8b1eb74ff6 100644 (file)
@@ -6,7 +6,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=adblock
-PKG_VERSION:=3.6.2
+PKG_VERSION:=3.6.3
 PKG_RELEASE:=1
 PKG_LICENSE:=GPL-3.0+
 PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>
index 2378a55b33110cc5077429802d5c0f9465623e51..74cbf01bb38446ba510b3f4fb720280e7b743316 100755 (executable)
@@ -8,7 +8,7 @@ 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  Print dns query statistics
+       report  <SEARCH> Print dns query statistics with an optional search parameter
        status  Print runtime information"
 
 adb_init="/etc/init.d/adblock"
@@ -81,7 +81,7 @@ query()
 report()
 {
        [ -s "${adb_pidfile}" ] && return 1
-       rc_procd "${adb_script}" report "${1}"
+       rc_procd "${adb_script}" report "${1:-"+"}" "${2:-"50"}" "${3:-"false"}" "${4:-"true"}"
 }
 
 status()
index 5e2bb897254c1f5bd03096cd4d177f1ed85435b9..2f36c40bcc544e8e2cf78575c134f0c3ab26f95c 100755 (executable)
@@ -10,7 +10,7 @@
 #
 LC_ALL=C
 PATH="/usr/sbin:/usr/bin:/sbin:/bin"
-adb_ver="3.6.2"
+adb_ver="3.6.3"
 adb_sysver="unknown"
 adb_enabled=0
 adb_debug=0
@@ -50,7 +50,7 @@ adb_pidfile="/var/run/adblock.pid"
 #
 f_envload()
 {
-       local dns_up sys_call sys_desc sys_model sys_ver cnt=0
+       local dns_up sys_call sys_desc sys_model cnt=0
 
        # get system information
        #
@@ -59,11 +59,6 @@ f_envload()
        then
                sys_desc="$(printf '%s' "${sys_call}" | jsonfilter -e '@.release.description')"
                sys_model="$(printf '%s' "${sys_call}" | jsonfilter -e '@.model')"
-               sys_ver="$(cat /etc/turris-version 2>/dev/null)"
-               if [ -n "${sys_ver}" ]
-               then
-                       sys_desc="${sys_desc}/${sys_ver}"
-               fi
                adb_sysver="${sys_model}, ${sys_desc}"
        fi
 
@@ -721,8 +716,9 @@ f_query()
                esac
                while [ "${domain}" != "${tld}" ]
                do
-                       search="${domain//./\.}"
-                       result="$(awk -F '/|\"| ' "/^($search|${prefix}+${search}.*${suffix}$)/{i++;{printf(\"  + %s\n\",\$${field})};if(i>9){printf(\"  + %s\n\",\"[...]\");exit}}" "${adb_dnsdir}/${adb_dnsfile}")"
+                       search="${domain//./\\.}"
+                       search="${search//[+*~%\$&\"\']/}"
+                       result="$(awk -F '/|\"| ' "/^(${search}|${prefix}+${search}.*${suffix}$)/{i++;{printf(\"  + %s\n\",\$${field})};if(i>9){printf(\"  + %s\n\",\"[...]\");exit}}" "${adb_dnsdir}/${adb_dnsfile}")"
                        printf '%s\n%s\n%s\n' ":::" "::: results for domain '${domain}'" ":::"
                        printf '%s\n' "${result:-"  - no match"}"
                        domain="${tld}"
@@ -731,7 +727,8 @@ f_query()
 
                if [ ${adb_backup} -eq 1 ] && [ -d "${adb_backupdir}" ]
                then
-                       search="${1//./\.}"
+                       search="${1//./\\.}"
+                       search="${search//[+*~%\$&\"\']/}"
                        printf '%s\n%s\n%s\n' ":::" "::: results for domain '${1}' in backups" ":::"
                        for file in ${adb_backupdir}/${adb_dnsprefix}.*.gz
                        do
@@ -1059,7 +1056,7 @@ f_main()
 #
 f_report()
 {
-       local bg_pid total blocked percent rep_clients rep_domains rep_blocked rep_latest index hold ports cnt=0 print="${1:-"true"}"
+local bg_pid total blocked percent rep_clients rep_domains rep_blocked index hold ports cnt=0 search="${1}" count="${2}" filter="${3}" print="${4}"
 
        if [ ! -x "${adb_reputil}" ]
        then
@@ -1080,6 +1077,7 @@ f_report()
                        unset bg_pid
                fi
        fi
+
        if [ -z "${bg_pid}" ] && [ "${adb_action}" != "report" ] && [ "${adb_action}" != "stop" ]
        then
                for port in ${adb_replisten}
@@ -1093,13 +1091,14 @@ f_report()
                done
                ("${adb_reputil}" -nn -s0 -l -i ${adb_repiface} ${ports} -C${adb_repchunksize} -W${adb_repchunkcnt} -w "${adb_repdir}/adb_report.pcap" >/dev/null 2>&1 &)
        fi
-       if [ "${adb_action}" = "report" ]
+
+       if [ "${adb_action}" = "report" ] && [ "${filter}" = "false" ]
        then
                > "${adb_repdir}/adb_report.raw"
                for file in "${adb_repdir}"/adb_report.pcap*
                do
                        (
-                               "${adb_reputil}" -nn -tttt -r $file 2>/dev/null | \
+                               "${adb_reputil}" -tttt -r $file 2>/dev/null | \
                                        awk -v cnt=${cnt} '!/\.lan\. /&&/ A[\? ]+|NXDomain/{a=$1;b=substr($2,0,8);c=$4;sub(/\.[0-9]+$/,"",c); \
                                        d=cnt $7;e=$(NF-1);sub(/[0-9]\/[0-9]\/[0-9]/,"NX",e);sub(/\.$/,"",e);sub(/([0-9]{1,3}\.){3}[0-9]{1,3}/,"OK",e);printf("%s\t%s\t%s\t%s\t%s\n", a,b,c,d,e)}' >> "${adb_repdir}/adb_report.raw"
                        )&
@@ -1127,7 +1126,6 @@ f_report()
                        rep_clients="$(awk '{print $3}' ${adb_repdir}/adb_report | sort | uniq -c | sort -r | awk '{ORS=" ";if(NR<=10) printf("%s_%s ",$1,$2)}')"
                        rep_domains="$(awk '{if($5!="NX")print $4}' ${adb_repdir}/adb_report | sort | uniq -c | sort -r | awk '{ORS=" ";if(NR<=10)printf("%s_%s ",$1,$2)}')"
                        rep_blocked="$(awk '{if($5=="NX")print $4}' ${adb_repdir}/adb_report | sort | uniq -c | sort -r | awk '{ORS=" ";if(NR<=10)printf("%s_%s ",$1,$2)}')"
-                       rep_latest="$(awk 'BEGIN{printf("  + %-15s%-15s%-45s%-50s%s\n","Date","Time","Client","Domain","Answer")}FNR<=50{printf("  + %-15s%-15s%-45s%-50s%s\n",$1,$2,$3,$4,$5)}' ${adb_repdir}/adb_report)"
 
                        > "${adb_repdir}/adb_report.json"
                        json_load_file "${adb_repdir}/adb_report.json" >/dev/null 2>&1
@@ -1171,69 +1169,85 @@ f_report()
                        json_dump > "${adb_repdir}/adb_report.json"
                fi
                rm -f "${adb_repdir}/adb_report.raw"
+       fi
 
-               if [ "${print}" = "true" ]
+       if [ -s "${adb_repdir}/adb_report" ]
+       then
+               search="${search//./\\.}"
+               search="${search//[+*~%\$&\"\' ]/}"
+               > "${adb_repdir}/adb_report.final"
+               awk "BEGIN{i=0}/(${search})/{i++;if(i<=${count}){printf \"%s\t%s\t%s\t%s\t%s\n\",\$1,\$2,\$3,\$4,\$5}}" "${adb_repdir}/adb_report" > "${adb_repdir}/adb_report.final"
+               if [ ! -s "${adb_repdir}/adb_report.final" ]
                then
-                       if [ -s "${adb_repdir}/adb_report.json" ]
+                       printf "%s\t%s\t%s\t%s\t%s\n" "-" "-" "-" "-" "-" > "${adb_repdir}/adb_report.final"
+               fi
+       fi
+
+       if [ "${print}" = "true" ]
+       then
+               if [ -s "${adb_repdir}/adb_report.json" ]
+               then
+                       printf "%s\n%s\n%s\n" ":::" "::: Adblock DNS-Query Report" ":::"
+                       json_load_file "${adb_repdir}/adb_report.json"
+                       json_select "data"
+                       json_get_keys keylist
+                       for key in ${keylist}
+                       do
+                               json_get_var value "${key}"
+                               eval "${key}=\"${value}\""
+                       done
+                       printf "  + %s\n  + %s\n" "Start    ::: ${start_date}, ${start_time}" "End      ::: ${end_date}, ${end_time}"
+                       printf "  + %s\n  + %s %s\n" "Total    ::: ${total}" "Blocked  ::: ${blocked}" "(${percent})"
+                       json_select ".."
+                       if json_get_type Status "top_clients" && [ "${Status}" = "array" ]
                        then
-                               printf "%s\n%s\n%s\n" ":::" "::: Adblock DNS-Query Report" ":::"
-                               json_load_file "${adb_repdir}/adb_report.json"
-                               json_select "data"
-                               json_get_keys keylist
-                               for key in ${keylist}
+                               printf "%s\n%s\n%s\n" ":::" "::: Top 10 Clients" ":::"
+                               json_select "top_clients"
+                               index=1
+                               while json_get_type Status ${index} && [ "${Status}" = "object" ]
                                do
-                                       json_get_var value "${key}"
-                                       eval "${key}=\"${value}\""
+                                       json_get_values client ${index}
+                                       printf "  + %-9s::: %s\n" ${client}
+                                       index=$((index + 1))
                                done
-                               printf "  + %s\n  + %s\n" "Start    ::: ${start_date}, ${start_time}" "End      ::: ${end_date}, ${end_time}"
-                               printf "  + %s\n  + %s %s\n" "Total    ::: ${total}" "Blocked  ::: ${blocked}" "(${percent})"
-                               json_select ".."
-                               if json_get_type Status "top_clients" && [ "${Status}" = "array" ]
-                               then
-                                       printf "%s\n%s\n%s\n" ":::" "::: Top 10 Clients" ":::"
-                                       json_select "top_clients"
-                                       index=1
-                                       while json_get_type Status ${index} && [ "${Status}" = "object" ]
-                                       do
-                                               json_get_values client ${index}
-                                               printf "  + %-9s::: %s\n" ${client}
-                                               index=$((index + 1))
-                                       done
-                               fi
-                               json_select ".."
-                               if json_get_type Status "top_domains" && [ "${Status}" = "array" ]
-                               then
-                                       printf "%s\n%s\n%s\n" ":::" "::: Top 10 Domains" ":::"
-                                       json_select "top_domains"
-                                       index=1
-                                       while json_get_type Status ${index} && [ "${Status}" = "object" ]
-                                       do
-                                               json_get_values domain ${index}
-                                               printf "  + %-9s::: %s\n" ${domain}
-                                               index=$((index + 1))
-                                       done
-                               fi
-                               json_select ".."
-                               if json_get_type Status "top_blocked" && [ "${Status}" = "array" ]
-                               then
-                                       printf "%s\n%s\n%s\n" ":::" "::: Top 10 Blocked Domains" ":::"
-                                       json_select "top_blocked"
-                                       index=1
-                                       while json_get_type Status ${index} && [ "${Status}" = "object" ]
-                                       do
-                                               json_get_values blocked ${index}
-                                               printf "  + %-9s::: %s\n" ${blocked}
-                                               index=$((index + 1))
-                                       done
-                               fi
+                       fi
+                       json_select ".."
+                       if json_get_type Status "top_domains" && [ "${Status}" = "array" ]
+                       then
+                               printf "%s\n%s\n%s\n" ":::" "::: Top 10 Domains" ":::"
+                               json_select "top_domains"
+                               index=1
+                               while json_get_type Status ${index} && [ "${Status}" = "object" ]
+                               do
+                                       json_get_values domain ${index}
+                                       printf "  + %-9s::: %s\n" ${domain}
+                                       index=$((index + 1))
+                               done
+                       fi
+                       json_select ".."
+                       if json_get_type Status "top_blocked" && [ "${Status}" = "array" ]
+                       then
+                               printf "%s\n%s\n%s\n" ":::" "::: Top 10 Blocked Domains" ":::"
+                               json_select "top_blocked"
+                               index=1
+                               while json_get_type Status ${index} && [ "${Status}" = "object" ]
+                               do
+                                       json_get_values blocked ${index}
+                                       printf "  + %-9s::: %s\n" ${blocked}
+                                       index=$((index + 1))
+                               done
+                       fi
+                       if [ -s "${adb_repdir}/adb_report.final" ]
+                       then
                                printf "%s\n%s\n%s\n" ":::" "::: Latest DNS Queries" ":::"
-                               printf "%s\n" "${rep_latest}"
-                       else
-                               printf "%s\n%s\n%s\n" ":::" "::: no reporting data available yet" ":::"
+                               printf "%-15s%-15s%-45s%-50s%s\n" "Date" "Time" "Client" "Domain" "Answer"
+                               awk '{printf "%-15s%-15s%-45s%-50s%s\n",$1,$2,$3,$4,$5}' "${adb_repdir}/adb_report.final"
                        fi
+               else
+                       printf "%s\n%s\n%s\n" ":::" "::: no reporting data available yet" ":::"
                fi
        fi
-       f_log "debug" "f_report ::: action: ${adb_action}, report: ${adb_report}, print: ${print}, reputil: ${adb_reputil}, repdir: ${adb_repdir}, repiface: ${adb_repiface}, replisten: ${adb_replisten}, repchunksize: ${adb_repchunksize}, repchunkcnt: ${adb_repchunkcnt}, bg_pid: ${bg_pid}"
+       f_log "debug" "f_report ::: action: ${adb_action}, report: ${adb_report}, search: ${1}, count: ${2}, filter: ${3}, print: ${4}, reputil: ${adb_reputil}, repdir: ${adb_repdir}, repiface: ${adb_repiface}, replisten: ${adb_replisten}, repchunksize: ${adb_repchunksize}, repchunkcnt: ${adb_repchunkcnt}, bg_pid: ${bg_pid}"
 }
 
 # source required system libraries
@@ -1251,11 +1265,11 @@ fi
 f_envload
 case "${adb_action}" in
        stop)
-               f_report false
+               f_report "+" "50" "false" "false"
                f_rmdns
        ;;
        restart)
-               f_report false
+               f_report "+" "50" "false" "false"
                f_rmdns
                f_envcheck
                f_main
@@ -1267,13 +1281,13 @@ case "${adb_action}" in
                f_switch resume
        ;;
        report)
-               f_report "${2}"
+               f_report "${2}" "${3}" "${4}" "${5}"
        ;;
        query)
                f_query "${2}"
        ;;
        start|reload)
-               f_report false
+               f_report "+" "50" "false" "false"
                f_envcheck
                f_main
        ;;