#!/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}

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

echo -n "
<body>
"; cgi_show_title "Ӧ·->->DNSܿ" 
echo -n "
<br>
<table width=1080 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=130 align=right>Դַ</td>
	<td width=130 align=right>ĿDNS</td>
	<td width=130 align=right></td>
	<td width=250 align=right>ִж</td>
	<td width=100 align=right>ƥ</td>
        <td width=*   align=right><a style=\"color:#0000ff;font-size:14px\" href=\"javascript:onAddRule()\">Ӳ>>&nbsp;&nbsp;</a></td>
</tr>
";
idname="row1"
${FLOWEYE} dns listrule | \
while read polno intype inip outtype outip dnstype dns bdg action actarg pkts pxystate disabled others 
do
	if [ "${disabled}" = "0" ]; then
		echo "<tr id=${idname} height=22>"
	else
		echo "<tr id=row4 height=22>"
	fi
	echo "<td align=center>${polno}</td>"
	if [ $bdg -eq 0 ]; then
		echo "<td align=right>·&nbsp;</td>"
	else
		echo "<td align=right>$bdg&nbsp;</td>"
	fi
        if [ "${intype}" = "table" ]; then
                echo "<td align=right><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${inip}')\">${inip}&nbsp;</a></td>"
        else
                echo "<td align=right>${inip}&nbsp;</td>"
        fi
        if [ "${outtype}" = "table" ]; then
                echo "<td align=right><a style=\"color:#0000ff\" href=\"javascript:showIPGrp('${outip}')\">${outip}&nbsp;</a></td>"
        else
                echo "<td align=right>${outip}&nbsp;</td>"
        fi
	if [ "${dns}" = "any" ]; then
		echo "<td align=right>&nbsp;</td>"
	else
		if [ "${dnstype}" = "usr" ]; then
			echo "<td align=right><a style=\"color:#0000ff\" href=\"javascript:dnsEdit('${dns}')\">${dns}&nbsp;</a></td>"
		else
			echo "<td align=right>*${dns}&nbsp;</td>"
		fi
	fi
	case "${action}" in
	"pass")
		echo "<td align=right>&nbsp;</td>"
		;;
	"rdr")
		actarg="${actarg#_wg.}"
		if [ "${pxystate}" = "1" ]; then
			echo "<td align=right>ض-><a style=\"color:#0000ff\" href=\"javascript:showProxy('${actarg}')\"><b>${actarg}&nbsp;</b></a></td>"
		else
			echo "<td align=right>ض-><a style=\"color:#ff0000\" href=\"javascript:showProxy('${actarg}')\"><b>${actarg}&nbsp;</b></a></td>"
		fi
		;;
	"reply")
		echo "<td align=right>ٳIP->${actarg}&nbsp;</td>"
		;;
	"deny")
		echo "<td align=right>&nbsp;</td>"
		;;
	esac
	echo "<td align=right>${pkts}&nbsp;</td>"
       	echo "<td align=right>"
	echo "<a style=\"color:#0000ff\" href=\"javascript:modifyRule('${polno}')\">&nbsp;༭&nbsp;</a>"
	echo "<a style="color:#0000ff" href=\"javascript:deleteRule('${polno}')\">&nbsp;ɾ&nbsp;</a>"
        if [ ${disabled} -eq 0 ]; then 
		echo "<a style=\"color:#0000ff\" href=\"javascript:disablePolicy('${polno}')\">&nbsp;&nbsp;</a>"
	else
                echo "<a style=\"color:#ff0000\" href=\"javascript:enablePolicy('${polno}')\">&nbsp;&nbsp;&nbsp;</a>"
	fi
	echo "</td></tr>"
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else
		idname="row1"
	fi
done

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