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

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function beforeSet(frm)
{
	var ipaddr  = document.getElementsByName(\"ipaddr\")[0];
	var macaddr = document.getElementsByName(\"macaddr\")[0];
	ipaddr.value = TrimAll(ipaddr.value);
	if (!IsIPAddr(ipaddr.value)) {
		alert(\"ϷIPַ!\");
		ipaddr.select();
		return false;
	}
	macaddr.value = TrimAll(macaddr.value);
	var adds1 = macaddr.value.split(\":\");
	if (adds1.length != 6) {
		var adds2 = macaddr.value.split(\"-\");
		if (adds2.length != 6) {
			alert(\"ЧMACַ!\");
			macaddr.select();
			return false;
		}
	}
	return true;
}
function onCancel(returl)
{
	if (returl == \"config\")
		window.location.href = \"/cgi-bin/Setup/ipmac_list\";
	else
		window.location.href = \"/cgi-bin/Monitor/ipmac_stat\";
}
</script>
";
if [ "${REQUEST_METHOD}" = "POST" ]; then
	operator_check "${myself}"
	errmsg=`${FLOWEYE} ipmac set ipmac=${CGI_macaddr}-${CGI_ipaddr}`
	if [ "$?" != "0" ]; then
		afm_dialog_msg "ʧ:${errmsg}"
	else
		afm_dialog_msg "ɹ!"
		if [ "${CGI_returl}" = "config" ]; then
			afm_load_page 0 "/cgi-bin/Setup/ipmac_list"
		else
			afm_load_page 0 "/cgi-bin/Monitor/ipmac_stat"
		fi
		exit 0
	fi
fi

echo -n "
<body>
"; cgi_show_title "MACܿ->޸MAC" 
echo -n "
<br>
<form method=post onsubmit=\"return beforeSet(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>IPַ</td>
	<td width=* align=left>
		<input type=text name=ipaddr style=\"width:120px\" value=\"${CGI_ipaddr}\"></input>
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>MACַ</td>
        <td width=* align=left>
		<input type=text name=macaddr style=\"width:150px\" value=\"${CGI_macaddr}\"></input>
		&nbsp;(xx-xx-xx-xx-xx-xxxx:xx:xx:xx:xx:xx)
	</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>
		<input type=hidden name=returl value=\"${CGI_returl}\"></input>
		<input type=button style=\"width:80\" value=\"ȡ\" onclick=\"onCancel('${CGI_returl}')\"></input>
	</td>
</tr>
</table>
</form>
</body>
</html>
";