public.php 3.1 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 Jörn Friedrich Dreyer <jfd@butonic.de>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  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_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  37. OC_Template::printErrorPage('Service unavailable');
  38. exit;
  39. }
  40. OC::checkMaintenanceMode();
  41. $request = \OC::$server->getRequest();
  42. $pathInfo = $request->getPathInfo();
  43. if (!$pathInfo && $request->getParam('service', '') === '') {
  44. header('HTTP/1.0 404 Not Found');
  45. exit;
  46. } elseif ($request->getParam('service', '')) {
  47. $service = $request->getParam('service', '');
  48. } else {
  49. $pathInfo = trim($pathInfo, '/');
  50. list($service) = explode('/', $pathInfo);
  51. }
  52. $file = OCP\Config::getAppValue('core', 'public_' . strip_tags($service));
  53. if (is_null($file)) {
  54. header('HTTP/1.0 404 Not Found');
  55. exit;
  56. }
  57. $parts = explode('/', $file, 2);
  58. $app = $parts[0];
  59. // Load all required applications
  60. \OC::$REQUESTEDAPP = $app;
  61. OC_App::loadApps(array('authentication'));
  62. OC_App::loadApps(array('filesystem', 'logging'));
  63. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  64. throw new Exception('App not installed: ' . $app);
  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. if ($ex instanceof \OC\ServiceUnavailableException) {
  72. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  73. } else {
  74. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  75. }
  76. //show the user a detailed error page
  77. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  78. OC_Template::printExceptionErrorPage($ex);
  79. } catch (Error $ex) {
  80. //show the user a detailed error page
  81. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  82. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  83. OC_Template::printExceptionErrorPage($ex);
  84. }