caldav.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Thomas Citharel <nextcloud@tcit.fr>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. // Backends
  29. use OCA\DAV\CalDAV\CalDavBackend;
  30. use OCA\DAV\Connector\LegacyDAVACL;
  31. use OCA\DAV\CalDAV\CalendarRoot;
  32. use OCA\DAV\Connector\Sabre\Auth;
  33. use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
  34. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  35. use OCA\DAV\Connector\Sabre\Principal;
  36. $authBackend = new Auth(
  37. \OC::$server->getSession(),
  38. \OC::$server->getUserSession(),
  39. \OC::$server->getRequest(),
  40. \OC::$server->getTwoFactorAuthManager(),
  41. \OC::$server->getBruteForceThrottler(),
  42. 'principals/'
  43. );
  44. $principalBackend = new Principal(
  45. \OC::$server->getUserManager(),
  46. \OC::$server->getGroupManager(),
  47. \OC::$server->getShareManager(),
  48. \OC::$server->getUserSession(),
  49. \OC::$server->getAppManager(),
  50. \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
  51. \OC::$server->getConfig(),
  52. 'principals/'
  53. );
  54. $db = \OC::$server->getDatabaseConnection();
  55. $userManager = \OC::$server->getUserManager();
  56. $random = \OC::$server->getSecureRandom();
  57. $logger = \OC::$server->getLogger();
  58. $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
  59. $legacyDispatcher = \OC::$server->getEventDispatcher();
  60. $calDavBackend = new CalDavBackend($db, $principalBackend, $userManager, \OC::$server->getGroupManager(), $random, $logger, $dispatcher, $legacyDispatcher, true);
  61. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  62. $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes';
  63. // Root nodes
  64. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  65. $principalCollection->disableListing = !$debugging; // Disable listing
  66. $addressBookRoot = new CalendarRoot($principalBackend, $calDavBackend);
  67. $addressBookRoot->disableListing = !$debugging; // Disable listing
  68. $nodes = [
  69. $principalCollection,
  70. $addressBookRoot,
  71. ];
  72. // Fire up server
  73. $server = new \Sabre\DAV\Server($nodes);
  74. $server::$exposeVersion = false;
  75. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  76. $server->setBaseUri($baseuri);
  77. // Add plugins
  78. $server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
  79. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
  80. $server->addPlugin(new \Sabre\CalDAV\Plugin());
  81. $server->addPlugin(new LegacyDAVACL());
  82. if ($debugging) {
  83. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  84. }
  85. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  86. $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
  87. $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig()));
  88. if ($sendInvitations) {
  89. $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
  90. }
  91. $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger()));
  92. // And off we go!
  93. $server->exec();