#!/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
cgipath="/cgi-bin/Monitor/`basename $0`"
afm_load_page 30 ${cgipath}
curpolinfo=`${FLOWEYE} conlimit getcurgrp`
curpolicy=`echo ${curpolinfo} | cut -d' ' -f1`
curpolicyname=`echo ${curpolinfo} | cut -d' ' -f2`

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script languate=javascript>
function onAddRule(policy) 
{
	var url = \"/cgi-bin/Setup/conlimit_addrule?policy=\" + policy;
	ShowWindow(url, \"\", 640, 460);
}
function modifyRule(group, polno) 
{
	var url = \"/cgi-bin/Setup/conlimit_setrule?policy=\" + group + \"&polno=\" + polno;
	ShowWindow(url, \"\", 640, 450);
}
function deleteRule(group, rule)
{
	if (confirm(\"ȷҪɾò?\")) 
		window.location.href = \"${cgipath}?action=rmvrule\" + 
		                       \"&group=\" + group + \"&ruleid=\" + rule;
}
function openPolicyTime()
{
	var url = \"/cgi-bin/Setup/conlimit_listime\";
	ShowWindow(url, \"\", 840, 500);
}
function showIPGrp(gname)
{
        var url = \"/cgi-bin/Protocol/ipgrp_list?ipgrp=\" + gname;
        ShowWindow(url, \"\", 860, 630);
}
function showApp(appid, appname)
{
        var url = \"/cgi-bin/Monitor/app_show?appid=\" + appid + \"&title=\" + appname;
        ShowWindow(url, \"\", 700, 540);
}
</script>
";
if [ "${CGI_action}" = "rmvrule" ]; then
	operator_check "${cgipath}"
	errmsg=`${FLOWEYE} conlimit rmvrule ${CGI_group} ${CGI_ruleid}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	fi
fi

echo -n "
<body>
"; cgi_show_title "ǰ->ӿ" 
echo -n "
"; if [ ${curpolicy} -eq 0 ]; then 
echo -n "
	<br>
	<table style=\"width:100%; color:#0000ff\">
	<tr><td align=left>Ŀǰûв鱻ȣ
		<a style=\"color:#ff0000;font-bold:true;font-size:15px;\" href=\"javascript:openPolicyTime()\"><b>˴Ե</b></a>
	</td></tr>
	</table>
	<br>
	</body>
	</html>
";
	exit 0
fi

echo -n "
<br> 
<table style=\"width:900; font-bold:true;font-size:15px; color:#CE6C04\">
<tr>
        <td align=left><b>Active:${curpolicyname}</b>&nbsp; <a style=\"color:#ff0000;font-bold:true;font-size: 15px;\" href=\"javascript:openPolicyTime()\"><b>(˴޸ĲԵ)</b></a></td>
</tr>   
</table>
<table width=1080 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
        <td width=40  align=center></td>
	<td width=70 align=center>·</td>
        <td width=150 align=center>IP</td>
        <td width=150 align=center>IP</td>
        <td width=80 align=center>ӦЭ</td>
        <td width=200 align=center>IP(TCP/UDP/)</td>
	<td width=160 align=center>ܾ(TCP/UDP)</td>
	<td width=80 align=center>ͨ</td>
        <td width=*  align=center><a style=\"color:#0000ff\" href=\"javascript:onAddRule('${curpolicy}')\">Ӳ>></a></td>
</tr> 
";
idname="row1"
${FLOWEYE} conlimit getgrp ${curpolicy} | \
while read polno appid appname bridge intype inip inport outtype outip outport \
maxtflow maxuflow maxflow tflowdenied uflowdenied flowpassed others
do 
echo -n "
	<tr id=${idname}>
	<td align=center>${polno}</td>
";	if [ "${bridge}" = "0" ]; then 
echo -n "
		<td align=center>any</td>
";	else 
echo -n "
		<td align=center>${bridge}</td>
";	fi 
	if [ "${inport}" = "any" ]; then 
        	if [ "${intype}" = "table" ]; then 
echo -n "
                	<td align=center><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${inip}')\">${inip}</a></td>
	    "; else 
echo -n "
                	<td align=center>${inip}</td>
	    "; fi 
	else 
        	if [ "${intype}" = "table" ]; then 
echo -n "
               		<td align=center>
				<a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${inip}')\">${inip}:${inport}</a>
			</td>
	    "; else 
echo -n "
               		<td align=center>${inip}:${inport}</td>
	    "; fi 
        fi 
	if [ "${outport}" = "any" ]; then 
        	if [ "${outtype}" = "table" ]; then 
echo -n "
                	<td align=center><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${outip}')\">${outip}</a></td>
		"; else 
echo -n "
                	<td align=center>${outip}</td>
		"; fi
	else 
        	if [ "${outtype}" = "table" ]; then 
echo -n "
               	<td align=center><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${outip}')\">${outip}</a>:${outport}</td>
		"; else 
echo -n "
               	<td align=center>${outip}:${outport}</td>
		"; fi
        fi 
        if [ "${appid}" = "any" ]; then
                echo "<td align=center>${appname}</td>"
        else
                echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:showApp('${appid}', '${appname}')\">${appname}</a></td>"
        fi 
echo -n "
	<td align=center>${maxtflow}/${maxuflow}/${maxflow}</td>
	<td align=right style=\"color:#ff0000\">${tflowdenied}/${uflowdenied}</td>
	<td align=right style=\"color:#0000ff\">${flowpassed}</td>
       	<td align=center>
		<a style=\"color:#0000ff\" href=\"javascript:modifyRule('${curpolicy}', '${polno}')\">&nbsp;&nbsp;༭&nbsp;&nbsp;
		<a style=\"color:#0000ff\" href=\"javascript:deleteRule('${curpolicy}', '${polno}')\">&nbsp;&nbsp;ɾ&nbsp;&nbsp;</a>
	</td>
"; 
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else    
		idname="row1"
	fi
done

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