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

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function beforeCommit(frm)
{
	var postip = document.getElementsByName(\"post_ip\")[0];
	var posttag = document.getElementsByName(\"post_tag\")[0];
	var postport = document.getElementsByName(\"post_port\")[0];
  
	posttag.value = TrimAll(posttag.value);
	if (posttag.value == \"\" ) {
		alert(\"λʶΪ!\");
		posttag.select();
		return false;
	}
	postip.value = TrimAll(postip.value);
	if (postip.value != \"\" && !IsIPAddr(postip.value)) {
		alert(\"ȷIPַ!\");
		postip.select();
		return false;
	}
	postport.value = TrimAll(postport.value);
	if (postport.value == \"\" && !IsDigitIn(postport.value, 1, 65535)) {
		alert(\"Ķ˿ں!\");
		postport.select();
		return false;
	}

	return true;
}
</script>
";

if [ "${REQUEST_METHOD}" = "POST" ]; then
	operator_check "${myself}"

	if [ "${CGI_post_tag}" = "" -o "${CGI_post_ip}" = "" -o \
       "${CGI_post_port}" = "" ]; then
  		afm_dialog_msg "ЧĲ!"
  else
      server_tag=${CGI_post_tag}
      server_ip=${CGI_post_ip}
      server_port=${CGI_post_port}
      echo -n "server_tag=${server_tag}
server_ip=${CGI_post_ip}
server_port=${CGI_post_port}
lasttime=`date +%s`
" > ${PGETC}/idping.conf
      if [ $? -eq 0 ]; then
          sync
          afm_dialog_msg "ɹ!"
      		afm_load_page 0 "${myself}"
      		exit 0
      else
  		    afm_dialog_msg "ʧ!"
      fi
  fi

fi

if [ -f ${PGETC}/idping.conf ]; then 
			. ${PGETC}/idping.conf
fi
echo -n "
<body>
"; cgi_show_title "߼-->λ" 

echo -n "
<br>
<table style=\"width:540; border-bottom:1px #787882 solid; font:bold  14px; color:#0000ff\">
<tbody><tr>
	<td style=\"width:100%;font:14px\"><b>˵ùܰûԼĶ̬IPַ</b></td>
</tr>
</tbody></table>
<br>
<form method=post onsubmit=\"return beforeCommit(this)\" action=\"${myself}\">
<table width=720 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr id=row1>
	<td style=\"width:50\"></td>
        <td align=left style=\"width:120\">λʶ</td>
        <td align=left width=*><input type=text name=post_tag value=\"${server_tag}\" style=\"width:110\"></input>
        &nbsp;32Ӣģ16ģ˱ǻᷢ͸λʶû˭
        </td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>λIP</td>
        <td align=left width=*><input type=text name=post_ip value=\"${server_ip}\" style=\"width:110\"></input>
        &nbsp;( x.x.x.x )
        </td>
</tr>
<tr id=row1>
	<td></td>
        <td align=left>λ˿</td>
        <td align=left width=*>
		<input type=text name=post_port value=\"${server_port}\" style=\"width:110\"></input>
		&nbsp;(1~65535)
	</td>
</tr>
</table>
<table style=\"width:720; border-bottom:1px #787882 solid; color:#0000ff\">
<tr><td align=right>&nbsp;</td></tr>
</table>
<table style=\"width:720\"> 
<tr>
        <td align=right>
		<input type=submit style=\"width:80\" value=\"ύ\"></input>
	</td>
</tr>
</table>
</form>
</body>
</html>
";
