#!/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 Validate(frm)
{
	frm.curpwd.value  = TrimAll(frm.curpwd.value);
	frm.newpwd1.value = TrimAll(frm.newpwd1.value);
	frm.newpwd2.value = TrimAll(frm.newpwd2.value);
	if (frm.curpwd.value == \"\")
	{
		alert(\"뵱ǰ\");
		frm.curpwd.select();
		return false;
	}
	if (frm.newpwd1.value == \"\")
	{
		alert(\"!\");
		frm.newpwd1.select();
		return false;
	}
	if (frm.newpwd2.value != frm.newpwd1.value)
	{
		alert(\"벻ƥ䣬!\");
		frm.newpwd2.select();
		return false;
	}
	return true;
}
</script>
";
PASSWDFILE=${PGPATH}/admin/.htpasswd
if [ "${REQUEST_METHOD}" = "POST" ]; then
	if [ "${CGI_newpwd1}" != "${CGI_newpwd2}" ]; then
		afm_dialog_msg "벻һ£!"
		afm_load_page 0 "${myself}"
		exit 0
	fi
	if [ ! -f ${PASSWDFILE} ]; then
		afm_dialog_msg "شϵͳļٻ!"
		afm_load_page 0 "${myself}"
		exit 0
	fi
	curpasswd=`cat ${PASSWDFILE} | grep "${PANABIT_USER}:" | cut -d':' -f2-`
	if [ "${curpasswd}" != "${CGI_curpwd}" ]; then
		afm_dialog_msg "Բ벻ԣ޷޸ϵͳ!"
		afm_load_page 0 "${myself}"
		exit 0
	fi
	mkdir -p /usr/ramdisk/tmp
	tmpfile=/usr/ramdisk/tmp/tmppwd.tmp
	[ -f ${tmpfile} ] && rm -f ${tmpfile}
	touch -f {tmpfile}
	cat ${PASSWDFILE} | while read line; do
		username=`echo ${line} | cut -d':' -f1`
		userpasswd=`echo ${line} | cut -d':' -f2-`
		if [ "${username}" = "${PANABIT_USER}" ]; then
			echo "${PANABIT_USER}:${CGI_newpwd1}" >> ${tmpfile}
		else
			echo "${username}:${userpasswd}" >> ${tmpfile}
		fi
	done
	mv ${tmpfile} ${PASSWDFILE}
	# save to disk
	. /etc/PG.conf
	cp -f ${PASSWDFILE} ${PGPATH}/admin/.htpasswd
        sync
	afm_dialog_msg "ɹ!ûйرյǰڣȻʹþ.\nµʱ뽫Ч!"
fi

echo -n "
<body>
"; cgi_show_title "ϵͳ->޸" 
echo -n "
<br>
<table width=500 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<form method=post onsubmit=\"return Validate(this)\" action=\"${myself}\">
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left>뵱ǰ</td>
	<td width=240 align=left>
		<input type=password class=text name=curpwd style=\"width:100\"></input>
	</td>
	<td></td>
</tr>
<tr id=row1>
	<td width=40></td>
	<td width=120 align=left></td>
	<td width=240 align=left>
		<input type=password class=text name=newpwd1 style=\"width:100\"></input>
		&nbsp;&nbsp;(вܰո)
	</td>
	<td></td>
</tr>
<tr id=row1>
	<td width=40></td>
	<td align=left>ٴ</td>
	<td align=left>
		<input type=password class=text name=newpwd2 style=\"width:100\"></input>
		&nbsp;&nbsp;(вܰո)
	</td>
	<td></td>
</tr>
</table>
<table style=\"width:500; border-bottom:1px #787882 solid; color:#0000ff\">
<tr><td align=right>&nbsp;</td></tr>
</table>     
<table width=500 border=0 cellspacing=0 cellpadding=3 bgcolor=\"#ffffff\">
<tr>
	<td width=* align=right width=100px class=cssTDArial><input type=submit style=\"width:100px\" value=\"ύ޸\"></input></td>
</tr>
</form>
</table>
</center>
</body>
</html>
";