#!/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);
	if (frm.curpwd.value == \"\")
	{
		alert(\"뵱ǰ\");
		frm.curpwd.select();
		return false;
	}
	if (confirm(\"ȷҪɾ־?\"))
		return true;
	else
		return false;
}
</script>
";
PASSWDFILE=${PGPATH}/admin/.htpasswd
if [ "${CGI_action}" = "clear" ]; then
	operator_check "${myself}"
	if [ ! -f ${PASSWDFILE} ]; then
		afm_dialog_msg "شϵͳļٻ!"
		afm_load_page 0 "${myself}"
		exit 0
	fi
	curpasswd=`cat ${PASSWDFILE} | grep "${ADMIN_NAME}:" | cut -d':' -f2-`
	if [ "${curpasswd}" != "${CGI_curpwd}" ]; then
		afm_dialog_msg "Բ벻ԣȨ־!"
		afm_load_page 0 "${myself}"
		exit 0
	fi
	# waiting for 10 seconds for scheduler.
	echo "<br><p style=\"color:#0000ff\">ر־ɼ......</p>"
	while true;
	do
		datamon=`ps ax | grep ipe_datamon`
		if [ "${datamon}" != "" ]; then
			errmsg=`${PGPATH}/bin/ipectrl stop datamon 2>&1`
		else
			break
		fi
		sleep 1
	done
	echo "<br><p style=\"color:#0000ff\">־ɼѾر,ɾ־......</p>"
	rm -rf ${DATAPATH}/panabit.rrd
	sync
	echo "<br><p style=\"color:#0000ff\">־Ѿɾ,־ɼ......</p>"
	echo "start_datamon yes" >> ${EVENTFILE}
	sleep 8
	yes=`ps ax | grep ipe_datamon`
	if [ "$yes" != "" ]; then
		afm_dialog_msg "ɹ!"
	else
		afm_dialog_msg "ʧ!"
	fi
	afm_load_page 0 "${myself}"
	exit 0
fi

echo -n "
<body>
"; cgi_show_title "־->־" 
echo -n "
<br>
<table width=\"76%\" 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=100 align=left>
		<input type=password class=text name=curpwd style=\"width:100\"></input>
	</td>
	<td align=right width=120px>
		<input type=submit style=\"width:100\" value=\"־\"></input>
		<input type=hidden name=action value=\"clear\"></input>
	</td>
	<td width=*></td>
</tr>
</table>
</form>
</table>
</center>
</body>
</html>
";