#!/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="20"
[ "${CGI_appid}" = "" ] && CGI_appid="http"
[ "${CGI_statype}" = "" ] && CGI_statype="all"
[ "${CGI_bridge}" = "" ] && CGI_bridge="0"
cgipath="/cgi-bin/Monitor/`basename $0`"
cgiargs="refresh=${CGI_refresh}&statype=${CGI_statype}&appid=${CGI_appid}&topn=${CGI_topn}&appname=${CGI_appname}&bridge=${CGI_bridge}"
cgiurl="${cgipath}?${cgiargs}"
[ ${CGI_refresh} -ne 0 ] && afm_load_page  ${CGI_refresh} "${cgiurl}"
[ "${width}" = "" ] && width=700
MOD_TAB_LIST="ͼ#/cgi-bin/Monitor/appview_graph?${cgiargs} û#/cgi-bin/Monitor/appview_topip?${cgiargs}"

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;
        url = \"/cgi-bin/Monitor/ipview_data?ipaddr=\" + ipaddr +
              \"&online=\" + online + \"&ttl=\" + ttl + \"&outbyte=\" + outbyte +
              \"&inbyte=\" + inbyte + \"&outrate=\" + outrate + \"&inrate=\" + inrate;
        ShowWindow(url, \"\", 650, 800);
}
</script>
<body>
"; cgi_show_title "`${FLOWEYE} app name ${CGI_appid}`" ${width} 
echo -n "
<br>
"; wid=`expr ${width} / 6` 
echo -n "
<table width=${width} border=0 cellspacing=1 cellpadding=1> 
<tr id=tblhdr height=22>
    <td width=${wid} align=center></td>
    <td width=${wid} align=center>ڵ</td>
    <td width=${wid} align=center></td>
    <td width=${wid} align=center></td>
    <td width=${wid} align=center></td>
    <td width=* align=center></td>
</tr>
";
output=`${FLOWEYE} app get ${CGI_appid}`
if [ "${output}" = "" ]; then
        afm_dialog_msg "Э${CGI_appid}!"
        echo "</body></html>"
        exit 0
fi
for nameval in ${output}; do
	eval "${nameval}"
done

echo -n "
<tr id=row1 height=22>
        <td align=right>${flowcnt}</td>
        <td align=right>${nodecnt}</td>
        <td align=right>${upbytes}</td>
        <td align=right>${downbytes}</td>
        <td align=right>${upbps}</td>
        <td align=right>${downbps}</td>
</tr>
</table>
<br>
"; cgi_print_mod_header "û" ${width} 
echo -n "
<table width=\"${width}\" border=0 cellspacing=1 cellpadding=1> 
<form method=post action=\"${cgipath}\">
<tr id=tblhdr height=22>
        <td width=153 align=left><b>&nbsp;</b>
        <select name=statype value=\"${CGI_statype}\" style=\"width:75;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
        
echo -n "
        </select>&nbsp;</td>
        <td width=183 align=left><b>&nbsp;ʾǰ&nbsp;</b>
        <select name=topn value=\"${CGI_topn}\" style=\"width:70;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>&nbsp;</td>
        <td width=173 align=left><b>&nbsp;ÿ&nbsp;</b>
        <select name=refresh value=\"${CGI_refresh}\" style=\"width:76;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>&nbsp;ˢ</td>
        <td width=* class=bgurl2 align=right><input type=submit value=\"  \" style=\"width:70;height:21\"></input>
        <input type=hidden name=appid value=\"${CGI_appid}\"></input></td>
        <input type=hidden name=appname value=\"${CGI_appname}\"></input></td>
</tr>
</form>
</table>
"; wid=`expr ${width} / 5` 
echo -n "
<table width=\"${width}\" border=0 cellspacing=1 cellpadding=1> 
<tr id=tblhdr>
        <td width=${wid} align=center><b>IPַ</b></td>
        <td width=${wid} align=center><b>˺</b></td>
	<td width=${wid} align=center><b>${CGI_appname}</b></td>
	<td width=${wid} align=center><b>${CGI_appname}</b></td>
        <td width=* align=center><b>${CGI_appname}</b></td>
</tr>
";
idname="row1"
args="-s ${CGI_statype} -app ${CGI_appid}"
if [ ${CGI_topn} -ne 0 ]; then
        args="-n ${CGI_topn} ${args}"
fi
${FLOWEYE} ipobj listipa ${args} | \
while read ip appid appname inbps outbps allbps account theothers
do
        echo "<tr id=${idname}>"
        echo "<td align=left><a href=\"javascript:showip('${ip}', '${onlinesec}', '${ttl}', '${outbyte}', '${inbyte}', '${outrate}', '${inrate}')\">&nbsp;&nbsp;&nbsp;&nbsp;${ip}</a></td>"
	if [ "${account}" != "none" ]; then
		echo "<td align=center><a href=\"javascript:showacct('${ip}', '${account}')\">${account}</a></td>"
	else
		echo "<td align=center></td>"
	fi
        echo "<td align=right>${inbps}</td>"
        echo "<td align=right>${outbps}</td>"
        echo "<td align=right>${allbps}</td>"
        if [ "${idname}" = "row1" ]; then
                idname="row2"
        else
                idname="row1"
        fi
done

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