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

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script languate=javascript>
function onAddRule()
{ 
	window.location.href = \"/cgi-bin/Setup/dns_addrule\";
}
function modifyRule(polno) 
{
	window.location.href = \"/cgi-bin/Setup/dns_setrule?polno=\" + polno;
}
function deleteRule(rule)
{
	if (confirm(\"ȷҪɾù?\")) {
		window.location.href = \"/cgi-bin/Setup/dns_listrule?action=rmvrule\" +
		                       \"&ruleid=\" + rule;
	}
}
function dnsEdit(grpname)
{
        var url = \"/cgi-bin/Protocol/urldnsgrp_edit?grpname=\" + grpname;
        ShowWindow(url, \"\", 840, 560);
}
</script>
";
if [ "${CGI_action}" = "rmvrule" ]; then
	errmsg=`${FLOWEYE} dns rmvrule ${CGI_ruleid}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
	fi
fi
policylist=`${FLOWEYE} urlfilter listgrp`

echo -n "
<body>
"; cgi_show_title "DNSܿ->ܿز" 
echo -n "
<br>
<table width=900 border=0 cellspacing=1 cellpadding=1> 
<tr id=tblhdr height=22>
        <td width=40  align=center></td>
	<td width=90  align=center>·</td>
	<td width=120 align=center>Դַ</td>
	<td width=120 align=center>ĿDNS</td>
	<td width=120 align=center></td>
	<td width=280 align=center>ִж</td>
        <td width=*   align=center><input type=button style=\"width:100%;height:21px\" onclick=\"onAddRule()\" value=\"Ӳ>>\"></input></td>
</tr>
";
idname="row1"
${FLOWEYE} dns listrule | \
while read polno intype inip outtype outip dnstype dns bdg action actarg pkts others 
do
	echo "<tr id=${idname}>"
	echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:modifyRule('${polno}')\">${polno}</a></td>"
	if [ $bdg -eq 0 ]; then
		echo "<td align=center>·</td>"
	else
		echo "<td align=center>$bdg</td>"
	fi
	echo "<td align=center>${inip}</td>"
	echo "<td align=center>${outip}</td>"
	
	if [ "${dns}" = "any" ]; then
		echo "<td align=center></td>"
	else
		if [ "${dnstype}" = "usr" ]; then
			echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:dnsEdit('${dns}')\">${dns}</a></td>"
		else
			echo "<td align=center>*${dns}</td>"
		fi
	fi
	case "${action}" in
	"pass")
		echo "<td align=center></td>"
		;;
	"rdr")
		echo "<td align=center>ض->${actarg}</td>"
		;;
	"reply")
		echo "<td align=center>ٳΪIP->${actarg}</td>"
		;;
	"deny")
		echo "<td align=center></td>"
		;;
	esac
       	echo "<td align=center><a style=\"color:#0000ff\" href=\"javascript:modifyRule('${polno}')\">&nbsp;&nbsp;༭&nbsp;&nbsp;</a><a style="color:#0000ff" href=\"javascript:deleteRule('${polno}')\">&nbsp;&nbsp;ɾ&nbsp;&nbsp;</a></td>"
	echo "</tr>"
	if [ "${idname}" = "row1" ]; then
		idname="row2"
	else
		idname="row1"
	fi
done

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