public.php 3.1 KB

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