public.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. try {
  31. require_once __DIR__ . '/lib/base.php';
  32. if (\OCP\Util::needUpgrade()) {
  33. // since the behavior of apps or remotes are unpredictable during
  34. // an upgrade, return a 503 directly
  35. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  36. OC_Template::printErrorPage('Service unavailable');
  37. exit;
  38. }
  39. OC::checkMaintenanceMode();
  40. $request = \OC::$server->getRequest();
  41. $pathInfo = $request->getPathInfo();
  42. if (!$pathInfo && $request->getParam('service', '') === '') {
  43. header('HTTP/1.0 404 Not Found');
  44. exit;
  45. } elseif ($request->getParam('service', '')) {
  46. $service = $request->getParam('service', '');
  47. } else {
  48. $pathInfo = trim($pathInfo, '/');
  49. list($service) = explode('/', $pathInfo);
  50. }
  51. $file = OCP\Config::getAppValue('core', 'public_' . strip_tags($service));
  52. if (is_null($file)) {
  53. header('HTTP/1.0 404 Not Found');
  54. exit;
  55. }
  56. $parts = explode('/', $file, 2);
  57. $app = $parts[0];
  58. // Load all required applications
  59. \OC::$REQUESTEDAPP = $app;
  60. OC_App::loadApps(array('authentication'));
  61. OC_App::loadApps(array('filesystem', 'logging'));
  62. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  63. throw new Exception('App not installed: ' . $app);
  64. }
  65. OC_App::loadApp($app);
  66. OC_User::setIncognitoMode(true);
  67. $baseuri = OC::$WEBROOT . '/public.php/' . $service . '/';
  68. require_once OC_App::getAppPath($app) . '/' . $parts[1];
  69. } catch (Exception $ex) {
  70. if ($ex instanceof \OC\ServiceUnavailableException) {
  71. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  72. } else {
  73. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  74. }
  75. //show the user a detailed error page
  76. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  77. OC_Template::printExceptionErrorPage($ex);
  78. } catch (Error $ex) {
  79. //show the user a detailed error page
  80. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  81. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  82. OC_Template::printExceptionErrorPage($ex);
  83. }