-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
360 lines (342 loc) · 12.6 KB
/
install.php
File metadata and controls
360 lines (342 loc) · 12.6 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
/**
* install.php
*
* This is the install controller for the application.
* After completion: YOU SHOULD DELETE THIS FILE.
*
* @version 2.0
* @author Joey Kimsey <JoeyKimsey@thetempusproject.com>
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Controllers;
require_once 'index.php';
use TempusProjectCore\Core\Controller;
use TempusProjectCore\Core\Installer;
use TempusProjectCore\Functions\Routes;
use TempusProjectCore\Classes\Redirect;
use TempusProjectCore\Classes\Session;
use TempusProjectCore\Classes\Config;
use TempusProjectCore\Classes\Cookie;
use TempusProjectCore\Classes\Debug;
use TempusProjectCore\Classes\Check;
use TempusProjectCore\Classes\Input;
use TempusProjectCore\Classes\Email;
use TempusProjectCore\Classes\Issue;
use TempusProjectCore\Classes\Image;
use TempusProjectCore\Classes\Hash;
class Install extends Controller
{
private static $installer;
private static $user;
public function __construct()
{
Debug::group("Controller: " . get_class($this), 1);
self::$title = 'TTP Installer';
self::$pageDescription = 'This is the install script for the tempus project.';
self::$installer = new Installer;
self::$template->noIndex();
self::$template->noFollow();
self::$template->set('menu-Welcome', 'disabled');
self::$template->set('menu-Terms', 'disabled');
self::$template->set('menu-Verify', 'disabled');
self::$template->set('menu-Configure', 'disabled');
self::$template->set('menu-Htaccess', 'disabled');
self::$template->set('menu-Install', 'disabled');
self::$template->set('menu-Resources', 'disabled');
self::$template->set('menu-User', 'disabled');
self::$template->set('menu-Complete', 'disabled');
if (self::$installer->getStatus() === false) {
$this->index();
exit;
}
if (self::$installer->checkSession() !== false) {
$location = self::$installer->getStatus();
$this->$location();
exit();
}
Issue::notice('We cannot verify your current install session. If you recieve this message in error, please delete App/install.json and begin the installation process again.');
exit();
}
public function __destruct()
{
Debug::log('Controller Destructing: '.get_class($this));
Debug::gend();
$this->build();
}
/**
* All traffic should come through the index page where the proper controller
* is loaded based on your security hash and the location of the installer you
* were last on.
*/
public function index()
{
self::$template->set('menu-Welcome', 'active');
self::$template->set('installer-nav', self::$template->standardView('navigation.installer'));
Debug::log("Controller initiated: " . __METHOD__ . '.');
if (Check::form('installStart')) {
self::$installer->nextStep('terms', true);
return;
}
$this->view('install.start');
}
public function terms()
{
self::$template->set('menu-Terms', 'active');
self::$template->set('installer-nav', self::$template->standardView('navigation.installer'));
Issue::info('Please accept the install agreement and review the warnings in order to continue.');
self::$template->set('TERMS', self::$template->standardView('terms'));
if (!Check::form('installAgreement')) {
$this->view('install.agreement');
return;
}
self::$installer->nextStep('verify', true);
}
public function verify()
{
self::$template->set('menu-Verify', 'active');
self::$template->set('installer-nav', self::$template->standardView('navigation.installer'));
Issue::info('Please ensure all checks pass in order to continue.');
if (!Input::exists()) {
$this->view('install.check');
return;
}
if (!Check::form('installCheck')) {
Issue::error('There was an error with the Installation.', Check::userErrors());
$this->view('install.check');
return;
}
self::$installer->nextStep('configure', true);
}
public function configure()
{
self::$template->set('menu-Configure', 'active');
self::$template->set('installer-nav', self::$template->standardView('navigation.installer'));
self::$template->set('TIMEZONELIST', self::$template->standardView('timezoneDropdown'));
Issue::info('Configure your new installation.');
if (!Input::exists()) {
$this->view('install.configure');
return;
}
if (!Check::form('installConfigure')) {
Issue::error('There was an error with your form.', Check::userErrors());
$this->view('install.configure');
return;
}
if (Input::exists('logo') && Image::upload('logo', 'System')) {
$logo = 'Uploads/Images/System/' . Image::last();
} else {
$logo = 'Images/logo.png';
}
$mods = [
[
'category' => 'main',
'name' => 'name',
'value' => Input::postNull('siteName')
],
[
'category' => 'main',
'name' => 'loginLimit',
'value' => 5
],
[
'category' => 'main',
'name' => 'logo',
'value' => $logo
],
[
'category' => 'main',
'name' => 'timezone',
'value' => Input::postNull('timezone')
],
[
'category' => 'main',
'name' => 'pageLimit',
'value' => 50
],
[
'category' => 'uploads',
'name' => 'files',
'value' => true
],
[
'category' => 'uploads',
'name' => 'images',
'value' => true
],
[
'category' => 'uploads',
'name' => 'maxFileSize',
'value' => 5000000
],
[
'category' => 'uploads',
'name' => 'maxImageSize',
'value' => 500000
],
[
'category' => 'database',
'name' => 'dbHost',
'value' => Input::postNull('dbHost')
],
[
'category' => 'database',
'name' => 'dbUsername',
'value' => Input::postNull('dbUsername')
],
[
'category' => 'database',
'name' => 'dbPrefix',
'value' => Input::postNull('dbPrefix')
],
[
'category' => 'database',
'name' => 'dbPassword',
'value' => Input::postNull('dbPassword')
],
[
'category' => 'database',
'name' => 'dbName',
'value' => Input::postNull('dbName')
],
[
'category' => 'database',
'name' => 'dbEnabled',
'value' => true
],
[
'category' => 'database',
'name' => 'dbMaxQuery',
'value' => 100
]
];
if (!Config::generateConfig($mods)) {
Issue::error('Config file already exists so the installer has been halted. If there was an error with installation, please delete App/config.php manually and try again. The installer should automatically bring you back to this step.');
return;
}
self::$installer->nextStep('htaccess', true);
}
public function htaccess()
{
self::$template->set('menu-Htaccess', 'active');
self::$template->set('installer-nav', self::$template->standardView('navigation.installer'));
Issue::info('Modify/Generate the htaccess file.');
if (!Input::exists()) {
$this->view('install.htaccess');
return;
}
if (!Check::form('installhtaccess')) {
Issue::error('There was an error with your form.', Check::userErrors());
$this->view('install.htaccess');
return;
}
self::$installer->checkHtaccess(true);
self::$installer->nextStep('install', true);
}
public function install()
{
self::$template->set('menu-Install', 'active');
self::$template->set('installer-nav', self::$template->standardView('navigation.installer'));
Issue::info('Installing models');
$models = self::$installer->getModelVersionList('App/Models');
if (!Input::exists()) {
$this->view('install.models', $models);
return;
}
if (!Check::form('installModels')) {
Issue::error('There was an error with your form.', Check::userErrors());
$this->view('install.models', $models);
return;
}
$error = false;
$models = Input::post('M_');
foreach ($models as $model) {
if (!self::$installer->installModel($model, '', ['installResources' => false])) {
$error = true;
}
}
if ($error) {
Issue::error('There was an error with the Installation.', self::$installer->getErrors());
return;
}
self::$installer->nextStep('resources', true);
}
public function resources()
{
self::$template->set('menu-Resources', 'active');
self::$template->set('installer-nav', self::$template->standardView('navigation.installer'));
Issue::info('Generate and install resources.');
if (!Input::exists()) {
$this->view('install.resources');
return;
}
if (!Check::form('installResources')) {
Issue::error('There was an error with your form.', Check::userErrors());
$this->view('install.resources');
return;
}
$flags = [
'installDB' => false,
'installPermissions' => false,
'installConfigs' => false,
'installResources' => true,
'installPreferences' => false
];
$error = false;
$models = self::$installer->getModelList('App/Models');
foreach ($models as $model) {
if (!self::$installer->installModel($model, 'App/Models', $flags)) {
$error = true;
}
}
if ($error) {
Issue::error('There was an error with the Installation.', self::$installer->getErrors());
return;
}
self::$installer->nextStep('user', true);
}
public function user()
{
self::$template->set('menu-User', 'active');
self::$template->set('installer-nav', self::$template->standardView('navigation.installer'));
Issue::info('Please register your administrator account.');
if (!Input::exists()) {
$this->view('install.adminUser');
return;
}
if (!Check::form('installAdminUser')) {
Issue::error('There was an error with your form.', Check::userErrors());
$this->view('install.adminUser');
return;
}
self::$user = $this->model('user');
if (!self::$user->create([
'username' => Input::post('newUsername'),
'password' => Hash::make(Input::post('userPassword')),
'email' => Input::post('userEmail'),
'lastLogin' => time(),
'registered' => time(),
'confirmed' => 1,
'terms' => 1,
'userGroup' => 1,
])) {
Issue::error('There was an error creating the admin user.');
return;
}
self::$installer->nextStep('complete', true);
}
public function complete()
{
self::$template->set('menu-Complete', 'active');
self::$template->set('installer-nav', self::$template->standardView('navigation.installer'));
Issue::success('The Tempus Project has been installed successfully.');
Email::send(Input::post('email'), 'install', null, ['template' => true]);
$this->view('install.complete');
self::$installer->nextStep('delete');
}
public function delete()
{
Issue::notice('Installation has been completed. Updates and installation can be managed in the admin panel under Installed. Please delete this file.');
}
}