blessing-skin-server/admin/install.php

232 lines
9.0 KiB
PHP
Raw Normal View History

<?php
/**
* @Author: printempw
* @Date: 2016-01-16 23:01:33
2016-03-05 19:23:24 +08:00
* @Last Modified by: printempw
2016-03-26 19:46:56 +08:00
* @Last Modified time: 2016-03-26 19:44:57
*
* Blessing Skin Server Installer
*/
// Sanity check
if (false): ?>
<!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>
<h1>错误PHP 未运行</h1>
<p>Blessing Skin Server 基于 PHP 开发,需要 PHP 运行环境。如果你看到这段话就说明主机的 PHP 未运行。</p>
<p>你问 PHP 是什么?为什么不问问神奇海螺呢?</p>
</body>
</html>
<?php endif;
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";
$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-13 09:06:58 +08:00
// if php version < 5.4
if (strnatcasecmp(phpversion(), '5.4') < 0): ?>
<h1>PHP 版本过低</h1>
<p>由于使用了一些新特性Blessing Skin Server 需要 PHP 版本 >= 5.4。您当前的 PHP 版本为 <?php echo phpversion(); ?></p>
2016-03-26 19:46:56 +08:00
<?php exit; endif;
2016-03-13 09:06:58 +08:00
2016-03-26 19:46:56 +08:00
// use error control to hide shitty connect warnings
error_reporting(0);
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWD, DB_NAME, DB_PORT);
2016-03-26 19:46:56 +08:00
error_reporting(E_ALL ^ E_NOTICE);
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'");
if (Database\Database::checkTableExist($conn)): ?>
<h1>已安装过</h1>
2016-03-26 19:46:56 +08:00
<p>Blessing Skin Server 看起来已经安装妥当。如果想重新安装,请删除数据库中的旧数据表,或者换一个数据表前缀。</p>
2016-03-12 21:15:43 +08:00
<p class="step"><a href="../index.php" class="button button-large">返回首页</a></p>
2016-03-26 19:46:56 +08:00
<?php exit; endif;
/*
* Stepped installation
*/
switch ($step) {
// Step 1
case 1: ?>
<h1>欢迎</h1>
<p>欢迎使用 Blessing Skin Server V2</p>
<p>成功连接至 MySQL 服务器 <?php echo DB_USER."@".DB_HOST; ?>,点击下一步以开始安装。</p>
<p class="step"><a href="install.php?step=2" class="button button-large">下一步</a></p>
<?php break;
// Step 2
case 2: ?>
<h1>填写信息</h1>
<p>您需要填写一些基本信息。无需担心填错,这些信息以后可以再次修改。</p>
<form id="setup" method="post" action="install.php?step=3" novalidate="novalidate">
<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>
<tr class="form-field form-required">
<th scope="row"><label for="password">密码</label></th>
<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">
<th scope="row"><label for="password2">重复密码(必填)</label></th>
<td>
<input type="password" name="password2" id="password2" autocomplete="off" />
<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>
</td>
</tr>
</table>
<?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;
// Step 3
case 3:
// check post
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['password2'])) {
if ($_POST['password'] != $_POST['password2']) {
2016-03-26 19:46:56 +08:00
header('Location: install.php?step=2&msg=确认密码不一致。'); exit;
}
$username = $_POST['username'];
$password = $_POST['password'];
$sitename = isset($_POST['sitename']) ? $_POST['sitename'] : "Blessing Skin Server";
if (User::checkValidUname($username)) {
if (strlen($password) > 16 || strlen($password) < 5) {
header('Location: install.php?step=2&msg=无效的密码。密码长度应该大于 6 并小于 15。');
2016-03-26 19:46:56 +08:00
exit;
} else if (Utils::convertString($password) != $password) {
2016-03-26 19:46:56 +08:00
header('Location: install.php?step=2&msg=无效的密码。密码中包含了奇怪的字符。'); exit;
}
} else {
2016-03-26 19:46:56 +08:00
header('Location: install.php?step=2&msg=无效的用户名。用户名只能包含数字,字母以及下划线。'); exit;
}
} else {
2016-03-26 19:46:56 +08:00
header('Location: install.php?step=2&msg=表单信息不完整。'); exit;
}
$table_users = DB_PREFIX."users";
$table_options = DB_PREFIX."options";
$sql1 = "CREATE TABLE IF NOT EXISTS `$table_users` (
`uid` int(20) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(255) 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=utf8;";
$sql2 = "CREATE TABLE IF NOT EXISTS `$table_options` (
`option_id` int(20) unsigned NOT NULL AUTO_INCREMENT,
`option_name` varchar(50) NOT NULL,
`option_value` longtext,
PRIMARY KEY (`option_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
// import options
$sql3 = "INSERT INTO `$table_options` (`option_id`, `option_name`, `option_value`) VALUES
(1, 'site_url', ''),
(2, 'site_name', '$sitename'),
(3, 'site_description', 'Minecraft 皮肤站'),
(4, 'user_can_register', '1'),
(5, 'regs_per_ip', '2'),
(6, 'api_type', '0'),
2016-03-19 10:28:18 +08:00
(7, 'announcement', '这是默认的公告~'),
(8, 'data_adapter', ''),
(9, 'data_table_name', 'authme for example'),
2016-03-19 20:54:13 +08:00
(10, 'data_column_uname', 'username'),
2016-03-19 10:28:18 +08:00
(11, 'data_column_passwd', 'password'),
2016-03-19 15:21:09 +08:00
(12, 'data_column_ip', 'ip'),
2016-03-19 16:52:17 +08:00
(13, 'color_scheme', 'skin-blue'),
2016-03-19 15:35:16 +08:00
(14, 'home_pic_url', './assets/images/bg.jpg');";
if (!$conn->query($sql1) || !$conn->query($sql2) || !$conn->query($sql3)) { ?>
<h1>数据表创建失败</h1>
<p>照理来说不应该的,请带上错误信息联系作者:</p>
<p><?php echo $conn->error; ?></p>
2016-03-26 19:46:56 +08:00
<?php exit;
}
// Insert user
$conn->query("INSERT INTO `$table_users` (`uid`, `username`, `password`, `ip`, `preference`) VALUES
(1, '".$username."', '".md5($_POST['password'])."', '127.0.0.1', 'default')");
if (!is_dir("../textures/")) {
if (!mkdir("../textures/")): ?>
<h1>文件夹创建失败</h1>
<p>textures 文件夹创建失败。确定你拥有该目录的写权限吗?</p>
<?php endif;
} ?>
<h1>成功!</h1>
<p>Blessing Skin Server 安装完成。您是否还沉浸在愉悦的安装过程中?很遗憾,一切皆已完成! :)</p>
<table class="form-table install-success">
<tr>
<th>用户名</th>
<td><?php echo $username; ?></td>
</tr>
<tr>
<th>密码</th>
<td><p><em><?php echo $password; ?></em></p></td>
</tr>
</table>
<p class="step"><a href="../index.php" class="button button-large">首页</a></p>
<?php
break;
}