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.

remote.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  38. throw new Exception('App not installed: ' . $app);
  39. }
  40. OC_App::loadApp($app);
  41. $file = OC_App::getAppPath($app) .'/'. $parts[1];
  42. break;
  43. }
  44. $baseuri = OC::$WEBROOT . '/remote.php/'.$service.'/';
  45. require_once $file;
  46. } catch (\OC\ServiceUnavailableException $ex) {
  47. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  48. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  49. OC_Template::printExceptionErrorPage($ex);
  50. } catch (Exception $ex) {
  51. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  52. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  53. OC_Template::printExceptionErrorPage($ex);
  54. }