caldav.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. // Backends
  8. use OC\KnownUser\KnownUserService;
  9. use OCA\DAV\CalDAV\CalDavBackend;
  10. use OCA\DAV\CalDAV\CalendarRoot;
  11. use OCA\DAV\CalDAV\DefaultCalendarValidator;
  12. use OCA\DAV\CalDAV\Security\RateLimitingPlugin;
  13. use OCA\DAV\CalDAV\Validation\CalDavValidatePlugin;
  14. use OCA\DAV\Connector\LegacyDAVACL;
  15. use OCA\DAV\Connector\Sabre\Auth;
  16. use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
  17. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  18. use OCA\DAV\Connector\Sabre\Principal;
  19. use OCP\Accounts\IAccountManager;
  20. use Psr\Log\LoggerInterface;
  21. $authBackend = new Auth(
  22. \OC::$server->getSession(),
  23. \OC::$server->getUserSession(),
  24. \OC::$server->getRequest(),
  25. \OC::$server->getTwoFactorAuthManager(),
  26. \OC::$server->getBruteForceThrottler(),
  27. 'principals/'
  28. );
  29. $principalBackend = new Principal(
  30. \OC::$server->getUserManager(),
  31. \OC::$server->getGroupManager(),
  32. \OC::$server->get(IAccountManager::class),
  33. \OC::$server->getShareManager(),
  34. \OC::$server->getUserSession(),
  35. \OC::$server->getAppManager(),
  36. \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
  37. \OC::$server->get(KnownUserService::class),
  38. \OC::$server->getConfig(),
  39. \OC::$server->getL10NFactory(),
  40. 'principals/'
  41. );
  42. $db = \OC::$server->getDatabaseConnection();
  43. $userManager = \OC::$server->getUserManager();
  44. $random = \OC::$server->getSecureRandom();
  45. $logger = \OC::$server->get(LoggerInterface::class);
  46. $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
  47. $config = \OC::$server->get(\OCP\IConfig::class);
  48. $calDavBackend = new CalDavBackend(
  49. $db,
  50. $principalBackend,
  51. $userManager,
  52. $random,
  53. $logger,
  54. $dispatcher,
  55. $config,
  56. OC::$server->get(\OCA\DAV\CalDAV\Sharing\Backend::class),
  57. true
  58. );
  59. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  60. $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes';
  61. // Root nodes
  62. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  63. $principalCollection->disableListing = !$debugging; // Disable listing
  64. $addressBookRoot = new CalendarRoot($principalBackend, $calDavBackend, 'principals', $logger);
  65. $addressBookRoot->disableListing = !$debugging; // Disable listing
  66. $nodes = [
  67. $principalCollection,
  68. $addressBookRoot,
  69. ];
  70. // Fire up server
  71. $server = new \Sabre\DAV\Server($nodes);
  72. $server::$exposeVersion = false;
  73. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  74. $server->setBaseUri($baseuri);
  75. // Add plugins
  76. $server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
  77. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
  78. $server->addPlugin(new \Sabre\CalDAV\Plugin());
  79. $server->addPlugin(new LegacyDAVACL());
  80. if ($debugging) {
  81. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  82. }
  83. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  84. $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
  85. $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DefaultCalendarValidator::class)));
  86. if ($sendInvitations) {
  87. $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
  88. }
  89. $server->addPlugin(new ExceptionLoggerPlugin('caldav', $logger));
  90. $server->addPlugin(\OCP\Server::get(RateLimitingPlugin::class));
  91. $server->addPlugin(\OCP\Server::get(CalDavValidatePlugin::class));
  92. // And off we go!
  93. $server->exec();