You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

public.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. OC::checkSingleUserMode(true);
  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. }