#!/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 "
<body>
"; cgi_show_title "${CGI_title}" 
echo -n "
<br>
";
for nameval in `${FLOWEYE} jflow stat`
do
	eval "${nameval}"
done
osver="${jflow_ipe_version}"
phymem=`sysctl -n hw.physmem`
phymem=`expr -e ${phymem} / 1024`
phymem=`expr -e ${phymem} / 1024`
cpunum=`sysctl -n hw.ncpu`
boottime=`sysctl -n kern.boottime | cut -d',' -f1 | cut -d'=' -f2`
curtime=`date +%s`
boottime=`expr ${curtime} - ${boottime}`
bootday=`expr ${boottime} / 86400`
dayhour=`expr ${bootday} \* 24`
boothour=`expr ${boottime} / 3600`
boothour=`expr ${boothour} - ${dayhour}`
bootsec=`expr ${boottime} % 3600`
bootmin=`expr ${bootsec} / 60`
bootsec=`expr ${boottime} % 60`
rrdfile=${DATAPATH}/cpu.rrd
imgfile=${TMPPATH}/cpu_stat.png
tminternal=`expr 3600 \* 24`
curtime=`expr ${curtime} - ${tminternal}`
cpumodel=`sysctl -n hw.model`
. ${PGETC}/panabit.inf
[ -f ${PGPATH}/etc/panabit.inf ] && . ${PGPATH}/etc/panabit.inf
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
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 14px; color:#CE6C04\">
<tr><td style=\"font:14px\"><b>Ҫ</b></td></tr>
</table>
<table width=700 border=0 cellspacing=1 cellpadding=1>
<tr id=row1>
	<td width=120 align=left>&nbsp;&nbsp;ڴ</td>
	<td align=left>${phymem}M, ֧${jflow_flow_pool_size}IP${jflow_ipobj_pool_size}</td>
</tr>
<tr id=row2>
	<td align=left>&nbsp;&nbsp;CPU</td>
	<td align=left>${cpumodel}(${cpunum})</td>
</tr>
";
if [ "${PRODUCT_VER}" != "" ]; then
	echo "<tr id=row1>"
	echo "<td align=left>&nbsp;&nbsp;Ʒͺ</td>"
	echo "<td align=left>&nbsp;&nbsp;${PRODUCT_VER}</td>"
	echo "</tr>"
fi

echo -n "
</table>
<br>
<table style=\"width:700; font:bold 14px; color:#CE6C04\">
<tr><td style=\"font:14px\"><b></b></td>
</table>
<table width=700 border=0 cellspacing=1 cesspadding=1> 
<tr id=row1>
	<td width=120 align=left>&nbsp;&nbsp;汾Ϣ</td>
	<td width=* align=left>汾Ϊ\"${BUILDREL}\"${BUILDDATE}</td>
</tr>
<tr id=row2>
	<td align=left>&nbsp;&nbsp;</td>
	<td align=left>汾Ϊ${osver}</td>
</tr>
<tr id=row1>
	<td align=left>&nbsp;&nbsp;</td>
	<td align=left>${flowcnt}IP${ipcnt}(IPֻõIPٻͳʱ)</td>
</tr>
<tr id=row2>
	<td align=left>&nbsp;&nbsp;ϵͳʱ</td> ";
	if [ $release -eq 0 ]; then
		echo "<td align=left>Panabit׼,ûʱ</td>"
	else
		echo "<td align=left>${startm}${endtm}</td>"
	fi 
echo -n "
</tr>
<tr id=row1>
	<td align=left>&nbsp;&nbsp;ʱ</td> ";
	if [ $release -eq 0 ]; then
		echo "<td align=left>Panabit׼,ûʱ</td>"
	else
		echo "<td align=left>${startm}${freeend}</td>"
	fi 
echo -n "
</tr>
</table>
<br>
<table style=\"width:700; font:bold 14px; color:#CE6C04\">
<tr><td><b>̷</b></td></tr>
</table>
<table width=700 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr>
	<td width=120 align=center><b></b></td>
	<td width=130 align=center><b>ҽӵ</b></td>
	<td width=130 align=center><b>ռС(M)</b></td>
	<td width=130 align=center><b>пռ(M)</b></td>
	<td width=* align=center><b>ʹñ</b></td>
</tr>
";
idname="row1" 
df -h | while read filesystem  size used  avail capacity  mntpoint
do
	[ "${filesystem}" = "Filesystem" ] && continue
	[ "${filesystem}" = "procfs" ] && continue
	echo "<tr id=${idname}>"
	echo "<td align=left>${filesystem}</td>"
	echo "<td align=center>${mntpoint}</td>"
	echo "<td align=right>${size}</td>"
	echo "<td align=right>${avail}</td>"
	echo "<td align=right>${capacity}</td></tr>"
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else
		idname="row1"
	fi
done

echo -n "
</table>
<br>
<table style=\"width:700; font:bold 14px; color:#CE6C04\">
<tr><td><b>Ҫ</b></td></tr>
</table>
";
httpd_status="inactive"
xping_status="inactive"
monitor_status="inactive"
datamon_status="inactive"
for psinfo in `ps ax | awk '{print $5, $6}'`; do
	[ "${psinfo}" = "${PGBIN}/ipe_monitor" ] && monitor_status="active"
	[ "${psinfo}" = "${PGBIN}/ipe_datamon" ] && datamon_status="active"
	[ "${psinfo}" = "${PGBIN}/ipe_xping" ] && xping_status="active"
	[ "${psinfo}" = "${PGBIN}/ipe_httpd" ] && httpd_status="active"
done

echo -n "
<table width=700 border=0 cellspacing=1 cellpadding=1> 
<tr id=tblhdr>
	<td width=120 align=center><b></b></td>
	<td width=420 align=center><b></b></td>
	<td width=* align=center><b>ǰ״̬</b></td>
</tr>
<tr id=row1>
	<td align=center>Web</td>
	<td align=center>ΪԱṩWeb</td>
	<td align=center style=\"color:#0000ff;\"><b>${httpd_status}</b></td>
</tr>
<tr id=row2>
	<td align=center>̨ط</td>
	<td align=center>񣬲ط񣬱֤ط</td>
	<td align=center style=\"color:#0000ff;\"><b>${monitor_status}</b></td>
</tr>
<tr id=row1>
	<td align=center></td>
	<td align=center>ṩ</td>
	";
		state="inactive"
		[ ${jflow_check_policy} -ne 0 ] && state="active"
	
echo -n "
	<td align=center style=\"color:#0000ff;\"><b>${state}</b></td>
</tr>
<tr id=row2>
	<td align=center>ݲɼ</td>
	<td align=center>ݵĲɼ</td>
	<td align=center style=\"color:#0000ff;\"><b>${datamon_status}</b></td>
</tr>
<tr id=row1>
	<td align=center>P2Pʶ</td>
	<td align=center>ԼܵeMuleSkypeP2Pʶ</td>
	<td align=center style=\"color:#0000ff;\"><b>${xping_status}</b></td>
</tr>
</table>
<br>
<table style=\"width:700; font:bold  14px; 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>
";