#!/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
myself="/cgi-bin/Route/`basename $0`"
afm_load_page 30 "${myself}?link=${CGI_link}"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function onAddRule() 
{
	window.location.href = \"/cgi-bin/Route/policy_addrule\";
}
function modifyRule(polno) 
{
	window.location.href = \"/cgi-bin/Route/policy_setrule?id=\" + polno;
}
function deleteRule(polno)
{
	if (confirm(\"ȷҪɾù?\")) {
		window.location.href = \"${myself}?action=remove&id=\" + polno;
	}
}
function showProxy(proxyname)
{
	var url = \"/cgi-bin/Monitor/proxy_show?proxyname=\" + proxyname;
	ShowWindow(url, \"\", 350, 400); 
}
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); 
}
function enablePolicy(polno)
{
	window.location.href = \"${myself}?action=enable&id=\" + polno;
}
function disablePolicy(polno)
{
	window.location.href = \"${myself}?action=disable&id=\" + polno;
}
</script>
";
if [ "${CGI_action}" = "remove" ]; then
	operator_check "${myself}"
	errmsg=`${FLOWEYE} route remove id=${CGI_id}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	fi
fi
if [ "${CGI_action}" = "enable" ]; then
	operator_check "${myself}"
	errmsg=`${FLOWEYE} route enable id=${CGI_id}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	fi
fi
if [ "${CGI_action}" = "disable" ]; then
	operator_check "${myself}"
	errmsg=`${FLOWEYE} route disable id=${CGI_id}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	fi
fi

echo -n "
<body>
"; cgi_show_title "Ӧ·->·ɲ" 
echo -n "
<br>
<table width=\"1080\" border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr>
        <td width=50  align=center></td>
        <td width=80 align=center>Դӿ</td>
        <td width=180 align=center>Դַ:˿</td>
        <td width=180 align=center>Ŀַ:˿</td>
        <td width=70  align=center>Э</td>
        <td width=100  align=center>Ӧ</td>
        <td width=60  align=center>DSCP</td>
        <td width=120 align=center>·ɶ</td>
        <td width=80  align=center></td>
        <td width=*   align=center><a style=\"color:#0000ff;font-size:14px;\" href=\"javascript:onAddRule()\">Ӳ>></a></td>
</tr> 
";
idname="row1"
${FLOWEYE} route list | while read polno iniftype inifname proto appid appname \
srctype srcip srcport dsttype dstip dstport dscp disabled action nexthop state pkts theothers
do 
echo -n "
"; if [ ${disabled} -ne 0 ]; then 
echo -n "
	<tr id=row4>
	<td align=center>${polno}</td>
"; else 
echo -n "
	<tr id=${idname}>
	<td align=center>${polno}</td>
"; fi 
echo -n "
	<td align=center>${inifname}</td>
"; if [ "${srcport}" = "any" ]; then
	 srcport=""
    else
	 srcport=":${srcport}"
    fi

echo -n " 
	"; if [ "${srctype}" = "table" ]; then 
echo -n "
		<td align=center><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${srcip}')\">${srcip}</a>${srcport}</td>
	"; else 
echo -n "
		<td align=center>${srcip}${srcport}</td>
	"; fi 
echo -n "
	"; if [ "${dstport}" = "any" ]; then
		 dstport=""
	    else
		 dstport=":${dstport}"
	    fi
	
echo -n " 
	"; if [ "${dsttype}" = "table" ]; then 
echo -n "
		<td align=center><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${dstip}')\">${dstip}</a>${dstport}</td>
	"; else 
echo -n "
		<td align=center>${dstip}${dstport}</td>
	"; fi 
echo -n "
	<td align=center>${proto}</td>
	"; if [ "${appid}" = "any" ]; then 
echo -n "
	<td align=center>any</td>
	"; else 
echo -n "
	<td align=center><a style=\"color:#0000ff\" href=\"javascript:showApp('${appid}', '${appname}')\">${appname}</a></td>
	"; fi 
echo -n "
	<td align=center>${dscp}</td>
";
	[ "${action}" = "nat" ] && action="NAT"
	[ "${action}" = "route" ] && action="FWD"

echo -n "
"; if [ ${state} -eq 0 ]; then 
echo -n "
	<td align=center>${action}-><a style=\"color:#ff0000\" href=\"javascript:showProxy('${nexthop}')\"><b>${nexthop}</b></a></td>
"; else 
echo -n "
	<td align=center>${action}-><a style=\"color:#0000ff\" href=\"javascript:showProxy('${nexthop}')\">${nexthop}</a></td>
"; fi 
echo -n "
	<td align=right>${pkts}</td>
	<td align=center>
		<a style=\"color:#0000ff\" href=\"javascript:modifyRule('${polno}')\">&nbsp;༭&nbsp;</a>
		<a style=\"color:#0000ff\" href=\"javascript:deleteRule('${polno}')\">&nbsp;ɾ&nbsp;</a>
	"; if [ ${disabled} -eq 0 ]; then 
echo -n "
		<a style=\"color:#0000ff\" href=\"javascript:disablePolicy('${polno}')\">&nbsp;&nbsp;</a>
	"; else 
echo -n "
		<a style=\"color:#ff0000\" href=\"javascript:enablePolicy('${polno}')\">&nbsp;&nbsp;</a>
	"; fi 
echo -n "
	</td>
       	</tr>
";
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else
		idname="row1"
	fi
done

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