1
0

public.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 === '') {
  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. http_response_code(501);
  64. exit;
  65. }
  66. OC_App::loadApp($app);
  67. OC_User::setIncognitoMode(true);
  68. $baseuri = OC::$WEBROOT . '/public.php/' . $service . '/';
  69. require_once OC_App::getAppPath($app) . '/' . $parts[1];
  70. } catch (Exception $ex) {
  71. $status = 500;
  72. if ($ex instanceof \OC\ServiceUnavailableException) {
  73. $status = 503;
  74. }
  75. //show the user a detailed error page
  76. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  77. OC_Template::printExceptionErrorPage($ex, $status);
  78. } catch (Error $ex) {
  79. //show the user a detailed error page
  80. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  81. OC_Template::printExceptionErrorPage($ex, 500);
  82. }