1
0

carddav.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\AppInfo\PluginManager;
  10. use OCA\DAV\CardDAV\AddressBookRoot;
  11. use OCA\DAV\CardDAV\CardDavBackend;
  12. use OCA\DAV\CardDAV\Security\CardDavRateLimitingPlugin;
  13. use OCA\DAV\CardDAV\Validation\CardDavValidatePlugin;
  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 OCP\App\IAppManager;
  21. use Psr\Log\LoggerInterface;
  22. use Sabre\CardDAV\Plugin;
  23. $authBackend = new Auth(
  24. \OC::$server->getSession(),
  25. \OC::$server->getUserSession(),
  26. \OC::$server->getRequest(),
  27. \OC::$server->getTwoFactorAuthManager(),
  28. \OC::$server->getBruteForceThrottler(),
  29. 'principals/'
  30. );
  31. $principalBackend = new Principal(
  32. \OC::$server->getUserManager(),
  33. \OC::$server->getGroupManager(),
  34. \OC::$server->get(IAccountManager::class),
  35. \OC::$server->getShareManager(),
  36. \OC::$server->getUserSession(),
  37. \OC::$server->getAppManager(),
  38. \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
  39. \OC::$server->get(KnownUserService::class),
  40. \OC::$server->getConfig(),
  41. \OC::$server->getL10NFactory(),
  42. 'principals/'
  43. );
  44. $db = \OC::$server->getDatabaseConnection();
  45. $cardDavBackend = new CardDavBackend(
  46. $db,
  47. $principalBackend,
  48. \OC::$server->getUserManager(),
  49. \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
  50. \OC::$server->get(\OCA\DAV\CardDAV\Sharing\Backend::class),
  51. );
  52. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  53. // Root nodes
  54. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  55. $principalCollection->disableListing = !$debugging; // Disable listing
  56. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  57. $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, $pluginManager, \OC::$server->getUserSession()->getUser(), \OC::$server->get(\OCP\IGroupManager::class));
  58. $addressBookRoot->disableListing = !$debugging; // Disable listing
  59. $nodes = [
  60. $principalCollection,
  61. $addressBookRoot,
  62. ];
  63. // Fire up server
  64. $server = new \Sabre\DAV\Server($nodes);
  65. $server::$exposeVersion = false;
  66. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  67. $server->setBaseUri($baseuri);
  68. // Add plugins
  69. $server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
  70. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
  71. $server->addPlugin(new Plugin());
  72. $server->addPlugin(new LegacyDAVACL());
  73. if ($debugging) {
  74. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  75. }
  76. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  77. $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
  78. $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(
  79. \OC::$server->getAppDataDir('dav-photocache'),
  80. \OC::$server->get(LoggerInterface::class)
  81. )));
  82. $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->get(LoggerInterface::class)));
  83. $server->addPlugin(\OCP\Server::get(CardDavRateLimitingPlugin::class));
  84. $server->addPlugin(\OCP\Server::get(CardDavValidatePlugin::class));
  85. // And off we go!
  86. $server->exec();