-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
268 lines (244 loc) · 8.9 KB
/
Copy pathinstall.php
File metadata and controls
268 lines (244 loc) · 8.9 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/**
* ReadIn52 Installation Script
*
* Run this script once to set up the database and create default users.
* DELETE THIS FILE after installation for security.
*/
// Prevent direct access in production
if (php_sapi_name() !== 'cli' && !isset($_GET['confirm'])) {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Install ReadIn52</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #5D4037 0%, #3E2723 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
background: white;
padding: 40px;
border-radius: 12px;
box-shadow: 0 10px 40px rgba(0,0,0,0.3);
max-width: 500px;
width: 100%;
}
h1 { color: #5D4037; margin-bottom: 10px; }
.tagline { color: #666; margin-bottom: 30px; }
.warning {
background: #FFF3E0;
border: 1px solid #FFB300;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
color: #E65100;
}
.info {
background: #E3F2FD;
border: 1px solid #1565C0;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
color: #0D47A1;
}
.btn {
display: inline-block;
background: #5D4037;
color: white;
padding: 12px 30px;
border-radius: 8px;
text-decoration: none;
font-weight: 600;
transition: background 0.3s;
}
.btn:hover { background: #3E2723; }
ul { margin: 15px 0; padding-left: 20px; }
li { margin: 5px 0; }
</style>
</head>
<body>
<div class="container">
<h1>ReadIn52 Installation</h1>
<p class="tagline">Journey Through Scripture in 52 Weeks</p>
<div class="warning">
<strong>Warning:</strong> This will create the database and default users.
Delete this file after installation!
</div>
<div class="info">
<strong>Default admin account will be created:</strong>
<ul>
<li><strong>Email:</strong> setup@localhost</li>
<li><strong>Password:</strong> ChangeMe52!</li>
</ul>
<p style="margin-top: 10px; font-size: 0.9em;"><strong>Note:</strong> You will be prompted to change your email and password on first login.</p>
</div>
<p style="margin-bottom: 20px;">Click the button below to start installation:</p>
<a href="?confirm=1" class="btn">Install ReadIn52</a>
</div>
</body>
</html>
<?php
exit;
}
// Run installation
require_once __DIR__ . '/config/config.php';
$messages = [];
$errors = [];
try {
// Step 1: Create data directory (for session storage, logs, etc.)
if (!is_dir(DATA_PATH)) {
if (mkdir(DATA_PATH, 0755, true)) {
$messages[] = 'Created data directory';
} else {
$errors[] = 'Failed to create data directory';
}
} else {
$messages[] = 'Data directory already exists';
}
// Step 2: Test database connection
try {
Database::getInstance();
$messages[] = 'Database connection successful';
} catch (Exception $e) {
$errors[] = 'Database connection failed: ' . $e->getMessage();
throw $e;
}
// Step 3: Initialize database schema
Database::initialize();
$messages[] = 'Database schema created/verified';
// Step 4: Insert default settings
Database::insertDefaultSettings();
$messages[] = 'Default settings inserted';
// Step 5: Create admin user (with must_change_password flag)
$adminExists = User::findByEmail('setup@localhost');
if (!$adminExists) {
// Create admin with mustChangePassword = true for security
$adminId = User::create('Administrator', 'setup@localhost', 'ChangeMe52!', 'admin', true);
if ($adminId) {
$messages[] = 'Admin user created (setup@localhost / ChangeMe52!)';
$messages[] = 'You will be prompted to change credentials on first login';
} else {
$errors[] = 'Failed to create admin user';
}
} else {
$messages[] = 'Admin user already exists';
}
// Step 6: Create .gitkeep in data folder
$gitkeepPath = DATA_PATH . '/.gitkeep';
if (!file_exists($gitkeepPath)) {
file_put_contents($gitkeepPath, '');
$messages[] = 'Created .gitkeep in data directory';
}
$success = empty($errors);
} catch (Exception $e) {
$errors[] = 'Installation error: ' . $e->getMessage();
$success = false;
}
// Display results
if (php_sapi_name() === 'cli') {
echo "\n=== ReadIn52 Installation ===\n\n";
foreach ($messages as $msg) {
echo "[OK] $msg\n";
}
foreach ($errors as $err) {
echo "[ERROR] $err\n";
}
echo "\n";
echo $success ? "Installation completed successfully!\n" : "Installation completed with errors.\n";
echo "\nIMPORTANT: Delete install.php for security!\n\n";
} else {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Installation <?php echo $success ? 'Complete' : 'Failed'; ?> - ReadIn52</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #5D4037 0%, #3E2723 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
background: white;
padding: 40px;
border-radius: 12px;
box-shadow: 0 10px 40px rgba(0,0,0,0.3);
max-width: 600px;
width: 100%;
}
h1 { color: <?php echo $success ? '#43A047' : '#D32F2F'; ?>; margin-bottom: 20px; }
.message {
padding: 10px 15px;
margin: 5px 0;
border-radius: 6px;
display: flex;
align-items: center;
}
.message.success { background: #E8F5E9; color: #2E7D32; }
.message.error { background: #FFEBEE; color: #C62828; }
.message::before { margin-right: 10px; font-weight: bold; }
.message.success::before { content: '✓'; }
.message.error::before { content: '✗'; }
.warning {
background: #FFF3E0;
border: 1px solid #FFB300;
padding: 15px;
border-radius: 8px;
margin-top: 20px;
color: #E65100;
}
.btn {
display: inline-block;
background: #5D4037;
color: white;
padding: 12px 30px;
border-radius: 8px;
text-decoration: none;
font-weight: 600;
margin-top: 20px;
transition: background 0.3s;
}
.btn:hover { background: #3E2723; }
</style>
</head>
<body>
<div class="container">
<h1><?php echo $success ? 'Installation Complete!' : 'Installation Failed'; ?></h1>
<?php foreach ($messages as $msg): ?>
<div class="message success"><?php echo htmlspecialchars($msg); ?></div>
<?php endforeach; ?>
<?php foreach ($errors as $err): ?>
<div class="message error"><?php echo htmlspecialchars($err); ?></div>
<?php endforeach; ?>
<?php if ($success): ?>
<div class="warning">
<strong>IMPORTANT:</strong> Delete this install.php file immediately for security!
</div>
<a href="/" class="btn">Go to ReadIn52</a>
<?php else: ?>
<div class="warning">
<strong>Note:</strong> Please fix the errors above and try again.
</div>
<?php endif; ?>
</div>
</body>
</html>
<?php
}