#!/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 
[ "${CGI_refresh}" = "" ] && CGI_refresh=0
[ "${CGI_topn}" = "" ] && CGI_topn="30"
[ "${CGI_statype}" = "" ] && CGI_statype="all"
cgipath="/cgi-bin/Monitor/ip_topn"
cgiargs="title=${CGI_title}&refresh=${CGI_refresh}&statype=${CGI_statype}&topn=${CGI_topn}"
cgiargs="${cgiargs}&startip=${CGI_startip}&endip=${CGI_endip}"
cgiurl="${cgipath}?${cgiargs}"
[ ${CGI_refresh} -ne 0 ] && afm_load_page  ${CGI_refresh} "${cgiurl}"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function showip(ipaddr, online, ttl, outbyte, inbyte, outrate, inrate) 
{
	var url = \"/cgi-bin/Monitor/ipview_data?ipaddr=\" + ipaddr +
	      \"&online=\" + online + \"&ttl=\" + ttl + \"&outbyte=\" + outbyte +
	      \"&inbyte=\" + inbyte + \"&outrate=\" + outrate + \"&inrate=\" + inrate;
	ShowWindow(url, \"\", 650, 700);
}
function validate(frm) 
{
	var start;
	var end;
	start = document.getElementsByName(\"startip\")[0].value;
	end   = document.getElementsByName(\"endip\")[0].value;
	start = TrimAll(start);
	end   = TrimAll(end);
	if (start != \"\" && !IsIPAddr(start)) {
		alert(\"ȷIPַ!\");
		document.getElementsByName(\"startip\")[0].select();
		return false;
	}
	if (end != \"\" && !IsIPAddr(end)) {
		alert(\"ȷIPַ!\");
		document.getElementsByName(\"endip\")[0].select();
		return false;
	}
	return true;
}
</script>
<body>
"; cgi_show_title "${CGI_title}" 
echo -n "
<br>
<table width=\"900\" border=0 cellspacing=1 cellpadding=1> 
<form method=post onsubmit=\"return validate(this)\" action=\"${cgipath}\">
<tr id=tblhdr height=22>
	<td width=183 align=left><b>&nbsp;</b>
        <select name=statype value=\"${CGI_statype}\" style=\"width:100;height:21\">
	";
		if [ "${CGI_statype}" = "all" ]; then
			echo "<option value=all selected></option>"
		else
			echo "<option value=all></option>"
		fi
		if [ "${CGI_statype}" = "in" ]; then
			echo "<option value=in selected></option>"
		else
			echo "<option value=in></option>"
		fi
		if [ "${CGI_statype}" = "out" ]; then
			echo "<option value=out selected></option>"
		else
			echo "<option value=out></option>"
		fi
		if [ "${CGI_statype}" = "allbps" ]; then
			echo "<option value=allbps selected></option>"
		else
			echo "<option value=allbps></option>"
		fi
		if [ "${CGI_statype}" = "inbps" ]; then
			echo "<option value=inbps selected>bps</option>"
		else
			echo "<option value=inbps>bps</option>"
		fi
		if [ "${CGI_statype}" = "outbps" ]; then
			echo "<option value=outbps selected>bps</option>"
		else
			echo "<option value=outbps>bps</option>"
		fi
		if [ "${CGI_statype}" = "flowcnt" ]; then
			echo "<option value=flowcnt selected></option>"
		else
			echo "<option value=flowcnt></option>"
		fi
		if [ "${CGI_statype}" = "ipaddr" ]; then
			echo "<option value=ipaddr selected>IPַ</option>"
		else
			echo "<option value=ipaddr>IPַ</option>"
		fi
		if [ "${CGI_statype}" = "account" ]; then
			echo "<option value=account selected>Ϣ</option>"
		else
			echo "<option value=account>Ϣ</option>"
		fi
		if [ "${CGI_statype}" = "natip" ]; then
			echo "<option value=natip selected>û</option>"
		else
			echo "<option value=natip >û</option>"
		fi
	
echo -n "
        </select>&nbsp;</td>
	<td width=100 align=left><b>ǰ</b>
	<select name=topn value=\"${CGI_topn}\" style=\"width:45;height:21\">
	";
		for tm in 10 20 30 50 100 0; do
			if [  ${tm} -eq 0 ]; then
				tmdesc=""
			else
				tmdesc="${tm}"
			fi
			if [ "${CGI_topn}" = "${tm}" ]; then
				echo "<option selected value=${tm}>${tmdesc}</option>"
			else
				echo "<option value=${tm}>${tmdesc}</option>"
			fi
		done
	
echo -n "
	</select></td>
	<td width=150 align=left><b>ÿ</b>
	<select name=refresh value=\"${CGI_refresh}\" style=\"width:65;height:21\">
	";
		for tm in 15 30 45 60 0; do
			if [ ${tm} -eq 0 ]; then
				tmdesc="ˢ"
			else
				tmdesc="${tm}"
			fi
			if [ "${CGI_refresh}" = "${tm}" ]; then
				echo "<option selected value=${tm}>${tmdesc}</option>"
			else
				echo "<option value=${tm}>${tmdesc}</option>"
			fi
		done
	
echo -n "
	</select>ˢ</td>
	<td width=* align=left><b>&nbsp;IPΧ</b>
		<input type=text style=\"width:85px;height:21\" name=startip value=${CGI_startip}></input>~
		<input type=text style=\"width:85px;height:21\" name=endip value=${CGI_endip}></input>&nbsp;
		<input type=submit value=\"  \" style=\"width:100;height:22\"></input>
		<input type=hidden name=title value=\"${CGI_title}\"></input></td>
</tr>
</form>
</table>
";
urlpath="${cgipath}?title=${CGI_title}&refresh=${CGI_refresh}&topn=${CGI_topn}&startip=${CGI_startip}&endip=${CGI_endip}"

echo -n "
<table width=900 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
	<td width=110 align=center><a href=\"${urlpath}&statype=ipaddr\">IPַ</a></td>
	<td width=90 align=center>˺</td>
	<td width=110 align=center>MACַ</td>
	<td width=50 align=center>TTL()</td>
	<td width=65 align=center>ʱ</td>
	<td width=60 align=center><a href=\"${urlpath}&statype=flowcnt\"></a></td>
	<td width=65 align=center><a href=\"${urlpath}&statype=out\"></a></td>
	<td width=65 align=center><a href=\"${urlpath}&statype=in\"></a></td>
	<td width=60 align=center><a href=\"${urlpath}&statype=outbps\">bps</a></td>
	<td width=60 align=center><a href=\"${urlpath}&statype=inbps\">bps</a></td>
	<td width=65 align=center><a href=\"${urlpath}&statype=account\">Ϣ</a></td>
	<td width=* align=center><a href=\"${urlpath}&statype=natip\">û</a></td>
</tr>
";
idname="row1"
args="-s ${CGI_statype}"
[ ${CGI_topn} -ne 0 ] && args="-n ${CGI_topn} ${args}"
[ "${CGI_startip}" != "" ] && args="${args} -ip ${CGI_startip}"
[ "${CGI_endip}" != "" ] && args="${args}-${CGI_endip}"
${FLOWEYE} ipobj list ${args} -summary | \
while read ip onlinesec ttl flowcnt mac inbyte outbyte inrate outrate accounts natips account theothers
do 
	if [ "${ip}" = "0.0.0.0" ]; then 

echo -n "
		<tr id=${idname} height=22>
		<td align=center><b>ϼ</b></td>
		<td align=center></td>
		<td align=right></td>
		<td align=right></td>
		<td align=right></td>
		<td align=right><b>${flowcnt}</b></td>
		<td align=right><b>${outbyte}</b></td>
		<td align=right><b>${inbyte}</b></td>
		<td align=right><b>${outrate}</b></td>
		<td align=right><b>${inrate}</b></td>
		<td align=right><b>${accounts}</b></td>
		<td align=right><b>${natips}</b></td>
"; 	else 
echo -n "
		<tr id=${idname} height=22>
		<td align=left><a href=\"javascript:showip('${ip}', '${onlinesec}', '${ttl}', '${outbyte}', '${inbyte}', '${outrate}', '${inrate}')\">&nbsp;${ip}</a></td>
";
		if [ "${account}" != "none" ]; then
			echo "<td align=center><a href=\"javascript:showacct('${ip}', '${account}')\">${account}</td>"
		else
			echo "<td align=center></td>"
		fi

echo -n "
		<td align=right>${mac}</td>
		<td align=right>${ttl}</td>
		<td align=right>${onlinesec}</td>
		<td align=right>${flowcnt}</td>
		<td align=right>${outbyte}</td>
		<td align=right>${inbyte}</td>
		<td align=right>${outrate}</td>
		<td align=right>${inrate}</td>
		<td align=right>${accounts}</td>
		<td align=right>${natips}</td>
";	fi 
echo -n "
	
"; 	if [ "${idname}" = "row1" ]; then
	        idname="row2"
	else
	        idname="row1"
        fi
done

echo -n "
</table>
</body>
</html>
";