-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
105 lines (85 loc) · 2.86 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
<?php
require_once 'lib/common.php';
require_once 'lib/install.php';
// We store stuff in the session, to survive the redirect to self
session_start();
// Only run the installer when we're responding to the form
if ($_POST) {
// Here's the install
$pdo = getPDO();
list($rowCounts, $error) = installBlog($pdo);
$password = '';
if (!$error) {
$username = 'admin';
list($password, $error) = createUser($pdo, $username);
}
$_SESSION['count'] = $rowCounts;
$_SESSION['error'] = $error;
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['try-install'] = true;
// ... and here we redirect from POST to GET
redirectAndExit('install.php');
}
// Let's see if we've just installed
$attempted = false;
if (isset($_SESSION['try-install'])) {
$attempted = true;
$count = $_SESSION['count'];
$error = $_SESSION['error'];
$username = $_SESSION['username'];
$password = $_SESSION['password'];
// Unset session variables, so we only report the install/failure once
unset($_SESSION['count']);
unset($_SESSION['error']);
unset($_SESSION['username']);
unset($_SESSION['password']);
unset($_SESSION['try-install']);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Blog installer</title>
<?php require 'templates/head.php' ?>
</head>
<body>
<?php if ($attempted): ?>
<?php if ($error): ?>
<div class="error box">
<?php echo $error ?>
</div>
<?php else: ?>
<div class="success box">
The database and demo data was created OK.
<?php // Report the counts for each table ?>
<?php foreach (array('post', 'comment') as $tableName): ?>
<?php if (isset($count[$tableName])): ?>
<?php // Prints the count ?>
<?php echo $count[$tableName] ?> new
<?php // Prints the name of the thing ?>
<?php echo $tableName ?>s
were created.
<?php endif ?>
<?php endforeach ?>
<?php // Report the new password ?>
The new '
<?php echo htmlEscape($username) ?>' password is
<span class="install-password">
<?php echo htmlEscape($password) ?>
</span>
(copy it to clipboard if you wish).
</div>
<p>
<a href="index.php">View the blog</a>,
or <a href="install.php">install again</a>.
</p>
<?php endif ?>
<?php else: ?>
<p>Click the install button to reset the database.</p>
<form method="post">
<input name="install" type="submit" value="Install" />
</form>
<?php endif ?>
</body>
</html>