#!/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 "";
if [ "${PALANG}" = "en" ]; then 
	LANG_001="Configure"
	LANG_002="Realtime"
	LANG_003="TopFlow"
	LANG_004="Trend"
	LANG_005="LogShow"
	LANG_006="Top"
	LANG_007="IP Scope"
	LANG_008="Submit"
	LANG_009="Name"
	LANG_0010="Protocol"
	LANG_0011="Connection"
	LANG_0012="Time"
	LANG_0013="BPS(Up/Down)"
	LANG_0014="All"
	LANG_0015="GameCloud->TopFlow"
fi
CGI_browsertitle="${LANG_0015:=Ϸ->}"
. ../../common/common.sh
URLROOT="/cgi-bin/App/gamecloud"
myself="${URLROOT}/`basename $0`"
[ "${CGI_sort}" = "" ] && CGI_sort="bytes"
[ "${CGI_topn}" = "" ] && CGI_topn=100
MOD_TAB_LIST="${LANG_001:=}#${URLROOT}/webmain ${LANG_002:=ʵʱ}#${URLROOT}/gamecloud_rtgraph ${LANG_003:=}#${URLROOT}/gamecloud_topflow"
MOD_TAB_LIST="${MOD_TAB_LIST} ${LANG_004:=ʷ}#${URLROOT}/gamecloud_graph ${LANG_005:=·־}#${URLROOT}/gamecloud_logshow" 

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<body>
"; cgi_print_mod_header "${LANG_003:=}" "100%" 
echo -n "
<form method=post action=\"${myself}\">
<table width=\"700\" border=0 cellspacing=1 cellpadding=1> 
<tr id=tblhdr height=22>
        <td width=120 align=left><b>&nbsp;${LANG_006:=ʾǰ}&nbsp;</b>
        <select name=topn value=\"${CGI_topn}\" style=\"width:70;height: 18px;line-height: 18px;\">
";
                for tm in 10 20 30 50 100 0; do
                        if [  ${tm} -eq 0 ]; then
                                tmdesc="${LANG_0014:=}"
                        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=330 align=left><b>&nbsp;${LANG_007:=IPΧ}</b>
                <input type=text style=\"width:180px;height: 18px;line-height: 18px;\" name=ipaddr value=\"${CGI_ipaddr}\" />
        </td>
        <td width=* class=bgurl2 align=left><input type=submit value=\"${LANG_008:=ύ}\" style=\"width:50;height: 18px;line-height: 18px; font-size: 10px;\"></input>
        <input type=hidden name=sort value=\"${CGI_sort}\"></input></td>
</tr>
</table>
<table width=700 border=0 cellspacing=1 cellpadding=1 class=\"table-striped\"> 
<tr id=tblhdr class=\"tbot-border\">
        <td width=100 class= align=left><a href=\"${myself}?sort=app&topn=${CGI_topn}&ipaddr=${CGI_ipaddr}\">${LANG_009:=Ӧ}</a></td>
        <td width=50  class= align=right><a href=\"${myself}?sort=proto&topn=${CGI_topn}&ipaddr=${CGI_ipaddr}\">${LANG_0010:=Э}</a></td>
        <td width=350 class= align=right><a href=\"${myself}?sort=conn&topn=${CGI_topn}&ipaddr=${CGI_ipaddr}\">${LANG_0011:=}</a></td>
        <td width=50  class= align=right><a href=\"${myself}?sort=time&topn=${CGI_topn}&ipaddr=${CGI_ipaddr}\">${LANG_0012:=ʱ}</a></td>
        <td width=* class= align=right><a href=\"${myself}?sort=bytes&topn=${CGI_topn}&ipaddr=${CGI_ipaddr}\">${LANG_0013:=(up/down)}</a></td>
</tr>
";
case "${CGI_sort}" in
"bytes")
        sortkey="-nk8"
        ;;
"app")
        sortkey="-k2"
        ;;
"proto")
        sortkey="-k3"
        ;;
"conn")
        sortkey="-k4"
        ;;
"time")
        sortkey="-nk1"
        ;;
*)
        sortkey="-k8"
        ;;
esac
idname="row1"
gcpxyid=`floweye gamecloud stat | grep "^pxyid=" | cut -d'=' -f2`
[ "${CGI_ipaddr}" != "" ] && arg="-ip ${CGI_ipaddr}"
${FLOWEYE} flow list proxy=${gcpxyid} ${arg} | sort ${sortkey} | awk -v topn="${CGI_topn}" '{if(topn && i++>topn) exit; print $0}' | \
while read life appname tcpudp conninfo bytes1 bytes2 ttl allbytes tos1 tos2 tos3 proxyname theothers
do
        [ "${proxyname}" = "NULL" ] && proxyname=""

echo -n "
        <tr id=${idname}>
        <td align=left>&nbsp;${appname}</td>
        <td align=right>${tcpudp}</td>
        <td align=right>${conninfo}</td>
        <td align=right>${life}</td>
        <td align=right>${bytes1}/${bytes2}</td>
        </tr>
";
        if [ "${idname}" = "row1" ]; then
                idname="row2"
        else
                idname="row1"
        fi
done

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