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

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
	function beofreCommit(frm)
	{
		var mac  = document.getElementsByName(\"mac\")[0];
		var ip   = document.getElementsByName(\"ip\")[0];
		var desc = document.getElementsByName(\"desc\")[0];
		mac.value  = TrimAll(mac.value);
		ip.value   = TrimAll(ip.value);
		desc.value = TrimAll(desc.value);
		var adds = mac.value.split(\":\");
		if (adds.length != 6) {
			var adds2 = mac.value.split(\"-\");
			if (adds2.length != 6) {
				alert(\"ȷMACַ!\");
				return false;
			}
		}
		if (!IsIPAddr(ip.value)) {
			alert(\"ȷIPַ!\");
			ip.select();
			return false;
		}
		if (mac.value == \"00:00:00:00:00:00\" ||
		    mac.value == \"00-00-00-00-00-00\") {
			alert(\"ЧMACַ!\");
			mac.select();
			return false;
		}
		if (desc.value != \"\" && ! IsName(desc.value)) {
			alert(\"ЧıעϢ!\");
			desc.select();
			return false;
		}
		return true;
	}
	function onCancel() {
		window.location.href = \"/cgi-bin/Route/dhcpsvr_static\";
	}
</script>
";
if [ "${REQUEST_METHOD}" = "POST" ]; then
	operator_check "${myself}"
	cmdargs="mac=${CGI_mac} ip=${CGI_ip}"
	[ "${CGI_desc}" != "" ] && cmdargs="${cmdargs} desc=${CGI_desc}"
	errmsg=`${FLOWEYE} dhcpsta set ${cmdargs}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ʧ:${errmsg}"
	else
		afm_load_page 0 "/cgi-bin/Route/dhcpsvr_static"
		exit 0
	fi
fi
for nameval in `${FLOWEYE} dhcpsta get mac=${CGI_mac}`
do
	eval "CGI_${nameval}"
done

echo -n "
<body>
"; cgi_show_title "DHCP->޸ľ̬" 
echo -n "
<br>
<form method=post onsubmit=\"return beofreCommit(this)\" action=\"${myself}\">
<table style=\"font:14px\" width=600 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td width=\"40\"></td>
        <td width=\"80\" align=left>MACַ</td>
        <td width=\"400\" align=left>
		<input type=text name=\"mac\" style=\"width:150px\" maxlength=\"17\" value=\"${CGI_mac}\" />
		&nbsp;(xx-xx-xx-xx-xx-xx  xx:xx:xx:xx:xx:xx)
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>̬IP</td>
	<td align=left><input type=text name=ip style=\"width:150px\" maxlength=\"15\" value=\"${CGI_ip}\" /></td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>ע</td>
	<td align=left>
		<input type=text name=desc style=\"width:150px\" maxlength=\"32\" value=\"${CGI_desc}\" />
		&nbsp;(ѡ)
	</td>
</tr>
</table>
<table style=\"width:600; border-bottom:1px #787882 solid; color:#0000ff\">
	<tr><td align=right>&nbsp;</td></tr>
</table>
<table style=\"width:600\"> 
<tr>
        <td align=right>
		<input type=submit style=\"width:80\" value=\"ύ\"/>
		<input type=button style=\"width:80\" value=\"ȡ\" onclick=\"onCancel()\"/>
	</td>
</tr>
</table>
</form>
</body>
</html>
";