#!/bin/sh
#This script is created by ssparser automatically. The parser first created by MaoShouyan
printf "Content-type: text/html
Cache-Control: no-cache

"
echo -n "";
. ../common/common.sh
myself="/cgi-bin/Monitor/`basename $0`"
afm_load_page 30 "${myself}?title=${CGI_title}"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function popupurl(url, width, height)
{
        ShowWindow(url, \"scrollbars=1,resizable=0\", width, height);
}
</script>
<body>
"; cgi_show_title "ϵͳſ->Ϣ" 
echo -n "
<br>
";
for nameval in `${FLOWEYE} jflow stat`
do
	eval "${nameval}"
done
osver="${jflow_ipe_version}"
phymem=`sysctl -n hw.physmem`
phymem=$((${phymem} / (1024 * 1024)))
cpunum=`sysctl -n hw.ncpu`
cpumodel=`sysctl -n hw.model | cut -d'@' -f2`
curtime=$((${curtime} - 3600 * 24))
imgfile=${TMPPATH}/cpu_stat.png
floweyearg="width=700 height=200 tag=cpu.busy yname=cpu%"
errmsg=`${FLOWEYE} chart show ${floweyearg} outimg=${TMPPATH}/cpu_day.png hours=24`

echo -n "
<table style=\"width:700; font-bold:true;font-size:15px; color:#CE6C04\">
<tr><td style=\"font-size:14px\"><b>ϵͳϢ</b></td>
</table>
<table width=700 border=0 cellspacing=1 cesspadding=1> 
<tr id=row1>
"; if [ "${TOPSEC}" = "" ]; then 
echo -n "
	<td width=120 align=left>&nbsp;&nbsp;汾Ϣ</td>
	<td width=* align=left>汾Ϊ\"${BUILDREL}\"${BUILDDATE}</td>
"; else 
echo -n "
";	relver=`echo "${TOPSEC}" | cut -d'-' -f2` 
echo -n "
	<td width=120 align=left>&nbsp;&nbsp;Ʒͺ</td>
	<td width=* align=left>TF-${relver}&nbsp;[Built at ${BUILDDATE}]</td>
"; fi 
echo -n "
</tr>
<tr id=row1>
	<td align=left>&nbsp;&nbsp;&nbsp;&nbsp;</td>
	<td align=left>${osver}</td>
</tr>
"; if [ ${JOS_RELEASE} -ne 0 ]; then 
	for nameval in `${FLOWEYE} key info`; do
		eval "${nameval}"
	done
	startm=${start}
	endtm=${end}
	if [ ${startm} -ne 0 ]; then
        	startm=`date -r ${startm} "+%Y-%m-%d %H:%M:%S"`
	fi
	if [ ${endtm} -ne 0 ]; then
        	endtm=`date -r ${endtm} "+%Y-%m-%d %H:%M:%S"`
	fi
	if [ ${freeend} -ne 0 ]; then
        	freeend=`date -r ${freeend} "+%Y-%m-%d %H:%M:%S"`
	fi 
	[ "${TOPSEC}" != "" ] && flowcnt=$((${flowcnt} + ${flowcnt}))

echo -n "
	<tr id=row1>
	<td align=left>&nbsp;&nbsp;</td>
	<td align=left>${flowcnt}IP${ipcnt}</td>
	</tr>
	<tr id=row1>
	<td align=left><a style=\"color:#ff0000\">&nbsp;&nbsp;ʹʱ</a></td>
	<td align=left><a style=\"color:#ff0000\"><b>${startm}</b>-<b>${endtm}</b></a></td>
	</tr>
"; if [ ${JOS_RELEASE} -eq 1 ]; then 
echo -n "
	<tr id=row1>
	<td align=left>&nbsp;&nbsp;</td> 
	<td align=left>${startm}-${freeend}</td>
	</tr>
"; fi 
echo -n "
"; else 
echo -n "
<tr id=row1>
	<td align=left>&nbsp;&nbsp;</td>
	<td align=left>Ǳ׼棬֧256ûȫѣκʱ</td>
</tr>
"; fi 
echo -n "
</table>
";
newrate=""
delrate=""
for rate in `${FLOWEYE} flow stat | grep rate | cut -d '=' -f2 | cut -d'/' -f1`
do
        if [ "${newrate}" = "" ]; then
                newrate="${rate}"
        else
                delrate="${rate}"
        fi
        [ "${newrate}" != "" -a "${delrate}" != "" ] && break
done
floweyearg="width=700 height=200 tag=flow.newrate tag=flow.delrate yname=flows/s"
endtm=`date +%s`
errmsg=`${FLOWEYE} chart show ${floweyearg} outimg=${TMPPATH}/flowrate_day.png hours=24`
floweyearg="width=700 height=200 tag=appobj.natipcnt tag=ip yname=ip-count"
errmsg=`${FLOWEYE} chart show ${floweyearg} outimg=${TMPPATH}/iptrend_day.png hours=24`
ipcount=`${FLOWEYE} ipobj stat | grep "ip_count" | cut -d'=' -f2`
natipcnt=`${FLOWEYE} appobj stat | grep "natipcnt" | cut -d'=' -f2`

echo -n "
<br>
<table style=\"width:700; font-bold:true;font-size:15px; color:#CE6C04\">
<tr>
	<td style=\"font:14px\"><b>½</b></td>
	<td width=* style=\"font:13px\" align=right>ǰ½${newrate},ɾ${delrate}&nbsp;&nbsp;&nbsp;&nbsp;
	<a href=\"javascript:popupurl('/cgi-bin/Monitor/flow_rate?time=3day', 700, 800)\"
		onmouseover=\"TagToTip('hlp3day')\" onmouseout=\"UnTip()\"><b>նԱ</b></a>&nbsp;&nbsp;
	<a href=\"javascript:popupurl('/cgi-bin/Monitor/flow_rate?time=mon', 700, 800)\"
		onmouseover=\"TagToTip('hlpall')\" onmouseout=\"UnTip()\"><b>ʷͼ</b></a>
	</td>
</tr>
</table>
<table width=\"700\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#ffffff\">
<tr>
<td><img src=\"/tmp/flowrate_day.png\"></img></td>
</tr>
</table>
<br>
<table style=\"width:700; font-bold:true;font-size:15px; color:#CE6C04\">
<tr>
	<td style=\"font:14px\"><b>û</b></td>
	<td align=right width=* style=\"font:13px\" align=right>ǰ${ipcount},${natipcnt}&nbsp;&nbsp;&nbsp;&nbsp;
	<a href=\"javascript:popupurl('/cgi-bin/Monitor/iptrend_graph?time=3day', 700, 800)\"
		onmouseover=\"TagToTip('hlp3day')\" onmouseout=\"UnTip()\"><b>նԱ</b></a>&nbsp;&nbsp;
	<a href=\"javascript:popupurl('/cgi-bin/Monitor/iptrend_graph?time=mon', 700, 800)\"
		onmouseover=\"TagToTip('hlpall')\" onmouseout=\"UnTip()\"><b>ʷͼ</b></a>
	</td>
</tr>
</table>
<table width=\"700\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#ffffff\">
<tr>
<td><img src=\"/tmp/iptrend_day.png\"></img></td>
</tr>
</table>
<br>
<table style=\"width:700; font-bold:true;font-size:15px; color:#CE6C04\">
<tr><td style=\"font:14px\"><b>CPUʹ</b></td></tr>
</table>
<table width=\"700\" border=\"0\" cellspacing=\"1\" cellpadding=\"1\" bgcolor=\"#ffffff\">
<tr>
<td><img src=\"/tmp/cpu_day.png\"></img></td>
</tr>
</table>
</body>
</html>
";