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 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. 'principals/'
  37. );
  38. $principalBackend = new Principal(
  39. \OC::$server->getUserManager(),
  40. \OC::$server->getGroupManager(),
  41. 'principals/'
  42. );
  43. $db = \OC::$server->getDatabaseConnection();
  44. $cardDavBackend = new CardDavBackend($db, $principalBackend);
  45. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  46. // Root nodes
  47. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  48. $principalCollection->disableListing = !$debugging; // Disable listing
  49. $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend);
  50. $addressBookRoot->disableListing = !$debugging; // Disable listing
  51. $nodes = array(
  52. $principalCollection,
  53. $addressBookRoot,
  54. );
  55. // Fire up server
  56. $server = new \Sabre\DAV\Server($nodes);
  57. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  58. $server->setBaseUri($baseuri);
  59. // Add plugins
  60. $server->addPlugin(new MaintenancePlugin());
  61. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
  62. $server->addPlugin(new Plugin());
  63. $server->addPlugin(new LegacyDAVACL());
  64. if ($debugging) {
  65. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  66. }
  67. $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
  68. $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
  69. // And off we go!
  70. $server->exec();