Below is a version of status.cgi which formats its output in HTML
rather than in plain text. The output of each command is placed
into a separate labeled box. I find this much easier to read.
However, it does require adding sed to m0n0wall (to escape
<, &, and > in the output of commands).
I also added output describing the router table (netstat -r).
Is there a protocol for submitting patches?
Should they be attachments rather than in-line?
--
Jim McBeath
jimmc at macrovision dot com
---------------------------------------------------------------
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH
#Do a command with a specified title
#Using this version of doCmdT gives an output like the old status.cgi
OLDdoCmdT() {
title="$1"; shift
echo "***** $title *****"
eval "$@"
}
#Do a command with the title being the same as the command
doCmd() {
doCmdT "$1" "$@"
}
#Do a command with a specified title, format results into html pre in table
doCmdT() {
title=`echo "$1" | sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g'`; shift
echo "<p>"
echo "<table border=1>"
echo "<tr bgcolor=lightblue><td align=center>$title</td></tr>"
echo -n "<tr bgcolor=white><td><pre>"
if [ $# -lt 1 ]; then
echo "!! Error in status script, not enough args to doCmdT !!"
else
eval "$@" 2>&1 | sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g'
fi
echo "</pre></tr>"
echo "</table>"
}
echo "Content-Type: text/html"
echo ""
hostname=`hostname`
title="Server statistics for $hostname"
echo "<html><head>"
echo "<title>$title</title>"
echo "</head>"
echo "<body bgcolor=white>"
echo "<h2>$title</h2>"
echo "<h3>`/bin/date`</h3>"
doCmdT "System uptime" uptime
doCmdT "Interfaces" "ifconfig -a"
doCmdT "netstat -ni" "netstat -ni"
doCmdT "Routing Tables" "netstat -nr" #new
doCmd "ipfw show"
doCmd "ipnat -lv"
doCmd "ipfstat -v"
doCmd "ipfstat -hio"
doCmdT "resolv.conf" "cat /etc/resolv.conf"
#We don't need to show our funny sed process that gets executed in doCmd,
#so put the ps output into a file and then show the file.
rm -f /tmp/ps.out
ps xauww > /tmp/ps.out
doCmdT "Processes" "cat /tmp/ps.out"
rm /tmp/ps.out
doCmd "top -b"
#echo "***** ppp status *****"
#pppctl /var/run/pppctl show links\; show physical\; \
# show lcp\; show ipcp\; show link\; show bundle
doCmdT "dhcpd.conf" "cat /var/etc/dhcpd.conf"
doCmdT "/conf/ez-ipupdate.cache" "cat /conf/ez-ipupdate.cache"
doCmdT "df" "/bin/df"
doCmdT "/var/etc/racoon.conf" "cat /var/etc/racoon.conf"
doCmdT "SPD" "/usr/sbin/setkey -DP"
doCmdT "SAD" "/usr/sbin/setkey -D"
doCmdT "last 200 system log entries" "clog /var/log/system.log | tail -n 200"
doCmdT "last 50 filter log entries" "clog /var/log/filter.log | tail -n 50"
doCmd "ls /conf"
doCmd "ls /var/run"
doCmdT "config.xml" "cat /conf/config.xml"
doCmd "kldstat"
doCmd "ngctl list"
echo "</body>"
echo "</html>" |