#!/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="0"
[ "${CGI_statype}" = "" ] && CGI_statype="last"
[ "${CGI_bridge}" = "" ] && CGI_bridge="0"
cgipath="/cgi-bin/Monitor/`basename $0`"
cgiargs="title=${CGI_title}&refresh=${CGI_refresh}&statype=${CGI_statype}&topn=${CGI_topn}&group=${CGI_group}&bridge=${CGI_bridge}"
cgiurl="${cgipath}?${cgiargs}"

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);
}
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?vlinkname=${CGI_vlinkname}&bridge=${CGI_bridge}&datasrc=\" + datasrc + \"&title=\" + title;
 	ShowWindow(url, \"scrollbars=1,resizable=0\", 670, 850);
}
function showapp(appid, appname) 
{
	var url = \"/cgi-bin/Monitor/vlink_viewapp?vlinkname=${CGI_vlinkname}&bridge=${CGI_bridge}&appid=\" + appid +
	      \"&appname=\" + appname;
 	ShowWindow(url, \"scrollbars=1,resizable=0\", 700, 500);
}
</script>
<body>
<script type=\"text/javascript\" src=\"/img/wz_tooltip.js\"></script>
<span id=\"hlp3day\" style=\"display:none\">鿴ͼ</span>
<span id=\"hlpall\" style=\"display:none\">鿴һܡһµͼ</span>
"; cgi_show_title "${CGI_title}(${CGI_vlinkname})" 
echo -n "
<br>
<table class=bgurl width=\"660\" border=0 cellspacing=1 cellpadding=1 bgcolor=\"#ffffff\">
<form method=post action=\"${cgipath}\">
<tr id=tblhdr height=22>
	<td width=200 class=bgurl2 align=left>&nbsp;<input type=hidden name=bridge value=\"${CGI_bridge}\" />
        <select name=statype value=\"${CGI_statype}\" style=\"width:120\"> ";
		if [ "${CGI_statype}" = "last" ]; then
			echo "<option value=last selected>10</option>"
		else
			echo "<option value=last>10</option>"
		fi
		if [ "${CGI_statype}" = "all" ]; then
			echo "<option value=all selected>ۼ</option>"
		else
			echo "<option value=all>ۼ</option>"
		fi
		if [ "${CGI_statype}" = "bpsup" ]; then
			echo "<option value=bpsup selected>bps</option>"
		else
			echo "<option value=bpsup>bps</option>"
		fi
		if [ "${CGI_statype}" = "bpsdn" ]; then
			echo "<option value=bpsdn selected>bps</option>"
		else
			echo "<option value=bpsdn>bps</option>"
		fi 
	
echo -n "
        </select>&nbsp;</td>
	<td width=* class=bgurl2 align=left>ʾǰ<select name=topn value=\"${CGI_topn}\" style=\"width:60\"> ";
		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>&nbsp;&nbsp;
		<input type=submit value=\"ˢ  \" style=\"width:70\"></input>&nbsp;&nbsp;
		<input type=button name=showselect disabled value=\"ѡӦöԱȷ\" style=\"width:120\" onclick=\"javascript:ShowSelected()\"></input>
		<input type=hidden name=title value=\"${CGI_title}\"></input>
		<input type=hidden name=group value=\"${CGI_group}\"></input>
	</td>
</tr>
</form>
</table>
";
urlpath="${cgipath}?vlinkname=${CGI_vlinkname}&title=${CGI_title}&bridge=${CGI_bridge}&topn=${CGI_topn}&refresh=${CGI_refresh}&group=${CGI_group}"

echo -n "
<table class=bgurl width=660 border=0 cellspacing=1 cellpadding=2>
<tr id=tblhdr height=22>
	<td width=118 align=center>Э</td>
	<td width=75 align=center><a href=\"${urlpath}&statype=bpsup\">bps</a></td>
	<td width=75 align=center><a href=\"${urlpath}&statype=bpsdn\">bps</a></td>
	<td width=200 align=center><a href=\"${urlpath}&statype=all\">ۼ</a></td>
	<td width=* align=center><a href=\"${urlpath}&statype=last\">10</a></td>
</tr>
";
args="sort=${CGI_statype} bridge=${CGI_bridge}"
[ ${CGI_topn} -ne 0 ] && args="${args} topn=${CGI_topn}"
idname="row1"
${FLOWEYE} app stat app=${CGI_group} ${args} | \
while read appid appname flow node aup adown all per1 lup ldown lall per2 rup rdown rall theother
do

echo -n "
	<tr id=${idname}>
	<td align=left>&nbsp;<input type=checkbox name=appselect value=\"${appid}\" onclick=\"onselected()\"></input>
	<a href=\"javascript:showapp('${appid}', '${appname}')\">${appname}</td>
	<td align=right>${rup}</td>
	<td align=right>${rdown}</td>
	"; wid=`echo "${per1}" |awk '{print ($1 * 90.00) / 100.00}'` 
echo -n "
	<td><table cellpading=0 cellspacing=0><tr id=${idname}><td width=80 align=right>${all}</td>
	<td align=left>&nbsp;<img src=\"/img/data_bar.gif\" width=${wid} height=10 alt=\"${per1}%\" border=0>&nbsp;${per1}</td>
	</tr></table></td>
	"; wid=`echo "${per2}" |awk '{print ($1 * 90.00) / 100.00}'` 
echo -n "
	<td><table cellpading=0 cellspacing=0><tr id=${idname}><td width=80 align=right>${lall}</td>
	<td align=left>&nbsp;<img src=\"/img/data_bar.gif\" width=${wid} height=10 alt=\"${per2}%\" border=0>&nbsp;${per2}</td>
	</tr></table></td>
	</tr>
"; 
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else
		idname="row1"
	fi
done

echo -n "
</table>
";
TMPPATH=${PGPATH}/admin/tmp
grpbps=${TMPPATH}/vlink_${CGI_bridge}_day_${CGI_group}_bps.png
rm -rf ${grpbps}
comargs="type=line bridge=${CGI_bridge} width=660 height=350 hours=24"
errmsg=`${FLOWEYE} chart show ${comargs} outimg=${grpbps} tag=${CGI_group}.bpsin tag=${CGI_group}.bpsout`

echo -n "
<br>
<table style=\"width:660; font:bold 14px; color:#CE6C04\">
<tr>
<td align=left><b>24Сʱͼ</b></td>
<td align=right>
<a href=\"javascript:popupurl('/cgi-bin/Monitor/grpgraph?vlinkname=${CGI_vlinkname}&group=${CGI_group}&bridge=${CGI_bridge}&type=bps&time=3day', 700, 700)\"
    onmouseover=\"TagToTip('hlp3day')\" onmouseout=\"UnTip()\">նԱ</a>
<a href=\"javascript:popupurl('/cgi-bin/Monitor/grpgraph?vlinkname=${CGI_vlinkname}&group=${CGI_group}&bridge=${CGI_bridge}&type=bps&time=mon', 700, 700)\"
    onmouseover=\"TagToTip('hlpall')\" onmouseout=\"UnTip()\">ʷͼ</a>
</td>
</tr>
</table>
<table width=660 border=0 cellspacing=1 cellpadding=1 bgcolor=\"#ffffff\">
<tr><td><img src=\"/tmp/vlink_${CGI_bridge}_day_${CGI_group}_bps.png\"></img></td></tr>
</table>
</body>
</html>
";