caldav.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 OC\KnownUser\KnownUserService;
  30. use OCA\DAV\CalDAV\CalDavBackend;
  31. use OCA\DAV\CalDAV\Security\RateLimitingPlugin;
  32. use OCA\DAV\Connector\LegacyDAVACL;
  33. use OCA\DAV\CalDAV\CalendarRoot;
  34. use OCA\DAV\Connector\Sabre\Auth;
  35. use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
  36. use OCA\DAV\Connector\Sabre\MaintenancePlugin;
  37. use OCA\DAV\Connector\Sabre\Principal;
  38. use OCP\Accounts\IAccountManager;
  39. use Psr\Log\LoggerInterface;
  40. $authBackend = new Auth(
  41. \OC::$server->getSession(),
  42. \OC::$server->getUserSession(),
  43. \OC::$server->getRequest(),
  44. \OC::$server->getTwoFactorAuthManager(),
  45. \OC::$server->getBruteForceThrottler(),
  46. 'principals/'
  47. );
  48. $principalBackend = new Principal(
  49. \OC::$server->getUserManager(),
  50. \OC::$server->getGroupManager(),
  51. \OC::$server->get(IAccountManager::class),
  52. \OC::$server->getShareManager(),
  53. \OC::$server->getUserSession(),
  54. \OC::$server->getAppManager(),
  55. \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
  56. \OC::$server->get(KnownUserService::class),
  57. \OC::$server->getConfig(),
  58. \OC::$server->getL10NFactory(),
  59. 'principals/'
  60. );
  61. $db = \OC::$server->getDatabaseConnection();
  62. $userManager = \OC::$server->getUserManager();
  63. $random = \OC::$server->getSecureRandom();
  64. $logger = \OC::$server->get(LoggerInterface::class);
  65. $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
  66. $config = \OC::$server->get(\OCP\IConfig::class);
  67. $calDavBackend = new CalDavBackend(
  68. $db,
  69. $principalBackend,
  70. $userManager,
  71. \OC::$server->getGroupManager(),
  72. $random,
  73. $logger,
  74. $dispatcher,
  75. $config,
  76. true
  77. );
  78. $debugging = \OC::$server->getConfig()->getSystemValue('debug', false);
  79. $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes';
  80. // Root nodes
  81. $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
  82. $principalCollection->disableListing = !$debugging; // Disable listing
  83. $addressBookRoot = new CalendarRoot($principalBackend, $calDavBackend, 'principals', $logger);
  84. $addressBookRoot->disableListing = !$debugging; // Disable listing
  85. $nodes = [
  86. $principalCollection,
  87. $addressBookRoot,
  88. ];
  89. // Fire up server
  90. $server = new \Sabre\DAV\Server($nodes);
  91. $server::$exposeVersion = false;
  92. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  93. $server->setBaseUri($baseuri);
  94. // Add plugins
  95. $server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
  96. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
  97. $server->addPlugin(new \Sabre\CalDAV\Plugin());
  98. $server->addPlugin(new LegacyDAVACL());
  99. if ($debugging) {
  100. $server->addPlugin(new Sabre\DAV\Browser\Plugin());
  101. }
  102. $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  103. $server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
  104. $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class)));
  105. if ($sendInvitations) {
  106. $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
  107. }
  108. $server->addPlugin(new ExceptionLoggerPlugin('caldav', $logger));
  109. $server->addPlugin(\OCP\Server::get(RateLimitingPlugin::class));
  110. // And off we go!
  111. $server->exec();