carddav.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class));
  67. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  68. // Root nodes
  69. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  70. $principalCollection->disableListing = !$debugging; // Disable listing
  71. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  72. $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, $pluginManager, \OC::$server->getUserSession()->getUser(), \OC::$server->get(\OCP\IGroupManager::class));
  73. $addressBookRoot->disableListing = !$debugging; // Disable listing
  74. $nodes = [
  75. $principalCollection,
  76. $addressBookRoot,
  77. ];
  78. // Fire up server
  79. $server = new \Sabre\DAV\Server($nodes);
  80. $server::$exposeVersion = false;
  81. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  82. $server->setBaseUri($baseuri);
  83. // Add plugins
  84. $server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
  85. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
  86. $server->addPlugin(new Plugin());
  87. $server->addPlugin(new LegacyDAVACL());
  88. if ($debugging) {
  89. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  90. }
  91. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  92. $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
  93. $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(
  94. \OC::$server->getAppDataDir('dav-photocache'),
  95. \OC::$server->get(LoggerInterface::class)
  96. )));
  97. $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->get(LoggerInterface::class)));
  98. // And off we go!
  99. $server->exec();