carddav.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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::$exposeVersion = false;
  63. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  64. $server->setBaseUri($baseuri);
  65. // Add plugins
  66. $server->addPlugin(new MaintenancePlugin());
  67. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
  68. $server->addPlugin(new Plugin());
  69. $server->addPlugin(new LegacyDAVACL());
  70. if ($debugging) {
  71. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  72. }
  73. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  74. $server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
  75. $server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(\OC::$server->getLogger()));
  76. $server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
  77. // And off we go!
  78. $server->exec();