carddav.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author John Molakvoæ <skjnldsv@protonmail.com>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Thomas Citharel <nextcloud@tcit.fr>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Anna Larch <anna.larch@gmx.net>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. // Backends
  31. use OC\KnownUser\KnownUserService;
  32. use OCA\DAV\AppInfo\PluginManager;
  33. use OCA\DAV\CardDAV\AddressBookRoot;
  34. use OCA\DAV\CardDAV\CardDavBackend;
  35. use OCA\DAV\Connector\LegacyDAVACL;
  36. use OCA\DAV\Connector\Sabre\Auth;
  37. use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
  38. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  39. use OCA\DAV\Connector\Sabre\Principal;
  40. use OCP\Accounts\IAccountManager;
  41. use OCP\App\IAppManager;
  42. use Psr\Log\LoggerInterface;
  43. use Sabre\CardDAV\Plugin;
  44. $authBackend = new Auth(
  45. \OC::$server->getSession(),
  46. \OC::$server->getUserSession(),
  47. \OC::$server->getRequest(),
  48. \OC::$server->getTwoFactorAuthManager(),
  49. \OC::$server->getBruteForceThrottler(),
  50. 'principals/'
  51. );
  52. $principalBackend = new Principal(
  53. \OC::$server->getUserManager(),
  54. \OC::$server->getGroupManager(),
  55. \OC::$server->get(IAccountManager::class),
  56. \OC::$server->getShareManager(),
  57. \OC::$server->getUserSession(),
  58. \OC::$server->getAppManager(),
  59. \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
  60. \OC::$server->get(KnownUserService::class),
  61. \OC::$server->getConfig(),
  62. \OC::$server->getL10NFactory(),
  63. 'principals/'
  64. );
  65. $db = \OC::$server->getDatabaseConnection();
  66. $cardDavBackend = new CardDavBackend(
  67. $db,
  68. $principalBackend,
  69. \OC::$server->getUserManager(),
  70. \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
  71. \OC::$server->get(\OCA\DAV\CardDAV\Sharing\Backend::class),
  72. );
  73. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  74. // Root nodes
  75. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  76. $principalCollection->disableListing = !$debugging; // Disable listing
  77. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  78. $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, $pluginManager, \OC::$server->getUserSession()->getUser(), \OC::$server->get(\OCP\IGroupManager::class));
  79. $addressBookRoot->disableListing = !$debugging; // Disable listing
  80. $nodes = [
  81. $principalCollection,
  82. $addressBookRoot,
  83. ];
  84. // Fire up server
  85. $server = new \Sabre\DAV\Server($nodes);
  86. $server::$exposeVersion = false;
  87. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  88. $server->setBaseUri($baseuri);
  89. // Add plugins
  90. $server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
  91. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
  92. $server->addPlugin(new Plugin());
  93. $server->addPlugin(new LegacyDAVACL());
  94. if ($debugging) {
  95. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  96. }
  97. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  98. $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
  99. $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(
  100. \OC::$server->getAppDataDir('dav-photocache'),
  101. \OC::$server->get(LoggerInterface::class)
  102. )));
  103. $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->get(LoggerInterface::class)));
  104. // And off we go!
  105. $server->exec();