caldav.php 3.3 KB

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