1
0

caldav.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 Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. // Backends
  26. use OCA\DAV\CalDAV\CalDavBackend;
  27. use OCA\DAV\Connector\LegacyDAVACL;
  28. use OCA\DAV\CalDAV\CalendarRoot;
  29. use OCA\DAV\Connector\Sabre\Auth;
  30. use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
  31. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  32. use OCA\DAV\Connector\Sabre\Principal;
  33. $authBackend = new Auth(
  34. \OC::$server->getSession(),
  35. \OC::$server->getUserSession(),
  36. \OC::$server->getRequest(),
  37. \OC::$server->getTwoFactorAuthManager(),
  38. \OC::$server->getBruteForceThrottler(),
  39. 'principals/'
  40. );
  41. $principalBackend = new Principal(
  42. \OC::$server->getUserManager(),
  43. \OC::$server->getGroupManager(),
  44. 'principals/'
  45. );
  46. $db = \OC::$server->getDatabaseConnection();
  47. $userManager = \OC::$server->getUserManager();
  48. $random = \OC::$server->getSecureRandom();
  49. $dispatcher = \OC::$server->getEventDispatcher();
  50. $calDavBackend = new CalDavBackend($db, $principalBackend, $userManager, $random, $dispatcher, true);
  51. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  52. // Root nodes
  53. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  54. $principalCollection->disableListing = !$debugging; // Disable listing
  55. $addressBookRoot = new CalendarRoot($principalBackend, $calDavBackend);
  56. $addressBookRoot->disableListing = !$debugging; // Disable listing
  57. $nodes = array(
  58. $principalCollection,
  59. $addressBookRoot,
  60. );
  61. // Fire up server
  62. $server = new \Sabre\DAV\Server($nodes);
  63. $server::$exposeVersion = false;
  64. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  65. $server->setBaseUri($baseuri);
  66. // Add plugins
  67. $server->addPlugin(new MaintenancePlugin());
  68. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
  69. $server->addPlugin(new \Sabre\CalDAV\Plugin());
  70. $server->addPlugin(new LegacyDAVACL());
  71. if ($debugging) {
  72. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  73. }
  74. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  75. $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
  76. $server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin());
  77. $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\IMipPlugin( \OC::$server->getMailer(), \OC::$server->getLogger()));
  78. $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger()));
  79. // And off we go!
  80. $server->exec();