carddav.php 2.3 KB

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