InvitationResponseServer.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018, Georg Ehrke.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Citharel <nextcloud@tcit.fr>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  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
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\CalDAV\InvitationResponse;
  27. use OCA\DAV\AppInfo\PluginManager;
  28. use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin;
  29. use OCA\DAV\CalDAV\Auth\PublicPrincipalPlugin;
  30. use OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin;
  31. use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
  32. use OCA\DAV\Connector\Sabre\CachingTree;
  33. use OCA\DAV\Connector\Sabre\DavAclPlugin;
  34. use OCA\DAV\Events\SabrePluginAuthInitEvent;
  35. use OCA\DAV\RootCollection;
  36. use OCP\EventDispatcher\IEventDispatcher;
  37. use Psr\Log\LoggerInterface;
  38. use Sabre\VObject\ITip\Message;
  39. class InvitationResponseServer {
  40. /** @var \OCA\DAV\Connector\Sabre\Server */
  41. public $server;
  42. /**
  43. * InvitationResponseServer constructor.
  44. */
  45. public function __construct(bool $public = true) {
  46. $baseUri = \OC::$WEBROOT . '/remote.php/dav/';
  47. $logger = \OC::$server->get(LoggerInterface::class);
  48. /** @var IEventDispatcher $dispatcher */
  49. $dispatcher = \OC::$server->query(IEventDispatcher::class);
  50. $root = new RootCollection();
  51. $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
  52. // Add maintenance plugin
  53. $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav')));
  54. // Set URL explicitly due to reverse-proxy situations
  55. $this->server->httpRequest->setUrl($baseUri);
  56. $this->server->setBaseUri($baseUri);
  57. $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
  58. $this->server->addPlugin(new AnonymousOptionsPlugin());
  59. // allow custom principal uri option
  60. if ($public) {
  61. $this->server->addPlugin(new PublicPrincipalPlugin());
  62. } else {
  63. $this->server->addPlugin(new CustomPrincipalPlugin());
  64. }
  65. // allow setup of additional auth backends
  66. $event = new SabrePluginAuthInitEvent($this->server);
  67. $dispatcher->dispatchTyped($event);
  68. $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
  69. $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
  70. $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
  71. // acl
  72. $acl = new DavAclPlugin();
  73. $acl->principalCollectionSet = [
  74. 'principals/users', 'principals/groups'
  75. ];
  76. $this->server->addPlugin($acl);
  77. // calendar plugins
  78. $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
  79. $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
  80. $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class)));
  81. $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
  82. $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
  83. //$this->server->addPlugin(new \OCA\DAV\DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
  84. $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
  85. \OC::$server->getConfig(),
  86. \OC::$server->getURLGenerator()
  87. ));
  88. // wait with registering these until auth is handled and the filesystem is setup
  89. $this->server->on('beforeMethod:*', function () use ($root): void {
  90. // register plugins from apps
  91. $pluginManager = new PluginManager(
  92. \OC::$server,
  93. \OC::$server->getAppManager()
  94. );
  95. foreach ($pluginManager->getAppPlugins() as $appPlugin) {
  96. $this->server->addPlugin($appPlugin);
  97. }
  98. foreach ($pluginManager->getAppCollections() as $appCollection) {
  99. $root->addChild($appCollection);
  100. }
  101. });
  102. }
  103. /**
  104. * @param Message $iTipMessage
  105. * @return void
  106. */
  107. public function handleITipMessage(Message $iTipMessage) {
  108. /** @var \OCA\DAV\CalDAV\Schedule\Plugin $schedulingPlugin */
  109. $schedulingPlugin = $this->server->getPlugin('caldav-schedule');
  110. $schedulingPlugin->scheduleLocalDelivery($iTipMessage);
  111. }
  112. public function isExternalAttendee(string $principalUri): bool {
  113. /** @var \Sabre\DAVACL\Plugin $aclPlugin */
  114. $aclPlugin = $this->getServer()->getPlugin('acl');
  115. return $aclPlugin->getPrincipalByUri($principalUri) === null;
  116. }
  117. public function getServer(): \OCA\DAV\Connector\Sabre\Server {
  118. return $this->server;
  119. }
  120. }