|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Björn Schießle <[email protected]> |
|
4
|
|
|
* @author Christopher Schäpers <[email protected]> |
|
5
|
|
|
* @author Jörn Friedrich Dreyer <[email protected]> |
|
6
|
|
|
* @author Lukas Reschke <[email protected]> |
|
7
|
|
|
* @author Philipp Schaffrath <[email protected]> |
|
8
|
|
|
* @author Robin Appelman <[email protected]> |
|
9
|
|
|
* @author Thomas Müller <[email protected]> |
|
10
|
|
|
* @author Victor Dubiniuk <[email protected]> |
|
11
|
|
|
* @author Vincent Petry <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
|
14
|
|
|
* @license AGPL-3.0 |
|
15
|
|
|
* |
|
16
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
17
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* as published by the Free Software Foundation. |
|
19
|
|
|
* |
|
20
|
|
|
* This program is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU Affero General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
27
|
|
|
* |
|
28
|
|
|
*/ |
|
29
|
|
|
try { |
|
30
|
|
|
require_once __DIR__ . '/lib/base.php'; |
|
31
|
|
|
if (\OCP\Util::needUpgrade()) { |
|
32
|
|
|
// since the behavior of apps or remotes are unpredictable during |
|
33
|
|
|
// an upgrade, return a 503 directly |
|
34
|
|
|
OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
35
|
|
|
OC_Template::printErrorPage('Service unavailable'); |
|
36
|
|
|
exit; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$request = \OC::$server->getRequest(); |
|
40
|
|
|
OC::checkMaintenanceMode($request); |
|
41
|
|
|
OC::checkSingleUserMode(true); |
|
42
|
|
|
$pathInfo = $request->getPathInfo(); |
|
43
|
|
|
|
|
44
|
|
|
if (!$pathInfo && $request->getParam('service', '') === '') { |
|
|
|
|
|
|
45
|
|
|
\header('HTTP/1.0 404 Not Found'); |
|
46
|
|
|
$dispatcher = \OC::$server->getEventDispatcher(); |
|
47
|
|
|
$dispatcher->dispatch(\OCP\Http\HttpEvents::EVENT_404, new OCP\Http\HttpEvents( |
|
48
|
|
|
\OCP\Http\HttpEvents::EVENT_404, |
|
49
|
|
|
OC::$server->getRequest() |
|
50
|
|
|
)); |
|
51
|
|
|
exit; |
|
52
|
|
|
} elseif ($request->getParam('service', '')) { |
|
53
|
|
|
$service = $request->getParam('service', ''); |
|
54
|
|
|
} else { |
|
55
|
|
|
$pathInfo = \trim($pathInfo, '/'); |
|
56
|
|
|
list($service) = \explode('/', $pathInfo); |
|
57
|
|
|
} |
|
58
|
|
|
$file = \OC::$server->getConfig()->getAppValue('core', 'public_' . \strip_tags($service)); |
|
59
|
|
View Code Duplication |
if ($file === null) { |
|
|
|
|
|
|
60
|
|
|
\header('HTTP/1.0 404 Not Found'); |
|
61
|
|
|
$dispatcher = \OC::$server->getEventDispatcher(); |
|
62
|
|
|
$dispatcher->dispatch(\OCP\Http\HttpEvents::EVENT_404, new OCP\Http\HttpEvents( |
|
63
|
|
|
\OCP\Http\HttpEvents::EVENT_404, |
|
64
|
|
|
OC::$server->getRequest() |
|
65
|
|
|
)); |
|
66
|
|
|
exit; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$parts = \explode('/', $file, 2); |
|
70
|
|
|
$app = $parts[0]; |
|
71
|
|
|
|
|
72
|
|
|
// Load all required applications |
|
73
|
|
|
\OC::$REQUESTEDAPP = $app; |
|
74
|
|
|
OC_App::loadApps(['authentication']); |
|
75
|
|
|
OC_App::loadApps(['filesystem', 'logging']); |
|
76
|
|
|
|
|
77
|
|
|
if (!\OC::$server->getAppManager()->isInstalled($app)) { |
|
78
|
|
|
throw new Exception('App not installed: ' . $app); |
|
79
|
|
|
} |
|
80
|
|
|
OC_App::loadApp($app); |
|
81
|
|
|
OC_User::setIncognitoMode(true); |
|
82
|
|
|
|
|
83
|
|
|
$baseuri = OC::$WEBROOT . '/public.php/' . $service . '/'; |
|
84
|
|
|
|
|
85
|
|
|
require_once OC_App::getAppPath($app) . '/' . $parts[1]; |
|
86
|
|
|
} catch (Exception $ex) { |
|
87
|
|
|
if ($ex instanceof \OC\ServiceUnavailableException) { |
|
88
|
|
|
OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); |
|
89
|
|
|
} else { |
|
90
|
|
|
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
91
|
|
|
} |
|
92
|
|
|
//show the user a detailed error page |
|
93
|
|
|
\OC::$server->getLogger()->logException($ex, ['app' => 'public']); |
|
94
|
|
|
OC_Template::printExceptionErrorPage($ex); |
|
95
|
|
|
} catch (Error $ex) { |
|
96
|
|
|
//show the user a detailed error page |
|
97
|
|
|
OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); |
|
98
|
|
|
\OC::$server->getLogger()->logException($ex, ['app' => 'public']); |
|
99
|
|
|
OC_Template::printExceptionErrorPage($ex); |
|
100
|
|
|
} |
|
101
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: