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.

caldav.php 2.5KB

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