|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* sysPass |
|
4
|
|
|
* |
|
5
|
|
|
* @author nuxsmin |
|
6
|
|
|
* @link https://syspass.org |
|
7
|
|
|
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of sysPass. |
|
10
|
|
|
* |
|
11
|
|
|
* sysPass is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* sysPass is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU General Public License |
|
22
|
|
|
* along with sysPass. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace SP\Modules\Web\Controllers; |
|
26
|
|
|
|
|
27
|
|
|
use SP\Core\Exceptions\SPException; |
|
28
|
|
|
use SP\Core\Language; |
|
29
|
|
|
use SP\Core\PhpExtensionChecker; |
|
30
|
|
|
use SP\Http\JsonResponse; |
|
31
|
|
|
use SP\Modules\Web\Controllers\Helpers\LayoutHelper; |
|
32
|
|
|
use SP\Modules\Web\Controllers\Traits\JsonTrait; |
|
33
|
|
|
use SP\Mvc\View\Components\SelectItemAdapter; |
|
34
|
|
|
use SP\Services\Install\InstallData; |
|
35
|
|
|
use SP\Services\Install\Installer; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Class InstallController |
|
39
|
|
|
* |
|
40
|
|
|
* @package SP\Modules\Web\Controllers |
|
41
|
|
|
*/ |
|
42
|
|
|
final class InstallController extends ControllerBase |
|
43
|
|
|
{ |
|
44
|
|
|
use JsonTrait; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* indexAction |
|
48
|
|
|
*/ |
|
49
|
|
|
public function indexAction() |
|
50
|
|
|
{ |
|
51
|
|
|
$layoutHelper = $this->dic->get(LayoutHelper::class); |
|
52
|
|
|
$layoutHelper->getPublicLayout('index', 'install'); |
|
53
|
|
|
|
|
54
|
|
|
$errors = []; |
|
55
|
|
|
|
|
56
|
|
|
foreach ($this->dic->get(PhpExtensionChecker::class)->getMissing() as $module) { |
|
57
|
|
|
$error[] = [ |
|
58
|
|
|
'type' => SPException::WARNING, |
|
59
|
|
|
'description' => sprintf('%s (%s)', __('Module unavailable'), $module), |
|
60
|
|
|
'hint' => __('Without this module the application could not run correctly') |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->view->assign('errors', $errors); |
|
65
|
|
|
$this->view->assign('langs', SelectItemAdapter::factory(Language::getAvailableLanguages())->getItemsFromArraySelected([Language::$globalLang])); |
|
66
|
|
|
|
|
67
|
|
|
$this->view(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Performs sysPass installation |
|
72
|
|
|
*/ |
|
73
|
|
|
public function installAction() |
|
74
|
|
|
{ |
|
75
|
|
|
$installData = new InstallData(); |
|
76
|
|
|
$installData->setSiteLang($this->request->analyzeString('sitelang', 'en_US')); |
|
77
|
|
|
$installData->setAdminLogin($this->request->analyzeString('adminlogin', 'admin')); |
|
78
|
|
|
$installData->setAdminPass($this->request->analyzeEncrypted('adminpass')); |
|
79
|
|
|
$installData->setMasterPassword($this->request->analyzeEncrypted('masterpassword')); |
|
80
|
|
|
$installData->setDbAdminUser($this->request->analyzeString('dbuser', 'root')); |
|
81
|
|
|
$installData->setDbAdminPass($this->request->analyzeEncrypted('dbpass')); |
|
82
|
|
|
$installData->setDbName($this->request->analyzeString('dbname', 'syspass')); |
|
83
|
|
|
$installData->setDbHost($this->request->analyzeString('dbhost', 'localhost')); |
|
84
|
|
|
$installData->setHostingMode($this->request->analyzeBool('hostingmode', false)); |
|
85
|
|
|
|
|
86
|
|
|
try { |
|
87
|
|
|
$this->dic->get(Installer::class)->run($installData); |
|
88
|
|
|
|
|
89
|
|
|
return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Installation finished')); |
|
90
|
|
|
} catch (\Exception $e) { |
|
91
|
|
|
processException($e); |
|
92
|
|
|
|
|
93
|
|
|
return $this->returnJsonResponseException($e); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return void |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function initialize() |
|
101
|
|
|
{ |
|
102
|
|
|
// TODO: Implement initialize() method. |
|
103
|
|
|
} |
|
104
|
|
|
} |