#!/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 
. /etc/PG.conf
myself="/cgi-bin/Maintain/`basename $0`"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
	function beforeAdd(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/Maintain/dhcp_static\";
	}
</script>
";
touch ${PGETC}/dhcpd.conf
touch ${PGETC}/dhcpd.static
.     ${PGETC}/dhcpd.conf
touch ${DATAPATH}/dhcpd.lease
MAC=
IP=
DESC=
if [ "X$CGI_EDIT" != "X" ]; then
	operator_check "$myself"
	MAC=$CGI_EDIT
	IP=$CGI_IP
	DESC=$CGI_DESC
fi
if [ "X$CGI_SUBMIT" != "X" ]; then
	operator_check "${myself}"
	if [ "X$ENABLE_STATIC" = "X" ]; then
		afm_dialog_msg "þ̬!"
		afm_load_page 0 "/cgi-bin/Maintain/dhcp_config"
	else
		if [ "X$CGI_EDIT" != "X" ]; then
			CGI_EDIT=`echo $CGI_EDIT | sed 's/-/:/g'`
			errmsg=`${PGPATH}/bin/ipe_dhctl del lease mac=$CGI_EDIT nip=$CGI_EDIP`
		fi
		CGI_MAC=`echo $CGI_MAC | sed 's/-/:/g' | tr "[A-F]" "[a-f]"`
		errmsg=`${PGPATH}/bin/ipe_dhctl add lease mac=$CGI_MAC nip=$CGI_IP desc=$CGI_DESC type=0`
		afm_dialog_msg "ɹ!"
		afm_load_page 0 "/cgi-bin/Maintain/dhcp_static"
	fi
fi
echo "<body>"
cgi_show_title "DHCP->̬" 

echo -n "
<br>
<form method=post onsubmit=\"return beforeAdd(this)\"
";
echo "action=\"${myself}\">"

echo -n "
<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\"
		";
		echo "value=\"$MAC\"/>"
		
echo -n "
		&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\"
		";
		echo "value=\"$IP\"/>"
		
echo -n "
	</td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>ע</td>
	<td align=left>
		<input type=text name=\"DESC\" style=\"width:150px\" maxlength=\"32\"
		";
		echo "value=\"$DESC\"/>"
		
echo -n "
		&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 name=\"SUBMIT\" style=\"width:80\" value=\"ύ\"/>
		<input type=button style=\"width:80\" value=\"ȡ\" onclick=\"onCancel()\"/>
		";
		echo "<input type=hidden name=EDIT value=\"$MAC\"/>"
		echo "<input type=hidden name=EDIP value=\"$IP\"/>"
		
echo -n "
	</td>
</tr>
</table>
</form>
</body>
</html>
";