caldav.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\CalDAV\CalDavBackend;
  23. use OCA\DAV\Connector\Sabre\Auth;
  24. use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
  25. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  26. use OCA\DAV\Connector\Sabre\Principal;
  27. use Sabre\CalDAV\CalendarRoot;
  28. $authBackend = new Auth(
  29. \OC::$server->getSession(),
  30. \OC::$server->getUserSession(),
  31. 'principals/'
  32. );
  33. $principalBackend = new Principal(
  34. \OC::$server->getUserManager(),
  35. \OC::$server->getGroupManager(),
  36. 'principals/'
  37. );
  38. $db = \OC::$server->getDatabaseConnection();
  39. $calDavBackend = new CalDavBackend($db, $principalBackend);
  40. // Root nodes
  41. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  42. $principalCollection->disableListing = true; // Disable listing
  43. $addressBookRoot = new CalendarRoot($principalBackend, $calDavBackend);
  44. $addressBookRoot->disableListing = true; // Disable listing
  45. $nodes = array(
  46. $principalCollection,
  47. $addressBookRoot,
  48. );
  49. // Fire up server
  50. $server = new \Sabre\DAV\Server($nodes);
  51. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  52. $server->setBaseUri($baseuri);
  53. // Add plugins
  54. $server->addPlugin(new MaintenancePlugin());
  55. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
  56. $server->addPlugin(new \Sabre\CalDAV\Plugin());
  57. $server->addPlugin(new \Sabre\DAVACL\Plugin());
  58. $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
  59. $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger()));
  60. // And off we go!
  61. $server->exec();