public.php 1.9 KB

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. OC::checkMaintenanceMode();
  12. OC::checkSingleUserMode();
  13. $request = \OC::$server->getRequest();
  14. $pathInfo = $request->getPathInfo();
  15. if (!$pathInfo && !isset($request->server['service'])) {
  16. header('HTTP/1.0 404 Not Found');
  17. exit;
  18. } elseif (isset($request->server['service'])) {
  19. $service = $request->server['service'];
  20. } else {
  21. $pathInfo = trim($pathInfo, '/');
  22. list($service) = explode('/', $pathInfo);
  23. }
  24. $file = OCP\CONFIG::getAppValue('core', 'public_' . strip_tags($service));
  25. if (is_null($file)) {
  26. header('HTTP/1.0 404 Not Found');
  27. exit;
  28. }
  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. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  36. throw new Exception('App not installed: ' . $app);
  37. }
  38. OC_App::loadApp($app);
  39. OC_User::setIncognitoMode(true);
  40. $baseuri = OC::$WEBROOT . '/public.php/' . $service . '/';
  41. require_once OC_App::getAppPath($app) . '/' . $parts[1];
  42. } catch (\OC\ServiceUnavailableException $ex) {
  43. //show the user a detailed error page
  44. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  45. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  46. OC_Template::printExceptionErrorPage($ex);
  47. } catch (Exception $ex) {
  48. //show the user a detailed error page
  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. }