caldav.php 4.0 KB

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