#!/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/Protocol/`basename $0`"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script languate=javascript>
function onDNSChanged(dnsobj)
{
	var ip = document.getElementsByName(\"dnsobj\")[0];
	ip.value = dnsobj.value;
	document.getElementsByName(\"adddns\")[0].disabled = false;
}
function onAddDNS(urldnsgrp)
{
	var dnsobj = document.getElementsByName(\"dnsobj\")[0];
	dnsobj.value = TrimAll(dnsobj.value);
	if (dnsobj.value == \"\") {
		alert(\",www.sohu.com!\");
		dnsobj.select();
		return false;
	}
	window.location.href = \"${myself}\" + \"?action=adddns&urldnsgrp=\" + urldnsgrp +\"&dns=\" + dnsobj.value;
}
function onRmvDNS(urldnsgrp)
{
	var dnsobj = document.getElementsByName(\"dnsobj\")[0];
	dnsobj.value = TrimAll(dnsobj.value);
	if (dnsobj.value == \"\") {
		alert(\"ѡҪɾIPַ!\");
		return false;
	}
	window.location.href = \"${myself}\" + \"?action=rmvdns&urldnsgrp=\" + urldnsgrp +\"&dns=\" + dnsobj.value;
}
</script>
";
if [ "${CGI_action}" = "adddns" ]; then
	errmsg=`${FLOWEYE} dns add ${CGI_urldnsgrp} "${CGI_dns}"`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
		afm_load_page 0 "${myself}?urldnsgrp=${CGI_urldnsgrp}"
		exit 0
	fi
fi
if [ "${CGI_action}" = "rmvdns" ]; then
	errmsg=`${FLOWEYE} dns remove ${CGI_urldnsgrp} "${CGI_dns}"`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
		afm_load_page 0 "${myself}?urldnsgrp=${CGI_urldnsgrp}"
		exit 0
	fi
fi
if [ "${CGI_action}" = "loadfile" ]; then
	errmsg=`${FLOWEYE} dns loadfile ${CGI_urldnsgrp} ${CGI_dnsfile}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ִ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
	fi
	rm -f ${CGI_dnsfile}
fi

echo -n "
<body>
"; 
if [ "${CGI_grpname}" != "" -a "${CGI_urldnsgrp}" = "" ]; then
	CGI_urldnsgrp=`${FLOWEYE} dns listgrp | awk '{print $2, $3, $4}' | grep " ${CGI_grpname} " | awk '{print $1}'`
	CGI_dnsgrpname="${CGI_grpname}"
fi
cgi_show_title "Զ->Ⱥ->༭"
CGI_dnsgrpname=`${FLOWEYE} dns listgrp | grep " ${CGI_urldnsgrp} " | awk '{print $3}'`

echo -n "
<br>
<table width=800 border=0 cellspacing=1 cellpadding=1 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=60></td>
	<td width=* style=\"color:#0000ff;font:13px\">˵:ϵͳȡ׺ƥ㷨sohu.com൱*.sohu.com</td>
</tr>
</table>
<br>
<table width=800 border=0 cellspacing=1 cellpadding=1>
<tr id=tblhdr height=22>
	<td width=120 align=center>Ⱥ</td>
	<td width=400 align=center><b>${CGI_dnsgrpname}</b></td>
        <td width=*   align=center></td>
</tr>
<tr id=row1 height=350>
	<td align=center valign=center>&nbsp;&nbsp;<b>б</b></td>
	<td><select style=\"width:100%;height:100%;\" name=dnslist size=50 onchange=\"onDNSChanged(this)\"> ";
		${FLOWEYE} dns dumpgrp ${CGI_urldnsgrp} | while read value
		do
			echo "<option value=\"${value}\">${value}</option>"
		done 
echo -n "
		</select>
	</td>
	<td></td>
</tr>
<tr id=row2>
	<td></td>
	<td><input type=text style=\"width:100%\" name=dnsobj></input></td>
	<td width=* align=center>
		<input type=button style=\"width:90;height:22px\" value=\"\" onclick=\"onAddDNS('${CGI_urldnsgrp}')\"></input>
	&nbsp;&nbsp;<input type=button name=adddns disabled style=\"width:90;height:22px\" value=\"ɾ\" onclick=\"onRmvDNS('${CGI_urldnsgrp}')\"></input>
	</td>
</tr>
</table>
<br>
<form method=post action=\"${myself}\" enctype=\"multipart/form-data\">
<table width=800 border=0 cellspacing=1 cellpadding=1 bgcolor=\"#ffffff\">
<tr height=22>
        <td width=340 style=\"font:14px bold\" align=left><b>ļDNSбڴļ·:</b></td>
        <td width=400 class=cssTDArial align=left>
                <input type=file name=dnsfile style=\"width:100%\">
        </td>
        <td align=right width=*>
                <input type=hidden name=action value=\"loadfile\"></input>
		<input type=hidden name=urldnsgrp value=\"${CGI_urldnsgrp}\"></input>
                <input type=submit style=\"width:90\" value=\"ύбļ\"></input>
        </td>
</tr>
</table>
</form>
</body>
</html>
";