1
0

carddav.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. // Backends
  30. use OC\KnownUser\KnownUserService;
  31. use OCA\DAV\AppInfo\PluginManager;
  32. use OCA\DAV\CardDAV\AddressBookRoot;
  33. use OCA\DAV\CardDAV\CardDavBackend;
  34. use OCA\DAV\Connector\LegacyDAVACL;
  35. use OCA\DAV\Connector\Sabre\Auth;
  36. use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
  37. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  38. use OCA\DAV\Connector\Sabre\Principal;
  39. use OCP\Accounts\IAccountManager;
  40. use OCP\App\IAppManager;
  41. use Psr\Log\LoggerInterface;
  42. use Sabre\CardDAV\Plugin;
  43. $authBackend = new Auth(
  44. \OC::$server->getSession(),
  45. \OC::$server->getUserSession(),
  46. \OC::$server->getRequest(),
  47. \OC::$server->getTwoFactorAuthManager(),
  48. \OC::$server->getBruteForceThrottler(),
  49. 'principals/'
  50. );
  51. $principalBackend = new Principal(
  52. \OC::$server->getUserManager(),
  53. \OC::$server->getGroupManager(),
  54. \OC::$server->get(IAccountManager::class),
  55. \OC::$server->getShareManager(),
  56. \OC::$server->getUserSession(),
  57. \OC::$server->getAppManager(),
  58. \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
  59. \OC::$server->get(KnownUserService::class),
  60. \OC::$server->getConfig(),
  61. \OC::$server->getL10NFactory(),
  62. 'principals/'
  63. );
  64. $db = \OC::$server->getDatabaseConnection();
  65. $cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class));
  66. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  67. // Root nodes
  68. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  69. $principalCollection->disableListing = !$debugging; // Disable listing
  70. $pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class));
  71. $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, $pluginManager);
  72. $addressBookRoot->disableListing = !$debugging; // Disable listing
  73. $nodes = [
  74. $principalCollection,
  75. $addressBookRoot,
  76. ];
  77. // Fire up server
  78. $server = new \Sabre\DAV\Server($nodes);
  79. $server::$exposeVersion = false;
  80. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  81. $server->setBaseUri($baseuri);
  82. // Add plugins
  83. $server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
  84. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
  85. $server->addPlugin(new Plugin());
  86. $server->addPlugin(new LegacyDAVACL());
  87. if ($debugging) {
  88. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  89. }
  90. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  91. $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
  92. $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(
  93. \OC::$server->getAppDataDir('dav-photocache'),
  94. \OC::$server->get(LoggerInterface::class)
  95. )));
  96. $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->get(LoggerInterface::class)));
  97. // And off we go!
  98. $server->exec();