You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

caldav.php 3.5KB

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