carddav.php 2.7 KB

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