On 10/30/2015 12:10 PM, matt darfeuille wrote:
> Hi tom,
>
> What need to be also changed:
>
> I have added a pattern for logd in the case statement in the function
> syslog_circular_buffer:
>
> syslog_circular_buffer() {
> local pid
> local tty
> local flags
> local cputime
> local path
> local args
> local arg
>
> ps 2> /dev/null | while read pid tty flags cputime path args; do
> case $path in
> syslogd|*/syslogd)
> for arg in $args; do
> if [ x$arg = x-C ]; then
> echo Yes
> return
> fi
> done
> ;;
> logd|*/logd)
> for arg in $args; do
> if [ x$arg = x-S ]; then
> echo Yes
> return
> fi
> done
> ;;
> esac
> done
> }
>
> and I have also added for logd a condition in the if statement:
> In the code block:
> g_logread=logread
> LOGFILE=logread -- LOGFILE will display logread instead of the
> default value of LOGFILE
>
> [ -z "$LOGFILE" ] && LOGFILE=/var/log/messages
>
> if ( ps ax 2> /dev/null | grep -v grep | qt grep 'syslogd.*-C' )
> ; then
> g_logread="logread | tac"
> elif ps2> /dev/null | grep -v grep | grep 'logd.*-S'; then
> g_logread=logread
> LOGFILE=$g_logread
> elif [ -r $LOGFILE ]; then
> g_logread="tac $LOGFILE"
> else
> fatal_error "LOGFILE ($LOGFILE) does not exist!"
> fi
>
> On openwrt "ps" can only be used with "w" and not with "ax"!
> Please give the attached patch a try, Matt. Thanks, -Tom -- Tom Eastep \ When I die, I want to go like my Grandfather who Shoreline, \ died peacefully in his sleep. Not screaming like Washington, USA \ all of the passengers in his car http://shorewall.net \________________________________________________
diff --git a/Shorewall-core/lib.cli b/Shorewall-core/lib.cli
index b17d68d..4accab7 100644
--- a/Shorewall-core/lib.cli
+++ b/Shorewall-core/lib.cli
@@ -154,7 +154,7 @@ syslog_circular_buffer() {
local args
local arg
- ps ax 2> /dev/null | while read pid tty flags cputime path args; do
+ ps w 2> /dev/null | while read pid tty stat time path args; do
case $path in
syslogd|*/syslogd)
for arg in $args; do
@@ -164,40 +164,96 @@ syslog_circular_buffer() {
fi
done
;;
+ logd|*/logd)
+ for arg in $args; do
+ if [ x$arg = x-S ]; then
+ echo Yes
+ return
+ fi
+ done
+ ;;
esac
done
}
+setup_logread() {
+ [ -z "$LOGFILE" ] && LOGFILE=/var/log/messages
+
+ if [ -n "$(syslog_circular_buffer)" ]; then
+ if qt mywhich tac; then
+ g_logread="logread | tac"
+ else
+ g_logread="logread"
+ fi
+ elif [ -r $LOGFILE ]; then
+ if qt mywhich tac; then
+ g_logread="tac $LOGFILE"
+ else
+ g_logread="cat $LOGFILE"
+ fi
+ else
+ fatal_error "LOGFILE ($LOGFILE) does not exist or is not readable!"
+ fi
+}
+
#
# Display the last $1 packets logged
#
packet_log() # $1 = number of messages
{
- if [ -n "$g_showmacs" -o $VERBOSITY -gt 2 ]; then
- if [ $g_family -eq 4 ]; then
- $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | head -n$1 | tac | sed 's/ kernel://; s/\[.*\] //' | sed s/" $host $LOGFORMAT"/" "/
+ if qt mywhich tac; then
+ if [ -n "$g_showmacs" -o $VERBOSITY -gt 2 ]; then
+ if [ $g_family -eq 4 ]; then
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | head -n$1 | tac | sed 's/ kernel://; s/\[.*\] //' | sed s/" $host $LOGFORMAT"/" "/
+ else
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*:.*DST=' | head -n$1 | tac | sed -r 's/ kernel://; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
+ fi
+ elif [ $g_family -eq 4 ]; then
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | head -n$1 | tac | sed 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] '// | sed s/" $host $LOGFORMAT"/" "/
else
- $g_logread | grep 'IN=.* OUT=.*SRC=.*:.*DST=' | head -n$1 | tac | sed -r 's/ kernel://; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*:.*DST=' | head -n$1 | tac | sed -r 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
fi
- elif [ $g_family -eq 4 ]; then
- $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | head -n$1 | tac | sed 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] '// | sed s/" $host $LOGFORMAT"/" "/
else
- $g_logread | grep 'IN=.* OUT=.*SRC=.*:.*DST=' | head -n$1 | tac | sed -r 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
- fi
+ if [ -n "$g_showmacs" -o $VERBOSITY -gt 2 ]; then
+ if [ $g_family -eq 4 ]; then
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | tail -n$1 | sed 's/ kernel://; s/\[.*\] //' | sed s/" $host $LOGFORMAT"/" "/
+ else
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*:.*DST=' | tail -n$1 | sed -r 's/ kernel://; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
+ fi
+ elif [ $g_family -eq 4 ]; then
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | tail -n$1 | sed 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] '// | sed s/" $host $LOGFORMAT"/" "/
+ else
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*:.*DST=' | tail -n$1 | sed -r 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
+ fi
+ fi
}
search_log() # $1 = IP address to search for
{
- if [ -n "$g_showmacs" -o $VERBOSITY -gt 2 ]; then
- if [ $g_family -eq 4 ]; then
- $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | tac | sed 's/ kernel://; s/\[.*\] //' | sed s/" $host $LOGFORMAT"/" "/
+ if qt mywhich tac; then
+ if [ -n "$g_showmacs" -o $VERBOSITY -gt 2 ]; then
+ if [ $g_family -eq 4 ]; then
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | tac | sed 's/ kernel://; s/\[.*\] //' | sed s/" $host $LOGFORMAT"/" "/
+ else
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | tac | sed -r 's/ kernel://; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
+ fi
+ elif [ $g_family -eq 4 ]; then
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | tac | sed 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] '// | sed s/" $host $LOGFORMAT"/" "/
else
- $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | tac | sed -r 's/ kernel://; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | tac | sed -r 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
fi
- elif [ $g_family -eq 4 ]; then
- $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | tac | sed 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] '// | sed s/" $host $LOGFORMAT"/" "/
else
- $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | tac | sed -r 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
+ if [ -n "$g_showmacs" -o $VERBOSITY -gt 2 ]; then
+ if [ $g_family -eq 4 ]; then
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | sed 's/ kernel://; s/\[.*\] //' | sed s/" $host $LOGFORMAT"/" "/
+ else
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | sed -r 's/ kernel://; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
+ fi
+ elif [ $g_family -eq 4 ]; then
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | sed 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] '// | sed s/" $host $LOGFORMAT"/" "/
+ else
+ $g_logread | grep 'IN=.* OUT=.*SRC=.*\..*DST=' | grep "$1" | sed -r 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] //; s/0000:/:/g; s/:::+/::/g; s/:0+/:/g' | sed s/" $host $LOGFORMAT"/" "/
+ fi
fi
}
@@ -280,17 +336,7 @@ show_bl() {
logwatch() # $1 = timeout -- if negative, prompt each time that
# an 'interesting' packet count changes
{
- if [ -z "$LOGFILE" ]; then
- LOGFILE=/var/log/messages
-
- if [ -n "$(syslog_circular_buffer)" ]; then
- g_logread="logread | tac"
- elif [ -r $LOGFILE ]; then
- g_logread="tac $LOGFILE"
- else
- fatal_error "LOGFILE ($LOGFILE) does not exist!"
- fi
- fi
+ setup_logread
host=$(echo $g_hostname | sed 's/\..*$//')
oldrejects=$($g_tool -L -v -n | grep 'LOG')
@@ -1038,17 +1084,7 @@ show_command() {
log)
[ $# -gt 2 ] && usage 1
- if [ -z "$LOGFILE" ]; then
- LOGFILE=/var/log/messages
-
- if [ -n "$(syslog_circular_buffer)" ]; then
- g_logread="logread | tac"
- elif [ -r $LOGFILE ]; then
- g_logread="tac $LOGFILE"
- else
- fatal_error "LOGFILE ($LOGFILE) does not exist!"
- fi
- fi
+ setup_logread
echo "$g_product $SHOREWALL_VERSION Log ($LOGFILE) at $g_hostname - $(date)"
echo
@@ -1427,17 +1463,7 @@ do_dump_command() {
esac
done
- if [ -z "$LOGFILE" ]; then
- LOGFILE=/var/log/messages
-
- if [ -n "$(syslog_circular_buffer)" ]; then
- g_logread="logread | tac"
- elif [ -r $LOGFILE ]; then
- g_logread="tac $LOGFILE"
- else
- fatal_error "LOGFILE ($LOGFILE) does not exist! - See http://www.shorewall.net/shorewall_logging.html"
- fi
- fi
+ setup_logread
g_ipt_options="$g_ipt_options $g_ipt_options1"
@@ -3544,15 +3570,7 @@ get_config() {
[ -n "$PATH" ] || PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
- [ -z "$LOGFILE" ] && LOGFILE=/var/log/messages
-
- if ( ps ax 2> /dev/null | grep -v grep | qt grep 'syslogd.*-C' ) ; then
- g_logread="logread | tac"
- elif [ -r $LOGFILE ]; then
- g_logread="tac $LOGFILE"
- else
- fatal_error "LOGFILE ($LOGFILE) does not exist!"
- fi
+ setup_logread
#
# See if we have a real version of "tail" -- use separate redirection so
# that ash (aka /bin/sh on LRP) doesn't crap
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------------
_______________________________________________ Shorewall-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/shorewall-users
