public.php 2.9 KB

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