remote.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. $path_info = OC_Request::getPathInfo();
  12. if ($path_info === false || $path_info === '') {
  13. OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  14. exit;
  15. }
  16. if (!$pos = strpos($path_info, '/', 1)) {
  17. $pos = strlen($path_info);
  18. }
  19. $service=substr($path_info, 1, $pos-1);
  20. $file = \OC::$server->getAppConfig()->getValue('core', 'remote_' . $service);
  21. if(is_null($file)) {
  22. OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
  23. exit;
  24. }
  25. $file=ltrim($file, '/');
  26. $parts=explode('/', $file, 2);
  27. $app=$parts[0];
  28. // Load all required applications
  29. \OC::$REQUESTEDAPP = $app;
  30. OC_App::loadApps(array('authentication'));
  31. OC_App::loadApps(array('filesystem', 'logging'));
  32. switch ($app) {
  33. case 'core':
  34. $file = OC::$SERVERROOT .'/'. $file;
  35. break;
  36. default:
  37. OC_Util::checkAppEnabled($app);
  38. OC_App::loadApp($app);
  39. $file = OC_App::getAppPath($app) .'/'. $parts[1];
  40. break;
  41. }
  42. $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
  43. require_once $file;
  44. } catch (\OC\ServiceUnavailableException $ex) {
  45. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  46. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  47. OC_Template::printExceptionErrorPage($ex);
  48. } catch (Exception $ex) {
  49. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  50. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  51. OC_Template::printExceptionErrorPage($ex);
  52. }