#!/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} urlfilter 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/urlfilter_addrule?policy=\" + policy;
	ShowWindow(url, \"\", 640, 450);
}
function modifyRule(group, polno) 
{
	var url = \"/cgi-bin/Setup/urlfilter_setrule?policy=\" + group + \"&polno=\" + polno;
	ShowWindow(url, \"\", 640, 430);
}
function deleteRule(group, rule)
{
	if (confirm(\"ȷҪɾò?\")) 
		window.location.href = \"${cgipath}?action=rmvrule\" + 
		                       \"&group=\" + group + \"&ruleid=\" + rule;
}
function openPolicyTime()
{
	var url = \"/cgi-bin/Setup/urlfilter_listime\";
	ShowWindow(url, \"\", 840, 500);
}
function dnsEdit(grpname)
{
        var url = \"/cgi-bin/Protocol/urldnsgrp_edit?grpname=\" + grpname;
        ShowWindow(url, \"\", 840, 560);
}
function showIPGrp(gname)
{
        var url = \"/cgi-bin/Protocol/ipgrp_list?ipgrp=\" + gname;
        ShowWindow(url, \"\", 860, 630);
}
</script>
";
if [ "${CGI_action}" = "rmvrule" ]; then
	errmsg=`${FLOWEYE} urlfilter rmvrule ${CGI_group} ${CGI_ruleid}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
	fi
fi

echo -n "
<body>
"; 
cgi_show_title "ǰ->HTTPܿز"
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:900; 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=900 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
        <td width=35  align=center></td>
        <td width=100 align=center>ַ</td>
	<td width=90  align=center>ʷʽ</td>
	<td width=100 align=center>Ŀ</td>
	<td width=80  align=center>ļ</td>
	<td width=80  align=center>û</td>
	<td width=220  align=center>ִж</td>
	<td width=80  align=center>ƥݰ</td>
        <td width=*   align=center><input type=button style=\"width:100%;height:21px\" onclick=\"onAddRule('${curpolicy}')\" value=\"Ӳ>>\"></input></td>
</tr> 
";
idname="row1"
${FLOWEYE} urlfilter getgrp ${curpolicy} | \
while read polno intype inip method dnstype dns ext natip action pkts actarg others
do      
	echo "<tr id=${idname}>"
	echo "<td align=center>${polno}</td>"
        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 [ "${method}" = "get" ]; then
		method="Ϣ"
	elif [ "${method}" = "post" ]; then
		method="Ϣϴ"
	else
		method="ⷽʽ"
	fi	
	echo "<td align=center>${method}</td>"
	if [ "${dns}" != "any" ]; then
		if [ "${dnstype}" = "sys" ]; then 
			echo "<td align=center>*${dns}</td>"
		else
			echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:dnsEdit('${dns}')\">${dns}</a></td>"
		fi
	else
		echo "<td align=center></td>"
	fi
	[ "${ext}" = "any" ] && ext=""
	echo "<td align=center>${ext}</td>"
	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}" = "accept" -o "${action}" = "permit" ]; then
		echo "<td align=center></td>"
	elif [ "${action}" = "prompt" ]; then
		echo "<td align=center>ʾϢ->\"${actarg}\"</td>"
	elif [ "${action}" = "redirect" ]; then
		echo "<td align=center>ض->${actarg}</td>"
	elif [ "${action}" = "reqfwd" ]; then
		echo "<td align=center>ת->${actarg}</td>"
	else
		echo "<td align=center>δ֪</td>"
	fi
	echo "<td align=right style=\"color:#ff0000\">${pkts}</td>"
       	echo "<td align=center><a style="color:#0000ff" href=\"javascript:modifyRule('${curpolicy}', '${polno}')\"</a>&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>
";