1
0

caldav.php 3.4 KB

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