caldav.php 3.6 KB

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