forked from rapid7/hackazon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall.php
102 lines (82 loc) · 3.14 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
<?php
namespace App\Controller;
use App\Exception\ForbiddenException;
use App\Exception\RedirectException;
use App\Installation\Installer;
use App\Page;
class Install extends Page {
/**
* show overview page
*/
public function action_index() {
$this->initView('installation');
try {
$installer = $this->pixie->installer;
$installer->setForceFreshInstall(!!$this->request->get('force', false));
$result = $installer->init($this->view)->runWizard($this->request);
} catch (RedirectException $e) {
$this->redirect($e->getLocation());
return;
} catch (ForbiddenException $e) {
$this->redirect('/install/login');
return;
}
// If wizard successfully passed, install entered data.
if ($result->isCompleted()) {
$this->pixie->installer->finish();
$this->pixie->session->set('isInstalled', true);
$this->redirect('/');
} else {
// Current step (maybe not that we asked by the url, but one of invalid previous ones)
$step = $result->getStep();
if (!$step) {
$step = $result->getLastStartedStep();
$this->redirect('/install/' . $step->getName());
}
// Move next on successful step
if ($step->getCompleted()) {
$this->redirect('/install/' . $step->getNextStep()->getName());
return;
}
// Redirect to invalid step if current step is greater than that step.
if ($result->needRedirect()) {
$this->redirect('/install/' . $step->getName());
return;
}
$this->view->subview = $step->getTemplate();
$this->view->errorMessage = implode('<br>', $step->getErrors());
$this->view->step = $step;
foreach ($result->getViewData() as $key => $value) {
$this->view->$key = $value;
}
$this->view->bodyClass = "installation-page";
}
}
public function action_login()
{
$this->initView('installation');
$this->pixie->session->get();
$params = $this->pixie->config->get('parameters') ?: [];
$storedPassword = trim($params['installer_password']);
if (!$storedPassword) {
$this->redirect('/install');
return;
}
if ($this->request->method == 'POST') {
$password = $this->request->post('password');
if ($password && $password == $storedPassword) {
$_SESSION[Installer::SESSION_KEY]['authorized'] = true;
$this->redirect('/install');
} else {
$this->view->errors = "Incorrect password.";
}
}
$this->view->subview = 'installation/login';
}
public function action_finish()
{
$this->pixie->session->get();
unset($_SESSION[Installer::SESSION_KEY]);
$this->redirect('/install');
}
}