1
0

public.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christopher Schäpers <kondou@ts.unde.re>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Vincent Petry <pvince81@owncloud.com>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. require_once __DIR__ . '/lib/versioncheck.php';
  31. try {
  32. require_once __DIR__ . '/lib/base.php';
  33. if (\OCP\Util::needUpgrade()) {
  34. // since the behavior of apps or remotes are unpredictable during
  35. // an upgrade, return a 503 directly
  36. OC_Template::printErrorPage('Service unavailable', '', 503);
  37. exit;
  38. }
  39. OC::checkMaintenanceMode();
  40. $request = \OC::$server->getRequest();
  41. $pathInfo = $request->getPathInfo();
  42. if (!$pathInfo && $request->getParam('service', '') === '') {
  43. http_response_code(404);
  44. exit;
  45. } elseif ($request->getParam('service', '')) {
  46. $service = $request->getParam('service', '');
  47. } else {
  48. $pathInfo = trim($pathInfo, '/');
  49. list($service) = explode('/', $pathInfo);
  50. }
  51. $file = \OC::$server->getConfig()->getAppValue('core', 'public_' . strip_tags($service));
  52. if ($file === null) {
  53. http_response_code(404);
  54. exit;
  55. }
  56. $parts = explode('/', $file, 2);
  57. $app = $parts[0];
  58. // Load all required applications
  59. \OC::$REQUESTEDAPP = $app;
  60. OC_App::loadApps(array('authentication'));
  61. OC_App::loadApps(array('filesystem', 'logging'));
  62. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  63. throw new Exception('App not installed: ' . $app);
  64. }
  65. OC_App::loadApp($app);
  66. OC_User::setIncognitoMode(true);
  67. $baseuri = OC::$WEBROOT . '/public.php/' . $service . '/';
  68. require_once OC_App::getAppPath($app) . '/' . $parts[1];
  69. } catch (Exception $ex) {
  70. $status = 500;
  71. if ($ex instanceof \OC\ServiceUnavailableException) {
  72. $status = 503;
  73. }
  74. //show the user a detailed error page
  75. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  76. OC_Template::printExceptionErrorPage($ex, $status);
  77. } catch (Error $ex) {
  78. //show the user a detailed error page
  79. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  80. OC_Template::printExceptionErrorPage($ex, 500);
  81. }