#!/bin/sh
#------------------------------------------------------------------------------
# syslog.cgi - show the syslog-file
#
# Creation: 24.02.2001 tg
# Last Update: $Id$
#
#------------------------------------------------------------------------------
# get main helper functions
. /srv/www/include/cgi-helper
# Functions
get_file_from_target ()
{
set -f # disable pathname expansion
while read a b
do
if [ "$FORM_target" = "$a" -a -f "$b" ]
then
syslogfile=$b
fi
done < /etc/syslog.conf
set +f
}
dump_log ()
{
case $FORM_filter in
"") cat $syslogfile ;;
*) grep -v $FORM_filter $syslogfile ;;
esac
}
format_output ()
{
htmlspecialchars | while read line
do
case "$line" in
'') ;;
*)
set -f
set -- $line
def="
$1 $2 | $3 | $4 | "
case $5$6$7 in
"--MARK--"*|"lastmessagerepeated"*)
def="$def | "
sn=4
facil="mark"
;;
kernel*)
def="$def$5 $6 | "
sn=6
facil="$6"
;;
*)
def="$def$5 | "
sn=5
facil="$5"
;;
esac
shift $sn
echo "$def$* |
"
set +f
;;
esac
done
}
: ${FORM_action:=view}
# Security
check_rights "logs" "$FORM_action"
if [ ! -f /etc/syslog.conf ]
then
show_html_header "$_MN_err"
show_error "$_MN_err" "$_SLOG_nosyslog"
show_html_footer
else
case $FORM_action in
reset|$_MN_reset)
get_file_from_target
case $syslogfile in
"") ;;
*)
> $syslogfile
;;
esac
echo "Location: $myname?target=$FORM_target"
echo
;;
download|$_MN_download)
get_file_from_target
case $syslogfile in "");;
*)
http_header download "ctype=text/plain;filename=`basename $syslogfile`"
dump_log
;;
esac
;;
*)
# standard sort method is reverse
: ${FORM_sort:=normal}
case $FORM_sort in reverse) sort="normal" ;; *) sort="reverse" ;; esac
# show all rows if the "all rows" button is pressed
case $FORM_showall in "") ;; *) FORM_lines="$_MN_all" ;; esac
# sanitize no. of rows: show the default of 50 rows if nothing or nonsens (no integer) is specified
case $FORM_lines in all|"$_MN_all") ;; *[^0-9]*|"") FORM_lines=50 ;; esac
while read target to
do
if [ -f "$to" ]
then
case $FORM_target in
""|"$target")
tabs="${tabs}\"$_SLOG_syslogfile: $to\" no "
FORM_target="$target"
;;
*)
tabs="${tabs}\"$_SLOG_syslogfile: $to\" \"$myname?target=$target&lines=$FORM_lines&sort=$FORM_sort\" "
;;
esac
fi
done < /etc/syslog.conf
### Remove syslog-dest in window-header
### show_html_header "Syslog" "subtitle=\"($FORM_target)\""
show_html_header "Syslog"
get_file_from_target
case $syslogfile in
"") show_error "$_MN_err" "$_SLOG_nofile ($FORM_target)" ;;
*)
case $FORM_lines in
all|"$_MN_all")
# is "all"
n="$_MN_all"
case $FORM_sort in
normal)
dump_log | format_output > /tmp/sysout.$$
;;
*)
dump_log | sed '1!G;h;$!d' | format_output > /tmp/sysout.$$
;;
esac
;;
*)
# is an integer
n=$FORM_lines
case $FORM_sort in
normal)
dump_log | do_tail $n | format_output > /tmp/sysout.$$
;;
*)
dump_log | do_tail $n | sed '1!G;h;$!d' | format_output > /tmp/sysout.$$
;;
esac
;;
esac
eval show_tab_header $tabs
echo "$_SLOG_syslogfile: $syslogfile ($FORM_target)
"
# Display form to change number of shown rows of logfile
cat <<-EOF
EOF
echo "$_MN_date | $_MN_time | $_SLOG_loghost | $_SLOG_syslogfacil | $_SLOG_message |
"
cat /tmp/sysout.$$
rm /tmp/sysout.$$
echo '
'
show_tab_footer
;;
esac
show_html_footer
;;
esac
fi