#!/bin/sh
#This script is created by ssparser automatically. The parser first created by MaoShouyan
printf "Content-type: text/html;charset=gb2312
Cache-Control: no-cache

"
echo -n "";
. ../common/common.sh
myself="/cgi-bin/Monitor/`basename $0`"
afm_load_page 30 ${myself}
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, 470);
}
function modifyRule(group, polno) 
{
	var url = \"/cgi-bin/Setup/urlfilter_setrule?policy=\" + group + \"&polno=\" + polno;
	ShowWindow(url, \"\", 640, 450);
}
function deleteRule(group, rule)
{
	if (confirm(\"ȷҪɾò?\")) 
		window.location.href = \"${myself}?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);
}
function enablePolicy(grp, polno)
{
        var url;
        url = \"${myself}?action=enable&policy=\" + grp + \"&ruleid=\" + polno;
        window.location.href = url;
}
function disablePolicy(grp, polno)
{
        var url;
        url = \"${myself}?action=disable&policy=\" + grp + \"&ruleid=\" + polno;
        window.location.href = url;
}
</script>
";
if [ "${CGI_action}" = "rmvrule" ]; then
	operator_check "${myself}"
	errmsg=`${FLOWEYE} urlfilter rmvrule ${CGI_group} ${CGI_ruleid}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	fi
elif [ "${CGI_action}" = "disable" ]; then
	operator_check "${myself}?policy=${CGI_policy}"
	errmsg=`${FLOWEYE} urlfilter setrule group=${CGI_policy} id=${CGI_ruleid} disable=1`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	fi
elif [ "${CGI_action}" = "enable" ]; then
	operator_check "${myself}?policy=${CGI_policy}"
	errmsg=`${FLOWEYE} urlfilter setrule group=${CGI_policy} id=${CGI_ruleid} disable=0`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	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:true;font-size: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:1200; 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:14px;\" href=\"javascript:openPolicyTime()\"><b>(˴޸ĲԵ)</b></a></td>
</tr>   
</table>
<table width=1200 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
        <td width=40  align=center></td>
        <td width=120 align=right>Դַ</td>
	<td width=70  align=right>ʷʽ</td>
	<td width=120 align=right>վ</td>
	<td width=70  align=right>ļ</td>
	<td width=70  align=right>û</td>
	<td width=70  align=right>ƶն</td>
	<td width=70  align=right>ƥһ</td>
	<td width=60  align=right>ִж</td>
	<td width=300 align=right></td>
	<td width=70  align=right>ƥ</td>
        <td width=*   align=right><a style=\"color:#0000ff\" href=\"javascript:onAddRule('${curpolicy}')\">Ӳ>></a></td>
</tr> 
";
idname="row1"
${FLOWEYE} urlfilter getgrp ${curpolicy} | \
while read polno intype inip method dnstype dns ext natip hasms onlyfirst disabled action pkts actarg ifname others
do
	if [ ${disabled} -eq 1 ]; then
		echo "<tr id=row4>"
	else 
		echo "<tr id=${idname}>"
	fi
	echo "<td align=center>${polno}</td>"
        if [ "${intype}" = "table" ]; then
                echo "<td align=right><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${inip}')\">${inip}</a></td>"
        else
                echo "<td align=right>${inip}</td>"
        fi
	if [ "${method}" = "get" ]; then
		method="GET"
	elif [ "${method}" = "post" ]; then
		method="POST"
	else
		method="any"
	fi	
	echo "<td align=right>${method}</td>"
	if [ "${dns}" != "any" ]; then
		if [ "${dnstype}" = "sys" ]; then 
			echo "<td align=right>*${dns}</td>"
		else
			echo "<td align=right><a style=\"color:#0000ff\" href=\"javascript:dnsEdit('${dns}')\">${dns}</a></td>"
		fi
	else
		echo "<td align=right>any</td>"
	fi
	[ "${ext}" = "any" ] && ext="any"
	echo "<td align=right>${ext}</td>"
	if [ "${natip}" != "0" ]; then
		echo "<td align=right>${natip}</td>"
	else
		echo "<td align=right></td>"
	fi
	if [ "${hasms}" = "0" ]; then 
		echo "<td align=right></td>"
	else
		echo "<td align=right></td>"
	fi
	if [ ${onlyfirst} -eq 0 ]; then
		echo "<td align=right>no</td>"
	else
		echo "<td align=right>yes</td>"
	fi
	if [ "${action}" = "deny" ]; then
		echo "<td align=right><img src=\"/img/no.png\" style=\"margin-right:5px;vertical-align:middle;\" /></td>"
	elif [ "${action}" = "accept" -o "${action}" = "permit" ]; then
		echo "<td align=right><img src=\"/img/yes.png\" style=\"margin-right:5px;vertical-align:middle;\" /></td>"
	elif [ "${action}" = "prompt" ]; then
		echo "<td align=right>Ϣʾ</td>"
	elif [ "${action}" = "redirect" ]; then
		echo "<td align=right>ת</td>"
	elif [ "${action}" = "reqfwd" ]; then
		echo "<td align=right>ľ</td>"
	else
		echo "<td align=right>δ֪</td>"
	fi
	[ "${actarg}" = "null" ] && actarg=""
	echo "<td align=right>${actarg}&nbsp;</td>"
	echo "<td align=right style=\"color:#ff0000\">${pkts}</td>"
       	echo "<td align=right>"
	echo "<img style=\"margin-top:3px;\" src=\"/img/edit.png\" title=\"޸Ĳ\" onclick=\"modifyRule('${curpolicy}', '${polno}')\" />&nbsp;"
	echo "<img style=\"margin-top:3px;\" src=\"/img/delete.png\" title=\"ɾ\" onclick=\"deleteRule('${curpolicy}', '${polno}')\" />&nbsp;"
	if [ ${disabled} -eq 0 ]; then 
               	echo "<img style=\"margin-top:3px\" src=\"/img/disable.png\" title=\"ò\" onclick=\"disablePolicy('${curpolicy}', '${polno}')\" />&nbsp;"
	else 
               	echo "<img style=\"margin-top:3px\" src=\"/img/enable.png\" title=\"ò\" onclick=\"enablePolicy('${curpolicy}', '${polno}')\" />&nbsp;"
	fi
	echo "</td></tr>"
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else    
		idname="row1"
	fi
done

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