public.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. $pathInfo = OC_Request::getPathInfo();
  14. if (!$pathInfo && !isset($_GET['service'])) {
  15. header('HTTP/1.0 404 Not Found');
  16. exit;
  17. } elseif (isset($_GET['service'])) {
  18. $service = $_GET['service'];
  19. } else {
  20. $pathInfo = trim($pathInfo, '/');
  21. list($service) = explode('/', $pathInfo);
  22. }
  23. $file = OCP\CONFIG::getAppValue('core', 'public_' . strip_tags($service));
  24. if (is_null($file)) {
  25. header('HTTP/1.0 404 Not Found');
  26. exit;
  27. }
  28. $parts = explode('/', $file, 2);
  29. $app = $parts[0];
  30. // Load all required applications
  31. \OC::$REQUESTEDAPP = $app;
  32. OC_App::loadApps(array('authentication'));
  33. OC_App::loadApps(array('filesystem', 'logging'));
  34. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  35. throw new Exception('App not installed: ' . $app);
  36. }
  37. OC_App::loadApp($app);
  38. OC_User::setIncognitoMode(true);
  39. $baseuri = OC::$WEBROOT . '/public.php/' . $service . '/';
  40. require_once OC_App::getAppPath($app) . '/' . $parts[1];
  41. } catch (\OC\ServiceUnavailableException $ex) {
  42. //show the user a detailed error page
  43. OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
  44. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  45. OC_Template::printExceptionErrorPage($ex);
  46. } catch (Exception $ex) {
  47. //show the user a detailed error page
  48. OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
  49. \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
  50. OC_Template::printExceptionErrorPage($ex);
  51. }