You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

carddav.php 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\CardDAV\AddressBookRoot;
  30. use OCA\DAV\CardDAV\CardDavBackend;
  31. use OCA\DAV\Connector\LegacyDAVACL;
  32. use OCA\DAV\Connector\Sabre\Auth;
  33. use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
  34. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  35. use OCA\DAV\Connector\Sabre\Principal;
  36. use Sabre\CardDAV\Plugin;
  37. $authBackend = new Auth(
  38. \OC::$server->getSession(),
  39. \OC::$server->getUserSession(),
  40. \OC::$server->getRequest(),
  41. \OC::$server->getTwoFactorAuthManager(),
  42. \OC::$server->getBruteForceThrottler(),
  43. 'principals/'
  44. );
  45. $principalBackend = new Principal(
  46. \OC::$server->getUserManager(),
  47. \OC::$server->getGroupManager(),
  48. \OC::$server->getShareManager(),
  49. \OC::$server->getUserSession(),
  50. \OC::$server->getAppManager(),
  51. \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
  52. \OC::$server->getConfig(),
  53. 'principals/'
  54. );
  55. $db = \OC::$server->getDatabaseConnection();
  56. $cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->getEventDispatcher());
  57. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  58. // Root nodes
  59. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  60. $principalCollection->disableListing = !$debugging; // Disable listing
  61. $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend);
  62. $addressBookRoot->disableListing = !$debugging; // Disable listing
  63. $nodes = array(
  64. $principalCollection,
  65. $addressBookRoot,
  66. );
  67. // Fire up server
  68. $server = new \Sabre\DAV\Server($nodes);
  69. $server::$exposeVersion = false;
  70. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  71. $server->setBaseUri($baseuri);
  72. // Add plugins
  73. $server->addPlugin(new MaintenancePlugin());
  74. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
  75. $server->addPlugin(new Plugin());
  76. $server->addPlugin(new LegacyDAVACL());
  77. if ($debugging) {
  78. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  79. }
  80. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  81. $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
  82. $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(
  83. \OC::$server->getAppDataDir('dav-photocache'),
  84. \OC::$server->getLogger()
  85. )));
  86. $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
  87. // And off we go!
  88. $server->exec();