#!/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 dns = document.getElementsByName(\"dnstoadd\")[0];
	dns.value = dnsobj.value;
}
function beforeAddDns(frm)
{
	var dnsobj = document.getElementsByName(\"dnstoadd\")[0];
	dnsobj.value = TrimAll(dnsobj.value);
	if (dnsobj.value == \"\") {
		alert(\",www.sohu.com!\");
		dnsobj.select();
		return false;
	}
	return true;
}
function beforeRmvDns(frm)
{
	var dnslist = document.getElementsByName(\"dnslist\")[0];
	var dns = document.getElementsByName(\"dnstormv\")[0];
	if (dnslist.value == \"\") {
		alert(\"ѡҪɾURL!\");
		return false;
	}
	dns.value = dnslist.value;
	return true;
}
function beforeLoadfile(frm)
{
	var dnsfile = document.getElementsByName(\"dnsfile\")[0];
	if (dnsfile.value == \"\") {
		alert(\"ļ·!\");
		return false;
	}
	return true;
}
</script>
";
if [ "${CGI_action}" = "adddns" ]; then
	operator_check "${myself}?urldnsgrp=${CGI_urldnsgrp}"
	errmsg=`${FLOWEYE} dns add ${CGI_urldnsgrp} "${CGI_dnstoadd}"`
	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
	operator_check "${myself}?urldnsgrp=${CGI_urldnsgrp}"
	errmsg=`${FLOWEYE} dns remove ${CGI_urldnsgrp} "${CGI_dnstormv}"`
	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
	operator_check "${myself}?urldnsgrp=${CGI_urldnsgrp}"
	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}"
else
	CGI_dnsgrpname=`${FLOWEYE} dns listgrp | awk '{print $2,$3}' | grep "^${CGI_urldnsgrp} " | awk '{print $2}'`
fi
cgi_show_title "Զ->Ⱥ->༭"

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>
<form method=post action=\"${myself}\" onsubmit=\"return beforeRmvDns(this)\">
<tr id=row1 height=350>
	<td align=center valign=center>&nbsp;&nbsp;<b>б</b></td>
	<td><select style=\"width:100%;height:350;\" 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 width=* align=center>
		<input type=hidden name=urldnsgrp value=\"${CGI_urldnsgrp}\"></input>
		<input type=hidden name=dnstormv  value=\"\"></input>
		<input type=hidden name=action value=\"rmvdns\"></input>
		<input type=submit name=rmvdns value=\"ɾ\"></input>
	</td>
</tr>
</form>
<form method=post action=\"${myself}\" onsubmit=\"return beforeAddDns(this)\">
<tr id=row2>
	<td></td>
	<td><input type=text style=\"width:100%\" name=dnstoadd value=\"\"></input></td>
	<td width=* align=center>
		<input type=hidden name=urldnsgrp value=\"${CGI_urldnsgrp}\"></input>
		<input type=hidden name=action value=\"adddns\"></input>
		<input type=submit style=\"width:90;height:22px\" value=\"\"></input>
	</td>
</tr>
</form>
</table>
<br>
<form method=post action=\"${myself}\" onsubmit=\"return beforeLoadfile(this)\" enctype=\"multipart/form-data\">
<table width=800 border=0 cellspacing=1 cellpadding=1 bgcolor=\"#ffffff\">
<tr height=22>
        <td width=120 align=center style=\"font-size:13px\"><b>ļض:</b></td>
        <td width=600 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:100%\" value=\"ļ\"></input>
        </td>
</tr>
</table>
</form>
</body>
</html>
";