#!/bin/sh #------------------------------------------------------------------------------ # logip.cgi - show log of wan-ip # # Creation: 20007-10-18 lanspezi # Last Update: $Id$ # #------------------------------------------------------------------------------ # get main helper functions . /srv/www/include/cgi-helper format_output() { htmlspecialchars | while read line do dat=`echo $line | cut -d "|" -f 1` typ=`echo $line | cut -d "|" -f 2` ip=`echo $line | cut -d "|" -f 3` interface=`echo $line | cut -d "|" -f 4` name=`echo $line | cut -d "|" -f 5` is_default_route=`echo $line | cut -d "|" -f 6` if [ "x$interface" = "x" ] then interface="-" fi if [ "x$is_default_route" = "x" ] then is_default_route="-" fi echo "" echo "$dat" echo "$typ" echo "$ip" echo "$interface" echo "$name" echo "$is_default_route" echo "" done } : ${FORM_action:=view} # Security check_rights "logs" "$FORM_action" logip_ok=true if [ -f /var/run/logip.conf ] then . /var/run/logip.conf else logip_ok=false fi # Check if logip.log exist if [ ! -f ${LOGIP_LOGDIR}/logip.log -o "$logip_ok" = "false" ] then show_html_header "$_MN_err" show_error "$_MN_err" "logip.log $_MM_notexist." show_html_footer exit 1 fi ATIME=1 tmp="/tmp/$myname.$$" case $FORM_action in reset|$_MN_reset) show_html_header "$_MN_resetting ${LOGIP_LOGDIR}/logip.log ..." "refresh=$ATIME;url=$myname" > ${LOGIP_LOGDIR}/logip.log show_info "" "$_MN_resetting ${LOGIP_LOGDIR}/logip.log" show_html_footer ;; download|$_MN_download) http_header download "ctype=text/plain;filename=logip.log" cat ${LOGIP_LOGDIR}/logip.log ;; *) : ${FORM_sort:=reverse} 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=30 ;; esac case $FORM_lines in all|"$_MN_all"|*[^0-9]*) # is "all" n="$_MN_all" case $FORM_sort in normal) cat ${LOGIP_LOGDIR}/logip.log | format_output > /tmp/logip.$$ ;; *) cat ${LOGIP_LOGDIR}/logip.log | sed '1!G;h;$!d' | format_output > /tmp/logip.$$ ;; esac ;; *[0-9]*) # is an integer n=$FORM_lines case $FORM_sort in normal) cat ${LOGIP_LOGDIR}/logip.log | do_tail $n | format_output > /tmp/logip.$$ ;; *) cat ${LOGIP_LOGDIR}/logip.log | do_tail $n | sed '1!G;h;$!d' | format_output > /tmp/logip.$$ ;; esac ;; esac show_html_header "$_LOGIP_maintitle" show_tab_header "$_LOGIP_title" no echo "

$_LOGIP_maintitle ($n $_MN_rows)

" cat <<-EOF
 $_MN_rows  
EOF echo '' echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" cat /tmp/logip.$$ rm /tmp/logip.$$ echo "
$_LOGIP_date$_LOGIP_typ$_LOGIP_ip$_LOGIP_interface$_LOGIP_name$_LOGIP_is_default_route
" show_tab_footer show_html_footer ;; esac