carddav.php 3.5 KB

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