remote.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. $file=ltrim($file, '/');
  27. $parts=explode('/', $file, 2);
  28. $app=$parts[0];
  29. // Load all required applications
  30. \OC::$REQUESTEDAPP = $app;
  31. OC_App::loadApps(array('authentication'));
  32. OC_App::loadApps(array('filesystem', 'logging'));
  33. switch ($app) {
  34. case 'core':
  35. $file = OC::$SERVERROOT .'/'. $file;
  36. break;
  37. default:
  38. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  39. throw new Exception('App not installed: ' . $app);
  40. }
  41. OC_App::loadApp($app);
  42. $file = OC_App::getAppPath($app) .'/'. $parts[1];
  43. break;
  44. }
  45. $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
  46. require_once $file;
  47. } catch (\OC\ServiceUnavailableException $ex) {
  48. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  49. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  50. OC_Template::printExceptionErrorPage($ex);
  51. } catch (Exception $ex) {
  52. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  53. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  54. OC_Template::printExceptionErrorPage($ex);
  55. }