public.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Christopher Schäpers <kondou@ts.unde.re>
  5. * @author Georg Ehrke <georg@owncloud.com>
  6. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  7. * @author Lukas Reschke <lukas@owncloud.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <icewind@owncloud.com>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  11. *
  12. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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 '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. }