remote.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @author Brice Maron <brice@bmaron.net>
  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. $request = \OC::$server->getRequest();
  39. $pathInfo = $request->getPathInfo();
  40. if ($pathInfo === false || $pathInfo === '') {
  41. OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  42. exit;
  43. }
  44. if (!$pos = strpos($pathInfo, '/', 1)) {
  45. $pos = strlen($pathInfo);
  46. }
  47. $service=substr($pathInfo, 1, $pos-1);
  48. $file = \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service);
  49. if(is_null($file)) {
  50. OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  51. exit;
  52. }
  53. // force language as given in the http request
  54. \OC_L10N::setLanguageFromRequest();
  55. $file=ltrim($file, '/');
  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. switch ($app) {
  63. case 'core':
  64. $file = OC::$SERVERROOT .'/'. $file;
  65. break;
  66. default:
  67. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  68. throw new Exception('App not installed: ' . $app);
  69. }
  70. OC_App::loadApp($app);
  71. $file = OC_App::getAppPath($app) .'/'. $parts[1];
  72. break;
  73. }
  74. $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
  75. require_once $file;
  76. } catch (\OC\ServiceUnavailableException $ex) {
  77. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  78. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  79. OC_Template::printExceptionErrorPage($ex);
  80. } catch (Exception $ex) {
  81. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  82. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  83. OC_Template::printExceptionErrorPage($ex);
  84. }