aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/bbfw-log.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/bbfw-log.in')
-rwxr-xr-xsrc/bbfw-log.in131
1 files changed, 131 insertions, 0 deletions
diff --git a/src/bbfw-log.in b/src/bbfw-log.in
new file mode 100755
index 0000000..26acb43
--- /dev/null
+++ b/src/bbfw-log.in
@@ -0,0 +1,131 @@
1#!/bin/sh
2#
3# Bindle Binaries Linux Firewall
4# Copyright (c) 2019 David M. Syzdek <david@syzdek.net>.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
9#
10# * Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# * Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# * Neither the name of David M. Syzdek nor the
16# names of its contributors may be used to endorse or promote products
17# derived from this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR
23# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29# SUCH DAMAGE.
30#
31
32
33###############
34# ENVIRONMENT #
35###############
36
37PATH=/usr/bin:/bin:/usr/sbin:/sbin
38export PATH
39
40
41# sets script/package information
42PROG_NAME="$(basename "${0}")"
43PACKAGE_NAME="$(echo '@PACKAGE_NAME@' |sed -e 's/[@].*[@]/ /g')"
44PACKAGE_VERSION="$(echo '@PACKAGE_VERSION@' |sed -e 's/[@].*[@]/ /g')"
45PACKAGE_BUGREPORT="$(echo '@PACKAGE_BUGREPORT@' |sed -e 's/[@].*[@]/ /g')"
46
47
48
49#############
50# FUNCTIONS #
51#############
52
53usage()
54{
55 printf "Usage: ${PROG_NAME} [OPTIONS]\n"
56 printf "OPTIONS:\n"
57 printf " -h, --help print this help and exit\n"
58 printf " -k, --kerneltime print kernel timestamp\n"
59 printf " -n, --notime do not print timestamp\n"
60 printf " -t, --timestamp print human readable timestamp\n"
61 printf " -v, --version print version and exit\n"
62 printf " -w, --follow wait for new messages\n"
63 printf "\n"
64 printf "Please send bug reports to ${PACKAGE_BUGREPORT}.\n"
65}
66
67
68version()
69{
70 printf "${PROG_NAME} (${PACKAGE_NAME}) ${PACKAGE_VERSION}\n"
71 printf "\n"
72 printf "Please send bug reports to ${PACKAGE_BUGREPORT}.\n"
73}
74
75
76############
77### MAIN ###
78############
79
80DMESG_TIME="-T"
81DMESG_FOLLOW=""
82DMESG_PATTERN=" IN=[-.:/a-zA-Z0-9]{0,} OUT=[-.:/a-zA-Z0-9]{0,} MAC=[:a-fA-F0-9]{0,} SRC=[:.0-9a-fA-F]{0,} DST=[:.0-9a-fA-F]{0,} "
83
84while true; do
85 case "$@" in
86 -h|--help) usage; exit 0;;
87 -k|--kerneltime) DMESG_TIME=""; shift ;;
88 -n|--notime) DMESG_TIME="-t"; shift ;;
89 -t|--timestamp) DMESG_TIME="-T"; shift ;;
90 -v|--version) version; exit 0;;
91 -w|--follow) DMESG_FOLLOW="-w"; shift ;;
92 "") break ;;
93 --) shift; break ;;
94 *) usage; exit 1 ;;
95 esac
96done
97
98
99/bin/dmesg ${DMESG_TIME} ${DMESG_FOLLOW} \
100 |egrep "${DMESG_PATTERN}" \
101 |sed \
102 -e 's/[^[:graph:]]/ /g' \
103 -e 's/ip6tables drop: /,in,/g' \
104 -e 's/ip6tables input: /,in,/g' \
105 -e 's/ip6tables forward: /,fwd,/g' \
106 -e 's/ip6tables output: /,out,/g' \
107 -e 's/ip6tables blackhole: /,blkhol,/g' \
108 -e 's/ip6tables \([-_a-z0-9:;,]\{1,\}\): /,\1,/gi' \
109 -e 's/[[:space:][:cntrl:]]\{1,\}/ /g' \
110 -e 's/ [[:upper:]]\{1,\} / /g' \
111 -e 's/ MAC=[:[:xdigit:]]\{1,\} / /g' \
112 -e 's/ ID=[[:digit:]]\{1,\} / /g' \
113 -e 's/ TTL=[[:digit:]]\{1,\} / /g' \
114 -e 's/ LEN=[[:digit:]]\{1,\} / /g' \
115 -e 's/ URGP=[[:digit:]]\{1,\} / /g' \
116 -e 's/ WINDOW=[[:digit:]]\{1,\} / /g' \
117 -e 's/ PREC=0x[[:xdigit:]]\{1,\} / /g' \
118 -e 's/ RES=0x[[:xdigit:]]\{1,\} / /g' \
119 -e 's/ TOS=0x[[:xdigit:]]\{1,\} / /g' \
120 -e 's/ ACK / /g' \
121 -e 's/ CWR / /g' \
122 -e 's/ DF / /g' \
123 -e 's/ ECE / /g' \
124 -e 's/ RST / /g' \
125 -e 's/ SYN / /g' \
126 -e 's/ PSH / /g' \
127 -e 's/ \([A-Z]\{1,\}=\)/,\1/g' \
128 |column -t -s ','
129
130
131# End of scripts