carddav.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@owncloud.com>
  6. * @author Georg Ehrke <georg@owncloud.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. // Backends
  27. use OCA\DAV\CardDAV\AddressBookRoot;
  28. use OCA\DAV\CardDAV\CardDavBackend;
  29. use OCA\DAV\Connector\LegacyDAVACL;
  30. use OCA\DAV\Connector\Sabre\Auth;
  31. use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
  32. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  33. use OCA\DAV\Connector\Sabre\Principal;
  34. use Sabre\CardDAV\Plugin;
  35. $authBackend = new Auth(
  36. \OC::$server->getSession(),
  37. \OC::$server->getUserSession(),
  38. \OC::$server->getRequest(),
  39. \OC::$server->getTwoFactorAuthManager(),
  40. \OC::$server->getBruteForceThrottler(),
  41. 'principals/'
  42. );
  43. $principalBackend = new Principal(
  44. \OC::$server->getUserManager(),
  45. \OC::$server->getGroupManager(),
  46. 'principals/'
  47. );
  48. $db = \OC::$server->getDatabaseConnection();
  49. $cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager());
  50. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  51. // Root nodes
  52. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  53. $principalCollection->disableListing = !$debugging; // Disable listing
  54. $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend);
  55. $addressBookRoot->disableListing = !$debugging; // Disable listing
  56. $nodes = array(
  57. $principalCollection,
  58. $addressBookRoot,
  59. );
  60. // Fire up server
  61. $server = new \Sabre\DAV\Server($nodes);
  62. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  63. $server->setBaseUri($baseuri);
  64. // Add plugins
  65. $server->addPlugin(new MaintenancePlugin());
  66. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
  67. $server->addPlugin(new Plugin());
  68. $server->addPlugin(new LegacyDAVACL());
  69. if ($debugging) {
  70. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  71. }
  72. $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
  73. $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(\OC::$server->getLogger()));
  74. $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
  75. // And off we go!
  76. $server->exec();