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

"
echo -n ""; 
CGI_browsertitle="·-${CGI_link}"
. ../common/common.sh 
[ "${CGI_refresh}" = "" ] && CGI_refresh=3
[ "${CGI_topn}" = "" ] && CGI_topn="20"
[ "${CGI_sort}" = "" ] && CGI_sort="bps"
cgipath="/cgi-bin/Monitor/proxy_apprate"
cgiurl="/cgi-bin/Monitor/proxy_apprate?refresh=${CGI_refresh}&sort=${CGI_sort}&topn=${CGI_topn}&link=${CGI_link}"
urlpath="/cgi-bin/Monitor/proxy_apprate?refresh=${CGI_refresh}&topn=${CGI_topn}&link=${CGI_link}"
[ ${CGI_refresh} -ne 0 ] && afm_load_page  ${CGI_refresh} "${cgiurl}"
MOD_TAB_LIST="#/cgi-bin/Monitor/ifpxy_rtgraph?type=proxy&name=${CGI_link} TopӦ#/cgi-bin/Monitor/proxy_apprate?link=${CGI_link}"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function ShowDetail(ipaddr)
{
	var url = \"/cgi-bin/Monitor/ip_detail?ipaddr=\" + ipaddr;
	ShowWindow(url, \"\", 500, 640);
}
function ShowFlow(ipaddr)
{
	var url = \"/cgi-bin/Monitor/ip_flow?ipaddr=\" + ipaddr;
	ShowWindow(url, \"\", 650, 700);
}
function onselected()
{
        var i;
	var count;
        var apps;
	count = 0;
        apps = document.getElementsByName(\"appselect\");
        for (i = 0; i < apps.length; i++) {
                if (apps[i].checked) count++;
        }
	document.getElementsByName(\"showselect\")[0].disabled = count > 0 ? false : true;
}
function ShowSelected()
{
        var i;
        var url;
        var apps;
        var datasrc;
        var statype;
        var title;
        datasrc=\"\";
        statype = document.getElementsByName(\"statype\")[0];
        apps = document.getElementsByName(\"appselect\");
        for (i = 0; i < apps.length; i++) {
                if (apps[i].checked) {
                        if (statype.value == \"last\" || statype.value == \"all\") 
                                datasrc = datasrc + \",\" + apps[i].value + \".bps\";
                        else
                        if (statype.value == \"bpsup\") 
                                datasrc = datasrc + \",\" + apps[i].value + \".bpsout\";
                        else
                        if (statype.value == \"bpsdn\") 
                                datasrc = datasrc + \",\" + apps[i].value + \".bpsin\";
                        else
                        if (statype.value == \"flow\") 
                                datasrc = datasrc + \",\" + apps[i].value + \".flow\";
                }
        }
        if (statype.value == \"last\" || statype.value == \"all\")
                title = \"ͼ\"
        else
        if (statype.value == \"bpsup\")
                title = \"ͼ\"
        else
        if (statype.value == \"bpsdn\")
                title = \"ͼ\"
        else
        if (statype.value == \"flow\")
                title = \"ͼ\"
        url = \"/cgi-bin/Monitor/appreport?datasrc=\" + datasrc + \"&title=\" + title;
        ShowWindow(url, \"scrollbars=1,resizable=0\", 670, 850);
}
function showapp(appid, appname)
{
        var url = \"/cgi-bin/Monitor/appview_topip?appid=\" + appid +
              \"&appname=\" + appname;
        ShowWindow(url, \"scrollbars=1,resizable=1\", 740, 800);
}
function showapp(appid, appname)
{
        var url = \"/cgi-bin/Monitor/appview_topip?appid=\" + appid +
              \"&appname=\" + appname;
        ShowWindow(url, \"scrollbars=1,resizable=1\", 740, 800);
}
</script>
<body>
"; cgi_print_mod_header  "TopӦ"  700 
echo -n "
<br>
<table width=700 border=0 cellspacing=0 cellpadding=0>
<form method=post action=\"${cgipath}\">
<tr id=tblhdr>
	<td width=280 align=left>&nbsp;<b>${CGI_link}</b>&nbsp;
        <select name=sort value=\"${CGI_sort}\" style=\"width:110\"> ";
		if [ "${CGI_sort}" = "bpsup" ]; then
			echo "<option value=bpsup selected>bps</option>"
		else
			echo "<option value=bpsup>bps</option>"
		fi
		if [ "${CGI_sort}" = "bpsdn" ]; then
			echo "<option value=bpsdn selected>bps</option>"
		else
			echo "<option value=bpsdn>bps</option>"
		fi 
		if [ "${CGI_sort}" = "bps" ]; then
			echo "<option value=bps selected></option>"
		else
			echo "<option value=bps></option>"
		fi 
	
echo -n "
        </select>&nbsp;</td>
	<td width=272 align=left>&nbsp;ʾǰ<select name=topn value=\"${CGI_topn}\" style=\"width:70\"> ";
		for tm in 10 20 30 50 100 2 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>&nbsp;
	<select name=refresh value=\"${CGI_refresh}\" style=\"width:70\">
	";
		for tm in 3 5 10 30 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>&nbsp;ˢ</td>
	<td width=* align=left>
		<input type=submit value=\"ˢ  \" style=\"width:70\"></input>&nbsp;&nbsp;
		<input type=hidden name=link value=\"${CGI_link}\" />
	</td>
</tr>
</form>
</table>
<table width=700 border=0 cellspacing=1 cellpadding=0>
<tr id=tblhdr>
	<td width=160 align=right>Э</td>
	<td width=150 align=right><a href=\"${urlpath}&sort=bpsup\">bps</a></td>
	<td width=150 align=right><a href=\"${urlpath}&sort=bpsdn\">bps</a></td>
	<td width=*   align=right><a href=\"${urlpath}&sort=bps\"></a></td>
</tr>
";
args="sort=${CGI_sort} topn=${CGI_topn} link=${CGI_link}"
idname="row1"
${FLOWEYE} app rate ${args} | while read name cname upbps downbps bps theothers
do

echo -n "
	<tr id=${idname}>
	<td align=right><a href=\"javascript:showapp('${name}', '${cname}')\">${cname}</a></td>
	<td align=right>${upbps}&nbsp;</td>
	<td align=right>${downbps}&nbsp;</td>
	<td align=right>${bps}&nbsp;</td>
";
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else
		idname="row1"
	fi
done

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