Completed
Pull Request — stable9 (#2518)
by Lukas
09:47 queued 03:53
created

public.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Björn Schießle <[email protected]>
6
 * @author Christopher Schäpers <[email protected]>
7
 * @author Jörn Friedrich Dreyer <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Robin Appelman <[email protected]>
10
 * @author Thomas Müller <[email protected]>
11
 * @author Vincent Petry <[email protected]>
12
 *
13
 * @license AGPL-3.0
14
 *
15
 * This code is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License, version 3,
17
 * as published by the Free Software Foundation.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License, version 3,
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
26
 *
27
 */
28
try {
29
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
	OC::checkMaintenanceMode();
40
	OC::checkSingleUserMode(true);
41
	$request = \OC::$server->getRequest();
42
	$pathInfo = $request->getPathInfo();
43
44
	if (!$pathInfo && $request->getParam('service', '') === '') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $pathInfo of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
45
		header('HTTP/1.0 404 Not Found');
46
		exit;
47
	} elseif ($request->getParam('service', '')) {
48
		$service = $request->getParam('service', '');
49
	} else {
50
		$pathInfo = trim($pathInfo, '/');
51
		list($service) = explode('/', $pathInfo);
52
	}
53
	$file = OCP\CONFIG::getAppValue('core', 'public_' . strip_tags($service));
0 ignored issues
show
Deprecated Code introduced by
The method OCP\Config::getAppValue() has been deprecated with message: 8.0.0 use method getAppValue of \OCP\IConfig This function gets a value from the appconfig table. If the key does
not exist the default value will be returned

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
54
	if (is_null($file)) {
55
		header('HTTP/1.0 404 Not Found');
56
		exit;
57
	}
58
59
	$parts = explode('/', $file, 2);
60
	$app = $parts[0];
61
62
	// Load all required applications
63
	\OC::$REQUESTEDAPP = $app;
64
	OC_App::loadApps(array('authentication'));
65
	OC_App::loadApps(array('filesystem', 'logging'));
66
67
	if (!\OC::$server->getAppManager()->isInstalled($app)) {
68
		throw new Exception('App not installed: ' . $app);
69
	}
70
	OC_App::loadApp($app);
71
	OC_User::setIncognitoMode(true);
72
73
	$baseuri = OC::$WEBROOT . '/public.php/' . $service . '/';
74
75
	require_once OC_App::getAppPath($app) . '/' . $parts[1];
76
77
} catch (\OC\ServiceUnavailableException $ex) {
78
	//show the user a detailed error page
79
	OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
80
	\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
81
	OC_Template::printExceptionErrorPage($ex);
82
} catch (Exception $ex) {
83
	//show the user a detailed error page
84
	OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
85
	\OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
86
	OC_Template::printExceptionErrorPage($ex);
87
}
88