-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
113 lines (100 loc) · 4.91 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
session_start();
require("inc/config.php");
function sendIt($db, $username, $password, $email) {
$q = $db->prepare("CREATE TABLE `chat` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(20) NOT NULL DEFAULT 'Anonymous', `message` text NOT NULL, `date` int(11) NOT NULL, `user_id` int(11) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$try[] = $q->execute();
$q = $db->prepare("CREATE TABLE `users` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(255) NOT NULL DEFAULT '', `password` varchar(255) NOT NULL DEFAULT '', `email` varchar(255) NOT NULL DEFAULT '', `low_username` varchar(255) NOT NULL DEFAULT '', `date_created` int(20) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
$try[] = $q->execute();
$q = $db->prepare("CREATE TABLE `user_comments` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `poster_id` int(11) NOT NULL, `post_date` int(11) NOT NULL, `comment` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL, PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8mb4;");
$try[] = $q->execute();
$q = $db->prepare("INSERT INTO `chat` (`id`, `username`, `message`, `date`, `user_id`) VALUES (?, ?, ?, ?, ?);");
$try[] = $q->execute(array(1, "Lyfa", "Thanks for using my chat box", 1542472793, 1));
$q = $db->prepare("INSERT INTO `users` (`id`, `username`, `password`, `email`, `low_username`, `date_created`) VALUES (?, ?, ?, ?, ?, ?);");
$try[] = $q->execute(array(1, "Anonymous", "Anonymous", "Anonymous", "anonymous", time()));
$q = $db->prepare("INSERT INTO `users` (`username`, `password`, `email`, `low_username`, `date_created`) VALUES (?, ?, ?, ?, ?);");
$stry[] = $q->execute(array($username, password_hash($password, PASSWORD_DEFAULT), $email, strtolower($username), time()));
if(in_array(false, $try)) {
$success = false;
} else {
$success = true;
}
return $success;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Chatbox</title>
<!-- Bootstrap core CSS -->
<link href="<?=$baseurl?>css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="<?=$baseurl?>css/cover.css" rel="stylesheet">
</head>
<body>
<div class="container d-flex h-100 p-3 mx-auto flex-column">
<main class="masthead mb-auto">
<div class="inner">
<div class="row outer-container">
<div class="col-md-4"></div>
<div class="col-md-4">
<? if($_GET['sendit'] == "true") {
$success = sendIt($db, $_POST['username'], $_POST['password'], $_POST['email']);
if($success == true) { ?>
<div class="alert text-center alert-success">
Your chat box has been installed.
<br />
You can now create a new user.
<hr />
Please delete <pre>install.php</pre> in order to use the chat box.
</div>
<? } else if ($success == false) { ?>
<div class="alert text-center alert-danger">
There has been an error while trying to install your chatbox.
<br />
<br />
Please check the following
<br />
<br />
<div class="text-left">
<dl>
<dt>inc/config.php</dt>
<dd>Ensure everything is setup correctly.</dd>
<dt>`<?=$dbdatabase?>`</dt>
<dd>Ensure your database is empty</dd>
</dl>
</div>
<br />
If you continue to have errors<br />please <a href="mailto:[email protected]?subject=Chatbox installation errors" class="text-muted">contact me.</a>
</div>
<? } ?>
<? } else if($db_error == true) { ?>
<div class="alert text-center alert-danger">
Database connection error.
<br /><br />
Please verify everything is correct in<pre>inc/config.php</pre>
<a href="install.php" class="text-muted">Try again</a>
</div>
<? } else { ?>
<div class="alert text-center alert-success">Please remember to delete <pre>install.php</pre> after completing the install</div>
<form action="install.php?sendit=true" method="POST">
<input type="text" name="username" class="form-control" placeholder="Username" required autofocus>
<input type="password" name="password" class="form-control" placeholder="Password" required>
<input type="email" name="email" class="form-control" placeholder="Email address" required>
<br />
<input type="submit" class="btn btn-lg btn-primary btn-block" value="Install">
</form>
<? } ?>
</div>
<div class="col-md-4"></div>
</div>
</div>
</main>
<? require("style/footer.php"); ?>
</div>
</body>
</html>