remote.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. try {
  3. require_once 'lib/base.php';
  4. if (\OCP\Util::needUpgrade()) {
  5. // since the behavior of apps or remotes are unpredictable during
  6. // an upgrade, return a 503 directly
  7. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  8. OC_Template::printErrorPage('Service unavailable');
  9. exit;
  10. }
  11. $request = \OC::$server->getRequest();
  12. $pathInfo = $request->getPathInfo();
  13. if ($pathInfo === false || $pathInfo === '') {
  14. OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  15. exit;
  16. }
  17. if (!$pos = strpos($pathInfo, '/', 1)) {
  18. $pos = strlen($pathInfo);
  19. }
  20. $service=substr($pathInfo, 1, $pos-1);
  21. $file = \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service);
  22. if(is_null($file)) {
  23. OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  24. exit;
  25. }
  26. // force language as given in the http request
  27. \OC_L10N::setLanguageFromRequest();
  28. $file=ltrim($file, '/');
  29. $parts=explode('/', $file, 2);
  30. $app=$parts[0];
  31. // Load all required applications
  32. \OC::$REQUESTEDAPP = $app;
  33. OC_App::loadApps(array('authentication'));
  34. OC_App::loadApps(array('filesystem', 'logging'));
  35. switch ($app) {
  36. case 'core':
  37. $file = OC::$SERVERROOT .'/'. $file;
  38. break;
  39. default:
  40. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  41. throw new Exception('App not installed: ' . $app);
  42. }
  43. OC_App::loadApp($app);
  44. $file = OC_App::getAppPath($app) .'/'. $parts[1];
  45. break;
  46. }
  47. $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
  48. require_once $file;
  49. } catch (\OC\ServiceUnavailableException $ex) {
  50. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  51. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  52. OC_Template::printExceptionErrorPage($ex);
  53. } catch (Exception $ex) {
  54. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  55. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  56. OC_Template::printExceptionErrorPage($ex);
  57. }