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.0KB

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 Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Vincent Petry <pvince81@owncloud.com>
  12. *
  13. * @copyright Copyright (c) 2015, ownCloud, Inc.
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. try {
  30. require_once 'lib/base.php';
  31. if (\OCP\Util::needUpgrade()) {
  32. // since the behavior of apps or remotes are unpredictable during
  33. // an upgrade, return a 503 directly
  34. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  35. OC_Template::printErrorPage('Service unavailable');
  36. exit;
  37. }
  38. OC::checkMaintenanceMode();
  39. OC::checkSingleUserMode(true);
  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 (\OC\ServiceUnavailableException $ex) {
  70. //show the user a detailed error page
  71. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  72. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  73. OC_Template::printExceptionErrorPage($ex);
  74. } catch (Exception $ex) {
  75. //show the user a detailed error page
  76. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  77. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  78. OC_Template::printExceptionErrorPage($ex);
  79. }