-
Notifications
You must be signed in to change notification settings - Fork 14
/
install.php
113 lines (101 loc) · 3.42 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
$config = array();
require './config.php';
// Extract the components
$username = $config['DATABASE_USERNAME'] ?? '';
$password = $config['DATABASE_PASSWORD'] ?? '';
$host = $config['DATABASE_HOST'] ?? '';
$database = $config['DATABASE_DBNAME'] ?? '';
$table = $config['DATABASE_TABLENAME'] ?? '';
function createDB(&$conn){
global $table;
try {
$conn->query("DROP TABLE IF EXISTS " . $table );
} catch (mysqli_sql_exception $e) {
echo "Error Failed to drop table : " . $e . "\n";
return False;
}
try {
$conn->query("CREATE TABLE " . $table . " (
`no` int(1) NOT NULL AUTO_INCREMENT,
`resto` int(1) NOT NULL,
`root` timestamp NOT NULL,
`time` int(1) NOT NULL,
`md5chksum` text,
`category` text NOT NULL,
`tim` bigint(1) NOT NULL,
`fname` text NOT NULL,
`ext` text NOT NULL,
`imgw` smallint(1) NOT NULL,
`imgh` smallint(1) NOT NULL,
`imgsize` text NOT NULL,
`tw` smallint(1) NOT NULL,
`th` smallint(1) NOT NULL,
`pwd` text NOT NULL,
`now` text NOT NULL,
`name` text NOT NULL,
`email` text NOT NULL,
`sub` text NOT NULL,
`com` text NOT NULL,
`host` text NOT NULL,
`status` text NOT NULL,
PRIMARY KEY (`no`),
index (resto),
index (root),
index (time)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;");
} catch (mysqli_sql_exception $e) {
echo "Error Failed to create table : " . $e . "\n";
return False;
}
echo "database Successfully set up!\n";
return True;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Kokonotsuba Installer</title>
<link rel="stylesheet" type="text/css" href="<?php echo $config['STATIC_URL'] ?>/css/heyuriclassic.css">
</head>
<body>
<h1>Kokonotsuba Installer</h1><hr>
<h2>DO NOT RUN THIS SCRIPT WHITH A TABLE ALREADY IN USE!</h2>
Doing so would drop that table. If you want to use that table, delete this <i>install.php</i>. script and add your own MySQL creds to <i>config.php</i><br><br>
<div class="reply">
Once you have a MySQL server set up with a basic username, password, and database, put the MySQL credentials in <i>config.php</i> and run this form.<br>
verify these creds are correct.<hr>
<form method="post">
<label>Username: </label><?php echo htmlspecialchars($username);?><br>
<label>Password: </label><?php echo htmlspecialchars($password);?><br>
<label>Domain/ip: </label><?php echo htmlspecialchars($host);?><br>
<label>Database Name: </label><?php echo htmlspecialchars($database);?><br>
<label>Table name: </label><?php echo htmlspecialchars($table);?><br>
<button type="submit">install</button>
</form>
</div>
<?php
// on post request recived.
//connect to the DB and create the table.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "<div class=\"postblock\">";
$connection = NULL;
try {
$connection = new mysqli($host, $username, $password, $database);
} catch (mysqli_sql_exception $e) {
echo "invalid credentals. is you database running? " . $e ."\n";
}
if ($connection) {
createDB($connection);
$connection->close();
}
if (!is_dir($config['IMG_DIR'])) mkdir($config['IMG_DIR']);
if (!is_dir($config['THUMB_DIR'])) mkdir($config['THUMB_DIR']);
echo "</div>";
}
?>
</body>
</html>