@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | /** |
122 | 122 | * List all installed apps |
123 | 123 | * |
124 | - * @return string[] |
|
124 | + * @return integer[] |
|
125 | 125 | */ |
126 | 126 | public function getInstalledApps() { |
127 | 127 | return array_keys($this->getInstalledAppsValues()); |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * Returns a list of apps that need upgrade |
314 | 314 | * |
315 | 315 | * @param string $version Nextcloud version as array of version components |
316 | - * @param $l10n string User language code |
|
316 | + * @param string $l10n string User language code |
|
317 | 317 | * @return array list of app info from apps that need an upgrade |
318 | 318 | * |
319 | 319 | * @internal |
@@ -384,6 +384,9 @@ discard block |
||
384 | 384 | return in_array($appId, $this->shippedApps, true); |
385 | 385 | } |
386 | 386 | |
387 | + /** |
|
388 | + * @param string $appId |
|
389 | + */ |
|
387 | 390 | private function isAlwaysEnabled($appId) { |
388 | 391 | $alwaysEnabled = $this->getAlwaysEnabledApps(); |
389 | 392 | return in_array($appId, $alwaysEnabled, true); |
@@ -43,369 +43,369 @@ |
||
43 | 43 | |
44 | 44 | class AppManager implements IAppManager { |
45 | 45 | |
46 | - /** |
|
47 | - * Apps with these types can not be enabled for certain groups only |
|
48 | - * @var string[] |
|
49 | - */ |
|
50 | - protected $protectedAppTypes = [ |
|
51 | - 'filesystem', |
|
52 | - 'prelogin', |
|
53 | - 'authentication', |
|
54 | - 'logging', |
|
55 | - 'prevent_group_restriction', |
|
56 | - ]; |
|
57 | - |
|
58 | - /** @var IUserSession */ |
|
59 | - private $userSession; |
|
60 | - |
|
61 | - /** @var IAppConfig */ |
|
62 | - private $appConfig; |
|
63 | - |
|
64 | - /** @var IGroupManager */ |
|
65 | - private $groupManager; |
|
66 | - |
|
67 | - /** @var ICacheFactory */ |
|
68 | - private $memCacheFactory; |
|
69 | - |
|
70 | - /** @var EventDispatcherInterface */ |
|
71 | - private $dispatcher; |
|
72 | - |
|
73 | - /** @var string[] $appId => $enabled */ |
|
74 | - private $installedAppsCache; |
|
75 | - |
|
76 | - /** @var string[] */ |
|
77 | - private $shippedApps; |
|
78 | - |
|
79 | - /** @var string[] */ |
|
80 | - private $alwaysEnabled; |
|
81 | - |
|
82 | - /** |
|
83 | - * @param IUserSession $userSession |
|
84 | - * @param IAppConfig $appConfig |
|
85 | - * @param IGroupManager $groupManager |
|
86 | - * @param ICacheFactory $memCacheFactory |
|
87 | - * @param EventDispatcherInterface $dispatcher |
|
88 | - */ |
|
89 | - public function __construct(IUserSession $userSession, |
|
90 | - IAppConfig $appConfig, |
|
91 | - IGroupManager $groupManager, |
|
92 | - ICacheFactory $memCacheFactory, |
|
93 | - EventDispatcherInterface $dispatcher) { |
|
94 | - $this->userSession = $userSession; |
|
95 | - $this->appConfig = $appConfig; |
|
96 | - $this->groupManager = $groupManager; |
|
97 | - $this->memCacheFactory = $memCacheFactory; |
|
98 | - $this->dispatcher = $dispatcher; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return string[] $appId => $enabled |
|
103 | - */ |
|
104 | - private function getInstalledAppsValues() { |
|
105 | - if (!$this->installedAppsCache) { |
|
106 | - $values = $this->appConfig->getValues(false, 'enabled'); |
|
107 | - |
|
108 | - $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
|
109 | - foreach($alwaysEnabledApps as $appId) { |
|
110 | - $values[$appId] = 'yes'; |
|
111 | - } |
|
112 | - |
|
113 | - $this->installedAppsCache = array_filter($values, function ($value) { |
|
114 | - return $value !== 'no'; |
|
115 | - }); |
|
116 | - ksort($this->installedAppsCache); |
|
117 | - } |
|
118 | - return $this->installedAppsCache; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * List all installed apps |
|
123 | - * |
|
124 | - * @return string[] |
|
125 | - */ |
|
126 | - public function getInstalledApps() { |
|
127 | - return array_keys($this->getInstalledAppsValues()); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * List all apps enabled for a user |
|
132 | - * |
|
133 | - * @param \OCP\IUser $user |
|
134 | - * @return string[] |
|
135 | - */ |
|
136 | - public function getEnabledAppsForUser(IUser $user) { |
|
137 | - $apps = $this->getInstalledAppsValues(); |
|
138 | - $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
139 | - return $this->checkAppForUser($enabled, $user); |
|
140 | - }); |
|
141 | - return array_keys($appsForUser); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Check if an app is enabled for user |
|
146 | - * |
|
147 | - * @param string $appId |
|
148 | - * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used |
|
149 | - * @return bool |
|
150 | - */ |
|
151 | - public function isEnabledForUser($appId, $user = null) { |
|
152 | - if ($this->isAlwaysEnabled($appId)) { |
|
153 | - return true; |
|
154 | - } |
|
155 | - if ($user === null) { |
|
156 | - $user = $this->userSession->getUser(); |
|
157 | - } |
|
158 | - $installedApps = $this->getInstalledAppsValues(); |
|
159 | - if (isset($installedApps[$appId])) { |
|
160 | - return $this->checkAppForUser($installedApps[$appId], $user); |
|
161 | - } else { |
|
162 | - return false; |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $enabled |
|
168 | - * @param IUser $user |
|
169 | - * @return bool |
|
170 | - */ |
|
171 | - private function checkAppForUser($enabled, $user) { |
|
172 | - if ($enabled === 'yes') { |
|
173 | - return true; |
|
174 | - } elseif ($user === null) { |
|
175 | - return false; |
|
176 | - } else { |
|
177 | - if(empty($enabled)){ |
|
178 | - return false; |
|
179 | - } |
|
180 | - |
|
181 | - $groupIds = json_decode($enabled); |
|
182 | - |
|
183 | - if (!is_array($groupIds)) { |
|
184 | - $jsonError = json_last_error(); |
|
185 | - \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
186 | - return false; |
|
187 | - } |
|
188 | - |
|
189 | - $userGroups = $this->groupManager->getUserGroupIds($user); |
|
190 | - foreach ($userGroups as $groupId) { |
|
191 | - if (in_array($groupId, $groupIds, true)) { |
|
192 | - return true; |
|
193 | - } |
|
194 | - } |
|
195 | - return false; |
|
196 | - } |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Check if an app is installed in the instance |
|
201 | - * |
|
202 | - * @param string $appId |
|
203 | - * @return bool |
|
204 | - */ |
|
205 | - public function isInstalled($appId) { |
|
206 | - $installedApps = $this->getInstalledAppsValues(); |
|
207 | - return isset($installedApps[$appId]); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Enable an app for every user |
|
212 | - * |
|
213 | - * @param string $appId |
|
214 | - * @throws AppPathNotFoundException |
|
215 | - */ |
|
216 | - public function enableApp($appId) { |
|
217 | - // Check if app exists |
|
218 | - $this->getAppPath($appId); |
|
219 | - |
|
220 | - $this->installedAppsCache[$appId] = 'yes'; |
|
221 | - $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
222 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
223 | - ManagerEvent::EVENT_APP_ENABLE, $appId |
|
224 | - )); |
|
225 | - $this->clearAppsCache(); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Whether a list of types contains a protected app type |
|
230 | - * |
|
231 | - * @param string[] $types |
|
232 | - * @return bool |
|
233 | - */ |
|
234 | - public function hasProtectedAppType($types) { |
|
235 | - if (empty($types)) { |
|
236 | - return false; |
|
237 | - } |
|
238 | - |
|
239 | - $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
240 | - return !empty($protectedTypes); |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Enable an app only for specific groups |
|
245 | - * |
|
246 | - * @param string $appId |
|
247 | - * @param \OCP\IGroup[] $groups |
|
248 | - * @throws \Exception if app can't be enabled for groups |
|
249 | - */ |
|
250 | - public function enableAppForGroups($appId, $groups) { |
|
251 | - $info = $this->getAppInfo($appId); |
|
252 | - if (!empty($info['types'])) { |
|
253 | - $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']); |
|
254 | - if (!empty($protectedTypes)) { |
|
255 | - throw new \Exception("$appId can't be enabled for groups."); |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - $groupIds = array_map(function ($group) { |
|
260 | - /** @var \OCP\IGroup $group */ |
|
261 | - return $group->getGID(); |
|
262 | - }, $groups); |
|
263 | - $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
264 | - $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
265 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
266 | - ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
267 | - )); |
|
268 | - $this->clearAppsCache(); |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Disable an app for every user |
|
273 | - * |
|
274 | - * @param string $appId |
|
275 | - * @throws \Exception if app can't be disabled |
|
276 | - */ |
|
277 | - public function disableApp($appId) { |
|
278 | - if ($this->isAlwaysEnabled($appId)) { |
|
279 | - throw new \Exception("$appId can't be disabled."); |
|
280 | - } |
|
281 | - unset($this->installedAppsCache[$appId]); |
|
282 | - $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
283 | - $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
284 | - ManagerEvent::EVENT_APP_DISABLE, $appId |
|
285 | - )); |
|
286 | - $this->clearAppsCache(); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Get the directory for the given app. |
|
291 | - * |
|
292 | - * @param string $appId |
|
293 | - * @return string |
|
294 | - * @throws AppPathNotFoundException if app folder can't be found |
|
295 | - */ |
|
296 | - public function getAppPath($appId) { |
|
297 | - $appPath = \OC_App::getAppPath($appId); |
|
298 | - if($appPath === false) { |
|
299 | - throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
300 | - } |
|
301 | - return $appPath; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Clear the cached list of apps when enabling/disabling an app |
|
306 | - */ |
|
307 | - public function clearAppsCache() { |
|
308 | - $settingsMemCache = $this->memCacheFactory->create('settings'); |
|
309 | - $settingsMemCache->clear('listApps'); |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Returns a list of apps that need upgrade |
|
314 | - * |
|
315 | - * @param string $version Nextcloud version as array of version components |
|
316 | - * @param $l10n string User language code |
|
317 | - * @return array list of app info from apps that need an upgrade |
|
318 | - * |
|
319 | - * @internal |
|
320 | - */ |
|
321 | - public function getAppsNeedingUpgrade($version, $l10n) { |
|
322 | - $appsToUpgrade = []; |
|
323 | - $apps = $this->getInstalledApps(); |
|
324 | - foreach ($apps as $appId) { |
|
325 | - $appInfo = $this->getAppInfo($appId, $l10n); |
|
326 | - $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
327 | - if ($appDbVersion |
|
328 | - && isset($appInfo['version']) |
|
329 | - && version_compare($appInfo['version'], $appDbVersion, '>') |
|
330 | - && \OC_App::isAppCompatible($version, $appInfo) |
|
331 | - ) { |
|
332 | - $appsToUpgrade[] = $appInfo; |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - return $appsToUpgrade; |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Returns the app information from "appinfo/info.xml". |
|
341 | - * |
|
342 | - * @param string $appId app id |
|
343 | - * @param $l10n string Language Code |
|
344 | - * |
|
345 | - * @return array app info |
|
346 | - * |
|
347 | - * @internal |
|
348 | - */ |
|
349 | - public function getAppInfo($appId, $l10n = null) { |
|
350 | - $appInfo = \OC_App::getAppInfo($appId, false, $l10n); |
|
351 | - if (!isset($appInfo['version'])) { |
|
352 | - // read version from separate file |
|
353 | - $appInfo['version'] = \OC_App::getAppVersion($appId); |
|
354 | - } |
|
355 | - return $appInfo; |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * Returns a list of apps incompatible with the given version |
|
360 | - * |
|
361 | - * @param string $version Nextcloud version as array of version components |
|
362 | - * |
|
363 | - * @return array list of app info from incompatible apps |
|
364 | - * |
|
365 | - * @internal |
|
366 | - */ |
|
367 | - public function getIncompatibleApps($version) { |
|
368 | - $apps = $this->getInstalledApps(); |
|
369 | - $incompatibleApps = array(); |
|
370 | - foreach ($apps as $appId) { |
|
371 | - $info = $this->getAppInfo($appId); |
|
372 | - if (!\OC_App::isAppCompatible($version, $info)) { |
|
373 | - $incompatibleApps[] = $info; |
|
374 | - } |
|
375 | - } |
|
376 | - return $incompatibleApps; |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * @inheritdoc |
|
381 | - */ |
|
382 | - public function isShipped($appId) { |
|
383 | - $this->loadShippedJson(); |
|
384 | - return in_array($appId, $this->shippedApps, true); |
|
385 | - } |
|
386 | - |
|
387 | - private function isAlwaysEnabled($appId) { |
|
388 | - $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
389 | - return in_array($appId, $alwaysEnabled, true); |
|
390 | - } |
|
391 | - |
|
392 | - private function loadShippedJson() { |
|
393 | - if ($this->shippedApps === null) { |
|
394 | - $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
395 | - if (!file_exists($shippedJson)) { |
|
396 | - throw new \Exception("File not found: $shippedJson"); |
|
397 | - } |
|
398 | - $content = json_decode(file_get_contents($shippedJson), true); |
|
399 | - $this->shippedApps = $content['shippedApps']; |
|
400 | - $this->alwaysEnabled = $content['alwaysEnabled']; |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * @inheritdoc |
|
406 | - */ |
|
407 | - public function getAlwaysEnabledApps() { |
|
408 | - $this->loadShippedJson(); |
|
409 | - return $this->alwaysEnabled; |
|
410 | - } |
|
46 | + /** |
|
47 | + * Apps with these types can not be enabled for certain groups only |
|
48 | + * @var string[] |
|
49 | + */ |
|
50 | + protected $protectedAppTypes = [ |
|
51 | + 'filesystem', |
|
52 | + 'prelogin', |
|
53 | + 'authentication', |
|
54 | + 'logging', |
|
55 | + 'prevent_group_restriction', |
|
56 | + ]; |
|
57 | + |
|
58 | + /** @var IUserSession */ |
|
59 | + private $userSession; |
|
60 | + |
|
61 | + /** @var IAppConfig */ |
|
62 | + private $appConfig; |
|
63 | + |
|
64 | + /** @var IGroupManager */ |
|
65 | + private $groupManager; |
|
66 | + |
|
67 | + /** @var ICacheFactory */ |
|
68 | + private $memCacheFactory; |
|
69 | + |
|
70 | + /** @var EventDispatcherInterface */ |
|
71 | + private $dispatcher; |
|
72 | + |
|
73 | + /** @var string[] $appId => $enabled */ |
|
74 | + private $installedAppsCache; |
|
75 | + |
|
76 | + /** @var string[] */ |
|
77 | + private $shippedApps; |
|
78 | + |
|
79 | + /** @var string[] */ |
|
80 | + private $alwaysEnabled; |
|
81 | + |
|
82 | + /** |
|
83 | + * @param IUserSession $userSession |
|
84 | + * @param IAppConfig $appConfig |
|
85 | + * @param IGroupManager $groupManager |
|
86 | + * @param ICacheFactory $memCacheFactory |
|
87 | + * @param EventDispatcherInterface $dispatcher |
|
88 | + */ |
|
89 | + public function __construct(IUserSession $userSession, |
|
90 | + IAppConfig $appConfig, |
|
91 | + IGroupManager $groupManager, |
|
92 | + ICacheFactory $memCacheFactory, |
|
93 | + EventDispatcherInterface $dispatcher) { |
|
94 | + $this->userSession = $userSession; |
|
95 | + $this->appConfig = $appConfig; |
|
96 | + $this->groupManager = $groupManager; |
|
97 | + $this->memCacheFactory = $memCacheFactory; |
|
98 | + $this->dispatcher = $dispatcher; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return string[] $appId => $enabled |
|
103 | + */ |
|
104 | + private function getInstalledAppsValues() { |
|
105 | + if (!$this->installedAppsCache) { |
|
106 | + $values = $this->appConfig->getValues(false, 'enabled'); |
|
107 | + |
|
108 | + $alwaysEnabledApps = $this->getAlwaysEnabledApps(); |
|
109 | + foreach($alwaysEnabledApps as $appId) { |
|
110 | + $values[$appId] = 'yes'; |
|
111 | + } |
|
112 | + |
|
113 | + $this->installedAppsCache = array_filter($values, function ($value) { |
|
114 | + return $value !== 'no'; |
|
115 | + }); |
|
116 | + ksort($this->installedAppsCache); |
|
117 | + } |
|
118 | + return $this->installedAppsCache; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * List all installed apps |
|
123 | + * |
|
124 | + * @return string[] |
|
125 | + */ |
|
126 | + public function getInstalledApps() { |
|
127 | + return array_keys($this->getInstalledAppsValues()); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * List all apps enabled for a user |
|
132 | + * |
|
133 | + * @param \OCP\IUser $user |
|
134 | + * @return string[] |
|
135 | + */ |
|
136 | + public function getEnabledAppsForUser(IUser $user) { |
|
137 | + $apps = $this->getInstalledAppsValues(); |
|
138 | + $appsForUser = array_filter($apps, function ($enabled) use ($user) { |
|
139 | + return $this->checkAppForUser($enabled, $user); |
|
140 | + }); |
|
141 | + return array_keys($appsForUser); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Check if an app is enabled for user |
|
146 | + * |
|
147 | + * @param string $appId |
|
148 | + * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used |
|
149 | + * @return bool |
|
150 | + */ |
|
151 | + public function isEnabledForUser($appId, $user = null) { |
|
152 | + if ($this->isAlwaysEnabled($appId)) { |
|
153 | + return true; |
|
154 | + } |
|
155 | + if ($user === null) { |
|
156 | + $user = $this->userSession->getUser(); |
|
157 | + } |
|
158 | + $installedApps = $this->getInstalledAppsValues(); |
|
159 | + if (isset($installedApps[$appId])) { |
|
160 | + return $this->checkAppForUser($installedApps[$appId], $user); |
|
161 | + } else { |
|
162 | + return false; |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $enabled |
|
168 | + * @param IUser $user |
|
169 | + * @return bool |
|
170 | + */ |
|
171 | + private function checkAppForUser($enabled, $user) { |
|
172 | + if ($enabled === 'yes') { |
|
173 | + return true; |
|
174 | + } elseif ($user === null) { |
|
175 | + return false; |
|
176 | + } else { |
|
177 | + if(empty($enabled)){ |
|
178 | + return false; |
|
179 | + } |
|
180 | + |
|
181 | + $groupIds = json_decode($enabled); |
|
182 | + |
|
183 | + if (!is_array($groupIds)) { |
|
184 | + $jsonError = json_last_error(); |
|
185 | + \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']); |
|
186 | + return false; |
|
187 | + } |
|
188 | + |
|
189 | + $userGroups = $this->groupManager->getUserGroupIds($user); |
|
190 | + foreach ($userGroups as $groupId) { |
|
191 | + if (in_array($groupId, $groupIds, true)) { |
|
192 | + return true; |
|
193 | + } |
|
194 | + } |
|
195 | + return false; |
|
196 | + } |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Check if an app is installed in the instance |
|
201 | + * |
|
202 | + * @param string $appId |
|
203 | + * @return bool |
|
204 | + */ |
|
205 | + public function isInstalled($appId) { |
|
206 | + $installedApps = $this->getInstalledAppsValues(); |
|
207 | + return isset($installedApps[$appId]); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Enable an app for every user |
|
212 | + * |
|
213 | + * @param string $appId |
|
214 | + * @throws AppPathNotFoundException |
|
215 | + */ |
|
216 | + public function enableApp($appId) { |
|
217 | + // Check if app exists |
|
218 | + $this->getAppPath($appId); |
|
219 | + |
|
220 | + $this->installedAppsCache[$appId] = 'yes'; |
|
221 | + $this->appConfig->setValue($appId, 'enabled', 'yes'); |
|
222 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent( |
|
223 | + ManagerEvent::EVENT_APP_ENABLE, $appId |
|
224 | + )); |
|
225 | + $this->clearAppsCache(); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Whether a list of types contains a protected app type |
|
230 | + * |
|
231 | + * @param string[] $types |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | + public function hasProtectedAppType($types) { |
|
235 | + if (empty($types)) { |
|
236 | + return false; |
|
237 | + } |
|
238 | + |
|
239 | + $protectedTypes = array_intersect($this->protectedAppTypes, $types); |
|
240 | + return !empty($protectedTypes); |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Enable an app only for specific groups |
|
245 | + * |
|
246 | + * @param string $appId |
|
247 | + * @param \OCP\IGroup[] $groups |
|
248 | + * @throws \Exception if app can't be enabled for groups |
|
249 | + */ |
|
250 | + public function enableAppForGroups($appId, $groups) { |
|
251 | + $info = $this->getAppInfo($appId); |
|
252 | + if (!empty($info['types'])) { |
|
253 | + $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']); |
|
254 | + if (!empty($protectedTypes)) { |
|
255 | + throw new \Exception("$appId can't be enabled for groups."); |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + $groupIds = array_map(function ($group) { |
|
260 | + /** @var \OCP\IGroup $group */ |
|
261 | + return $group->getGID(); |
|
262 | + }, $groups); |
|
263 | + $this->installedAppsCache[$appId] = json_encode($groupIds); |
|
264 | + $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds)); |
|
265 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent( |
|
266 | + ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups |
|
267 | + )); |
|
268 | + $this->clearAppsCache(); |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Disable an app for every user |
|
273 | + * |
|
274 | + * @param string $appId |
|
275 | + * @throws \Exception if app can't be disabled |
|
276 | + */ |
|
277 | + public function disableApp($appId) { |
|
278 | + if ($this->isAlwaysEnabled($appId)) { |
|
279 | + throw new \Exception("$appId can't be disabled."); |
|
280 | + } |
|
281 | + unset($this->installedAppsCache[$appId]); |
|
282 | + $this->appConfig->setValue($appId, 'enabled', 'no'); |
|
283 | + $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent( |
|
284 | + ManagerEvent::EVENT_APP_DISABLE, $appId |
|
285 | + )); |
|
286 | + $this->clearAppsCache(); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Get the directory for the given app. |
|
291 | + * |
|
292 | + * @param string $appId |
|
293 | + * @return string |
|
294 | + * @throws AppPathNotFoundException if app folder can't be found |
|
295 | + */ |
|
296 | + public function getAppPath($appId) { |
|
297 | + $appPath = \OC_App::getAppPath($appId); |
|
298 | + if($appPath === false) { |
|
299 | + throw new AppPathNotFoundException('Could not find path for ' . $appId); |
|
300 | + } |
|
301 | + return $appPath; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Clear the cached list of apps when enabling/disabling an app |
|
306 | + */ |
|
307 | + public function clearAppsCache() { |
|
308 | + $settingsMemCache = $this->memCacheFactory->create('settings'); |
|
309 | + $settingsMemCache->clear('listApps'); |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Returns a list of apps that need upgrade |
|
314 | + * |
|
315 | + * @param string $version Nextcloud version as array of version components |
|
316 | + * @param $l10n string User language code |
|
317 | + * @return array list of app info from apps that need an upgrade |
|
318 | + * |
|
319 | + * @internal |
|
320 | + */ |
|
321 | + public function getAppsNeedingUpgrade($version, $l10n) { |
|
322 | + $appsToUpgrade = []; |
|
323 | + $apps = $this->getInstalledApps(); |
|
324 | + foreach ($apps as $appId) { |
|
325 | + $appInfo = $this->getAppInfo($appId, $l10n); |
|
326 | + $appDbVersion = $this->appConfig->getValue($appId, 'installed_version'); |
|
327 | + if ($appDbVersion |
|
328 | + && isset($appInfo['version']) |
|
329 | + && version_compare($appInfo['version'], $appDbVersion, '>') |
|
330 | + && \OC_App::isAppCompatible($version, $appInfo) |
|
331 | + ) { |
|
332 | + $appsToUpgrade[] = $appInfo; |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + return $appsToUpgrade; |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Returns the app information from "appinfo/info.xml". |
|
341 | + * |
|
342 | + * @param string $appId app id |
|
343 | + * @param $l10n string Language Code |
|
344 | + * |
|
345 | + * @return array app info |
|
346 | + * |
|
347 | + * @internal |
|
348 | + */ |
|
349 | + public function getAppInfo($appId, $l10n = null) { |
|
350 | + $appInfo = \OC_App::getAppInfo($appId, false, $l10n); |
|
351 | + if (!isset($appInfo['version'])) { |
|
352 | + // read version from separate file |
|
353 | + $appInfo['version'] = \OC_App::getAppVersion($appId); |
|
354 | + } |
|
355 | + return $appInfo; |
|
356 | + } |
|
357 | + |
|
358 | + /** |
|
359 | + * Returns a list of apps incompatible with the given version |
|
360 | + * |
|
361 | + * @param string $version Nextcloud version as array of version components |
|
362 | + * |
|
363 | + * @return array list of app info from incompatible apps |
|
364 | + * |
|
365 | + * @internal |
|
366 | + */ |
|
367 | + public function getIncompatibleApps($version) { |
|
368 | + $apps = $this->getInstalledApps(); |
|
369 | + $incompatibleApps = array(); |
|
370 | + foreach ($apps as $appId) { |
|
371 | + $info = $this->getAppInfo($appId); |
|
372 | + if (!\OC_App::isAppCompatible($version, $info)) { |
|
373 | + $incompatibleApps[] = $info; |
|
374 | + } |
|
375 | + } |
|
376 | + return $incompatibleApps; |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * @inheritdoc |
|
381 | + */ |
|
382 | + public function isShipped($appId) { |
|
383 | + $this->loadShippedJson(); |
|
384 | + return in_array($appId, $this->shippedApps, true); |
|
385 | + } |
|
386 | + |
|
387 | + private function isAlwaysEnabled($appId) { |
|
388 | + $alwaysEnabled = $this->getAlwaysEnabledApps(); |
|
389 | + return in_array($appId, $alwaysEnabled, true); |
|
390 | + } |
|
391 | + |
|
392 | + private function loadShippedJson() { |
|
393 | + if ($this->shippedApps === null) { |
|
394 | + $shippedJson = \OC::$SERVERROOT . '/core/shipped.json'; |
|
395 | + if (!file_exists($shippedJson)) { |
|
396 | + throw new \Exception("File not found: $shippedJson"); |
|
397 | + } |
|
398 | + $content = json_decode(file_get_contents($shippedJson), true); |
|
399 | + $this->shippedApps = $content['shippedApps']; |
|
400 | + $this->alwaysEnabled = $content['alwaysEnabled']; |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * @inheritdoc |
|
406 | + */ |
|
407 | + public function getAlwaysEnabledApps() { |
|
408 | + $this->loadShippedJson(); |
|
409 | + return $this->alwaysEnabled; |
|
410 | + } |
|
411 | 411 | } |
@@ -59,1028 +59,1028 @@ |
||
59 | 59 | * OC_autoload! |
60 | 60 | */ |
61 | 61 | class OC { |
62 | - /** |
|
63 | - * Associative array for autoloading. classname => filename |
|
64 | - */ |
|
65 | - public static $CLASSPATH = array(); |
|
66 | - /** |
|
67 | - * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
68 | - */ |
|
69 | - public static $SERVERROOT = ''; |
|
70 | - /** |
|
71 | - * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
72 | - */ |
|
73 | - private static $SUBURI = ''; |
|
74 | - /** |
|
75 | - * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
76 | - */ |
|
77 | - public static $WEBROOT = ''; |
|
78 | - /** |
|
79 | - * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
80 | - * web path in 'url' |
|
81 | - */ |
|
82 | - public static $APPSROOTS = array(); |
|
83 | - |
|
84 | - /** |
|
85 | - * @var string |
|
86 | - */ |
|
87 | - public static $configDir; |
|
88 | - |
|
89 | - /** |
|
90 | - * requested app |
|
91 | - */ |
|
92 | - public static $REQUESTEDAPP = ''; |
|
93 | - |
|
94 | - /** |
|
95 | - * check if Nextcloud runs in cli mode |
|
96 | - */ |
|
97 | - public static $CLI = false; |
|
98 | - |
|
99 | - /** |
|
100 | - * @var \OC\Autoloader $loader |
|
101 | - */ |
|
102 | - public static $loader = null; |
|
103 | - |
|
104 | - /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
105 | - public static $composerAutoloader = null; |
|
106 | - |
|
107 | - /** |
|
108 | - * @var \OC\Server |
|
109 | - */ |
|
110 | - public static $server = null; |
|
111 | - |
|
112 | - /** |
|
113 | - * @var \OC\Config |
|
114 | - */ |
|
115 | - private static $config = null; |
|
116 | - |
|
117 | - /** |
|
118 | - * @throws \RuntimeException when the 3rdparty directory is missing or |
|
119 | - * the app path list is empty or contains an invalid path |
|
120 | - */ |
|
121 | - public static function initPaths() { |
|
122 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
123 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
124 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
125 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
126 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
127 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
128 | - } else { |
|
129 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
130 | - } |
|
131 | - self::$config = new \OC\Config(self::$configDir); |
|
132 | - |
|
133 | - OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
134 | - /** |
|
135 | - * FIXME: The following lines are required because we can't yet instantiate |
|
136 | - * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
137 | - */ |
|
138 | - $params = [ |
|
139 | - 'server' => [ |
|
140 | - 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
141 | - 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
142 | - ], |
|
143 | - ]; |
|
144 | - $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
145 | - $scriptName = $fakeRequest->getScriptName(); |
|
146 | - if (substr($scriptName, -1) == '/') { |
|
147 | - $scriptName .= 'index.php'; |
|
148 | - //make sure suburi follows the same rules as scriptName |
|
149 | - if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
150 | - if (substr(OC::$SUBURI, -1) != '/') { |
|
151 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
152 | - } |
|
153 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - if (OC::$CLI) { |
|
159 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
160 | - } else { |
|
161 | - if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
162 | - OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
163 | - |
|
164 | - if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
165 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
166 | - } |
|
167 | - } else { |
|
168 | - // The scriptName is not ending with OC::$SUBURI |
|
169 | - // This most likely means that we are calling from CLI. |
|
170 | - // However some cron jobs still need to generate |
|
171 | - // a web URL, so we use overwritewebroot as a fallback. |
|
172 | - OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
173 | - } |
|
174 | - |
|
175 | - // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
176 | - // slash which is required by URL generation. |
|
177 | - if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
178 | - substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
179 | - header('Location: '.\OC::$WEBROOT.'/'); |
|
180 | - exit(); |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - // search the apps folder |
|
185 | - $config_paths = self::$config->getValue('apps_paths', array()); |
|
186 | - if (!empty($config_paths)) { |
|
187 | - foreach ($config_paths as $paths) { |
|
188 | - if (isset($paths['url']) && isset($paths['path'])) { |
|
189 | - $paths['url'] = rtrim($paths['url'], '/'); |
|
190 | - $paths['path'] = rtrim($paths['path'], '/'); |
|
191 | - OC::$APPSROOTS[] = $paths; |
|
192 | - } |
|
193 | - } |
|
194 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
195 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
196 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
197 | - OC::$APPSROOTS[] = array( |
|
198 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
199 | - 'url' => '/apps', |
|
200 | - 'writable' => true |
|
201 | - ); |
|
202 | - } |
|
203 | - |
|
204 | - if (empty(OC::$APPSROOTS)) { |
|
205 | - throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
206 | - . ' or the folder above. You can also configure the location in the config.php file.'); |
|
207 | - } |
|
208 | - $paths = array(); |
|
209 | - foreach (OC::$APPSROOTS as $path) { |
|
210 | - $paths[] = $path['path']; |
|
211 | - if (!is_dir($path['path'])) { |
|
212 | - throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
213 | - . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
214 | - . ' config.php file.', $path['path'])); |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - // set the right include path |
|
219 | - set_include_path( |
|
220 | - implode(PATH_SEPARATOR, $paths) |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - public static function checkConfig() { |
|
225 | - $l = \OC::$server->getL10N('lib'); |
|
226 | - |
|
227 | - // Create config if it does not already exist |
|
228 | - $configFilePath = self::$configDir .'/config.php'; |
|
229 | - if(!file_exists($configFilePath)) { |
|
230 | - @touch($configFilePath); |
|
231 | - } |
|
232 | - |
|
233 | - // Check if config is writable |
|
234 | - $configFileWritable = is_writable($configFilePath); |
|
235 | - if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
236 | - || !$configFileWritable && self::checkUpgrade(false)) { |
|
237 | - |
|
238 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
239 | - |
|
240 | - if (self::$CLI) { |
|
241 | - echo $l->t('Cannot write into "config" directory!')."\n"; |
|
242 | - echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
243 | - echo "\n"; |
|
244 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
245 | - exit; |
|
246 | - } else { |
|
247 | - OC_Template::printErrorPage( |
|
248 | - $l->t('Cannot write into "config" directory!'), |
|
249 | - $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
250 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
251 | - ); |
|
252 | - } |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - public static function checkInstalled() { |
|
257 | - if (defined('OC_CONSOLE')) { |
|
258 | - return; |
|
259 | - } |
|
260 | - // Redirect to installer if not installed |
|
261 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
262 | - if (OC::$CLI) { |
|
263 | - throw new Exception('Not installed'); |
|
264 | - } else { |
|
265 | - $url = OC::$WEBROOT . '/index.php'; |
|
266 | - header('Location: ' . $url); |
|
267 | - } |
|
268 | - exit(); |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - public static function checkMaintenanceMode() { |
|
273 | - // Allow ajax update script to execute without being stopped |
|
274 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
275 | - // send http status 503 |
|
276 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
277 | - header('Status: 503 Service Temporarily Unavailable'); |
|
278 | - header('Retry-After: 120'); |
|
279 | - |
|
280 | - // render error page |
|
281 | - $template = new OC_Template('', 'update.user', 'guest'); |
|
282 | - OC_Util::addScript('maintenance-check'); |
|
283 | - OC_Util::addStyle('core', 'guest'); |
|
284 | - $template->printPage(); |
|
285 | - die(); |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Checks if the version requires an update and shows |
|
291 | - * @param bool $showTemplate Whether an update screen should get shown |
|
292 | - * @return bool|void |
|
293 | - */ |
|
294 | - public static function checkUpgrade($showTemplate = true) { |
|
295 | - if (\OCP\Util::needUpgrade()) { |
|
296 | - if (function_exists('opcache_reset')) { |
|
297 | - opcache_reset(); |
|
298 | - } |
|
299 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
300 | - if ($showTemplate && !$systemConfig->getValue('maintenance', false)) { |
|
301 | - self::printUpgradePage(); |
|
302 | - exit(); |
|
303 | - } else { |
|
304 | - return true; |
|
305 | - } |
|
306 | - } |
|
307 | - return false; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Prints the upgrade page |
|
312 | - */ |
|
313 | - private static function printUpgradePage() { |
|
314 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
315 | - |
|
316 | - $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
317 | - $tooBig = false; |
|
318 | - if (!$disableWebUpdater) { |
|
319 | - $apps = \OC::$server->getAppManager(); |
|
320 | - $tooBig = false; |
|
321 | - if ($apps->isInstalled('user_ldap')) { |
|
322 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
323 | - |
|
324 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
325 | - ->from('ldap_user_mapping') |
|
326 | - ->execute(); |
|
327 | - $row = $result->fetch(); |
|
328 | - $result->closeCursor(); |
|
329 | - |
|
330 | - $tooBig = ($row['user_count'] > 50); |
|
331 | - } |
|
332 | - if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
333 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
334 | - |
|
335 | - $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
336 | - ->from('user_saml_users') |
|
337 | - ->execute(); |
|
338 | - $row = $result->fetch(); |
|
339 | - $result->closeCursor(); |
|
340 | - |
|
341 | - $tooBig = ($row['user_count'] > 50); |
|
342 | - } |
|
343 | - if (!$tooBig) { |
|
344 | - // count users |
|
345 | - $stats = \OC::$server->getUserManager()->countUsers(); |
|
346 | - $totalUsers = array_sum($stats); |
|
347 | - $tooBig = ($totalUsers > 50); |
|
348 | - } |
|
349 | - } |
|
350 | - $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
351 | - $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
352 | - |
|
353 | - if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
354 | - // send http status 503 |
|
355 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
356 | - header('Status: 503 Service Temporarily Unavailable'); |
|
357 | - header('Retry-After: 120'); |
|
358 | - |
|
359 | - // render error page |
|
360 | - $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
361 | - $template->assign('productName', 'nextcloud'); // for now |
|
362 | - $template->assign('version', OC_Util::getVersionString()); |
|
363 | - $template->assign('tooBig', $tooBig); |
|
364 | - |
|
365 | - $template->printPage(); |
|
366 | - die(); |
|
367 | - } |
|
368 | - |
|
369 | - // check whether this is a core update or apps update |
|
370 | - $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
371 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
372 | - |
|
373 | - // if not a core upgrade, then it's apps upgrade |
|
374 | - $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
375 | - |
|
376 | - $oldTheme = $systemConfig->getValue('theme'); |
|
377 | - $systemConfig->setValue('theme', ''); |
|
378 | - OC_Util::addScript('config'); // needed for web root |
|
379 | - OC_Util::addScript('update'); |
|
380 | - |
|
381 | - /** @var \OC\App\AppManager $appManager */ |
|
382 | - $appManager = \OC::$server->getAppManager(); |
|
383 | - |
|
384 | - $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
385 | - $tmpl->assign('version', OC_Util::getVersionString()); |
|
386 | - $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
387 | - |
|
388 | - // get third party apps |
|
389 | - $ocVersion = \OCP\Util::getVersion(); |
|
390 | - $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
391 | - $incompatibleShippedApps = []; |
|
392 | - foreach ($incompatibleApps as $appInfo) { |
|
393 | - if ($appManager->isShipped($appInfo['id'])) { |
|
394 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - $l10n = \OC::$server->getL10N('core'); |
|
399 | - if (!empty($incompatibleShippedApps)) { |
|
400 | - $hint = $l10n->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
401 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
402 | - } |
|
403 | - |
|
404 | - $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion, $l10n->getLanguageCode())); |
|
405 | - $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
406 | - $tmpl->assign('productName', 'Nextcloud'); // for now |
|
407 | - $tmpl->assign('oldTheme', $oldTheme); |
|
408 | - $tmpl->printPage(); |
|
409 | - } |
|
410 | - |
|
411 | - public static function initSession() { |
|
412 | - // prevents javascript from accessing php session cookies |
|
413 | - ini_set('session.cookie_httponly', true); |
|
414 | - |
|
415 | - // set the cookie path to the Nextcloud directory |
|
416 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
417 | - ini_set('session.cookie_path', $cookie_path); |
|
418 | - |
|
419 | - // Let the session name be changed in the initSession Hook |
|
420 | - $sessionName = OC_Util::getInstanceId(); |
|
421 | - |
|
422 | - try { |
|
423 | - // Allow session apps to create a custom session object |
|
424 | - $useCustomSession = false; |
|
425 | - $session = self::$server->getSession(); |
|
426 | - OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
427 | - if (!$useCustomSession) { |
|
428 | - // set the session name to the instance id - which is unique |
|
429 | - $session = new \OC\Session\Internal($sessionName); |
|
430 | - } |
|
431 | - |
|
432 | - $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
433 | - $session = $cryptoWrapper->wrapSession($session); |
|
434 | - self::$server->setSession($session); |
|
435 | - |
|
436 | - // if session can't be started break with http 500 error |
|
437 | - } catch (Exception $e) { |
|
438 | - \OCP\Util::logException('base', $e); |
|
439 | - //show the user a detailed error page |
|
440 | - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
441 | - OC_Template::printExceptionErrorPage($e); |
|
442 | - die(); |
|
443 | - } |
|
444 | - |
|
445 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
446 | - |
|
447 | - // session timeout |
|
448 | - if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
449 | - if (isset($_COOKIE[session_name()])) { |
|
450 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
451 | - } |
|
452 | - \OC::$server->getUserSession()->logout(); |
|
453 | - } |
|
454 | - |
|
455 | - $session->set('LAST_ACTIVITY', time()); |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - private static function getSessionLifeTime() { |
|
462 | - return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
463 | - } |
|
464 | - |
|
465 | - public static function loadAppClassPaths() { |
|
466 | - foreach (OC_App::getEnabledApps() as $app) { |
|
467 | - $appPath = OC_App::getAppPath($app); |
|
468 | - if ($appPath === false) { |
|
469 | - continue; |
|
470 | - } |
|
471 | - |
|
472 | - $file = $appPath . '/appinfo/classpath.php'; |
|
473 | - if (file_exists($file)) { |
|
474 | - require_once $file; |
|
475 | - } |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Try to set some values to the required Nextcloud default |
|
481 | - */ |
|
482 | - public static function setRequiredIniValues() { |
|
483 | - @ini_set('default_charset', 'UTF-8'); |
|
484 | - @ini_set('gd.jpeg_ignore_warning', 1); |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Send the same site cookies |
|
489 | - */ |
|
490 | - private static function sendSameSiteCookies() { |
|
491 | - $cookieParams = session_get_cookie_params(); |
|
492 | - $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
493 | - $policies = [ |
|
494 | - 'lax', |
|
495 | - 'strict', |
|
496 | - ]; |
|
497 | - |
|
498 | - // Append __Host to the cookie if it meets the requirements |
|
499 | - $cookiePrefix = ''; |
|
500 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
501 | - $cookiePrefix = '__Host-'; |
|
502 | - } |
|
503 | - |
|
504 | - foreach($policies as $policy) { |
|
505 | - header( |
|
506 | - sprintf( |
|
507 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
508 | - $cookiePrefix, |
|
509 | - $policy, |
|
510 | - $cookieParams['path'], |
|
511 | - $policy |
|
512 | - ), |
|
513 | - false |
|
514 | - ); |
|
515 | - } |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
520 | - * be set in every request if cookies are sent to add a second level of |
|
521 | - * defense against CSRF. |
|
522 | - * |
|
523 | - * If the cookie is not sent this will set the cookie and reload the page. |
|
524 | - * We use an additional cookie since we want to protect logout CSRF and |
|
525 | - * also we can't directly interfere with PHP's session mechanism. |
|
526 | - */ |
|
527 | - private static function performSameSiteCookieProtection() { |
|
528 | - $request = \OC::$server->getRequest(); |
|
529 | - |
|
530 | - // Some user agents are notorious and don't really properly follow HTTP |
|
531 | - // specifications. For those, have an automated opt-out. Since the protection |
|
532 | - // for remote.php is applied in base.php as starting point we need to opt out |
|
533 | - // here. |
|
534 | - $incompatibleUserAgents = [ |
|
535 | - // OS X Finder |
|
536 | - '/^WebDAVFS/', |
|
537 | - ]; |
|
538 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
539 | - return; |
|
540 | - } |
|
541 | - |
|
542 | - if(count($_COOKIE) > 0) { |
|
543 | - $requestUri = $request->getScriptName(); |
|
544 | - $processingScript = explode('/', $requestUri); |
|
545 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
546 | - // FIXME: In a SAML scenario we don't get any strict or lax cookie |
|
547 | - // send for the ACS endpoint. Since we have some legacy code in Nextcloud |
|
548 | - // (direct PHP files) the enforcement of lax cookies is performed here |
|
549 | - // instead of the middleware. |
|
550 | - // |
|
551 | - // This means we cannot exclude some routes from the cookie validation, |
|
552 | - // which normally is not a problem but is a little bit cumbersome for |
|
553 | - // this use-case. |
|
554 | - // Once the old legacy PHP endpoints have been removed we can move |
|
555 | - // the verification into a middleware and also adds some exemptions. |
|
556 | - // |
|
557 | - // Questions about this code? Ask Lukas ;-) |
|
558 | - $currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
559 | - if($currentUrl === '/index.php/apps/user_saml/saml/acs' || $currentUrl === '/apps/user_saml/saml/acs') { |
|
560 | - return; |
|
561 | - } |
|
562 | - // For the "index.php" endpoint only a lax cookie is required. |
|
563 | - if($processingScript === 'index.php') { |
|
564 | - if(!$request->passesLaxCookieCheck()) { |
|
565 | - self::sendSameSiteCookies(); |
|
566 | - header('Location: '.$_SERVER['REQUEST_URI']); |
|
567 | - exit(); |
|
568 | - } |
|
569 | - } else { |
|
570 | - // All other endpoints require the lax and the strict cookie |
|
571 | - if(!$request->passesStrictCookieCheck()) { |
|
572 | - self::sendSameSiteCookies(); |
|
573 | - // Debug mode gets access to the resources without strict cookie |
|
574 | - // due to the fact that the SabreDAV browser also lives there. |
|
575 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
576 | - http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
577 | - exit(); |
|
578 | - } |
|
579 | - } |
|
580 | - } |
|
581 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
582 | - self::sendSameSiteCookies(); |
|
583 | - } |
|
584 | - } |
|
585 | - |
|
586 | - public static function init() { |
|
587 | - // calculate the root directories |
|
588 | - OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
589 | - |
|
590 | - // register autoloader |
|
591 | - $loaderStart = microtime(true); |
|
592 | - require_once __DIR__ . '/autoloader.php'; |
|
593 | - self::$loader = new \OC\Autoloader([ |
|
594 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
595 | - ]); |
|
596 | - if (defined('PHPUNIT_RUN')) { |
|
597 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
598 | - } |
|
599 | - spl_autoload_register(array(self::$loader, 'load')); |
|
600 | - $loaderEnd = microtime(true); |
|
601 | - |
|
602 | - self::$CLI = (php_sapi_name() == 'cli'); |
|
603 | - |
|
604 | - // Add default composer PSR-4 autoloader |
|
605 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
606 | - |
|
607 | - try { |
|
608 | - self::initPaths(); |
|
609 | - // setup 3rdparty autoloader |
|
610 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
611 | - if (!file_exists($vendorAutoLoad)) { |
|
612 | - throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
613 | - } |
|
614 | - require_once $vendorAutoLoad; |
|
615 | - |
|
616 | - } catch (\RuntimeException $e) { |
|
617 | - if (!self::$CLI) { |
|
618 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
619 | - $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
620 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
621 | - } |
|
622 | - // we can't use the template error page here, because this needs the |
|
623 | - // DI container which isn't available yet |
|
624 | - print($e->getMessage()); |
|
625 | - exit(); |
|
626 | - } |
|
627 | - |
|
628 | - // setup the basic server |
|
629 | - self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
630 | - \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
631 | - \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
632 | - |
|
633 | - // Don't display errors and log them |
|
634 | - error_reporting(E_ALL | E_STRICT); |
|
635 | - @ini_set('display_errors', 0); |
|
636 | - @ini_set('log_errors', 1); |
|
637 | - |
|
638 | - if(!date_default_timezone_set('UTC')) { |
|
639 | - throw new \RuntimeException('Could not set timezone to UTC'); |
|
640 | - }; |
|
641 | - |
|
642 | - //try to configure php to enable big file uploads. |
|
643 | - //this doesn´t work always depending on the webserver and php configuration. |
|
644 | - //Let´s try to overwrite some defaults anyway |
|
645 | - |
|
646 | - //try to set the maximum execution time to 60min |
|
647 | - if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
648 | - @set_time_limit(3600); |
|
649 | - } |
|
650 | - @ini_set('max_execution_time', 3600); |
|
651 | - @ini_set('max_input_time', 3600); |
|
652 | - |
|
653 | - //try to set the maximum filesize to 10G |
|
654 | - @ini_set('upload_max_filesize', '10G'); |
|
655 | - @ini_set('post_max_size', '10G'); |
|
656 | - @ini_set('file_uploads', '50'); |
|
657 | - |
|
658 | - self::setRequiredIniValues(); |
|
659 | - self::handleAuthHeaders(); |
|
660 | - self::registerAutoloaderCache(); |
|
661 | - |
|
662 | - // initialize intl fallback is necessary |
|
663 | - \Patchwork\Utf8\Bootup::initIntl(); |
|
664 | - OC_Util::isSetLocaleWorking(); |
|
665 | - |
|
666 | - if (!defined('PHPUNIT_RUN')) { |
|
667 | - OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
668 | - $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
669 | - OC\Log\ErrorHandler::register($debug); |
|
670 | - } |
|
671 | - |
|
672 | - \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
673 | - OC_App::loadApps(array('session')); |
|
674 | - if (!self::$CLI) { |
|
675 | - self::initSession(); |
|
676 | - } |
|
677 | - \OC::$server->getEventLogger()->end('init_session'); |
|
678 | - self::checkConfig(); |
|
679 | - self::checkInstalled(); |
|
680 | - |
|
681 | - OC_Response::addSecurityHeaders(); |
|
682 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
683 | - ini_set('session.cookie_secure', true); |
|
684 | - } |
|
685 | - |
|
686 | - self::performSameSiteCookieProtection(); |
|
687 | - |
|
688 | - if (!defined('OC_CONSOLE')) { |
|
689 | - $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
690 | - if (count($errors) > 0) { |
|
691 | - if (self::$CLI) { |
|
692 | - // Convert l10n string into regular string for usage in database |
|
693 | - $staticErrors = []; |
|
694 | - foreach ($errors as $error) { |
|
695 | - echo $error['error'] . "\n"; |
|
696 | - echo $error['hint'] . "\n\n"; |
|
697 | - $staticErrors[] = [ |
|
698 | - 'error' => (string)$error['error'], |
|
699 | - 'hint' => (string)$error['hint'], |
|
700 | - ]; |
|
701 | - } |
|
702 | - |
|
703 | - try { |
|
704 | - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
705 | - } catch (\Exception $e) { |
|
706 | - echo('Writing to database failed'); |
|
707 | - } |
|
708 | - exit(1); |
|
709 | - } else { |
|
710 | - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
711 | - OC_Util::addStyle('guest'); |
|
712 | - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
713 | - exit; |
|
714 | - } |
|
715 | - } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
716 | - \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
717 | - } |
|
718 | - } |
|
719 | - //try to set the session lifetime |
|
720 | - $sessionLifeTime = self::getSessionLifeTime(); |
|
721 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
722 | - |
|
723 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
724 | - |
|
725 | - // User and Groups |
|
726 | - if (!$systemConfig->getValue("installed", false)) { |
|
727 | - self::$server->getSession()->set('user_id', ''); |
|
728 | - } |
|
729 | - |
|
730 | - OC_User::useBackend(new \OC\User\Database()); |
|
731 | - \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
732 | - |
|
733 | - // Subscribe to the hook |
|
734 | - \OCP\Util::connectHook( |
|
735 | - '\OCA\Files_Sharing\API\Server2Server', |
|
736 | - 'preLoginNameUsedAsUserName', |
|
737 | - '\OC\User\Database', |
|
738 | - 'preLoginNameUsedAsUserName' |
|
739 | - ); |
|
740 | - |
|
741 | - //setup extra user backends |
|
742 | - if (!self::checkUpgrade(false)) { |
|
743 | - OC_User::setupBackends(); |
|
744 | - } else { |
|
745 | - // Run upgrades in incognito mode |
|
746 | - OC_User::setIncognitoMode(true); |
|
747 | - } |
|
748 | - |
|
749 | - self::registerCacheHooks(); |
|
750 | - self::registerFilesystemHooks(); |
|
751 | - self::registerShareHooks(); |
|
752 | - self::registerLogRotate(); |
|
753 | - self::registerEncryptionWrapper(); |
|
754 | - self::registerEncryptionHooks(); |
|
755 | - self::registerAccountHooks(); |
|
756 | - self::registerSettingsHooks(); |
|
757 | - |
|
758 | - $settings = new \OC\Settings\Application(); |
|
759 | - $settings->register(); |
|
760 | - |
|
761 | - //make sure temporary files are cleaned up |
|
762 | - $tmpManager = \OC::$server->getTempManager(); |
|
763 | - register_shutdown_function(array($tmpManager, 'clean')); |
|
764 | - $lockProvider = \OC::$server->getLockingProvider(); |
|
765 | - register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
766 | - |
|
767 | - // Check whether the sample configuration has been copied |
|
768 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
769 | - $l = \OC::$server->getL10N('lib'); |
|
770 | - header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
771 | - header('Status: 503 Service Temporarily Unavailable'); |
|
772 | - OC_Template::printErrorPage( |
|
773 | - $l->t('Sample configuration detected'), |
|
774 | - $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
775 | - ); |
|
776 | - return; |
|
777 | - } |
|
778 | - |
|
779 | - $request = \OC::$server->getRequest(); |
|
780 | - $host = $request->getInsecureServerHost(); |
|
781 | - /** |
|
782 | - * if the host passed in headers isn't trusted |
|
783 | - * FIXME: Should not be in here at all :see_no_evil: |
|
784 | - */ |
|
785 | - if (!OC::$CLI |
|
786 | - // overwritehost is always trusted, workaround to not have to make |
|
787 | - // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
788 | - && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
789 | - && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
790 | - && self::$server->getConfig()->getSystemValue('installed', false) |
|
791 | - ) { |
|
792 | - // Allow access to CSS resources |
|
793 | - $isScssRequest = false; |
|
794 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
795 | - $isScssRequest = true; |
|
796 | - } |
|
797 | - |
|
798 | - if (!$isScssRequest) { |
|
799 | - header('HTTP/1.1 400 Bad Request'); |
|
800 | - header('Status: 400 Bad Request'); |
|
801 | - |
|
802 | - \OC::$server->getLogger()->warning( |
|
803 | - 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
804 | - [ |
|
805 | - 'app' => 'core', |
|
806 | - 'remoteAddress' => $request->getRemoteAddress(), |
|
807 | - 'host' => $host, |
|
808 | - ] |
|
809 | - ); |
|
810 | - |
|
811 | - $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
812 | - $tmpl->assign('domain', $host); |
|
813 | - $tmpl->printPage(); |
|
814 | - |
|
815 | - exit(); |
|
816 | - } |
|
817 | - } |
|
818 | - \OC::$server->getEventLogger()->end('boot'); |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * register hooks for the cache |
|
823 | - */ |
|
824 | - public static function registerCacheHooks() { |
|
825 | - //don't try to do this before we are properly setup |
|
826 | - if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) { |
|
827 | - |
|
828 | - // NOTE: This will be replaced to use OCP |
|
829 | - $userSession = self::$server->getUserSession(); |
|
830 | - $userSession->listen('\OC\User', 'postLogin', function () { |
|
831 | - try { |
|
832 | - $cache = new \OC\Cache\File(); |
|
833 | - $cache->gc(); |
|
834 | - } catch (\OC\ServerNotAvailableException $e) { |
|
835 | - // not a GC exception, pass it on |
|
836 | - throw $e; |
|
837 | - } catch (\OC\ForbiddenException $e) { |
|
838 | - // filesystem blocked for this request, ignore |
|
839 | - } catch (\Exception $e) { |
|
840 | - // a GC exception should not prevent users from using OC, |
|
841 | - // so log the exception |
|
842 | - \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
843 | - } |
|
844 | - }); |
|
845 | - } |
|
846 | - } |
|
847 | - |
|
848 | - public static function registerSettingsHooks() { |
|
849 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
850 | - $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) { |
|
851 | - /** @var \OCP\App\ManagerEvent $event */ |
|
852 | - \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID()); |
|
853 | - }); |
|
854 | - $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_UPDATE, function($event) { |
|
855 | - /** @var \OCP\App\ManagerEvent $event */ |
|
856 | - $jobList = \OC::$server->getJobList(); |
|
857 | - $job = 'OC\\Settings\\RemoveOrphaned'; |
|
858 | - if(!($jobList->has($job, null))) { |
|
859 | - $jobList->add($job); |
|
860 | - } |
|
861 | - }); |
|
862 | - } |
|
863 | - |
|
864 | - private static function registerEncryptionWrapper() { |
|
865 | - $manager = self::$server->getEncryptionManager(); |
|
866 | - \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
867 | - } |
|
868 | - |
|
869 | - private static function registerEncryptionHooks() { |
|
870 | - $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
871 | - if ($enabled) { |
|
872 | - \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
873 | - \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
874 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
875 | - \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
876 | - } |
|
877 | - } |
|
878 | - |
|
879 | - private static function registerAccountHooks() { |
|
880 | - $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
881 | - \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * register hooks for the cache |
|
886 | - */ |
|
887 | - public static function registerLogRotate() { |
|
888 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
889 | - if ($systemConfig->getValue('installed', false) && $systemConfig->getValue('log_rotate_size', false) && !self::checkUpgrade(false)) { |
|
890 | - //don't try to do this before we are properly setup |
|
891 | - //use custom logfile path if defined, otherwise use default of nextcloud.log in data directory |
|
892 | - \OC::$server->getJobList()->add('OC\Log\Rotate'); |
|
893 | - } |
|
894 | - } |
|
895 | - |
|
896 | - /** |
|
897 | - * register hooks for the filesystem |
|
898 | - */ |
|
899 | - public static function registerFilesystemHooks() { |
|
900 | - // Check for blacklisted files |
|
901 | - OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
902 | - OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
903 | - } |
|
904 | - |
|
905 | - /** |
|
906 | - * register hooks for sharing |
|
907 | - */ |
|
908 | - public static function registerShareHooks() { |
|
909 | - if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
910 | - OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
911 | - OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
912 | - OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
913 | - } |
|
914 | - } |
|
915 | - |
|
916 | - protected static function registerAutoloaderCache() { |
|
917 | - // The class loader takes an optional low-latency cache, which MUST be |
|
918 | - // namespaced. The instanceid is used for namespacing, but might be |
|
919 | - // unavailable at this point. Furthermore, it might not be possible to |
|
920 | - // generate an instanceid via \OC_Util::getInstanceId() because the |
|
921 | - // config file may not be writable. As such, we only register a class |
|
922 | - // loader cache if instanceid is available without trying to create one. |
|
923 | - $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
924 | - if ($instanceId) { |
|
925 | - try { |
|
926 | - $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
927 | - self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
928 | - } catch (\Exception $ex) { |
|
929 | - } |
|
930 | - } |
|
931 | - } |
|
932 | - |
|
933 | - /** |
|
934 | - * Handle the request |
|
935 | - */ |
|
936 | - public static function handleRequest() { |
|
937 | - |
|
938 | - \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
939 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
940 | - // load all the classpaths from the enabled apps so they are available |
|
941 | - // in the routing files of each app |
|
942 | - OC::loadAppClassPaths(); |
|
943 | - |
|
944 | - // Check if Nextcloud is installed or in maintenance (update) mode |
|
945 | - if (!$systemConfig->getValue('installed', false)) { |
|
946 | - \OC::$server->getSession()->clear(); |
|
947 | - $setupHelper = new OC\Setup(\OC::$server->getSystemConfig(), \OC::$server->getIniWrapper(), |
|
948 | - \OC::$server->getL10N('lib'), \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), |
|
949 | - \OC::$server->getSecureRandom()); |
|
950 | - $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
951 | - $controller->run($_POST); |
|
952 | - exit(); |
|
953 | - } |
|
954 | - |
|
955 | - $request = \OC::$server->getRequest(); |
|
956 | - $requestPath = $request->getRawPathInfo(); |
|
957 | - if ($requestPath === '/heartbeat') { |
|
958 | - return; |
|
959 | - } |
|
960 | - if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
961 | - self::checkMaintenanceMode(); |
|
962 | - self::checkUpgrade(); |
|
963 | - } |
|
964 | - |
|
965 | - // emergency app disabling |
|
966 | - if ($requestPath === '/disableapp' |
|
967 | - && $request->getMethod() === 'POST' |
|
968 | - && ((array)$request->getParam('appid')) !== '' |
|
969 | - ) { |
|
970 | - \OCP\JSON::callCheck(); |
|
971 | - \OCP\JSON::checkAdminUser(); |
|
972 | - $appIds = (array)$request->getParam('appid'); |
|
973 | - foreach($appIds as $appId) { |
|
974 | - $appId = \OC_App::cleanAppId($appId); |
|
975 | - \OC_App::disable($appId); |
|
976 | - } |
|
977 | - \OC_JSON::success(); |
|
978 | - exit(); |
|
979 | - } |
|
980 | - |
|
981 | - // Always load authentication apps |
|
982 | - OC_App::loadApps(['authentication']); |
|
983 | - |
|
984 | - // Load minimum set of apps |
|
985 | - if (!self::checkUpgrade(false) |
|
986 | - && !$systemConfig->getValue('maintenance', false)) { |
|
987 | - // For logged-in users: Load everything |
|
988 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
989 | - OC_App::loadApps(); |
|
990 | - } else { |
|
991 | - // For guests: Load only filesystem and logging |
|
992 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
993 | - self::handleLogin($request); |
|
994 | - } |
|
995 | - } |
|
996 | - |
|
997 | - if (!self::$CLI) { |
|
998 | - try { |
|
999 | - if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) { |
|
1000 | - OC_App::loadApps(array('filesystem', 'logging')); |
|
1001 | - OC_App::loadApps(); |
|
1002 | - } |
|
1003 | - OC_Util::setupFS(); |
|
1004 | - OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
1005 | - return; |
|
1006 | - } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
1007 | - //header('HTTP/1.0 404 Not Found'); |
|
1008 | - } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
1009 | - OC_Response::setStatus(405); |
|
1010 | - return; |
|
1011 | - } |
|
1012 | - } |
|
1013 | - |
|
1014 | - // Handle WebDAV |
|
1015 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
1016 | - // not allowed any more to prevent people |
|
1017 | - // mounting this root directly. |
|
1018 | - // Users need to mount remote.php/webdav instead. |
|
1019 | - header('HTTP/1.1 405 Method Not Allowed'); |
|
1020 | - header('Status: 405 Method Not Allowed'); |
|
1021 | - return; |
|
1022 | - } |
|
1023 | - |
|
1024 | - // Someone is logged in |
|
1025 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1026 | - OC_App::loadApps(); |
|
1027 | - OC_User::setupBackends(); |
|
1028 | - OC_Util::setupFS(); |
|
1029 | - // FIXME |
|
1030 | - // Redirect to default application |
|
1031 | - OC_Util::redirectToDefaultPage(); |
|
1032 | - } else { |
|
1033 | - // Not handled and not logged in |
|
1034 | - header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1035 | - } |
|
1036 | - } |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * Check login: apache auth, auth token, basic auth |
|
1040 | - * |
|
1041 | - * @param OCP\IRequest $request |
|
1042 | - * @return boolean |
|
1043 | - */ |
|
1044 | - static function handleLogin(OCP\IRequest $request) { |
|
1045 | - $userSession = self::$server->getUserSession(); |
|
1046 | - if (OC_User::handleApacheAuth()) { |
|
1047 | - return true; |
|
1048 | - } |
|
1049 | - if ($userSession->tryTokenLogin($request)) { |
|
1050 | - return true; |
|
1051 | - } |
|
1052 | - if (isset($_COOKIE['nc_username']) |
|
1053 | - && isset($_COOKIE['nc_token']) |
|
1054 | - && isset($_COOKIE['nc_session_id']) |
|
1055 | - && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1056 | - return true; |
|
1057 | - } |
|
1058 | - if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1059 | - return true; |
|
1060 | - } |
|
1061 | - return false; |
|
1062 | - } |
|
1063 | - |
|
1064 | - protected static function handleAuthHeaders() { |
|
1065 | - //copy http auth headers for apache+php-fcgid work around |
|
1066 | - if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1067 | - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1068 | - } |
|
1069 | - |
|
1070 | - // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1071 | - $vars = array( |
|
1072 | - 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1073 | - 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1074 | - ); |
|
1075 | - foreach ($vars as $var) { |
|
1076 | - if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1077 | - list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1078 | - $_SERVER['PHP_AUTH_USER'] = $name; |
|
1079 | - $_SERVER['PHP_AUTH_PW'] = $password; |
|
1080 | - break; |
|
1081 | - } |
|
1082 | - } |
|
1083 | - } |
|
62 | + /** |
|
63 | + * Associative array for autoloading. classname => filename |
|
64 | + */ |
|
65 | + public static $CLASSPATH = array(); |
|
66 | + /** |
|
67 | + * The installation path for Nextcloud on the server (e.g. /srv/http/nextcloud) |
|
68 | + */ |
|
69 | + public static $SERVERROOT = ''; |
|
70 | + /** |
|
71 | + * the current request path relative to the Nextcloud root (e.g. files/index.php) |
|
72 | + */ |
|
73 | + private static $SUBURI = ''; |
|
74 | + /** |
|
75 | + * the Nextcloud root path for http requests (e.g. nextcloud/) |
|
76 | + */ |
|
77 | + public static $WEBROOT = ''; |
|
78 | + /** |
|
79 | + * The installation path array of the apps folder on the server (e.g. /srv/http/nextcloud) 'path' and |
|
80 | + * web path in 'url' |
|
81 | + */ |
|
82 | + public static $APPSROOTS = array(); |
|
83 | + |
|
84 | + /** |
|
85 | + * @var string |
|
86 | + */ |
|
87 | + public static $configDir; |
|
88 | + |
|
89 | + /** |
|
90 | + * requested app |
|
91 | + */ |
|
92 | + public static $REQUESTEDAPP = ''; |
|
93 | + |
|
94 | + /** |
|
95 | + * check if Nextcloud runs in cli mode |
|
96 | + */ |
|
97 | + public static $CLI = false; |
|
98 | + |
|
99 | + /** |
|
100 | + * @var \OC\Autoloader $loader |
|
101 | + */ |
|
102 | + public static $loader = null; |
|
103 | + |
|
104 | + /** @var \Composer\Autoload\ClassLoader $composerAutoloader */ |
|
105 | + public static $composerAutoloader = null; |
|
106 | + |
|
107 | + /** |
|
108 | + * @var \OC\Server |
|
109 | + */ |
|
110 | + public static $server = null; |
|
111 | + |
|
112 | + /** |
|
113 | + * @var \OC\Config |
|
114 | + */ |
|
115 | + private static $config = null; |
|
116 | + |
|
117 | + /** |
|
118 | + * @throws \RuntimeException when the 3rdparty directory is missing or |
|
119 | + * the app path list is empty or contains an invalid path |
|
120 | + */ |
|
121 | + public static function initPaths() { |
|
122 | + if(defined('PHPUNIT_CONFIG_DIR')) { |
|
123 | + self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
124 | + } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
125 | + self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
126 | + } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
127 | + self::$configDir = rtrim($dir, '/') . '/'; |
|
128 | + } else { |
|
129 | + self::$configDir = OC::$SERVERROOT . '/config/'; |
|
130 | + } |
|
131 | + self::$config = new \OC\Config(self::$configDir); |
|
132 | + |
|
133 | + OC::$SUBURI = str_replace("\\", "/", substr(realpath($_SERVER["SCRIPT_FILENAME"]), strlen(OC::$SERVERROOT))); |
|
134 | + /** |
|
135 | + * FIXME: The following lines are required because we can't yet instantiate |
|
136 | + * \OC::$server->getRequest() since \OC::$server does not yet exist. |
|
137 | + */ |
|
138 | + $params = [ |
|
139 | + 'server' => [ |
|
140 | + 'SCRIPT_NAME' => $_SERVER['SCRIPT_NAME'], |
|
141 | + 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], |
|
142 | + ], |
|
143 | + ]; |
|
144 | + $fakeRequest = new \OC\AppFramework\Http\Request($params, null, new \OC\AllConfig(new \OC\SystemConfig(self::$config))); |
|
145 | + $scriptName = $fakeRequest->getScriptName(); |
|
146 | + if (substr($scriptName, -1) == '/') { |
|
147 | + $scriptName .= 'index.php'; |
|
148 | + //make sure suburi follows the same rules as scriptName |
|
149 | + if (substr(OC::$SUBURI, -9) != 'index.php') { |
|
150 | + if (substr(OC::$SUBURI, -1) != '/') { |
|
151 | + OC::$SUBURI = OC::$SUBURI . '/'; |
|
152 | + } |
|
153 | + OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + if (OC::$CLI) { |
|
159 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
160 | + } else { |
|
161 | + if (substr($scriptName, 0 - strlen(OC::$SUBURI)) === OC::$SUBURI) { |
|
162 | + OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
|
163 | + |
|
164 | + if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
|
165 | + OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
166 | + } |
|
167 | + } else { |
|
168 | + // The scriptName is not ending with OC::$SUBURI |
|
169 | + // This most likely means that we are calling from CLI. |
|
170 | + // However some cron jobs still need to generate |
|
171 | + // a web URL, so we use overwritewebroot as a fallback. |
|
172 | + OC::$WEBROOT = self::$config->getValue('overwritewebroot', ''); |
|
173 | + } |
|
174 | + |
|
175 | + // Resolve /nextcloud to /nextcloud/ to ensure to always have a trailing |
|
176 | + // slash which is required by URL generation. |
|
177 | + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] === \OC::$WEBROOT && |
|
178 | + substr($_SERVER['REQUEST_URI'], -1) !== '/') { |
|
179 | + header('Location: '.\OC::$WEBROOT.'/'); |
|
180 | + exit(); |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + // search the apps folder |
|
185 | + $config_paths = self::$config->getValue('apps_paths', array()); |
|
186 | + if (!empty($config_paths)) { |
|
187 | + foreach ($config_paths as $paths) { |
|
188 | + if (isset($paths['url']) && isset($paths['path'])) { |
|
189 | + $paths['url'] = rtrim($paths['url'], '/'); |
|
190 | + $paths['path'] = rtrim($paths['path'], '/'); |
|
191 | + OC::$APPSROOTS[] = $paths; |
|
192 | + } |
|
193 | + } |
|
194 | + } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
195 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
196 | + } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
197 | + OC::$APPSROOTS[] = array( |
|
198 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
199 | + 'url' => '/apps', |
|
200 | + 'writable' => true |
|
201 | + ); |
|
202 | + } |
|
203 | + |
|
204 | + if (empty(OC::$APPSROOTS)) { |
|
205 | + throw new \RuntimeException('apps directory not found! Please put the Nextcloud apps folder in the Nextcloud folder' |
|
206 | + . ' or the folder above. You can also configure the location in the config.php file.'); |
|
207 | + } |
|
208 | + $paths = array(); |
|
209 | + foreach (OC::$APPSROOTS as $path) { |
|
210 | + $paths[] = $path['path']; |
|
211 | + if (!is_dir($path['path'])) { |
|
212 | + throw new \RuntimeException(sprintf('App directory "%s" not found! Please put the Nextcloud apps folder in the' |
|
213 | + . ' Nextcloud folder or the folder above. You can also configure the location in the' |
|
214 | + . ' config.php file.', $path['path'])); |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + // set the right include path |
|
219 | + set_include_path( |
|
220 | + implode(PATH_SEPARATOR, $paths) |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + public static function checkConfig() { |
|
225 | + $l = \OC::$server->getL10N('lib'); |
|
226 | + |
|
227 | + // Create config if it does not already exist |
|
228 | + $configFilePath = self::$configDir .'/config.php'; |
|
229 | + if(!file_exists($configFilePath)) { |
|
230 | + @touch($configFilePath); |
|
231 | + } |
|
232 | + |
|
233 | + // Check if config is writable |
|
234 | + $configFileWritable = is_writable($configFilePath); |
|
235 | + if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() |
|
236 | + || !$configFileWritable && self::checkUpgrade(false)) { |
|
237 | + |
|
238 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
239 | + |
|
240 | + if (self::$CLI) { |
|
241 | + echo $l->t('Cannot write into "config" directory!')."\n"; |
|
242 | + echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
|
243 | + echo "\n"; |
|
244 | + echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
245 | + exit; |
|
246 | + } else { |
|
247 | + OC_Template::printErrorPage( |
|
248 | + $l->t('Cannot write into "config" directory!'), |
|
249 | + $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
|
250 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
251 | + ); |
|
252 | + } |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + public static function checkInstalled() { |
|
257 | + if (defined('OC_CONSOLE')) { |
|
258 | + return; |
|
259 | + } |
|
260 | + // Redirect to installer if not installed |
|
261 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false) && OC::$SUBURI !== '/index.php' && OC::$SUBURI !== '/status.php') { |
|
262 | + if (OC::$CLI) { |
|
263 | + throw new Exception('Not installed'); |
|
264 | + } else { |
|
265 | + $url = OC::$WEBROOT . '/index.php'; |
|
266 | + header('Location: ' . $url); |
|
267 | + } |
|
268 | + exit(); |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + public static function checkMaintenanceMode() { |
|
273 | + // Allow ajax update script to execute without being stopped |
|
274 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { |
|
275 | + // send http status 503 |
|
276 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
277 | + header('Status: 503 Service Temporarily Unavailable'); |
|
278 | + header('Retry-After: 120'); |
|
279 | + |
|
280 | + // render error page |
|
281 | + $template = new OC_Template('', 'update.user', 'guest'); |
|
282 | + OC_Util::addScript('maintenance-check'); |
|
283 | + OC_Util::addStyle('core', 'guest'); |
|
284 | + $template->printPage(); |
|
285 | + die(); |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Checks if the version requires an update and shows |
|
291 | + * @param bool $showTemplate Whether an update screen should get shown |
|
292 | + * @return bool|void |
|
293 | + */ |
|
294 | + public static function checkUpgrade($showTemplate = true) { |
|
295 | + if (\OCP\Util::needUpgrade()) { |
|
296 | + if (function_exists('opcache_reset')) { |
|
297 | + opcache_reset(); |
|
298 | + } |
|
299 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
300 | + if ($showTemplate && !$systemConfig->getValue('maintenance', false)) { |
|
301 | + self::printUpgradePage(); |
|
302 | + exit(); |
|
303 | + } else { |
|
304 | + return true; |
|
305 | + } |
|
306 | + } |
|
307 | + return false; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Prints the upgrade page |
|
312 | + */ |
|
313 | + private static function printUpgradePage() { |
|
314 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
315 | + |
|
316 | + $disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false); |
|
317 | + $tooBig = false; |
|
318 | + if (!$disableWebUpdater) { |
|
319 | + $apps = \OC::$server->getAppManager(); |
|
320 | + $tooBig = false; |
|
321 | + if ($apps->isInstalled('user_ldap')) { |
|
322 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
323 | + |
|
324 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
325 | + ->from('ldap_user_mapping') |
|
326 | + ->execute(); |
|
327 | + $row = $result->fetch(); |
|
328 | + $result->closeCursor(); |
|
329 | + |
|
330 | + $tooBig = ($row['user_count'] > 50); |
|
331 | + } |
|
332 | + if (!$tooBig && $apps->isInstalled('user_saml')) { |
|
333 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
334 | + |
|
335 | + $result = $qb->selectAlias($qb->createFunction('COUNT(*)'), 'user_count') |
|
336 | + ->from('user_saml_users') |
|
337 | + ->execute(); |
|
338 | + $row = $result->fetch(); |
|
339 | + $result->closeCursor(); |
|
340 | + |
|
341 | + $tooBig = ($row['user_count'] > 50); |
|
342 | + } |
|
343 | + if (!$tooBig) { |
|
344 | + // count users |
|
345 | + $stats = \OC::$server->getUserManager()->countUsers(); |
|
346 | + $totalUsers = array_sum($stats); |
|
347 | + $tooBig = ($totalUsers > 50); |
|
348 | + } |
|
349 | + } |
|
350 | + $ignoreTooBigWarning = isset($_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup']) && |
|
351 | + $_GET['IKnowThatThisIsABigInstanceAndTheUpdateRequestCouldRunIntoATimeoutAndHowToRestoreABackup'] === 'IAmSuperSureToDoThis'; |
|
352 | + |
|
353 | + if ($disableWebUpdater || ($tooBig && !$ignoreTooBigWarning)) { |
|
354 | + // send http status 503 |
|
355 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
356 | + header('Status: 503 Service Temporarily Unavailable'); |
|
357 | + header('Retry-After: 120'); |
|
358 | + |
|
359 | + // render error page |
|
360 | + $template = new OC_Template('', 'update.use-cli', 'guest'); |
|
361 | + $template->assign('productName', 'nextcloud'); // for now |
|
362 | + $template->assign('version', OC_Util::getVersionString()); |
|
363 | + $template->assign('tooBig', $tooBig); |
|
364 | + |
|
365 | + $template->printPage(); |
|
366 | + die(); |
|
367 | + } |
|
368 | + |
|
369 | + // check whether this is a core update or apps update |
|
370 | + $installedVersion = $systemConfig->getValue('version', '0.0.0'); |
|
371 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
372 | + |
|
373 | + // if not a core upgrade, then it's apps upgrade |
|
374 | + $isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '=')); |
|
375 | + |
|
376 | + $oldTheme = $systemConfig->getValue('theme'); |
|
377 | + $systemConfig->setValue('theme', ''); |
|
378 | + OC_Util::addScript('config'); // needed for web root |
|
379 | + OC_Util::addScript('update'); |
|
380 | + |
|
381 | + /** @var \OC\App\AppManager $appManager */ |
|
382 | + $appManager = \OC::$server->getAppManager(); |
|
383 | + |
|
384 | + $tmpl = new OC_Template('', 'update.admin', 'guest'); |
|
385 | + $tmpl->assign('version', OC_Util::getVersionString()); |
|
386 | + $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); |
|
387 | + |
|
388 | + // get third party apps |
|
389 | + $ocVersion = \OCP\Util::getVersion(); |
|
390 | + $incompatibleApps = $appManager->getIncompatibleApps($ocVersion); |
|
391 | + $incompatibleShippedApps = []; |
|
392 | + foreach ($incompatibleApps as $appInfo) { |
|
393 | + if ($appManager->isShipped($appInfo['id'])) { |
|
394 | + $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + $l10n = \OC::$server->getL10N('core'); |
|
399 | + if (!empty($incompatibleShippedApps)) { |
|
400 | + $hint = $l10n->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
|
401 | + throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
402 | + } |
|
403 | + |
|
404 | + $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion, $l10n->getLanguageCode())); |
|
405 | + $tmpl->assign('incompatibleAppsList', $incompatibleApps); |
|
406 | + $tmpl->assign('productName', 'Nextcloud'); // for now |
|
407 | + $tmpl->assign('oldTheme', $oldTheme); |
|
408 | + $tmpl->printPage(); |
|
409 | + } |
|
410 | + |
|
411 | + public static function initSession() { |
|
412 | + // prevents javascript from accessing php session cookies |
|
413 | + ini_set('session.cookie_httponly', true); |
|
414 | + |
|
415 | + // set the cookie path to the Nextcloud directory |
|
416 | + $cookie_path = OC::$WEBROOT ? : '/'; |
|
417 | + ini_set('session.cookie_path', $cookie_path); |
|
418 | + |
|
419 | + // Let the session name be changed in the initSession Hook |
|
420 | + $sessionName = OC_Util::getInstanceId(); |
|
421 | + |
|
422 | + try { |
|
423 | + // Allow session apps to create a custom session object |
|
424 | + $useCustomSession = false; |
|
425 | + $session = self::$server->getSession(); |
|
426 | + OC_Hook::emit('OC', 'initSession', array('session' => &$session, 'sessionName' => &$sessionName, 'useCustomSession' => &$useCustomSession)); |
|
427 | + if (!$useCustomSession) { |
|
428 | + // set the session name to the instance id - which is unique |
|
429 | + $session = new \OC\Session\Internal($sessionName); |
|
430 | + } |
|
431 | + |
|
432 | + $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); |
|
433 | + $session = $cryptoWrapper->wrapSession($session); |
|
434 | + self::$server->setSession($session); |
|
435 | + |
|
436 | + // if session can't be started break with http 500 error |
|
437 | + } catch (Exception $e) { |
|
438 | + \OCP\Util::logException('base', $e); |
|
439 | + //show the user a detailed error page |
|
440 | + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
441 | + OC_Template::printExceptionErrorPage($e); |
|
442 | + die(); |
|
443 | + } |
|
444 | + |
|
445 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
446 | + |
|
447 | + // session timeout |
|
448 | + if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
|
449 | + if (isset($_COOKIE[session_name()])) { |
|
450 | + setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
451 | + } |
|
452 | + \OC::$server->getUserSession()->logout(); |
|
453 | + } |
|
454 | + |
|
455 | + $session->set('LAST_ACTIVITY', time()); |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + private static function getSessionLifeTime() { |
|
462 | + return \OC::$server->getConfig()->getSystemValue('session_lifetime', 60 * 60 * 24); |
|
463 | + } |
|
464 | + |
|
465 | + public static function loadAppClassPaths() { |
|
466 | + foreach (OC_App::getEnabledApps() as $app) { |
|
467 | + $appPath = OC_App::getAppPath($app); |
|
468 | + if ($appPath === false) { |
|
469 | + continue; |
|
470 | + } |
|
471 | + |
|
472 | + $file = $appPath . '/appinfo/classpath.php'; |
|
473 | + if (file_exists($file)) { |
|
474 | + require_once $file; |
|
475 | + } |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Try to set some values to the required Nextcloud default |
|
481 | + */ |
|
482 | + public static function setRequiredIniValues() { |
|
483 | + @ini_set('default_charset', 'UTF-8'); |
|
484 | + @ini_set('gd.jpeg_ignore_warning', 1); |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Send the same site cookies |
|
489 | + */ |
|
490 | + private static function sendSameSiteCookies() { |
|
491 | + $cookieParams = session_get_cookie_params(); |
|
492 | + $secureCookie = ($cookieParams['secure'] === true) ? 'secure; ' : ''; |
|
493 | + $policies = [ |
|
494 | + 'lax', |
|
495 | + 'strict', |
|
496 | + ]; |
|
497 | + |
|
498 | + // Append __Host to the cookie if it meets the requirements |
|
499 | + $cookiePrefix = ''; |
|
500 | + if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
501 | + $cookiePrefix = '__Host-'; |
|
502 | + } |
|
503 | + |
|
504 | + foreach($policies as $policy) { |
|
505 | + header( |
|
506 | + sprintf( |
|
507 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
508 | + $cookiePrefix, |
|
509 | + $policy, |
|
510 | + $cookieParams['path'], |
|
511 | + $policy |
|
512 | + ), |
|
513 | + false |
|
514 | + ); |
|
515 | + } |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * Same Site cookie to further mitigate CSRF attacks. This cookie has to |
|
520 | + * be set in every request if cookies are sent to add a second level of |
|
521 | + * defense against CSRF. |
|
522 | + * |
|
523 | + * If the cookie is not sent this will set the cookie and reload the page. |
|
524 | + * We use an additional cookie since we want to protect logout CSRF and |
|
525 | + * also we can't directly interfere with PHP's session mechanism. |
|
526 | + */ |
|
527 | + private static function performSameSiteCookieProtection() { |
|
528 | + $request = \OC::$server->getRequest(); |
|
529 | + |
|
530 | + // Some user agents are notorious and don't really properly follow HTTP |
|
531 | + // specifications. For those, have an automated opt-out. Since the protection |
|
532 | + // for remote.php is applied in base.php as starting point we need to opt out |
|
533 | + // here. |
|
534 | + $incompatibleUserAgents = [ |
|
535 | + // OS X Finder |
|
536 | + '/^WebDAVFS/', |
|
537 | + ]; |
|
538 | + if($request->isUserAgent($incompatibleUserAgents)) { |
|
539 | + return; |
|
540 | + } |
|
541 | + |
|
542 | + if(count($_COOKIE) > 0) { |
|
543 | + $requestUri = $request->getScriptName(); |
|
544 | + $processingScript = explode('/', $requestUri); |
|
545 | + $processingScript = $processingScript[count($processingScript)-1]; |
|
546 | + // FIXME: In a SAML scenario we don't get any strict or lax cookie |
|
547 | + // send for the ACS endpoint. Since we have some legacy code in Nextcloud |
|
548 | + // (direct PHP files) the enforcement of lax cookies is performed here |
|
549 | + // instead of the middleware. |
|
550 | + // |
|
551 | + // This means we cannot exclude some routes from the cookie validation, |
|
552 | + // which normally is not a problem but is a little bit cumbersome for |
|
553 | + // this use-case. |
|
554 | + // Once the old legacy PHP endpoints have been removed we can move |
|
555 | + // the verification into a middleware and also adds some exemptions. |
|
556 | + // |
|
557 | + // Questions about this code? Ask Lukas ;-) |
|
558 | + $currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
559 | + if($currentUrl === '/index.php/apps/user_saml/saml/acs' || $currentUrl === '/apps/user_saml/saml/acs') { |
|
560 | + return; |
|
561 | + } |
|
562 | + // For the "index.php" endpoint only a lax cookie is required. |
|
563 | + if($processingScript === 'index.php') { |
|
564 | + if(!$request->passesLaxCookieCheck()) { |
|
565 | + self::sendSameSiteCookies(); |
|
566 | + header('Location: '.$_SERVER['REQUEST_URI']); |
|
567 | + exit(); |
|
568 | + } |
|
569 | + } else { |
|
570 | + // All other endpoints require the lax and the strict cookie |
|
571 | + if(!$request->passesStrictCookieCheck()) { |
|
572 | + self::sendSameSiteCookies(); |
|
573 | + // Debug mode gets access to the resources without strict cookie |
|
574 | + // due to the fact that the SabreDAV browser also lives there. |
|
575 | + if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
576 | + http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
|
577 | + exit(); |
|
578 | + } |
|
579 | + } |
|
580 | + } |
|
581 | + } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
582 | + self::sendSameSiteCookies(); |
|
583 | + } |
|
584 | + } |
|
585 | + |
|
586 | + public static function init() { |
|
587 | + // calculate the root directories |
|
588 | + OC::$SERVERROOT = str_replace("\\", '/', substr(__DIR__, 0, -4)); |
|
589 | + |
|
590 | + // register autoloader |
|
591 | + $loaderStart = microtime(true); |
|
592 | + require_once __DIR__ . '/autoloader.php'; |
|
593 | + self::$loader = new \OC\Autoloader([ |
|
594 | + OC::$SERVERROOT . '/lib/private/legacy', |
|
595 | + ]); |
|
596 | + if (defined('PHPUNIT_RUN')) { |
|
597 | + self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
598 | + } |
|
599 | + spl_autoload_register(array(self::$loader, 'load')); |
|
600 | + $loaderEnd = microtime(true); |
|
601 | + |
|
602 | + self::$CLI = (php_sapi_name() == 'cli'); |
|
603 | + |
|
604 | + // Add default composer PSR-4 autoloader |
|
605 | + self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
606 | + |
|
607 | + try { |
|
608 | + self::initPaths(); |
|
609 | + // setup 3rdparty autoloader |
|
610 | + $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
611 | + if (!file_exists($vendorAutoLoad)) { |
|
612 | + throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
|
613 | + } |
|
614 | + require_once $vendorAutoLoad; |
|
615 | + |
|
616 | + } catch (\RuntimeException $e) { |
|
617 | + if (!self::$CLI) { |
|
618 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
619 | + $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
|
620 | + header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
621 | + } |
|
622 | + // we can't use the template error page here, because this needs the |
|
623 | + // DI container which isn't available yet |
|
624 | + print($e->getMessage()); |
|
625 | + exit(); |
|
626 | + } |
|
627 | + |
|
628 | + // setup the basic server |
|
629 | + self::$server = new \OC\Server(\OC::$WEBROOT, self::$config); |
|
630 | + \OC::$server->getEventLogger()->log('autoloader', 'Autoloader', $loaderStart, $loaderEnd); |
|
631 | + \OC::$server->getEventLogger()->start('boot', 'Initialize'); |
|
632 | + |
|
633 | + // Don't display errors and log them |
|
634 | + error_reporting(E_ALL | E_STRICT); |
|
635 | + @ini_set('display_errors', 0); |
|
636 | + @ini_set('log_errors', 1); |
|
637 | + |
|
638 | + if(!date_default_timezone_set('UTC')) { |
|
639 | + throw new \RuntimeException('Could not set timezone to UTC'); |
|
640 | + }; |
|
641 | + |
|
642 | + //try to configure php to enable big file uploads. |
|
643 | + //this doesn´t work always depending on the webserver and php configuration. |
|
644 | + //Let´s try to overwrite some defaults anyway |
|
645 | + |
|
646 | + //try to set the maximum execution time to 60min |
|
647 | + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
|
648 | + @set_time_limit(3600); |
|
649 | + } |
|
650 | + @ini_set('max_execution_time', 3600); |
|
651 | + @ini_set('max_input_time', 3600); |
|
652 | + |
|
653 | + //try to set the maximum filesize to 10G |
|
654 | + @ini_set('upload_max_filesize', '10G'); |
|
655 | + @ini_set('post_max_size', '10G'); |
|
656 | + @ini_set('file_uploads', '50'); |
|
657 | + |
|
658 | + self::setRequiredIniValues(); |
|
659 | + self::handleAuthHeaders(); |
|
660 | + self::registerAutoloaderCache(); |
|
661 | + |
|
662 | + // initialize intl fallback is necessary |
|
663 | + \Patchwork\Utf8\Bootup::initIntl(); |
|
664 | + OC_Util::isSetLocaleWorking(); |
|
665 | + |
|
666 | + if (!defined('PHPUNIT_RUN')) { |
|
667 | + OC\Log\ErrorHandler::setLogger(\OC::$server->getLogger()); |
|
668 | + $debug = \OC::$server->getConfig()->getSystemValue('debug', false); |
|
669 | + OC\Log\ErrorHandler::register($debug); |
|
670 | + } |
|
671 | + |
|
672 | + \OC::$server->getEventLogger()->start('init_session', 'Initialize session'); |
|
673 | + OC_App::loadApps(array('session')); |
|
674 | + if (!self::$CLI) { |
|
675 | + self::initSession(); |
|
676 | + } |
|
677 | + \OC::$server->getEventLogger()->end('init_session'); |
|
678 | + self::checkConfig(); |
|
679 | + self::checkInstalled(); |
|
680 | + |
|
681 | + OC_Response::addSecurityHeaders(); |
|
682 | + if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
683 | + ini_set('session.cookie_secure', true); |
|
684 | + } |
|
685 | + |
|
686 | + self::performSameSiteCookieProtection(); |
|
687 | + |
|
688 | + if (!defined('OC_CONSOLE')) { |
|
689 | + $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
690 | + if (count($errors) > 0) { |
|
691 | + if (self::$CLI) { |
|
692 | + // Convert l10n string into regular string for usage in database |
|
693 | + $staticErrors = []; |
|
694 | + foreach ($errors as $error) { |
|
695 | + echo $error['error'] . "\n"; |
|
696 | + echo $error['hint'] . "\n\n"; |
|
697 | + $staticErrors[] = [ |
|
698 | + 'error' => (string)$error['error'], |
|
699 | + 'hint' => (string)$error['hint'], |
|
700 | + ]; |
|
701 | + } |
|
702 | + |
|
703 | + try { |
|
704 | + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); |
|
705 | + } catch (\Exception $e) { |
|
706 | + echo('Writing to database failed'); |
|
707 | + } |
|
708 | + exit(1); |
|
709 | + } else { |
|
710 | + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
711 | + OC_Util::addStyle('guest'); |
|
712 | + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); |
|
713 | + exit; |
|
714 | + } |
|
715 | + } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { |
|
716 | + \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); |
|
717 | + } |
|
718 | + } |
|
719 | + //try to set the session lifetime |
|
720 | + $sessionLifeTime = self::getSessionLifeTime(); |
|
721 | + @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
722 | + |
|
723 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
724 | + |
|
725 | + // User and Groups |
|
726 | + if (!$systemConfig->getValue("installed", false)) { |
|
727 | + self::$server->getSession()->set('user_id', ''); |
|
728 | + } |
|
729 | + |
|
730 | + OC_User::useBackend(new \OC\User\Database()); |
|
731 | + \OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); |
|
732 | + |
|
733 | + // Subscribe to the hook |
|
734 | + \OCP\Util::connectHook( |
|
735 | + '\OCA\Files_Sharing\API\Server2Server', |
|
736 | + 'preLoginNameUsedAsUserName', |
|
737 | + '\OC\User\Database', |
|
738 | + 'preLoginNameUsedAsUserName' |
|
739 | + ); |
|
740 | + |
|
741 | + //setup extra user backends |
|
742 | + if (!self::checkUpgrade(false)) { |
|
743 | + OC_User::setupBackends(); |
|
744 | + } else { |
|
745 | + // Run upgrades in incognito mode |
|
746 | + OC_User::setIncognitoMode(true); |
|
747 | + } |
|
748 | + |
|
749 | + self::registerCacheHooks(); |
|
750 | + self::registerFilesystemHooks(); |
|
751 | + self::registerShareHooks(); |
|
752 | + self::registerLogRotate(); |
|
753 | + self::registerEncryptionWrapper(); |
|
754 | + self::registerEncryptionHooks(); |
|
755 | + self::registerAccountHooks(); |
|
756 | + self::registerSettingsHooks(); |
|
757 | + |
|
758 | + $settings = new \OC\Settings\Application(); |
|
759 | + $settings->register(); |
|
760 | + |
|
761 | + //make sure temporary files are cleaned up |
|
762 | + $tmpManager = \OC::$server->getTempManager(); |
|
763 | + register_shutdown_function(array($tmpManager, 'clean')); |
|
764 | + $lockProvider = \OC::$server->getLockingProvider(); |
|
765 | + register_shutdown_function(array($lockProvider, 'releaseAll')); |
|
766 | + |
|
767 | + // Check whether the sample configuration has been copied |
|
768 | + if($systemConfig->getValue('copied_sample_config', false)) { |
|
769 | + $l = \OC::$server->getL10N('lib'); |
|
770 | + header('HTTP/1.1 503 Service Temporarily Unavailable'); |
|
771 | + header('Status: 503 Service Temporarily Unavailable'); |
|
772 | + OC_Template::printErrorPage( |
|
773 | + $l->t('Sample configuration detected'), |
|
774 | + $l->t('It has been detected that the sample configuration has been copied. This can break your installation and is unsupported. Please read the documentation before performing changes on config.php') |
|
775 | + ); |
|
776 | + return; |
|
777 | + } |
|
778 | + |
|
779 | + $request = \OC::$server->getRequest(); |
|
780 | + $host = $request->getInsecureServerHost(); |
|
781 | + /** |
|
782 | + * if the host passed in headers isn't trusted |
|
783 | + * FIXME: Should not be in here at all :see_no_evil: |
|
784 | + */ |
|
785 | + if (!OC::$CLI |
|
786 | + // overwritehost is always trusted, workaround to not have to make |
|
787 | + // \OC\AppFramework\Http\Request::getOverwriteHost public |
|
788 | + && self::$server->getConfig()->getSystemValue('overwritehost') === '' |
|
789 | + && !\OC::$server->getTrustedDomainHelper()->isTrustedDomain($host) |
|
790 | + && self::$server->getConfig()->getSystemValue('installed', false) |
|
791 | + ) { |
|
792 | + // Allow access to CSS resources |
|
793 | + $isScssRequest = false; |
|
794 | + if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
795 | + $isScssRequest = true; |
|
796 | + } |
|
797 | + |
|
798 | + if (!$isScssRequest) { |
|
799 | + header('HTTP/1.1 400 Bad Request'); |
|
800 | + header('Status: 400 Bad Request'); |
|
801 | + |
|
802 | + \OC::$server->getLogger()->warning( |
|
803 | + 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', |
|
804 | + [ |
|
805 | + 'app' => 'core', |
|
806 | + 'remoteAddress' => $request->getRemoteAddress(), |
|
807 | + 'host' => $host, |
|
808 | + ] |
|
809 | + ); |
|
810 | + |
|
811 | + $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); |
|
812 | + $tmpl->assign('domain', $host); |
|
813 | + $tmpl->printPage(); |
|
814 | + |
|
815 | + exit(); |
|
816 | + } |
|
817 | + } |
|
818 | + \OC::$server->getEventLogger()->end('boot'); |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * register hooks for the cache |
|
823 | + */ |
|
824 | + public static function registerCacheHooks() { |
|
825 | + //don't try to do this before we are properly setup |
|
826 | + if (\OC::$server->getSystemConfig()->getValue('installed', false) && !self::checkUpgrade(false)) { |
|
827 | + |
|
828 | + // NOTE: This will be replaced to use OCP |
|
829 | + $userSession = self::$server->getUserSession(); |
|
830 | + $userSession->listen('\OC\User', 'postLogin', function () { |
|
831 | + try { |
|
832 | + $cache = new \OC\Cache\File(); |
|
833 | + $cache->gc(); |
|
834 | + } catch (\OC\ServerNotAvailableException $e) { |
|
835 | + // not a GC exception, pass it on |
|
836 | + throw $e; |
|
837 | + } catch (\OC\ForbiddenException $e) { |
|
838 | + // filesystem blocked for this request, ignore |
|
839 | + } catch (\Exception $e) { |
|
840 | + // a GC exception should not prevent users from using OC, |
|
841 | + // so log the exception |
|
842 | + \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
843 | + } |
|
844 | + }); |
|
845 | + } |
|
846 | + } |
|
847 | + |
|
848 | + public static function registerSettingsHooks() { |
|
849 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
850 | + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_DISABLE, function($event) { |
|
851 | + /** @var \OCP\App\ManagerEvent $event */ |
|
852 | + \OC::$server->getSettingsManager()->onAppDisabled($event->getAppID()); |
|
853 | + }); |
|
854 | + $dispatcher->addListener(OCP\App\ManagerEvent::EVENT_APP_UPDATE, function($event) { |
|
855 | + /** @var \OCP\App\ManagerEvent $event */ |
|
856 | + $jobList = \OC::$server->getJobList(); |
|
857 | + $job = 'OC\\Settings\\RemoveOrphaned'; |
|
858 | + if(!($jobList->has($job, null))) { |
|
859 | + $jobList->add($job); |
|
860 | + } |
|
861 | + }); |
|
862 | + } |
|
863 | + |
|
864 | + private static function registerEncryptionWrapper() { |
|
865 | + $manager = self::$server->getEncryptionManager(); |
|
866 | + \OCP\Util::connectHook('OC_Filesystem', 'preSetup', $manager, 'setupStorage'); |
|
867 | + } |
|
868 | + |
|
869 | + private static function registerEncryptionHooks() { |
|
870 | + $enabled = self::$server->getEncryptionManager()->isEnabled(); |
|
871 | + if ($enabled) { |
|
872 | + \OCP\Util::connectHook('OCP\Share', 'post_shared', 'OC\Encryption\HookManager', 'postShared'); |
|
873 | + \OCP\Util::connectHook('OCP\Share', 'post_unshare', 'OC\Encryption\HookManager', 'postUnshared'); |
|
874 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OC\Encryption\HookManager', 'postRename'); |
|
875 | + \OCP\Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OC\Encryption\HookManager', 'postRestore'); |
|
876 | + } |
|
877 | + } |
|
878 | + |
|
879 | + private static function registerAccountHooks() { |
|
880 | + $hookHandler = new \OC\Accounts\Hooks(\OC::$server->getLogger()); |
|
881 | + \OCP\Util::connectHook('OC_User', 'changeUser', $hookHandler, 'changeUserHook'); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * register hooks for the cache |
|
886 | + */ |
|
887 | + public static function registerLogRotate() { |
|
888 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
889 | + if ($systemConfig->getValue('installed', false) && $systemConfig->getValue('log_rotate_size', false) && !self::checkUpgrade(false)) { |
|
890 | + //don't try to do this before we are properly setup |
|
891 | + //use custom logfile path if defined, otherwise use default of nextcloud.log in data directory |
|
892 | + \OC::$server->getJobList()->add('OC\Log\Rotate'); |
|
893 | + } |
|
894 | + } |
|
895 | + |
|
896 | + /** |
|
897 | + * register hooks for the filesystem |
|
898 | + */ |
|
899 | + public static function registerFilesystemHooks() { |
|
900 | + // Check for blacklisted files |
|
901 | + OC_Hook::connect('OC_Filesystem', 'write', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
902 | + OC_Hook::connect('OC_Filesystem', 'rename', 'OC\Files\Filesystem', 'isBlacklisted'); |
|
903 | + } |
|
904 | + |
|
905 | + /** |
|
906 | + * register hooks for sharing |
|
907 | + */ |
|
908 | + public static function registerShareHooks() { |
|
909 | + if (\OC::$server->getSystemConfig()->getValue('installed')) { |
|
910 | + OC_Hook::connect('OC_User', 'post_deleteUser', 'OC\Share20\Hooks', 'post_deleteUser'); |
|
911 | + OC_Hook::connect('OC_User', 'post_removeFromGroup', 'OC\Share20\Hooks', 'post_removeFromGroup'); |
|
912 | + OC_Hook::connect('OC_User', 'post_deleteGroup', 'OC\Share20\Hooks', 'post_deleteGroup'); |
|
913 | + } |
|
914 | + } |
|
915 | + |
|
916 | + protected static function registerAutoloaderCache() { |
|
917 | + // The class loader takes an optional low-latency cache, which MUST be |
|
918 | + // namespaced. The instanceid is used for namespacing, but might be |
|
919 | + // unavailable at this point. Furthermore, it might not be possible to |
|
920 | + // generate an instanceid via \OC_Util::getInstanceId() because the |
|
921 | + // config file may not be writable. As such, we only register a class |
|
922 | + // loader cache if instanceid is available without trying to create one. |
|
923 | + $instanceId = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
924 | + if ($instanceId) { |
|
925 | + try { |
|
926 | + $memcacheFactory = \OC::$server->getMemCacheFactory(); |
|
927 | + self::$loader->setMemoryCache($memcacheFactory->createLocal('Autoloader')); |
|
928 | + } catch (\Exception $ex) { |
|
929 | + } |
|
930 | + } |
|
931 | + } |
|
932 | + |
|
933 | + /** |
|
934 | + * Handle the request |
|
935 | + */ |
|
936 | + public static function handleRequest() { |
|
937 | + |
|
938 | + \OC::$server->getEventLogger()->start('handle_request', 'Handle request'); |
|
939 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
940 | + // load all the classpaths from the enabled apps so they are available |
|
941 | + // in the routing files of each app |
|
942 | + OC::loadAppClassPaths(); |
|
943 | + |
|
944 | + // Check if Nextcloud is installed or in maintenance (update) mode |
|
945 | + if (!$systemConfig->getValue('installed', false)) { |
|
946 | + \OC::$server->getSession()->clear(); |
|
947 | + $setupHelper = new OC\Setup(\OC::$server->getSystemConfig(), \OC::$server->getIniWrapper(), |
|
948 | + \OC::$server->getL10N('lib'), \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), |
|
949 | + \OC::$server->getSecureRandom()); |
|
950 | + $controller = new OC\Core\Controller\SetupController($setupHelper); |
|
951 | + $controller->run($_POST); |
|
952 | + exit(); |
|
953 | + } |
|
954 | + |
|
955 | + $request = \OC::$server->getRequest(); |
|
956 | + $requestPath = $request->getRawPathInfo(); |
|
957 | + if ($requestPath === '/heartbeat') { |
|
958 | + return; |
|
959 | + } |
|
960 | + if (substr($requestPath, -3) !== '.js') { // we need these files during the upgrade |
|
961 | + self::checkMaintenanceMode(); |
|
962 | + self::checkUpgrade(); |
|
963 | + } |
|
964 | + |
|
965 | + // emergency app disabling |
|
966 | + if ($requestPath === '/disableapp' |
|
967 | + && $request->getMethod() === 'POST' |
|
968 | + && ((array)$request->getParam('appid')) !== '' |
|
969 | + ) { |
|
970 | + \OCP\JSON::callCheck(); |
|
971 | + \OCP\JSON::checkAdminUser(); |
|
972 | + $appIds = (array)$request->getParam('appid'); |
|
973 | + foreach($appIds as $appId) { |
|
974 | + $appId = \OC_App::cleanAppId($appId); |
|
975 | + \OC_App::disable($appId); |
|
976 | + } |
|
977 | + \OC_JSON::success(); |
|
978 | + exit(); |
|
979 | + } |
|
980 | + |
|
981 | + // Always load authentication apps |
|
982 | + OC_App::loadApps(['authentication']); |
|
983 | + |
|
984 | + // Load minimum set of apps |
|
985 | + if (!self::checkUpgrade(false) |
|
986 | + && !$systemConfig->getValue('maintenance', false)) { |
|
987 | + // For logged-in users: Load everything |
|
988 | + if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
989 | + OC_App::loadApps(); |
|
990 | + } else { |
|
991 | + // For guests: Load only filesystem and logging |
|
992 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
993 | + self::handleLogin($request); |
|
994 | + } |
|
995 | + } |
|
996 | + |
|
997 | + if (!self::$CLI) { |
|
998 | + try { |
|
999 | + if (!$systemConfig->getValue('maintenance', false) && !self::checkUpgrade(false)) { |
|
1000 | + OC_App::loadApps(array('filesystem', 'logging')); |
|
1001 | + OC_App::loadApps(); |
|
1002 | + } |
|
1003 | + OC_Util::setupFS(); |
|
1004 | + OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo()); |
|
1005 | + return; |
|
1006 | + } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { |
|
1007 | + //header('HTTP/1.0 404 Not Found'); |
|
1008 | + } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { |
|
1009 | + OC_Response::setStatus(405); |
|
1010 | + return; |
|
1011 | + } |
|
1012 | + } |
|
1013 | + |
|
1014 | + // Handle WebDAV |
|
1015 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
1016 | + // not allowed any more to prevent people |
|
1017 | + // mounting this root directly. |
|
1018 | + // Users need to mount remote.php/webdav instead. |
|
1019 | + header('HTTP/1.1 405 Method Not Allowed'); |
|
1020 | + header('Status: 405 Method Not Allowed'); |
|
1021 | + return; |
|
1022 | + } |
|
1023 | + |
|
1024 | + // Someone is logged in |
|
1025 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1026 | + OC_App::loadApps(); |
|
1027 | + OC_User::setupBackends(); |
|
1028 | + OC_Util::setupFS(); |
|
1029 | + // FIXME |
|
1030 | + // Redirect to default application |
|
1031 | + OC_Util::redirectToDefaultPage(); |
|
1032 | + } else { |
|
1033 | + // Not handled and not logged in |
|
1034 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute('core.login.showLoginForm')); |
|
1035 | + } |
|
1036 | + } |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * Check login: apache auth, auth token, basic auth |
|
1040 | + * |
|
1041 | + * @param OCP\IRequest $request |
|
1042 | + * @return boolean |
|
1043 | + */ |
|
1044 | + static function handleLogin(OCP\IRequest $request) { |
|
1045 | + $userSession = self::$server->getUserSession(); |
|
1046 | + if (OC_User::handleApacheAuth()) { |
|
1047 | + return true; |
|
1048 | + } |
|
1049 | + if ($userSession->tryTokenLogin($request)) { |
|
1050 | + return true; |
|
1051 | + } |
|
1052 | + if (isset($_COOKIE['nc_username']) |
|
1053 | + && isset($_COOKIE['nc_token']) |
|
1054 | + && isset($_COOKIE['nc_session_id']) |
|
1055 | + && $userSession->loginWithCookie($_COOKIE['nc_username'], $_COOKIE['nc_token'], $_COOKIE['nc_session_id'])) { |
|
1056 | + return true; |
|
1057 | + } |
|
1058 | + if ($userSession->tryBasicAuthLogin($request, \OC::$server->getBruteForceThrottler())) { |
|
1059 | + return true; |
|
1060 | + } |
|
1061 | + return false; |
|
1062 | + } |
|
1063 | + |
|
1064 | + protected static function handleAuthHeaders() { |
|
1065 | + //copy http auth headers for apache+php-fcgid work around |
|
1066 | + if (isset($_SERVER['HTTP_XAUTHORIZATION']) && !isset($_SERVER['HTTP_AUTHORIZATION'])) { |
|
1067 | + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; |
|
1068 | + } |
|
1069 | + |
|
1070 | + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. |
|
1071 | + $vars = array( |
|
1072 | + 'HTTP_AUTHORIZATION', // apache+php-cgi work around |
|
1073 | + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative |
|
1074 | + ); |
|
1075 | + foreach ($vars as $var) { |
|
1076 | + if (isset($_SERVER[$var]) && preg_match('/Basic\s+(.*)$/i', $_SERVER[$var], $matches)) { |
|
1077 | + list($name, $password) = explode(':', base64_decode($matches[1]), 2); |
|
1078 | + $_SERVER['PHP_AUTH_USER'] = $name; |
|
1079 | + $_SERVER['PHP_AUTH_PW'] = $password; |
|
1080 | + break; |
|
1081 | + } |
|
1082 | + } |
|
1083 | + } |
|
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | OC::init(); |
@@ -119,14 +119,14 @@ discard block |
||
119 | 119 | * the app path list is empty or contains an invalid path |
120 | 120 | */ |
121 | 121 | public static function initPaths() { |
122 | - if(defined('PHPUNIT_CONFIG_DIR')) { |
|
123 | - self::$configDir = OC::$SERVERROOT . '/' . PHPUNIT_CONFIG_DIR . '/'; |
|
124 | - } elseif(defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT . '/tests/config/')) { |
|
125 | - self::$configDir = OC::$SERVERROOT . '/tests/config/'; |
|
126 | - } elseif($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
127 | - self::$configDir = rtrim($dir, '/') . '/'; |
|
122 | + if (defined('PHPUNIT_CONFIG_DIR')) { |
|
123 | + self::$configDir = OC::$SERVERROOT.'/'.PHPUNIT_CONFIG_DIR.'/'; |
|
124 | + } elseif (defined('PHPUNIT_RUN') and PHPUNIT_RUN and is_dir(OC::$SERVERROOT.'/tests/config/')) { |
|
125 | + self::$configDir = OC::$SERVERROOT.'/tests/config/'; |
|
126 | + } elseif ($dir = getenv('NEXTCLOUD_CONFIG_DIR')) { |
|
127 | + self::$configDir = rtrim($dir, '/').'/'; |
|
128 | 128 | } else { |
129 | - self::$configDir = OC::$SERVERROOT . '/config/'; |
|
129 | + self::$configDir = OC::$SERVERROOT.'/config/'; |
|
130 | 130 | } |
131 | 131 | self::$config = new \OC\Config(self::$configDir); |
132 | 132 | |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | //make sure suburi follows the same rules as scriptName |
149 | 149 | if (substr(OC::$SUBURI, -9) != 'index.php') { |
150 | 150 | if (substr(OC::$SUBURI, -1) != '/') { |
151 | - OC::$SUBURI = OC::$SUBURI . '/'; |
|
151 | + OC::$SUBURI = OC::$SUBURI.'/'; |
|
152 | 152 | } |
153 | - OC::$SUBURI = OC::$SUBURI . 'index.php'; |
|
153 | + OC::$SUBURI = OC::$SUBURI.'index.php'; |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | OC::$WEBROOT = substr($scriptName, 0, 0 - strlen(OC::$SUBURI)); |
163 | 163 | |
164 | 164 | if (OC::$WEBROOT != '' && OC::$WEBROOT[0] !== '/') { |
165 | - OC::$WEBROOT = '/' . OC::$WEBROOT; |
|
165 | + OC::$WEBROOT = '/'.OC::$WEBROOT; |
|
166 | 166 | } |
167 | 167 | } else { |
168 | 168 | // The scriptName is not ending with OC::$SUBURI |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | OC::$APPSROOTS[] = $paths; |
192 | 192 | } |
193 | 193 | } |
194 | - } elseif (file_exists(OC::$SERVERROOT . '/apps')) { |
|
195 | - OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT . '/apps', 'url' => '/apps', 'writable' => true); |
|
196 | - } elseif (file_exists(OC::$SERVERROOT . '/../apps')) { |
|
194 | + } elseif (file_exists(OC::$SERVERROOT.'/apps')) { |
|
195 | + OC::$APPSROOTS[] = array('path' => OC::$SERVERROOT.'/apps', 'url' => '/apps', 'writable' => true); |
|
196 | + } elseif (file_exists(OC::$SERVERROOT.'/../apps')) { |
|
197 | 197 | OC::$APPSROOTS[] = array( |
198 | - 'path' => rtrim(dirname(OC::$SERVERROOT), '/') . '/apps', |
|
198 | + 'path' => rtrim(dirname(OC::$SERVERROOT), '/').'/apps', |
|
199 | 199 | 'url' => '/apps', |
200 | 200 | 'writable' => true |
201 | 201 | ); |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | $l = \OC::$server->getL10N('lib'); |
226 | 226 | |
227 | 227 | // Create config if it does not already exist |
228 | - $configFilePath = self::$configDir .'/config.php'; |
|
229 | - if(!file_exists($configFilePath)) { |
|
228 | + $configFilePath = self::$configDir.'/config.php'; |
|
229 | + if (!file_exists($configFilePath)) { |
|
230 | 230 | @touch($configFilePath); |
231 | 231 | } |
232 | 232 | |
@@ -241,13 +241,13 @@ discard block |
||
241 | 241 | echo $l->t('Cannot write into "config" directory!')."\n"; |
242 | 242 | echo $l->t('This can usually be fixed by giving the webserver write access to the config directory')."\n"; |
243 | 243 | echo "\n"; |
244 | - echo $l->t('See %s', [ $urlGenerator->linkToDocs('admin-dir_permissions') ])."\n"; |
|
244 | + echo $l->t('See %s', [$urlGenerator->linkToDocs('admin-dir_permissions')])."\n"; |
|
245 | 245 | exit; |
246 | 246 | } else { |
247 | 247 | OC_Template::printErrorPage( |
248 | 248 | $l->t('Cannot write into "config" directory!'), |
249 | 249 | $l->t('This can usually be fixed by giving the webserver write access to the config directory. See %s', |
250 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) |
|
250 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
251 | 251 | ); |
252 | 252 | } |
253 | 253 | } |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | if (OC::$CLI) { |
263 | 263 | throw new Exception('Not installed'); |
264 | 264 | } else { |
265 | - $url = OC::$WEBROOT . '/index.php'; |
|
266 | - header('Location: ' . $url); |
|
265 | + $url = OC::$WEBROOT.'/index.php'; |
|
266 | + header('Location: '.$url); |
|
267 | 267 | } |
268 | 268 | exit(); |
269 | 269 | } |
@@ -391,14 +391,14 @@ discard block |
||
391 | 391 | $incompatibleShippedApps = []; |
392 | 392 | foreach ($incompatibleApps as $appInfo) { |
393 | 393 | if ($appManager->isShipped($appInfo['id'])) { |
394 | - $incompatibleShippedApps[] = $appInfo['name'] . ' (' . $appInfo['id'] . ')'; |
|
394 | + $incompatibleShippedApps[] = $appInfo['name'].' ('.$appInfo['id'].')'; |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
398 | 398 | $l10n = \OC::$server->getL10N('core'); |
399 | 399 | if (!empty($incompatibleShippedApps)) { |
400 | 400 | $hint = $l10n->t('The files of the app %$1s were not replaced correctly. Make sure it is a version compatible with the server.', [implode(', ', $incompatibleShippedApps)]); |
401 | - throw new \OC\HintException('The files of the app ' . implode(', ', $incompatibleShippedApps) . ' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
401 | + throw new \OC\HintException('The files of the app '.implode(', ', $incompatibleShippedApps).' were not replaced correctly. Make sure it is a version compatible with the server.', $hint); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion, $l10n->getLanguageCode())); |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | ini_set('session.cookie_httponly', true); |
414 | 414 | |
415 | 415 | // set the cookie path to the Nextcloud directory |
416 | - $cookie_path = OC::$WEBROOT ? : '/'; |
|
416 | + $cookie_path = OC::$WEBROOT ?: '/'; |
|
417 | 417 | ini_set('session.cookie_path', $cookie_path); |
418 | 418 | |
419 | 419 | // Let the session name be changed in the initSession Hook |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | // session timeout |
448 | 448 | if ($session->exists('LAST_ACTIVITY') && (time() - $session->get('LAST_ACTIVITY') > $sessionLifeTime)) { |
449 | 449 | if (isset($_COOKIE[session_name()])) { |
450 | - setcookie(session_name(), null, -1, self::$WEBROOT ? : '/'); |
|
450 | + setcookie(session_name(), null, -1, self::$WEBROOT ?: '/'); |
|
451 | 451 | } |
452 | 452 | \OC::$server->getUserSession()->logout(); |
453 | 453 | } |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | continue; |
470 | 470 | } |
471 | 471 | |
472 | - $file = $appPath . '/appinfo/classpath.php'; |
|
472 | + $file = $appPath.'/appinfo/classpath.php'; |
|
473 | 473 | if (file_exists($file)) { |
474 | 474 | require_once $file; |
475 | 475 | } |
@@ -497,14 +497,14 @@ discard block |
||
497 | 497 | |
498 | 498 | // Append __Host to the cookie if it meets the requirements |
499 | 499 | $cookiePrefix = ''; |
500 | - if($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
500 | + if ($cookieParams['secure'] === true && $cookieParams['path'] === '/') { |
|
501 | 501 | $cookiePrefix = '__Host-'; |
502 | 502 | } |
503 | 503 | |
504 | - foreach($policies as $policy) { |
|
504 | + foreach ($policies as $policy) { |
|
505 | 505 | header( |
506 | 506 | sprintf( |
507 | - 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;' . $secureCookie . 'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
507 | + 'Set-Cookie: %snc_sameSiteCookie%s=true; path=%s; httponly;'.$secureCookie.'expires=Fri, 31-Dec-2100 23:59:59 GMT; SameSite=%s', |
|
508 | 508 | $cookiePrefix, |
509 | 509 | $policy, |
510 | 510 | $cookieParams['path'], |
@@ -535,14 +535,14 @@ discard block |
||
535 | 535 | // OS X Finder |
536 | 536 | '/^WebDAVFS/', |
537 | 537 | ]; |
538 | - if($request->isUserAgent($incompatibleUserAgents)) { |
|
538 | + if ($request->isUserAgent($incompatibleUserAgents)) { |
|
539 | 539 | return; |
540 | 540 | } |
541 | 541 | |
542 | - if(count($_COOKIE) > 0) { |
|
542 | + if (count($_COOKIE) > 0) { |
|
543 | 543 | $requestUri = $request->getScriptName(); |
544 | 544 | $processingScript = explode('/', $requestUri); |
545 | - $processingScript = $processingScript[count($processingScript)-1]; |
|
545 | + $processingScript = $processingScript[count($processingScript) - 1]; |
|
546 | 546 | // FIXME: In a SAML scenario we don't get any strict or lax cookie |
547 | 547 | // send for the ACS endpoint. Since we have some legacy code in Nextcloud |
548 | 548 | // (direct PHP files) the enforcement of lax cookies is performed here |
@@ -555,30 +555,30 @@ discard block |
||
555 | 555 | // the verification into a middleware and also adds some exemptions. |
556 | 556 | // |
557 | 557 | // Questions about this code? Ask Lukas ;-) |
558 | - $currentUrl = substr(explode('?',$request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
559 | - if($currentUrl === '/index.php/apps/user_saml/saml/acs' || $currentUrl === '/apps/user_saml/saml/acs') { |
|
558 | + $currentUrl = substr(explode('?', $request->getRequestUri(), 2)[0], strlen(\OC::$WEBROOT)); |
|
559 | + if ($currentUrl === '/index.php/apps/user_saml/saml/acs' || $currentUrl === '/apps/user_saml/saml/acs') { |
|
560 | 560 | return; |
561 | 561 | } |
562 | 562 | // For the "index.php" endpoint only a lax cookie is required. |
563 | - if($processingScript === 'index.php') { |
|
564 | - if(!$request->passesLaxCookieCheck()) { |
|
563 | + if ($processingScript === 'index.php') { |
|
564 | + if (!$request->passesLaxCookieCheck()) { |
|
565 | 565 | self::sendSameSiteCookies(); |
566 | 566 | header('Location: '.$_SERVER['REQUEST_URI']); |
567 | 567 | exit(); |
568 | 568 | } |
569 | 569 | } else { |
570 | 570 | // All other endpoints require the lax and the strict cookie |
571 | - if(!$request->passesStrictCookieCheck()) { |
|
571 | + if (!$request->passesStrictCookieCheck()) { |
|
572 | 572 | self::sendSameSiteCookies(); |
573 | 573 | // Debug mode gets access to the resources without strict cookie |
574 | 574 | // due to the fact that the SabreDAV browser also lives there. |
575 | - if(!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
575 | + if (!\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
576 | 576 | http_response_code(\OCP\AppFramework\Http::STATUS_SERVICE_UNAVAILABLE); |
577 | 577 | exit(); |
578 | 578 | } |
579 | 579 | } |
580 | 580 | } |
581 | - } elseif(!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
581 | + } elseif (!isset($_COOKIE['nc_sameSiteCookielax']) || !isset($_COOKIE['nc_sameSiteCookiestrict'])) { |
|
582 | 582 | self::sendSameSiteCookies(); |
583 | 583 | } |
584 | 584 | } |
@@ -589,12 +589,12 @@ discard block |
||
589 | 589 | |
590 | 590 | // register autoloader |
591 | 591 | $loaderStart = microtime(true); |
592 | - require_once __DIR__ . '/autoloader.php'; |
|
592 | + require_once __DIR__.'/autoloader.php'; |
|
593 | 593 | self::$loader = new \OC\Autoloader([ |
594 | - OC::$SERVERROOT . '/lib/private/legacy', |
|
594 | + OC::$SERVERROOT.'/lib/private/legacy', |
|
595 | 595 | ]); |
596 | 596 | if (defined('PHPUNIT_RUN')) { |
597 | - self::$loader->addValidRoot(OC::$SERVERROOT . '/tests'); |
|
597 | + self::$loader->addValidRoot(OC::$SERVERROOT.'/tests'); |
|
598 | 598 | } |
599 | 599 | spl_autoload_register(array(self::$loader, 'load')); |
600 | 600 | $loaderEnd = microtime(true); |
@@ -602,12 +602,12 @@ discard block |
||
602 | 602 | self::$CLI = (php_sapi_name() == 'cli'); |
603 | 603 | |
604 | 604 | // Add default composer PSR-4 autoloader |
605 | - self::$composerAutoloader = require_once OC::$SERVERROOT . '/lib/composer/autoload.php'; |
|
605 | + self::$composerAutoloader = require_once OC::$SERVERROOT.'/lib/composer/autoload.php'; |
|
606 | 606 | |
607 | 607 | try { |
608 | 608 | self::initPaths(); |
609 | 609 | // setup 3rdparty autoloader |
610 | - $vendorAutoLoad = OC::$SERVERROOT. '/3rdparty/autoload.php'; |
|
610 | + $vendorAutoLoad = OC::$SERVERROOT.'/3rdparty/autoload.php'; |
|
611 | 611 | if (!file_exists($vendorAutoLoad)) { |
612 | 612 | throw new \RuntimeException('Composer autoloader not found, unable to continue. Check the folder "3rdparty". Running "git submodule update --init" will initialize the git submodule that handles the subfolder "3rdparty".'); |
613 | 613 | } |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | if (!self::$CLI) { |
618 | 618 | $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
619 | 619 | $protocol = in_array($claimedProtocol, ['HTTP/1.0', 'HTTP/1.1', 'HTTP/2']) ? $claimedProtocol : 'HTTP/1.1'; |
620 | - header($protocol . ' ' . OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
620 | + header($protocol.' '.OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
621 | 621 | } |
622 | 622 | // we can't use the template error page here, because this needs the |
623 | 623 | // DI container which isn't available yet |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | @ini_set('display_errors', 0); |
636 | 636 | @ini_set('log_errors', 1); |
637 | 637 | |
638 | - if(!date_default_timezone_set('UTC')) { |
|
638 | + if (!date_default_timezone_set('UTC')) { |
|
639 | 639 | throw new \RuntimeException('Could not set timezone to UTC'); |
640 | 640 | }; |
641 | 641 | |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | self::checkInstalled(); |
680 | 680 | |
681 | 681 | OC_Response::addSecurityHeaders(); |
682 | - if(self::$server->getRequest()->getServerProtocol() === 'https') { |
|
682 | + if (self::$server->getRequest()->getServerProtocol() === 'https') { |
|
683 | 683 | ini_set('session.cookie_secure', true); |
684 | 684 | } |
685 | 685 | |
@@ -692,11 +692,11 @@ discard block |
||
692 | 692 | // Convert l10n string into regular string for usage in database |
693 | 693 | $staticErrors = []; |
694 | 694 | foreach ($errors as $error) { |
695 | - echo $error['error'] . "\n"; |
|
696 | - echo $error['hint'] . "\n\n"; |
|
695 | + echo $error['error']."\n"; |
|
696 | + echo $error['hint']."\n\n"; |
|
697 | 697 | $staticErrors[] = [ |
698 | - 'error' => (string)$error['error'], |
|
699 | - 'hint' => (string)$error['hint'], |
|
698 | + 'error' => (string) $error['error'], |
|
699 | + 'hint' => (string) $error['hint'], |
|
700 | 700 | ]; |
701 | 701 | } |
702 | 702 | |
@@ -718,7 +718,7 @@ discard block |
||
718 | 718 | } |
719 | 719 | //try to set the session lifetime |
720 | 720 | $sessionLifeTime = self::getSessionLifeTime(); |
721 | - @ini_set('gc_maxlifetime', (string)$sessionLifeTime); |
|
721 | + @ini_set('gc_maxlifetime', (string) $sessionLifeTime); |
|
722 | 722 | |
723 | 723 | $systemConfig = \OC::$server->getSystemConfig(); |
724 | 724 | |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | register_shutdown_function(array($lockProvider, 'releaseAll')); |
766 | 766 | |
767 | 767 | // Check whether the sample configuration has been copied |
768 | - if($systemConfig->getValue('copied_sample_config', false)) { |
|
768 | + if ($systemConfig->getValue('copied_sample_config', false)) { |
|
769 | 769 | $l = \OC::$server->getL10N('lib'); |
770 | 770 | header('HTTP/1.1 503 Service Temporarily Unavailable'); |
771 | 771 | header('Status: 503 Service Temporarily Unavailable'); |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | ) { |
792 | 792 | // Allow access to CSS resources |
793 | 793 | $isScssRequest = false; |
794 | - if(strpos($request->getPathInfo(), '/css/') === 0) { |
|
794 | + if (strpos($request->getPathInfo(), '/css/') === 0) { |
|
795 | 795 | $isScssRequest = true; |
796 | 796 | } |
797 | 797 | |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | |
828 | 828 | // NOTE: This will be replaced to use OCP |
829 | 829 | $userSession = self::$server->getUserSession(); |
830 | - $userSession->listen('\OC\User', 'postLogin', function () { |
|
830 | + $userSession->listen('\OC\User', 'postLogin', function() { |
|
831 | 831 | try { |
832 | 832 | $cache = new \OC\Cache\File(); |
833 | 833 | $cache->gc(); |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | } catch (\Exception $e) { |
840 | 840 | // a GC exception should not prevent users from using OC, |
841 | 841 | // so log the exception |
842 | - \OC::$server->getLogger()->warning('Exception when running cache gc: ' . $e->getMessage(), array('app' => 'core')); |
|
842 | + \OC::$server->getLogger()->warning('Exception when running cache gc: '.$e->getMessage(), array('app' => 'core')); |
|
843 | 843 | } |
844 | 844 | }); |
845 | 845 | } |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | /** @var \OCP\App\ManagerEvent $event */ |
856 | 856 | $jobList = \OC::$server->getJobList(); |
857 | 857 | $job = 'OC\\Settings\\RemoveOrphaned'; |
858 | - if(!($jobList->has($job, null))) { |
|
858 | + if (!($jobList->has($job, null))) { |
|
859 | 859 | $jobList->add($job); |
860 | 860 | } |
861 | 861 | }); |
@@ -965,12 +965,12 @@ discard block |
||
965 | 965 | // emergency app disabling |
966 | 966 | if ($requestPath === '/disableapp' |
967 | 967 | && $request->getMethod() === 'POST' |
968 | - && ((array)$request->getParam('appid')) !== '' |
|
968 | + && ((array) $request->getParam('appid')) !== '' |
|
969 | 969 | ) { |
970 | 970 | \OCP\JSON::callCheck(); |
971 | 971 | \OCP\JSON::checkAdminUser(); |
972 | - $appIds = (array)$request->getParam('appid'); |
|
973 | - foreach($appIds as $appId) { |
|
972 | + $appIds = (array) $request->getParam('appid'); |
|
973 | + foreach ($appIds as $appId) { |
|
974 | 974 | $appId = \OC_App::cleanAppId($appId); |
975 | 975 | \OC_App::disable($appId); |
976 | 976 | } |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | if (!self::checkUpgrade(false) |
986 | 986 | && !$systemConfig->getValue('maintenance', false)) { |
987 | 987 | // For logged-in users: Load everything |
988 | - if(\OC::$server->getUserSession()->isLoggedIn()) { |
|
988 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
989 | 989 | OC_App::loadApps(); |
990 | 990 | } else { |
991 | 991 | // For guests: Load only filesystem and logging |