#!/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 "";
RAMDISK="/usr/ramdisk"
if [ -f ${RAMDISK}/PG.conf ]; then
        . ${RAMDISK}/PG.conf
        PGPATH="${RAMDISK}"
else
        . /etc/PG.conf
fi
FLOWEYE=${PGPATH}/bin/floweye
myself="/cgi-bin/`basename $0`"
echo "<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\">
<head><title>޸</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">
<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">
<META HTTP-EQUIV=\"Cache-Control\" content=\"no-cache\">
<style type="text/css">
body {background:#ffffff;font-family:arial;}
.login {position:absolute;width:350px;height:200px;top:40%;left:45%;margin-top:-100px;margin-left:-150px;}
</style></head><body>"

echo -n "
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script language=\"javascript\">
function TrimAll(str)
{
        var s=\"\";
        for (i = 0; i < str.length; i++) {
                if (str.charAt(i) != ' ') {
                        s = s + str.charAt(i);
                }
        }
        return s;
}
function beforeCommit(frm)
{
	var usrname = document.getElementById(\"username\");
	var curpwd  = document.getElementById(\"curpwd\");
	var passwd1 = document.getElementById(\"passwd1\");
	var passwd2 = document.getElementById(\"passwd2\");
	usrname.value = TrimAll(username.value);
	if (usrname.value == \"\") {
		alert(\"û!\");
		usrname.select();
		return false;
	}
	if (curpwd.value == \"\") {
		alert(\"뵱ǰ!\");
		curpwd.select();
		return false;
	}
	passwd1.value = TrimAll(passwd1.value);
	if (passwd1.value == \"\") {
		alert(\"!\");
		passwd1.select();
		return false;
	}
	passwd2.value = TrimAll(passwd2.value);
	if (passwd2.value != passwd1.value) {
		alert(\"벻ͬ!\");
		passwd1.select();
		return false;
	}
	return true;
}
function onGotoLogin()
{
        window.location.href = \"/cgi-bin/login?clientip=${CGI_clientip}\";
}
</script>
";
if [ "${REQUEST_METHOD}" = "POST" ]; then
	errmsg=`${FLOWEYE} usrinfo setpasswd name=${CGI_username} oldpw=${CGI_curpwd} newpw=${CGI_passwd1}`
	if [ "$?" != "0" ]; then
                echo "<script language=javascript>"
                echo "alert(\"ʧ:${errmsg}!\");"
                echo "</script>"
	else
                echo "<script language=javascript>"
                echo "alert(\"ɹ!\");"
                echo "</script>"
	fi
fi

echo -n "
<body>
<div class=\"login\" id=\"login\">
<form action=\"${myself}\" method=\"POST\" onsubmit=\"return beforeCommit(this)\" enctype=\"multipart/form-data\">
<table>
	<tr><td colspan=\"2\" align=\"center\"><img src=\"/login_logo.gif\" /></td></tr>
	<tr>
		<td style=\"width:90px;font-size:14px;\" align=\"center\"><b>û</b></td>
		<td><input type=\"text\" value=\"${CGI_username}\" id=\"username\" name=\"username\" style=\"width:170px;\" /></td>
	</tr>
	<tr><td align=\"center\" style=\"font-size:14px;\"><b>ǰ</b></td>
	<td><input type=\"password\" value=\"${CGI_curpwd}\" id=\"curpwd\" name=\"curpwd\" style=\"width:170px\" /></td></tr>
	<tr><td align=\"center\" style=\"font-size:14px;\"><b></b></td>
	<td><input type=\"password\" value=\"${CGI_passwd1}\" id=\"passwd1\" name=\"passwd1\" style=\"width:170px\" /></td></tr>
	<tr><td align=\"center\" style=\"font-size:14px;\"><b></b></td>
	<td><input type=\"password\" value=\"${CGI_passwd2}\" id=\"passwd2\" name=\"passwd2\" style=\"width:170px\" /></td></tr>
	<tr><td colspan=\"2\"></td></tr>
	<tr><td></td>
	<td><input type=\"submit\" value=\"ύ\" style=\"width:70px;height:22px;\"/>&nbsp;&nbsp;
	<input type=button value=\"ص¼...\" style=\"width:90px;height:22px;\" onclick=\"onGotoLogin()\" /></td></tr>
</table>
</form
</div>
</body>
</html>
";
