2016-01-09 23:26:14 +08:00
< ? php
2016-01-17 10:20:52 +08:00
/**
* @ Author : printempw
* @ Date : 2016 - 01 - 16 23 : 01 : 33
2016-03-05 19:23:24 +08:00
* @ Last Modified by : printempw
2016-04-03 17:17:42 +08:00
* @ Last Modified time : 2016 - 04 - 03 17 : 14 : 26
2016-01-17 10:20:52 +08:00
*
2016-03-12 21:07:36 +08:00
* Blessing Skin Server Installer
2016-01-17 10:20:52 +08:00
*/
2016-02-03 00:24:26 +08:00
$dir = dirname ( dirname ( __FILE__ ));
2016-03-26 18:50:47 +08:00
require " $dir /libraries/autoloader.php " ;
2016-03-12 21:07:36 +08:00
$step = isset ( $_GET [ 'step' ]) ? $_GET [ 'step' ] : 1 ;
?>
<! DOCTYPE html >
< html lang = " zh-CN " >
< head >
< meta name = " viewport " content = " width=device-width " />
< meta http - equiv = " Content-Type " content = " text/html; charset=utf-8 " />
< meta name = " robots " content = " noindex,nofollow " />
< title > Blessing Skin Server 安装程序 </ title >
< link rel = " stylesheet " type = " text/css " href = " ../assets/css/install.style.css " >
</ head >
< body class = " container " >
< p id = " logo " >< a href = " https://github.com/printempw/blessing-skin-server " tabindex = " -1 " > Blessing Skin Server </ a ></ p >
< ? php
2016-01-17 10:53:10 +08:00
2016-03-26 19:46:56 +08:00
// use error control to hide shitty connect warnings
2016-04-03 17:17:42 +08:00
@ $conn = new mysqli ( DB_HOST , DB_USER , DB_PASSWD , DB_NAME , DB_PORT );
2016-01-09 23:26:14 +08:00
2016-03-12 21:07:36 +08:00
if ( $conn -> connect_error ) : ?>
< h1 > MySQL 连接错误 </ h1 >
< p > 无法连接至 MySQL 服务器,确定你在 config . php 填写的数据库信息正确吗? </ p >
2016-03-13 09:39:51 +08:00
< p > 详细信息: < ? php echo $conn -> connect_error ; ?> </p>
2016-03-26 19:46:56 +08:00
< ? php exit ; endif ;
2016-03-19 14:17:32 +08:00
$conn -> query ( " SET names 'utf8' " );
2016-01-09 23:26:14 +08:00
2016-04-03 17:17:42 +08:00
$sql = " SELECT table_name FROM `INFORMATION_SCHEMA`.`TABLES` WHERE (table_name =' " . DB_PREFIX . " users'OR table_name =' " . DB_PREFIX . " options') AND TABLE_SCHEMA=' " . DB_NAME . " ' " ;
if ( $conn -> query ( $sql ) -> num_rows == 2 )
Utils :: redirect ( 'index.php' );
2016-01-09 23:26:14 +08:00
2016-03-12 21:07:36 +08:00
/*
* Stepped installation
*/
switch ( $step ) {
2016-03-27 15:02:16 +08:00
2016-03-12 21:07:36 +08:00
// Step 1
case 1 : ?>
< h1 > 填写信息 </ h1 >
< p > 您需要填写一些基本信息。无需担心填错,这些信息以后可以再次修改。 </ p >
2016-03-27 15:02:16 +08:00
< form id = " setup " method = " post " action = " install.php?step=2 " novalidate = " novalidate " >
2016-03-18 16:47:25 +08:00
< table class = " form-table " >
< tr >
< th scope = " row " >< label for = " username " > 管理员用户名 </ label ></ th >
< td >
< input name = " username " type = " text " id = " username " size = " 25 " value = " " />
< p > 用户名只能含有数字、字母、下划线。这是唯一的管理员账号。 </ p >
</ td >
</ tr >
2016-03-18 18:57:58 +08:00
< tr class = " form-field form-required " >
< th scope = " row " >< label for = " password " > 密码 </ label ></ th >
2016-03-18 16:47:25 +08:00
< td >
< input type = " password " name = " password " id = " password " class = " regular-text " autocomplete = " off " />
< p >
< span class = " description important " >
< b > 重要: </ b > 您将需要此密码来登录管理皮肤站,请将其保存在安全的位置。
</ span >
</ p >
</ td >
</ tr >
< tr class = " form-field form-required " >
2016-03-18 18:57:58 +08:00
< th scope = " row " >< label for = " password2 " > 重复密码 ( 必填 ) </ label ></ th >
2016-03-18 16:47:25 +08:00
< td >
< input type = " password " name = " password2 " id = " password2 " autocomplete = " off " />
2016-03-18 18:57:58 +08:00
< p >
< span class = " description important " ></ span >
</ p >
</ td >
</ tr >
< tr >
< th scope = " row " >< label for = " username " > 站点名称 </ label ></ th >
< td >
< input name = " sitename " type = " text " id = " sitename " size = " 25 " value = " " />
< p >
< span class = " description important " >
将会显示在首页以及标题栏,最好用纯英文(字体原因)
</ span >
</ p >
2016-03-18 16:47:25 +08:00
</ td >
</ tr >
</ table >
2016-03-12 21:07:36 +08:00
< ? php if ( isset ( $_GET [ 'msg' ])) echo " <div class='alert alert-warning' role='alert'> " . $_GET [ 'msg' ] . " </div> " ; ?>
< p class = " step " >< input type = " submit " name = " Submit " id = " submit " class = " button button-large " value = " 开始安装 " /></ p >
</ form >
< ? php break ;
2016-01-09 23:26:14 +08:00
2016-03-27 15:02:16 +08:00
// Step 2
case 2 :
2016-03-12 21:07:36 +08:00
// check post
if ( isset ( $_POST [ 'username' ]) && isset ( $_POST [ 'password' ]) && isset ( $_POST [ 'password2' ])) {
2016-03-18 16:47:25 +08:00
if ( $_POST [ 'password' ] != $_POST [ 'password2' ]) {
2016-04-03 17:17:42 +08:00
Utils :: redirect ( 'install.php?msg=确认密码不一致。' ); exit ;
2016-03-18 16:47:25 +08:00
}
$username = $_POST [ 'username' ];
$password = $_POST [ 'password' ];
2016-03-18 18:57:58 +08:00
$sitename = isset ( $_POST [ 'sitename' ]) ? $_POST [ 'sitename' ] : " Blessing Skin Server " ;
2016-03-18 16:47:25 +08:00
if ( User :: checkValidUname ( $username )) {
if ( strlen ( $password ) > 16 || strlen ( $password ) < 5 ) {
2016-04-03 17:17:42 +08:00
Utils :: redirect ( 'install.php?msg=无效的密码。密码长度应该大于 6 并小于 15。' );
2016-03-26 19:46:56 +08:00
exit ;
2016-03-18 16:47:25 +08:00
} else if ( Utils :: convertString ( $password ) != $password ) {
2016-04-03 17:17:42 +08:00
Utils :: redirect ( 'install.php?msg=无效的密码。密码中包含了奇怪的字符。' ); exit ;
2016-03-18 16:47:25 +08:00
}
} else {
2016-04-03 17:17:42 +08:00
Utils :: redirect ( 'install.php?msg=无效的用户名。用户名只能包含数字,字母以及下划线。' ); exit ;
2016-03-18 16:47:25 +08:00
}
2016-03-12 21:07:36 +08:00
} else {
2016-04-03 17:17:42 +08:00
Utils :: redirect ( 'install.php?msg=表单信息不完整。' ); exit ;
2016-03-12 21:07:36 +08:00
}
2016-01-09 23:26:14 +08:00
2016-03-18 16:47:25 +08:00
$table_users = DB_PREFIX . " users " ;
$table_options = DB_PREFIX . " options " ;
2016-04-03 17:17:42 +08:00
$sql = str_replace ( '{$prefix}' , DB_PREFIX , file_get_contents ( BASE_DIR . '/setup/tables.sql' ));
$sql = str_replace ( '{$sitename}' , $sitename , $sql );
// I don't know why semicolon in sql statement dosen't work ...
$sql = explode ( ';' , $sql );
2016-03-18 16:47:25 +08:00
2016-04-03 17:17:42 +08:00
if ( ! $conn -> query ( $sql [ 0 ]) || ! $conn -> query ( $sql [ 1 ]) || ! $conn -> query ( $sql [ 2 ])) { ?>
2016-03-18 16:47:25 +08:00
< h1 > 数据表创建失败 </ h1 >
< p > 照理来说不应该的,请带上错误信息联系作者: </ p >
< p >< ? php echo $conn -> error ; ?> </p>
2016-04-03 17:17:42 +08:00
< p > SQL 语句: </ p >
< p >< ? php echo nl2br ( $sql ); ?> </p>
2016-03-26 19:46:56 +08:00
< ? php exit ;
2016-03-12 21:07:36 +08:00
}
2016-02-03 15:47:06 +08:00
2016-03-12 21:07:36 +08:00
// Insert user
2016-03-18 18:57:58 +08:00
$conn -> query ( " INSERT INTO ` $table_users ` (`uid`, `username`, `password`, `ip`, `preference`) VALUES
( 1 , '".$username."' , '".md5($_POST[' password '])."' , '127.0.0.1' , 'default' ) " );
2016-01-09 23:26:14 +08:00
2016-03-12 21:07:36 +08:00
if ( ! is_dir ( " ../textures/ " )) {
2016-03-18 16:47:25 +08:00
if ( ! mkdir ( " ../textures/ " )) : ?>
< h1 > 文件夹创建失败 </ h1 >
< p > textures 文件夹创建失败。确定你拥有该目录的写权限吗? </ p >
< ? php endif ;
2016-03-12 21:07:36 +08:00
} ?>
2016-01-17 10:20:52 +08:00
2016-03-12 21:07:36 +08:00
< h1 > 成功! </ h1 >
< p > Blessing Skin Server 安装完成。您是否还沉浸在愉悦的安装过程中?很遗憾,一切皆已完成! : ) </ p >
< table class = " form-table install-success " >
2016-03-18 16:47:25 +08:00
< tr >
< th > 用户名 </ th >
< td >< ? php echo $username ; ?> </td>
</ tr >
< tr >
< th > 密码 </ th >
< td >< p >< em >< ? php echo $password ; ?> </em></p></td>
</ tr >
2016-03-12 21:07:36 +08:00
</ table >
< p class = " step " >< a href = " ../index.php " class = " button button-large " > 首页 </ a ></ p >
2016-03-27 15:02:16 +08:00
< ? php break ;
} ?>
</ body >
</ html >