#!/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 
if [ "${CGI_policy}" = "" ]; then
	for policy in `${FLOWEYE} conlimit listgrp | awk '{print $1}'`
	do
		CGI_policy="${policy}"
		break
	done
fi

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script languate=javascript>
function onAddPolicy()
{
	window.location.href = \"/cgi-bin/Setup/conlimit_addgrp\";
}
function onClonePolicy(policy)
{
	window.location.href = \"/cgi-bin/Setup/conlimit_clonegrp?fromgrp=${CGI_policy}\";
}
function onAddRule(policy)
{
	window.location.href = \"/cgi-bin/Setup/conlimit_addrule?policy=\" + policy;
}
function modifyRule(args)
{
	window.location.href = \"/cgi-bin/Setup/conlimit_setrule?\" + args;
}
function onSelectPolicy(obj)
{
	window.location.href = \"/cgi-bin/Setup/conlimit_getgrp?policy=\" + obj.value; 
}
function deleteRule(group, rule)
{
	if (confirm(\"ȷҪɾù?\")) {
		window.location.href = \"/cgi-bin/Setup/conlimit_getgrp?action=rmvrule\" +
		                        \"&group=\" + group + \"&ruleid=\" + rule;
	}
}
function onDeletePolicy(policy)
{
	if (confirm(\"ȷҪɾ˲?\")) {
		window.location.href = \"/cgi-bin/Setup/conlimit_getgrp?action=deletegroup\" +
		                       \"&policy=\" + policy;
	}
}
</script>
";
if [ "${CGI_action}" = "deletegroup" ]; then
	errmsg=`${FLOWEYE} conlimit rmvgrp ${CGI_policy}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
		afm_load_page 0 "/cgi-bin/Setup/conlimit_getgrp"
		exit 0
	fi
fi
if [ "${CGI_action}" = "rmvrule" ]; then
	errmsg=`${FLOWEYE} conlimit rmvrule ${CGI_group} ${CGI_ruleid}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
	fi
fi
policylist=`${FLOWEYE} conlimit listgrp`

echo -n "
<body>
"; cgi_show_title "ӿƲ->" 
echo -n "
<br>
<table style=\"width:900; border-bottom:1px #787882 solid; font:bold  14px; color:#0000ff\">
<tr>
	<td style=\"width:100%;font:14px\"><b>˵༭ԵȣŻЧ!</td>
</tr>
</table>
<br>
<table width=900 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=23>
	<td width=74 align=center>ѡ</td>
	<td width=402>";
	echo "<select name=policy value=\"${CGI_policy}\" style=\"width:100%;height:22\" onchange=\"onSelectPolicy(this)\">"
	${FLOWEYE} conlimit listgrp | while read policy policyname
	do
		if [ "${CGI_policy}" = "${policy}" ]; then
			echo "<option value=${policy} selected>${policyname}</option>"
		else
			echo "<option value=${policy}>${policyname}</option>"
		fi
	done 
	if [ "${policylist}" = "" ]; then
		echo "<option value=0>(ûжκβ)</option>"
	fi
	echo "</select>" 
echo -n "
	</td>
	<td width=* align=left>
";
	if [ "${CGI_policy}" != "" ]; then
		echo "&nbsp;<input type=button style=\"width:100;height:23\" onclick=\"onDeletePolicy('${CGI_policy}')\" value=\"ɾ\"></input>&nbsp;<input type=button style=\"width:100;height:23\" value=\"Ʋ>>\" onclick=\"onClonePolicy('${CGI_policy}')\"></input>"
	fi

echo -n "
	&nbsp;<input type=button style=\"width:100;height:23\" value=\">>\" onclick=\"onAddPolicy()\"></input>
	</td>
</tr>
</table>
";
if [ "${CGI_policy}" != "" ]; then
	rowno=1
	echo "<table width=900 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
        <td width=50  align=center></td>
	<td width=100 align=center>·</td>
	<td width=120 align=center>ַ</td>
	<td width=120 align=center>ַ</td>
	<td width=120 align=center>ӦЭ</td>
	<td width=240 align=center>IP(TCP/UDP/TOTAL)</td>
        <td width=*   align=center><input type=button style=\"width:100%;height:22px\" onclick=\"onAddRule('${CGI_policy}')\" value=\"Ӳ>>\"></input></td>
</tr>"
	idname="row1"
	${FLOWEYE} conlimit getgrp ${CGI_policy} | \
	while read polno appid appname bridge intype inip outtype outip maxtflow maxuflow maxflow \
tflowdenied uflowdenied flowpassed others 
	do
        	echo "<tr id=${idname}>"
        	echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:modifyRule('policy=${CGI_policy}&polno=${polno}&appid=${appid}&bridge=${bridge}&intype=${intype}&inip=${inip}&outtype=${outtype}&outip=${outip}&maxtflow=${maxtflow}&maxuflow=${maxuflow}&maxflow=${maxflow}')\">${polno}</a></td>"
		if [ "${bridge}" = "0" ]; then
			echo "<td align=center>·</td>"
		else
			echo "<td align=center>${bridge}</td>"
		fi
		if [ "${inip}" = "any" ]; then
			echo "<td align=center>ַ</td>"
		else
			echo "<td align=center>${inip}</td>"
		fi
		if [ "${outip}" = "any" ]; then
			echo "<td align=center>ַ</td>"
		else
			echo "<td align=center>${outip}</td>"
		fi
		if [ "${appname}" = "any" ]; then
			echo "<td align=center>Э</td>"
		else
			echo "<td align=center>${appname}</td>"
		fi
		echo "<td align=center>${maxtflow}/${maxuflow}/${maxflow}</td>"
        	echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:modifyRule('policy=${CGI_policy}&polno=${polno}&appid=${appid}&bridge=${bridge}&intype=${intype}&inip=${inip}&outtype=${outtype}&outip=${outip}&maxtflow=${maxtflow}&maxuflow=${maxuflow}&maxflow=${maxflow}')\">&nbsp;&nbsp;༭&nbsp;&nbsp;<a style="color:#0000ff" href=\"javascript:deleteRule('${CGI_policy}', '${polno}')\">&nbsp;&nbsp;ɾ&nbsp;&nbsp;</a></td>"
        	echo "</tr>"
        	if [ "${idname}" = "row1" ]; then
                	idname="row2"
        	else
                	idname="row1"
        	fi
	done
fi

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