<HTML><HEAD><TITLE>Vigor Board 安装程式</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
    <style type="text/css">
    .t {font-family: Verdana, Arial, Sans-serif;font-size  : 12px;padding-left: 10px;font-weight: normal;line-height: 150%;color : #333366;}
    .e {font-family: Arial, Sans-serif;font-size  : 12px;font-weight: normal;line-height: 200%;color : #0000EE;}
    .w {font-family: Arial, Sans-serif;font-size  : 12px;font-weight: normal;line-height: 200%;color : #EE0000;}
    .h {font-family: Arial, Sans-serif;padding-top: 5px;padding-left: 10px;font-size  : 20px;font-weight: bold;color : #000000;}
    .i {font-family: Arial, Sans-serif;padding-top: 5px;padding-left: 10px;font-size  : 14px;font-weight: bold;color : #000000;}
	table {border        : 2px solid;width         : 80%;align         : center;vertical-align: top;background-color: #FFFFFF;}
	input {font-family  : "Courier New", Courier, monospace;width        : 95%;border-top   :#000000 solid thin;border-bottom:#000000 solid thin;border-left  :#000000 solid thin;border-right :#000000 solid thin;background-color: #EEEEEE;}
    </style>

<BODY bgColor=#8888aa leftMargin=0 topMargin=10 marginwidth="0" marginheight="0">
<TABLE cellSpacing=0 cellPadding=6 align=center>
  <FORM action=install.php method=post>
  <TR>
    <TD class=h vAlign=top align=left colSpan=2><SPAN 
      style="COLOR: #cc0000">&gt;&gt;</SPAN> VigorBoard Installation Wizard
      <HR color=#000000 noShade SIZE=1>
    </TD></TR>
		<tr>
		<td class='t' valign='top' align='left' colspan='2'>
			欢迎来到 VIB 安装程式. 请确定您在运行本程式前已经<b>仔细阅读安装说明</b>. 并且请您仔细检查您的每个输入.
			<hr noshade size=1 color='#000000'><b>注意:</b>
			<br>
			<span class='e'>此种状况表示状态正确.</span>
			<br>
			<span class='w'>此种状况表示状态发生错误.</span><hr noshade size=1 color='#000000'>
		</td>
		</tr>
<?
if (!$step) {
	$check=1;
$filestocheck=array(
'adminglobal.php','vibread.php','footer.php',
'header.php','setuser.php','listpic.php','messanger.php',
'mime.class','mime.def','register.php','search.php','sendmail.php',
'sendpwd.php','setforum.php','userlist.php','vote.php',
'votepie.php','viboard.php','vibcode.lib','vibpost.php',
'viblist.php','viblogin.php','vibmanage.php','vibmanage2.php',
'global.php','vibprofile.php','vibucom.php','vibvote.php',
'admin.php','banname.php','setoptions.php','forumfix.php','forumbackup.php',
'post_global.php','setipbans.php','setbadwords.php','userbackup.php',
'dumpuser.php','shareforum.php','dumpforum.php','announcement.php',
'usertitle.php','mailuser.php','datafile/0.txt',
'datafile/10.txt','datafile/202.txt','datafile/210.txt','datafile/61.txt',
'datafile/config.php','datafile/style.php','datafile/usertitle.php'
);
$count=count($filestocheck);
echo "
<INPUT type=hidden value=2 name=step> 
  <TR><td class='i' colspan='2' align='left'>
  <span style='color:#CC0000'>&gt;</span>检查程序组件完整</td></tr>
  <tr><td class='t' colspan='2' align='left'>";

$correct='<font class=e>OK</font>';
$incorrect='<font class=w>不行，检测不通过</font>';
for ($i=0; $i<$count; $i++) {
	echo "$filestocheck[$i] ....... ";
	if (file_exists($filestocheck[$i])) echo $correct;
	else { echo $incorrect; $check=0; }
	echo "<br>";
}
echo "</TD></TR>";


if ($check) {
$writeablefiletocheck=array(
'datafile','datafile/config.php','datafile/style.php','datafile/usertitle.php');
echo "
  <TR><td class='i' colspan='2' align='left'>
  <span style='color:#CC0000'>&gt;</span>检查必要目录和文件是否可写入，如果发生错误，请更改文件/目录属性</td></tr>
  <tr><td colspan=2 align=left class='t'>";
	echo "讨论区根目录 ....... ";
if ($fp=fopen('test.test',"w")) {echo $correct; fclose($fp);}
else { echo $incorrect; $check=0; }
echo "<br>";
for ($i=0; $i<4; $i++) {
	echo "$writeablefiletocheck[$i] ....... ";
	if (is_writable($writeablefiletocheck[$i])) echo $correct;
	else { echo $incorrect; $check=0; }
	echo "<br>";
}
echo "</TD></TR>";
}

if ($check) {
 unlink('test.test');
 echo '
   <TR><td class="i" colspan=2 align=left>
  <span style="color:#CC0000">&gt;</span>检查完成，请填写您的用户目录名(如果此目录不存在，程序将尝试建立)</td></tr>
 <tr>
    <td class=t align=left width="40%"><span style="color:#CC0000">&gt;</span>您所指定的用户目录</td>
    <td class=t align=left width="60%"><INPUT name=userdir></td></tr>
    <tr><TD align=left class=t align=middle colSpan=2>这个目录将储存所有的用户信息，请注意目录名应当不容易被猜出。如果让程序自行建立，可以填写一个简单名称，比如 "UserDir_98653"。如果手工建立在其他目录，请填写完整绝对路径，比如 "/home/myaccount/user_dir"(Unix/Linux) 或者 "c:/user_dir"(NT)<br>
    注意：如果您将此目录建立在其他目录比如WEB目录外或者CGI目录内以取得更高安全性，程序无法自动建立。请您手动先建立好并设定其属性至 777</TD></TR>
    <tr><TD class=i align=middle colSpan=2><INPUT style="WIDTH: 50%; FONT-FAMILY: Verdana" type=submit value="Check This Information and Proceed to Step Two"></TD></TR>';
}

}elseif ($step==2) {
	$check=1;
	
 echo '
<INPUT type=hidden value=3 name=step>
   <TR><td class="i" colspan=2 align=left>
  <span style="color:#CC0000">&gt;</span>检查用户目录</td></tr>';
	if (!$userdir) {
	echo '<tr><TD align=left class=w align=middle colSpan=2>您没有指定目录，请返回</TD></TR>';
	$check=0;
	}

	if ($check && !file_exists($userdir) && !mkdir("$userdir", 0777)) {
	echo '<tr><TD align=left class=w align=middle colSpan=2>您没有建立该目录，程序尝试建立失败</TD></TR>';
	$check=0;
	}
	
	if ($check && !is_dir($userdir)) {
	echo '<tr><TD align=left class=w align=middle colSpan=2>您所指定的目录是一个文件名，请返回</TD></TR>';
	$check=0;
	}
	
	if ($check && !is_writable($userdir)) {
	echo '<tr><TD align=left class=w align=middle colSpan=2>您所指定的目录无法被写入，请更改属性</TD></TR>';
	$check=0;
	}
	
	if ($check) {
	writetofile('datafile/idunique.php',"<? \$id_unique='$userdir';");
	echo '<tr><TD align=left class=e align=middle colSpan=2>用户目录检测完毕，信息已经记录</TD></TR>';
	echo "<tr>
		<td class='i' colspan='2' align='left'><span style='color:#CC0000'>&gt;</span>建立超级用户帐号<br>&nbsp;</td>
        </tr><tr>
	 <td class='t' align='left' width='40%'>&nbsp;&nbsp;请输入您的用户名</td>
	 <td class='t' align='left' width='60%'><input type='text' name='MEMBER_NAME'></td>
	</tr><tr>
	 <td class='t' align='left' width='40%'>&nbsp;&nbsp;请输入您的密码</td>
	 <td class='t' align='left' width='60%'><input type='password' name='MEMBER_PASS'></td>
	</tr><tr>
	 <td class='t' align='left' width='40%'>&nbsp;&nbsp;请重复输入密码</td>
	 <td class='t' align='left' width='60%'><input type='password' name='MEMBER_PASS_TWO'></td>
	</tr><tr>
	 <td class='t' align='left' width='40%'>&nbsp;&nbsp;您的EMAIL 地址</td>
	 <td class='t' align='left' width='60%'><input type='text' name='EMAIL'></td>
	</tr><tr>
	 <td class='t' align='left' width='40%'>&nbsp;&nbsp;重复输入您的EMAIL 地址</td>
	 <td class='t' align='left' width='60%'><input type='text' name='EMAIL_TWO'></td>
	</tr><tr>
	 <td class='i' colspan='2' align='center'><INPUT type=hidden value='$userdir' name=userdir><input type='submit' value='Step Completed, Proceed to Step Three' style='font-family:Verdana;width:50%'></td>
	<tr>";
	} else echo "
	</tr><tr>
	 <td class='i' colspan='2' align='center'><input onclick='history.go(-1)' type='button' value='Error. Return to Check' style='font-family:Verdana;width:50%'></td>
	<tr>";
}elseif ($step==3) {
	$check=1;
	echo '<TR><td class="i" colspan=2 align=left>
  <span style="color:#CC0000">&gt;</span>最后：检查输入资料并写入</td></tr>';
	if ($MEMBER_PASS != $MEMBER_PASS_TWO) {
	echo '<tr><TD align=left class=w align=middle colSpan=2>您所输入的2个密码不一致</TD></TR>';
	$check=0;
	}

	if ($EMAIL != $EMAIL_TWO) {
	echo '<tr><TD align=left class=w align=middle colSpan=2>您所输入的2个EMAIL不一致</TD></TR>';
	$check=0;
	}

	if ($check) {
	writetofile('datafile/superadmin.php',"<? \$admin_name='$MEMBER_NAME'; \$admin_password='$MEMBER_PASS';");
	writetofile("$userdir/$MEMBER_NAME","$MEMBER_NAME|$MEMBER_PASS||$EMAIL||".time()."|||||||0||none|");

	$newuserfile = "datafile/newuser.php";
	if (file_exists($newuserfile)) $newuserinfo=readfromfile($newuserfile);
       	else $newuserinfo="|0|0";
	$newuser_info=explode("|",$newuserinfo);
	$newuser_info[1]++;
	$newuser_info[0]=$MEMBER_NAME;
	writetofile($newuserfile,$newuser_info[0]."|".$newuser_info[1]."|".$newuser_info[2]);
	writetofile('datafile/userlist.php',$MEMBER_NAME."\n",'a');
	mkdir("upload",0777);

	echo '<tr><TD align=left class=e align=middle colSpan=2>OK，超级用户资料已经写入并已经注册成功</TD></TR>';
	echo "<tr><td class='i' colspan='2' align='left'><span style='color:#CC0000'>&gt;</span>您的 VIB 已经成功安装<br>&nbsp;</td>
        </tr><tr>
	 <td class='t' align='left' width='40%'>&nbsp;&nbsp;你的帐户信息:</td>
	 <td class='t' align='left' width='60%'><b>Name</b>: $MEMBER_NAME <br><b>Password: $MEMBER_PASS </b></td>
	</tr><tr><td class='i' colspan='2' align='left'>
	<span style='color:#CC0000'>&gt;</span><a href='admin.php'>现在就进入管理面板，设置您的详细资料并创建版块</a></td></tr>";
	if (!unlink('install.php'))
	echo '<tr><TD align=left class=e align=middle colSpan=2>请记住用FTP删除本安装程序</TD></TR>';

	}else echo "
	</tr><tr>
	 <td class='i' colspan='2' align='center'><input onclick='history.go(-1)' type='button' value='Error. Return to Check' style='font-family:Verdana;width:50%'></td>
	<tr>";
}
?>
    </FORM></TABLE></BODY></HTML>


<?
function writetofile($file_name,$data,$method="w") {
	$filenum=fopen($file_name,$method);
	flock($filenum,LOCK_EX);
	$file_data=fwrite($filenum,$data);
	fclose($filenum);
	return $file_data;
}
function readfromfile ($path) {
// returns all data in $path, or nothing if it does not exist

if(file_exists($path)==0) {
	return "";
} else {
	$filesize=filesize($path);
	$filenum=fopen($path,"r");
	flock($filenum,LOCK_SH);
	$filestuff=fread($filenum,$filesize);
	fclose($filenum);
	return $filestuff;
	}
}
