Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

public.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christopher Schäpers <kondou@ts.unde.re>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Maxence Lange <maxence@artificial-owl.com>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Robin Appelman <robin@icewind.nl>
  14. * @author Roeland Jago Douma <roeland@famdouma.nl>
  15. * @author Thomas Müller <thomas.mueller@tmit.eu>
  16. * @author Vincent Petry <vincent@nextcloud.com>
  17. *
  18. * @license AGPL-3.0
  19. *
  20. * This code is free software: you can redistribute it and/or modify
  21. * it under the terms of the GNU Affero General Public License, version 3,
  22. * as published by the Free Software Foundation.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU Affero General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Affero General Public License, version 3,
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>
  31. *
  32. */
  33. require_once __DIR__ . '/lib/versioncheck.php';
  34. /**
  35. * @param $service
  36. * @return string
  37. */
  38. function resolveService(string $service): string {
  39. $services = [
  40. 'webdav' => 'dav/appinfo/v1/publicwebdav.php',
  41. 'dav' => 'dav/appinfo/v2/publicremote.php',
  42. ];
  43. if (isset($services[$service])) {
  44. return $services[$service];
  45. }
  46. return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service);
  47. }
  48. try {
  49. require_once __DIR__ . '/lib/base.php';
  50. // All resources served via the DAV endpoint should have the strictest possible
  51. // policy. Exempted from this is the SabreDAV browser plugin which overwrites
  52. // this policy with a softer one if debug mode is enabled.
  53. header("Content-Security-Policy: default-src 'none';");
  54. if (\OCP\Util::needUpgrade()) {
  55. // since the behavior of apps or remotes are unpredictable during
  56. // an upgrade, return a 503 directly
  57. throw new RemoteException('Service unavailable', 503);
  58. }
  59. $request = \OC::$server->getRequest();
  60. $pathInfo = $request->getPathInfo();
  61. if ($pathInfo === false || $pathInfo === '') {
  62. throw new RemoteException('Path not found', 404);
  63. }
  64. if (!$pos = strpos($pathInfo, '/', 1)) {
  65. $pos = strlen($pathInfo);
  66. }
  67. $service = substr($pathInfo, 1, $pos - 1);
  68. $file = resolveService($service);
  69. if (!$file) {
  70. throw new RemoteException('Path not found', 404);
  71. }
  72. $file = ltrim($file, '/');
  73. $parts = explode('/', $file, 2);
  74. $app = $parts[0];
  75. // Load all required applications
  76. \OC::$REQUESTEDAPP = $app;
  77. OC_App::loadApps(['authentication']);
  78. OC_App::loadApps(['extended_authentication']);
  79. OC_App::loadApps(['filesystem', 'logging']);
  80. if (!\OC::$server->getAppManager()->isInstalled($app)) {
  81. throw new RemoteException('App not installed: ' . $app);
  82. }
  83. OC_App::loadApp($app);
  84. OC_User::setIncognitoMode(true);
  85. $baseuri = OC::$WEBROOT . '/public.php/'.$service.'/';
  86. require_once $file;
  87. } catch (Exception $ex) {
  88. $status = 500;
  89. if ($ex instanceof \OC\ServiceUnavailableException) {
  90. $status = 503;
  91. }
  92. //show the user a detailed error page
  93. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  94. OC_Template::printExceptionErrorPage($ex, $status);
  95. } catch (Error $ex) {
  96. //show the user a detailed error page
  97. \OC::$server->getLogger()->logException($ex, ['app' => 'public']);
  98. OC_Template::printExceptionErrorPage($ex, 500);
  99. }