blessing-skin-server/admin/install.php

83 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/**
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: prpr
2016-02-04 23:49:31 +08:00
* @Last Modified time: 2016-02-04 18:42:51
*
* Create tables automatically
*/
2016-02-03 00:24:26 +08:00
$dir = dirname(dirname(__FILE__));
require "$dir/includes/autoload.inc.php";
2016-01-17 10:53:10 +08:00
echo "<style>body { font-family: Courier; }</style>";
if (!file_exists("./install.lock")) {
2016-02-03 00:24:26 +08:00
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWD, DB_NAME);
echo "<h2>Blessing Skin Server Install</h2>";
2016-02-03 00:24:26 +08:00
if ($conn->connect_error) {
utils::raise(-1, "Can not connect to mysql, check if database info correct in config.php. ".$conn->connect_error);
} else {
2016-02-03 00:24:26 +08:00
echo "Succesfully connected to database ".DB_USER."@".DB_HOST.". <br /><br />";
}
echo "Start creating tables... <br /><br />";
2016-02-03 00:24:26 +08:00
$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,
2016-01-17 15:55:46 +08:00
`preference` varchar(10) NOT NULL,
`skin_hash` varchar(64) NOT NULL,
`cape_hash` varchar(64) NOT NULL,
2016-02-03 15:53:44 +08:00
`last_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15;";
2016-02-03 00:24:26 +08:00
if(!$conn->query($sql)) {
2016-02-03 15:53:44 +08:00
die("Creating tables failed. <br /><br />".$conn->error);
}
/**
* username: admin
* password: 123456
*/
2016-02-03 00:24:26 +08:00
$conn->query("INSERT INTO `users` (`uid`, `username`, `password`, `ip`, `preference`) VALUES(1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', '127.0.0.1', 'default')");
2016-01-17 10:53:10 +08:00
echo "Creating tables successfully <br /><br />";
echo "
<pre style='font-family: Courier;'>
+-----------------------------------------------------------------------------------+-----------------+
| uid | username | password | ip | preference | skin_hash | cape_hash | last_modofied |
+-----------------------------------------------------------------------------------+-----------------+
| 1 | admin | 123456 | * | default | * | * | * |
+-----------------------------------------------------------------------------------+-----------------+
2016-01-17 10:53:10 +08:00
</pre>
";
if (!is_dir("../textures/")) {
2016-02-03 15:53:44 +08:00
echo mkdir("../textures/") ? "Creating textures directory...<br /><br />" :
"Creating textures directory failed. Check permissons.<br /><br />";
}
echo "Successfully installed. <a href='../index.php'>Index</a>";
2016-01-17 10:53:10 +08:00
if ($lock = fopen("./install.lock", 'w')) {
fwrite($lock, time());
fclose($lock);
} else {
2016-02-03 00:24:26 +08:00
die("Unable to write `install.lock`. Please check the permisson and create a `install.lock` file manually.");
}
} else {
2016-01-17 10:53:10 +08:00
echo "<br />";
echo "It seems that you have already installed. <a href='../index.php'>Index</a><br /><br />";
2016-02-03 00:24:26 +08:00
echo "May you should delete the file `install.lock` in ./admin to unlock installing.";
}
?>