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.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }