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\Bootstrap; |
28
|
|
|
use SP\Core\Crypt\CryptPKI; |
29
|
|
|
use SP\Modules\Web\Controllers\Traits\JsonTrait; |
30
|
|
|
use SP\Plugin\PluginManager; |
31
|
|
|
use SP\Providers\Auth\Browser\Browser; |
32
|
|
|
use SP\Services\Import\ImportService; |
33
|
|
|
use SP\Storage\File\FileException; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Class BootstrapController |
37
|
|
|
* |
38
|
|
|
* @package SP\Modules\Web\Controllers |
39
|
|
|
*/ |
40
|
|
|
final class BootstrapController extends SimpleControllerBase |
41
|
|
|
{ |
42
|
|
|
use JsonTrait; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns environment data |
46
|
|
|
* |
47
|
|
|
* @return bool |
48
|
|
|
* @throws \DI\DependencyException |
49
|
|
|
* @throws \DI\NotFoundException |
50
|
|
|
*/ |
51
|
|
|
public function getEnvironmentAction() |
52
|
|
|
{ |
53
|
|
|
$checkStatus = $this->session->getAuthCompleted() |
54
|
|
|
&& ($this->session->getUserData()->getIsAdminApp() || $this->configData->isDemoEnabled()); |
55
|
|
|
|
56
|
|
|
$data = [ |
57
|
|
|
'lang' => $this->getJsLang(), |
58
|
|
|
'locale' => $this->configData->getSiteLang(), |
59
|
|
|
'app_root' => Bootstrap::$WEBURI, |
60
|
|
|
'max_file_size' => $this->configData->getFilesAllowedSize(), |
61
|
|
|
'check_updates' => $checkStatus && $this->configData->isCheckUpdates(), |
62
|
|
|
'check_notices' => $checkStatus && $this->configData->isChecknotices(), |
63
|
|
|
'check_notifications' => $this->getNotificationsEnabled(), |
64
|
|
|
'timezone' => date_default_timezone_get(), |
65
|
|
|
'debug' => DEBUG || $this->configData->isDebug(), |
66
|
|
|
'cookies_enabled' => $this->getCookiesEnabled(), |
67
|
|
|
'plugins' => $this->getPlugins(), |
68
|
|
|
'loggedin' => $this->session->isLoggedIn(), |
69
|
|
|
'authbasic_autologin' => $this->getAuthBasicAutologinEnabled(), |
70
|
|
|
'pki_key' => $this->getPublicKey(), |
71
|
|
|
'pki_max_size' => CryptPKI::getMaxDataSize(), |
72
|
|
|
'import_allowed_mime' => ImportService::ALLOWED_MIME, |
73
|
|
|
'files_allowed_mime' => $this->configData->getFilesAllowedMime(), |
74
|
|
|
'session_timeout' => $this->configData->getSessionTimeout() |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
return $this->returnJsonResponseData($data); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
|
|
private function getJsLang() |
84
|
|
|
{ |
85
|
|
|
return require RESOURCES_PATH . DIRECTORY_SEPARATOR . 'strings.js.inc'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
|
|
private function getNotificationsEnabled() |
92
|
|
|
{ |
93
|
|
|
if ($this->session->isLoggedIn()) { |
94
|
|
|
return $this->session->getUserData()->getPreferences()->isCheckNotifications(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
|
|
private function getCookiesEnabled() |
104
|
|
|
{ |
105
|
|
|
return $this->router->request()->cookies()->get(session_name()) !== null; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
|
|
private function getPlugins() |
112
|
|
|
{ |
113
|
|
|
try { |
114
|
|
|
return $this->dic->get(PluginManager::class)->getEnabledPlugins(); |
115
|
|
|
} catch (\Exception $e) { |
116
|
|
|
processException($e); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return []; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return bool |
124
|
|
|
* @throws \DI\DependencyException |
125
|
|
|
* @throws \DI\NotFoundException |
126
|
|
|
*/ |
127
|
|
|
private function getAuthBasicAutologinEnabled() |
128
|
|
|
{ |
129
|
|
|
return $this->dic->get(Browser::class)->getServerAuthUser() !== null |
130
|
|
|
&& $this->configData->isAuthBasicAutoLoginEnabled(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return string |
135
|
|
|
* @throws \DI\DependencyException |
136
|
|
|
* @throws \DI\NotFoundException |
137
|
|
|
*/ |
138
|
|
|
private function getPublicKey() |
139
|
|
|
{ |
140
|
|
|
try { |
141
|
|
|
return $this->session->getPublicKey() ?: $this->dic->get(CryptPKI::class)->getPublicKey(); |
142
|
|
|
} catch (FileException $e) { |
143
|
|
|
processException($e); |
144
|
|
|
|
145
|
|
|
return ''; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return void |
151
|
|
|
*/ |
152
|
|
|
protected function initialize() |
153
|
|
|
{ |
154
|
|
|
// TODO: Implement initialize() method. |
155
|
|
|
} |
156
|
|
|
} |