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