站长论坛
标题:
readover不是PHP自带,是用户自定义
[打印本页]
作者:
tzlink
时间:
2007-9-30 14:40
标题:
readover不是PHP自带,是用户自定义
<?php
/*
[Ofstar Board] install.php - installation of Ofstar Board
SQL version
Author: fengyu,王学集 (
linayuena@163.com
)
Copyright: Ofstar Board (
www.ofstar.net
)
Last Modified: 2004/3/2 21:46
*/
//empty($db_debug) && error_reporting(0);
$magic_quotes_gpc = get_magic_quotes_gpc();
$register_globals = @ini_get('register_globals');
if(!$register_globals || !$magic_quotes_gpc)
{
@extract($HTTP_POST_VARS, EXTR_SKIP);
@extract($HTTP_GET_VARS, EXTR_SKIP);
}
if(!$step)
{
$ofstar_licence= readover('install/licence.txt');
$ofstar_licence = str_replace(' ', ' ', nl2br($ofstar_licence));
include PrintEot('intsall');exit;
}
elseif ($step==1){
require'./data/sql_config.php';
$check=1;
$correct='<font class=r>OK</font>';
$incorrect='<font class=c>777属性检测不通过</font>';
$uncorrect='<font class=c>文件不存在请上传此文件</font>';
//以后需要加入注册的那个文件验证
$writeablefiletocheck=array('data/sql_config.php',
'attachment','data/bbscache','data/groupdb','data/style');
if ($fp=@fopen('test.txt',"wb")) {$state=$correct; fclose($fp);}
else {$state= "$incorrect 论坛根目录无法书写,请速将根目录属性设置为777";}
$count=count($writeablefiletocheck);
for ($i=0; $i<$count; $i++) {
if(!file_exists($writeablefiletocheck[$i])){
$writeablefiletocheck[$i].= $uncorrect;
} elseif(is_writable($writeablefiletocheck[$i])){
$writeablefiletocheck[$i].= $correct;
} else{
$writeablefiletocheck[$i].=$incorrect; $check=0;
}
}
if ($check){
@unlink('test.txt');
}
include PrintEot('intsall');exit;
} elseif($step==3){
$check=1;
if($INSTALL_PASS != $INSTALL_PASS_TWO) {
$pwderror='<tr><TD align=left class=c align=middle colspan=2>您所输入的2个密码不一致</TD></TR>';
$check=0;
}
if($check){
$showpwd=$INSTALL_PASS;
$writepwd=md5($INSTALL_PASS);
$writetofile="<?php\n/**\n* 以下变量需根据您的服务器说明档修改\n*/\n\$dbhost = '$SERVER';\t// 数据库服务器\n\$dbuser = '$SQLUSER';\t// 数据库用户名\n\$dbpw = '$SQLPASSWORD';\t// 数据库密码\n\$dbname = '$SQLNAME';\t// 数据库名\n\n/**\n* 论坛创始人,拥有论坛所有权限\n*/\n\$manager='$INSTALL_NAME';\t//管理员用户名\n\$manager_pwd='$writepwd';\t//管理员密码\n\$adminemail = '$INSTALL_EMAIL';\t// 论坛系统 Email\n\$database = 'mysql';//数据库类型\n?>";
writeover('data/sql_config.php',$writetofile);
}
include PrintEot('intsall');exit;
} elseif($step==4){
include './data/sql_config.php';
include './require/db_'.$database.'.php';
require './admin/cache.php';
define('R_P','./');
$db = new DB($dbhost, $dbuser, $dbpw, '', $pconnect);
if(!@mysql_select_db($dbname)) {
mysql_query("CREATE DATABASE $dbname");
if(mysql_error()) {
$msg .= "<font color=\"#FF0000\">指定的数据库 $dbname 不存在, 系统也无法自动建立, 无法安装 Discuz!.</font>\t";
$quit = TRUE;
} else {
mysql_select_db($dbname);
$msg .= "指定的数据库 $dbname 不存在, 但系统已成功建立, 可以继续安装.\t";
}
}
$sql=readover('install/ofstar.sql');
creat_table($sql);
$timestamp=time();
$td=floor($timestamp/3600);
$t=getdate($timestamp);
$hour=$t['hours'];
$tdtime=$td*3600-$hour*3600;
$db->update("INSERT INTO of_members (username, password, email,publicmail, groupid, icon, gender, regdate ,lastvisit,thisvisit) VALUES ('$manager', '$manager_pwd', '$adminemail', '1', 'manager', '', '1', '$timestamp', '$timestamp', '$timestamp')");
$db->update("UPDATE of_bbsinfo SET newmember='$manager',tdtcontrol='$tdtime',totalmember=totalmember+1 WHERE id='1'");
writefile();
updatecache();
include PrintEot('intsall');
if (!unlink('install.php'))
echo '<tr><TD align=left class=r align=middle colSpan=2>请记住用FTP删除本安装程序</TD></TR>';
exit;
}
function creat_table($sql) {
global $db,$installinfo;
$sqlarray=array();
$sql=str_replace("\r",'',$sql);
$sqlarray=explode(";\n",$sql);
foreach($sqlarray as $query){
$query=trim($query);
if($query){
$query=trim(str_replace("\n",'',$query));
$db->query($query);
if(strpos($query,'CREATE TABLE') !==false) {
$name=substr($query,13,strpos($query,'(')-13);
$installinfo.='建立数据表 '.$name.' ... <font color="#0000EE">成功</font><br>';
}
}
}
}
function writefile(){
$writeinto=str_pad("<?die;?>",96)."\n";
writeover('data/bbscache/online.php',$writeinto);
writeover('data/bbscache/guest.php',$writeinto);
writeover('data/bbscache/olcache.php',"<?php\n\$userinbbs=1;\n\$guestinbbs=0;\n?>");
writeover('data/bbscache/dbset.php',"<?\n\$picpath='images';//图片目录名\n\$attachpath='attachment';//附件目录名");
}
function readover($filename,$method="rb")
{
if($handle=@fopen($filename,$method)){
flock($handle,LOCK_SH);
$filedata=fread($handle,filesize($filename));
fclose($handle);
}
return $filedata;
}
function writeover($filename,$data,$method="rb+"){
touch($filename);
$handle=fopen($filename,$method);
flock($handle,LOCK_EX);
fputs($handle,$data);
if($method=="rb+") ftruncate($handle,strlen($data));
fclose($handle);
}
function PrintEot($template,$EXT="htm"){
$path="install/$template.$EXT";
return $path;
}
?>
欢迎光临 站长论坛 (http://www.tzlink.com/bbs/)
Powered by Discuz! X3.2