#!/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} policy 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 language=\"javascript\">
function onAddPipe()
{
	var url = \"/cgi-bin/Setup/pipe_add\";
	ShowWindow(url, \"\", 640, 260);
}
function OnDeletePipe(pname)
{
	if (confirm(\"ɾͨϵͳɾʹôͨĲԣȷҪɾ\")) 
		window.location.href = \"${cgipath}?action=deletepipe&pname=\" + pname; 
}
function OnModifyPipe(url)
{
	ShowWindow(url, \"\", 640, 260);
}
function onAddRule(policy) 
{
	var url = \"/cgi-bin/Setup/policy_addrule?policy=\" + policy;
	ShowWindow(url, \"\", 640, 580);
}
function modifyRule(args) 
{
	var url = \"/cgi-bin/Setup/policy_setrule?\" + args;
	ShowWindow(url, \"\", 640, 560);
}
function deleteRule(group, rule)
{
	if (confirm(\"ȷҪɾù?\")) 
		window.location.href = \"${cgipath}?action=rmvrule\" + 
		                       \"&group=\" + group + \"&ruleid=\" + rule;
}
function openPolicyTime()
{
	var url = \"/cgi-bin/Setup/policy_listtime\";
	ShowWindow(url, \"\", 840, 500);
}
function showProxy(proxyname)
{
	var url = \"/cgi-bin/Monitor/proxy_show?proxyname=\" + proxyname;
	ShowWindow(url, \"\", 350, 320); 
}
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}" = "deletepipe" ]; then
	errmsg=`${FLOWEYE} policy rmvbwo ${CGI_pname}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ʧ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
	fi
fi
if [ "${CGI_action}" = "rmvrule" ]; then
	errmsg=`${FLOWEYE} policy rmvrule ${CGI_group} ${CGI_ruleid}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
	fi
fi

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

echo -n "
<br>
<table style=\"width:700; font:bold 14px; color:#CE6C04\">
<tr>
	<td align=left><b>Activeͨ</b></td>
</tr>
</table>
<table width=980 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
        <td width=120 align=center>ͨ</td>
        <td width=100 align=center>ͨ</td>
        <td width=120 align=center>ͨ·</td>
        <td width=120 align=center>ͨ(kb/s)</td>
	<td width=120 align=center>(bps)</td>
	<td width=120 align=center>(bps)</td>
	<td width=80  align=center>״̬</td>
	<td width=* align=center>
"; if [ ${curpolicy} -ne 0 ]; then 
echo -n "
		<input type=button value=\"ͨ>>\" style=\"width:120px;height:21px\" onclick=\"onAddPipe()\"></input>
"; fi 
echo -n "
	</td>
</tr>
";
idname="row1"
${FLOWEYE} policy listbwo | while read pid bridge pname ptype pdir prate plog active disable inbps outbps theothers
do
    [ "${active}" = "no" ] && continue
    echo "<tr id=${idname}>"
    echo "<td align=center>${pname}</td>"
    case "${ptype}" in
    "limit")
        echo "<td align=center></td>"
        ;;
    "gurantee")
        echo "<td align=center>֤</td>"
        ;;
    "reserve")
        echo "<td align=center>Ԥ</td>"
        ;;
    "reserved")
        echo "<td align=center>Ԥ</td>"
        ;;
    esac
   if [ ${bridge} -eq 0 ]; then
        echo "<td align=center>·</td>"
    else
        if [ "${pdir}" = "in" ]; then
            echo "<td align=center>${bridge}-></td>"
        else
            echo "<td align=center>${bridge}-></td>"
        fi
    fi
    echo "<td align=center>${prate}</td>"
    echo "<td align=right>${inbps}</td>"
    echo "<td align=right>${outbps}</td>"
    if [ "${disable}" = "yes" ]; then
        echo "<td align=center style=\"color:#ff0000\">ʧЧ</td>"
    else
        echo "<td align=center style=\"color:#0000ff\"></td>"
    fi
    echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:OnModifyPipe('/cgi-bin/Setup/pipe_edit?pname=${pname}&bridge=${bridge}&ptype=${ptype}&pdir=${pdir}&prate=${prate}&plog=${plog}')\">༭</a>&nbsp;&nbsp;&nbsp;<a style=\"color:#0000ff\" href=\"javascript:OnDeletePipe('${pname}')\">ɾ</a></td>"
    echo "</tr>"
    if [ "${idname}" = "row1" ]; then
        idname="row2"
    else
        idname="row1"
    fi
done

echo -n "
</table>
";
if [ "${curpolicy}" = "0" ]; then
	echo "</body></html>"
	exit 0
fi

echo -n "
<br> 
<table style=\"width:980; font:bold 14px; color:#CE6C04\">
<tr>
        <td align=left><b>Active:${curpolicyname}</b>&nbsp; <a style=\"color:#ff0000;font:bold  13px;\" href=\"javascript:openPolicyTime()\"><b>(˴޸ĲԵ)</b></a></td>
</tr>   
</table>
<table width=980 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
        <td width=30  align=center></td>
        <td width=75  align=center>·</td>
        <td width=105 align=center>ַ</td>
        <td width=105 align=center>ַ</td>
        <td width=70  align=center>Э</td>
        <td width=60  align=center>û</td>
        <td width=70  align=center></td>
        <td width=60  align=center>IP</td>
        <td width=60  align=center>Զ</td>
        <td width=30  align=center>DSCP</td>
        <td width=50  align=center>ȼ</td>
        <td width=50  align=center>ƥ</td>
        <td width=125 align=center>ǰ/(bps)</td>
        <td width=*   align=center><input type=button style=\"width:100%;height:20px\" onclick=\"onAddRule('${curpolicy}')\" value=\"Ӳ>>\"></input></td>
</tr> 
";
idname="row1"
${FLOWEYE} policy getgrp ${curpolicy} | \
while read polno bridge dir appid appname from intype inip to outtype outip action nextstep iprate prclevel \
pktbps pktbps2 tos pri natip theothers
do
	echo "<tr id=${idname}>"
	echo "<td align=center>${polno}</td>"
    	isproxy=`echo ${bridge} | cut -d'-' -f1`
    	if [ "${isproxy}" = "PROXY" -o "${isproxy}" = "proxy" ]; then
		bgname="${bridge}->"
	else
		if [ ${bridge} -eq 0 ]; then
			bgname=""
		else
			bgname="${bridge}->"
		fi
	fi
	case "${dir}" in
	"both")
		if [ "${bgname}" = "" ]; then
			echo "<td align=center>·</td>"
		else
			echo "<td align=center>${bgname}˫</td>"
		fi
		;;
	"in")
		echo "<td align=center>${bgname}</td>"
		;;
	"out")
		echo "<td align=center>${bgname}</td>"
		;;
	esac
	if [ "${intype}" = "table" ]; then
		echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${inip}')\">${inip}</a></td>"
	else
		echo "<td align=center>${inip}</td>"
	fi
	if [ "${outtype}" = "table" ]; then
		echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${outip}')\">${outip}</a></td>"
	else
		echo "<td align=center>${outip}</td>"
	fi
			
	if [ "${appname}" = "any" ]; then
		echo "<td align=center></td>"
	else
		echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:showApp('${appid}', '${appname}')\">${appname}</a></td>"
	fi
	if [ "${natip}" != "0" ]; then
		echo "<td align=center>${natip}</td>"
	else
		echo "<td align=center></td>"
	fi
	if [ "${action}" = "deny" ]; then
		echo "<td align=center></td>"
	elif [ "${action}" = "permit" ]; then
		echo "<td align=center></td>"
	else
		actiontype=`echo ${action} | cut -d'-' -f1`
		proxyname=`echo ${action} | cut -d'-' -f2-`
		if [ "${actiontype}" = "PROXY" ]; then
			echo "<td align=center>"
			echo "<a style=\"color:#0000ff\" href=\"javascript:showProxy('${proxyname}')\">${action}</a>"
			echo "</td>"
		else
			echo "<td align=center>${action}</td>"
		fi
	fi
	[ "${iprate}" = "0" ] && iprate=""
	echo "<td align=right>${iprate}</td>"
        if [ "${prclevel}" != "0" ]; then
                echo "<td align=center>${prclevel}ǿ</td>"
	else
                echo "<td align=center></td>"
        fi
	if [ "${tos}" != "0" ]; then
		echo "<td align=center>${tos}</td>"
	else
		echo "<td align=center></td>"
	fi
	if [ "${pri}" != "0" ]; then
		echo "<td align=center>${pri}</td>"
	else
		echo "<td align=center></td>"
	fi
	if [ "${nextstep}" = "continue" ]; then
		echo "<td align=center></td>"
	else
		echo "<td align=center>ֹͣ</td>"
	fi
	echo "<td style=\"color:#0000ff\" align=right>${pktbps}&nbsp;/&nbsp;${pktbps2}</td>"
	echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:modifyRule('group=${curpolicy}&polno=${polno}&intype=${intype}&inip=${inip}&outtype=${outtype}&outip=${outip}&action=${action}&matchact=${nextstep}&iprate=${iprate}&bridge=${bridge}&dir=${dir}&appid=${appid}&prclevel=${prclevel}&tos=${tos}&priority=${pri}&natip=${natip}')\">&nbsp;༭&nbsp;<a style="color:#0000ff" href=\"javascript:deleteRule('${curpolicy}', '${polno}')\">&nbsp;ɾ&nbsp;</a></td>"
        	echo "</tr>"
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else
		idname="row1"
	fi
done

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