public.php 3.0 KB

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