public.php 3.0 KB

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