carddav.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@owncloud.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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. \OC::$server->getShareManager(),
  47. \OC::$server->getUserSession(),
  48. \OC::$server->getConfig(),
  49. 'principals/'
  50. );
  51. $db = \OC::$server->getDatabaseConnection();
  52. $cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->getEventDispatcher());
  53. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  54. // Root nodes
  55. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  56. $principalCollection->disableListing = !$debugging; // Disable listing
  57. $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend);
  58. $addressBookRoot->disableListing = !$debugging; // Disable listing
  59. $nodes = array(
  60. $principalCollection,
  61. $addressBookRoot,
  62. );
  63. // Fire up server
  64. $server = new \Sabre\DAV\Server($nodes);
  65. $server::$exposeVersion = false;
  66. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  67. $server->setBaseUri($baseuri);
  68. // Add plugins
  69. $server->addPlugin(new MaintenancePlugin());
  70. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
  71. $server->addPlugin(new Plugin());
  72. $server->addPlugin(new LegacyDAVACL());
  73. if ($debugging) {
  74. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  75. }
  76. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  77. $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
  78. $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
  79. $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
  80. // And off we go!
  81. $server->exec();