diff --git a/admin/install.php b/admin/install.php
index cbc4bcd9..266b5660 100644
--- a/admin/install.php
+++ b/admin/install.php
@@ -3,82 +3,181 @@
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: printempw
- * @Last Modified time: 2016-03-12 16:44:47
+ * @Last Modified time: 2016-03-12 21:03:32
*
- * Create tables automatically
+ * Blessing Skin Server Installer
*/
+// Sanity check
+if (false): ?>
+
+
+
+
+
+
+出现错误 - Blessing Skin Server 安装程序
+
+
+
+Blessing Skin Server
+错误:PHP 未运行
+Blessing Skin Server 基于 PHP 开发,需要 PHP 运行环境。如果你看到这段话就说明主机的 PHP 未运行。
+你问 PHP 是什么?为什么不问问神奇海螺呢?
+
+
+body { font-family: Courier, 'Microsoft Yahei', 'Microsoft Jhenghei', sans-serif; }";
-
-if (!file_exists("./install.lock")) {
- $conn = new mysqli(DB_HOST, DB_USER, DB_PASSWD, DB_NAME, DB_PORT);
-
- echo "Blessing Skin Server 安装程序
";
-
- if ($conn->connect_error) {
- Utils::raise(-1, "无法连接至 MySQL 服务器,确定你在 config.php 填写的数据库信息正确吗?".$conn->connect_error);
- } else {
- echo "成功连接至 MySQL 服务器 ".DB_USER."@".DB_HOST."。
";
- }
-
- echo "开始创建数据表。。
";
-
- $sql = "CREATE TABLE IF NOT EXISTS `users` (
- `uid` int(11) NOT NULL AUTO_INCREMENT,
- `username` varchar(20) NOT NULL,
- `password` varchar(32) NOT NULL,
- `ip` varchar(32) NOT NULL,
- `preference` varchar(10) NOT NULL,
- `hash_steve` varchar(64) NOT NULL,
- `hash_alex` varchar(64) NOT NULL,
- `hash_cape` varchar(64) NOT NULL,
- `last_modified` datetime NOT NULL,
- PRIMARY KEY (`uid`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15;";
-
- if(!$conn->query($sql)) {
- die("数据表创建失败了。。请带上错误信息联系作者
".$conn->error);
- }
-
- /**
- * username: admin
- * password: 123456
- */
- $conn->query("INSERT INTO `users` (`uid`, `username`, `password`, `ip`, `preference`) VALUES(1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', '127.0.0.1', 'default')");
-
- echo "数据表创建成功!
";
-
- echo "
-
-+-------------------------------------------------------------------------------------------------+-----------------+
-| uid | username | password | ip | preference | hash_steve | hash_alex | hash_cape | last_modofied |
-+-------------------------------------------------------------------------------------------------+-----------------+
-| 1 | admin | 123456 | * | default | * | * | * | * |
-+-------------------------------------------------------------------------------------------------+-----------------+
-
- ";
-
- if (!is_dir("../textures/")) {
- echo mkdir("../textures/") ? "正在创建 textures 文件夹。。
" :
- "文件夹创建失败。确定你的目录权限正确吗?
";
- }
-
- echo "安装成功辣~ 首页";
-
- if ($lock = fopen("./install.lock", 'w')) {
- fwrite($lock, time());
- fclose($lock);
- } else {
- die("无法创建自动 `install.lock`。请人工新建一个 `install.lock` 置于 `admin` 目录下。");
- }
-
-} else {
- echo "
";
- echo "看起来你已经安装过一次了哦? 首页
";
- echo "或许你需要删除 `admin` 文件夹下的 `install.lock` 开解锁安装程序。";
-}
+$step = isset($_GET['step']) ? $_GET['step'] : 1;
?>
+
+
+
+
+
+
+Blessing Skin Server 安装程序
+
+
+
+Blessing Skin Server
+connect_error): ?>
+MySQL 连接错误
+无法连接至 MySQL 服务器,确定你在 config.php 填写的数据库信息正确吗?
+connect_error; ?>
+
+已安装过
+Blessing Skin Server 看起来已经安装妥当。如果想重新安装,请删除数据库中的旧数据表。
+
+欢迎
+欢迎使用 Blessing Skin Server V2!
+成功连接至 MySQL 服务器 ,点击下一步以开始安装。
+下一步
+
+填写信息
+您需要填写一些基本信息。无需担心填错,这些信息以后可以再次修改。
+
+ 16 || strlen($password) < 5) {
+ header('Location: install.php?step=2&msg=无效的密码。密码长度应该大于 6 并小于 15。');
+ die();
+ } else if (Utils::convertString($password) != $password) {
+ header('Location: install.php?step=2&msg=无效的密码。密码中包含了奇怪的字符。'); die();
+ }
+ } else {
+ header('Location: install.php?step=2&msg=无效的用户名。用户名只能包含数字,字母以及下划线。'); die();
+ }
+} else {
+ header('Location: install.php?step=2&msg=表单信息不完整。'); die();
+}
+
+$sql = "CREATE TABLE IF NOT EXISTS `users` (
+ `uid` int(11) NOT NULL AUTO_INCREMENT,
+ `username` varchar(20) NOT NULL,
+ `password` varchar(32) NOT NULL,
+ `ip` varchar(32) NOT NULL,
+ `preference` varchar(10) NOT NULL,
+ `hash_steve` varchar(64),
+ `hash_alex` varchar(64),
+ `hash_cape` varchar(64),
+ `last_modified` datetime,
+ PRIMARY KEY (`uid`)
+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15;";
+
+if (!$conn->query($sql)) { ?>
+ 数据表创建失败
+ 照理来说不应该的,请带上错误信息联系作者:
+ error; ?>
+ query("INSERT INTO `users` (`uid`, `username`, `password`, `ip`, `preference`) VALUES
+ (1, '".$username."', '".md5($_POST['password'])."', '127.0.0.1', 'default')");
+
+if (!is_dir("../textures/")) {
+ if (!mkdir("../textures/")): ?>
+ 文件夹创建失败
+ textures 文件夹创建失败。确定你拥有该目录的写权限吗?
+
+
+成功!
+Blessing Skin Server 安装完成。您是否还沉浸在愉悦的安装过程中?很遗憾,一切皆已完成! :)
+
+首页
+input {
+ font-family: Ubuntu, 'Microsoft Yahei', 'Microsoft Jhenghei', sans-serif;
+}
+fieldset {
+ padding: 0;
+ margin: 0
+}
+
+label {
+ cursor: pointer
+}
+
+.step {
+ margin: 20px 0 15px
+}
+
+.step,th {
+ text-align: left;
+ padding: 0
+}
+
+.language-chooser.wp-core-ui .step .button.button-large {
+ height: 36px;
+ vertical-align: middle;
+ font-size: 14px
+}
+
+.form-table td,.form-table th {
+ padding: 10px 20px 10px 0;
+ vertical-align: top;
+ font-size: 14px
+}
+
+textarea {
+ border: 1px solid #dfdfdf;
+ width: 100%;
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box
+}
+
+.form-table {
+ border-collapse: collapse;
+ margin-top: 1em;
+ width: 100%
+}
+
+.form-table td {
+ margin-bottom: 9px
+}
+
+.form-table th {
+ text-align: left;
+ width: 140px
+}
+
+.form-table code {
+ line-height: 18px;
+ font-size: 14px
+}
+
+.form-table p {
+ margin: 4px 0 0;
+ font-size: 11px
+}
+
+.form-table input {
+ line-height: 20px;
+ font-size: 15px;
+ padding: 3px 5px;
+ border: 1px solid #ddd;
+ -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,.07);
+ box-shadow: inset 0 1px 2px rgba(0,0,0,.07)
+}
+
+.form-table input[type=email],.form-table input[type=password],.form-table input[type=text],.form-table input[type=url] {
+ width: 206px
+}
+
+.form-table.install-success td,.form-table.install-success th {
+ vertical-align: middle;
+ padding: 16px 20px 16px 0
+}
+
+.form-table.install-success td p {
+ margin: 0;
+ font-size: 14px
+}
+
+.form-table.install-success td code {
+ margin: 0;
+ font-size: 18px
+}
+.container .button,.container .button-primary,.container .button-secondary {
+ display:inline-block;
+ text-decoration:none;
+ font-size:13px;
+ line-height:26px;
+ height:28px;
+ margin:0;
+ padding:0 10px 1px;
+ cursor:pointer;
+ border-width:1px;
+ border-style:solid;
+ -webkit-appearance:none;
+ -webkit-border-radius:3px;
+ border-radius:3px;
+ white-space:nowrap;
+ -webkit-box-sizing:border-box;
+ -moz-box-sizing:border-box;
+ box-sizing:border-box
+}
+.container button::-moz-focus-inner,.container input[type=reset]::-moz-focus-inner,.container input[type=button]::-moz-focus-inner,.container input[type=submit]::-moz-focus-inner {
+ border-width:0;
+ border-style:none;
+ padding:0
+}
+.container .button-group.button-large .button,.container .button.button-large {
+ height:30px;
+ line-height:28px;
+ padding:0 12px 2px
+}
+.container .button-group.button-small .button,.container .button.button-small {
+ height:24px;
+ line-height:22px;
+ padding:0 8px 1px;
+ font-size:11px
+}
+.container .button-group.button-hero .button,.container .button.button-hero {
+ font-size:14px;
+ height:46px;
+ line-height:44px;
+ padding:0 36px
+}
+.container .button:active,.container .button:focus {
+ outline:0
+}
+.container .button.hidden {
+ display:none
+}
+.container input[type=reset],.container input[type=reset]:active,.container input[type=reset]:focus,.container input[type=reset]:hover {
+ background:0 0;
+ border:none;
+ -webkit-box-shadow:none;
+ box-shadow:none;
+ padding:0 2px 1px;
+ width:auto
+}
+.container .button,.container .button-secondary {
+ color:#555;
+ border-color:#ccc;
+ background:#f7f7f7;
+ -webkit-box-shadow:0 1px 0 #ccc;
+ box-shadow:0 1px 0 #ccc;
+ vertical-align:top
+}
+.container p .button {
+ vertical-align:baseline
+}
+.container .button-secondary:focus,.container .button-secondary:hover,.container .button.focus,.container .button.hover,.container .button:focus,.container .button:hover {
+ background:#fafafa;
+ border-color:#999;
+ color:#23282d
+}
+.container .button-link:focus,.container .button-secondary:focus,.container .button.focus,.container .button:focus {
+ border-color:#5b9dd9;
+ -webkit-box-shadow:0 0 3px rgba(0,115,170,.8);
+ box-shadow:0 0 3px rgba(0,115,170,.8)
+}
+.container .button-secondary:active,.container .button.active,.container .button.active:hover,.container .button:active {
+ background:#eee;
+ border-color:#999;
+ -webkit-box-shadow:inset 0 2px 5px -3px rgba(0,0,0,.5);
+ box-shadow:inset 0 2px 5px -3px rgba(0,0,0,.5);
+ -webkit-transform:translateY(1px);
+ -ms-transform:translateY(1px);
+ transform:translateY(1px)
+}
+.container .button.active:focus {
+ border-color:#5b9dd9;
+ -webkit-box-shadow:inset 0 2px 5px -3px rgba(0,0,0,.5),0 0 3px rgba(0,115,170,.8);
+ box-shadow:inset 0 2px 5px -3px rgba(0,0,0,.5),0 0 3px rgba(0,115,170,.8)
+}
+.container .button-disabled,.container .button-secondary.disabled,.container .button-secondary:disabled,.container .button-secondary[disabled],.container .button.disabled,.container .button:disabled,.container .button[disabled] {
+ color:#a0a5aa!important;
+ border-color:#ddd!important;
+ background:#f7f7f7!important;
+ -webkit-box-shadow:none!important;
+ box-shadow:none!important;
+ text-shadow:0 1px 0 #fff!important;
+ cursor:default;
+ -webkit-transform:none!important;
+ -ms-transform:none!important;
+ transform:none!important
+}
+.container .button-link {
+ margin:0;
+ padding:0;
+ -webkit-box-shadow:none;
+ box-shadow:none;
+ border:0;
+ -webkit-border-radius:0;
+ border-radius:0;
+ background:0 0;
+ outline:0;
+ cursor:pointer
+}
+.container .button-primary {
+ background:#0085ba;
+ border-color:#0073aa #006799 #006799;
+ -webkit-box-shadow:0 1px 0 #006799;
+ box-shadow:0 1px 0 #006799;
+ color:#fff;
+ text-decoration:none;
+ text-shadow:0 -1px 1px #006799,1px 0 1px #006799,0 1px 1px #006799,-1px 0 1px #006799
+}
+.container .button-primary.focus,.container .button-primary.hover,.container .button-primary:focus,.container .button-primary:hover {
+ background:#008ec2;
+ border-color:#006799;
+ color:#fff
+}
+.container .button-primary.focus,.container .button-primary:focus {
+ -webkit-box-shadow:0 1px 0 #0073aa,0 0 2px 1px #33b3db;
+ box-shadow:0 1px 0 #0073aa,0 0 2px 1px #33b3db
+}
+.alert {
+ padding: 15px;
+ margin-top: 15px;
+ margin-bottom: 20px;
+ border: 1px solid transparent;
+ border-radius: 4px;
+}
+.alert-warning {
+ color: #8a6d3b;
+ background-color: #fcf8e3;
+ border-color: #faebcc;
+}
diff --git a/includes/Database.class.php b/includes/Database.class.php
index 9a1fe0cf..d0f79ea8 100644
--- a/includes/Database.class.php
+++ b/includes/Database.class.php
@@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-02-02 21:59:06
* @Last Modified by: printempw
- * @Last Modified time: 2016-03-12 18:42:21
+ * @Last Modified time: 2016-03-12 20:55:08
*/
class Database
@@ -18,17 +18,15 @@ class Database
if (!DEBUG_MODE) error_reporting(0);
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWD, DB_NAME, DB_PORT);
if ($conn->connect_error) {
- Utils::showErrorPage(-1, "Can not connect to mysql, check if database info correct in config.php. ".
- $conn->connect_error);
+ Utils::showErrorPage($conn->connect_errno,
+ "无法连接至 MySQL 服务器。请确认 config.php 中的配置是否正确:".$conn->connect_error);
}
if (!self::checkTableExist($conn)) {
- Utils::showErrorPage(-1, "Looks like that there is no `users` table in your database. ".
- "Please run `/admin/install.php` first.");
+ Utils::showErrorPage(-1, "数据库中不存在 users 表。请先运行 /admin/install.php 进行安装。");
}
$dir = dirname(dirname(__FILE__));
if (!is_dir("$dir/textures/")) {
- Utils::showErrorPage(-1, "No `textures` directory exists. Please run `/admin/install.php` ".
- "or put one manually.");
+ Utils::showErrorPage(-1, "textures 文件夹不存在。请先运行 /admin/install.php 进行安装,或者手动放置一个。");
}
return $conn;
}