2015-10-21 09:06:48 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2016-01-12 09:02:16 -05:00
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-01-12 09:02:16 -05:00
|
|
|
*/
|
2015-10-21 09:06:48 -04:00
|
|
|
namespace OCA\DAV;
|
|
|
|
|
|
2024-10-10 06:40:31 -04:00
|
|
|
use OC\Files\Filesystem;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\DAV\AppInfo\PluginManager;
|
2022-03-31 09:34:57 -04:00
|
|
|
use OCA\DAV\BulkUpload\BulkUploadPlugin;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin;
|
2017-11-10 20:02:17 -05:00
|
|
|
use OCA\DAV\CalDAV\BirthdayService;
|
2024-06-04 09:58:39 -04:00
|
|
|
use OCA\DAV\CalDAV\DefaultCalendarValidator;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\DAV\CalDAV\EventComparisonService;
|
|
|
|
|
use OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin;
|
|
|
|
|
use OCA\DAV\CalDAV\Publishing\PublishPlugin;
|
2024-04-29 14:29:17 -04:00
|
|
|
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\DAV\CalDAV\Schedule\IMipService;
|
2023-08-11 10:36:10 -04:00
|
|
|
use OCA\DAV\CalDAV\Security\RateLimitingPlugin;
|
2024-07-04 18:56:27 -04:00
|
|
|
use OCA\DAV\CalDAV\Validation\CalDavValidatePlugin;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\DAV\CardDAV\HasPhotoPlugin;
|
2016-06-21 09:25:44 -04:00
|
|
|
use OCA\DAV\CardDAV\ImageExportPlugin;
|
2018-10-24 02:22:31 -04:00
|
|
|
use OCA\DAV\CardDAV\MultiGetExportPlugin;
|
2017-05-03 08:22:02 -04:00
|
|
|
use OCA\DAV\CardDAV\PhotoCache;
|
2024-04-04 18:00:49 -04:00
|
|
|
use OCA\DAV\CardDAV\Security\CardDavRateLimitingPlugin;
|
2024-06-28 10:37:24 -04:00
|
|
|
use OCA\DAV\CardDAV\Validation\CardDavValidatePlugin;
|
2016-09-23 13:57:07 -04:00
|
|
|
use OCA\DAV\Comments\CommentsPlugin;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\AppleQuirksPlugin;
|
2015-10-21 09:06:48 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\Auth;
|
2017-05-18 14:09:51 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\BearerAuth;
|
2015-10-21 09:06:48 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
|
2017-06-14 12:11:55 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\CachingTree;
|
2021-06-04 10:22:39 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\ChecksumUpdatePlugin;
|
2016-11-08 04:03:25 -05:00
|
|
|
use OCA\DAV\Connector\Sabre\CommentPropertiesPlugin;
|
2016-09-23 13:57:07 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin;
|
2016-02-29 11:30:02 -05:00
|
|
|
use OCA\DAV\Connector\Sabre\DavAclPlugin;
|
2016-03-17 11:51:19 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\DummyGetResponsePlugin;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
|
2016-09-23 13:57:07 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\FakeLockerPlugin;
|
2016-02-18 14:11:59 -05:00
|
|
|
use OCA\DAV\Connector\Sabre\FilesPlugin;
|
2016-11-08 04:03:25 -05:00
|
|
|
use OCA\DAV\Connector\Sabre\FilesReportPlugin;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\LockPlugin;
|
|
|
|
|
use OCA\DAV\Connector\Sabre\MaintenancePlugin;
|
2020-04-02 09:17:04 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\PropfindCompressionPlugin;
|
2025-07-29 11:07:08 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\PropFindMonitorPlugin;
|
2025-08-05 07:12:00 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\PropFindPreloadNotifyPlugin;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\DAV\Connector\Sabre\QuotaPlugin;
|
2022-03-31 09:34:57 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\RequestIdHeaderPlugin;
|
2016-11-08 04:03:25 -05:00
|
|
|
use OCA\DAV\Connector\Sabre\SharesPlugin;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\DAV\Connector\Sabre\TagsPlugin;
|
2024-09-16 06:51:18 -04:00
|
|
|
use OCA\DAV\Connector\Sabre\ZipFolderPlugin;
|
2017-03-27 13:15:51 -04:00
|
|
|
use OCA\DAV\DAV\CustomPropertiesBackend;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\DAV\DAV\PublicAuth;
|
2022-05-18 08:54:27 -04:00
|
|
|
use OCA\DAV\DAV\ViewOnlyPlugin;
|
2025-08-13 05:03:40 -04:00
|
|
|
use OCA\DAV\Db\PropertyMapper;
|
2023-07-11 05:50:07 -04:00
|
|
|
use OCA\DAV\Events\SabrePluginAddEvent;
|
2020-10-27 10:23:27 -04:00
|
|
|
use OCA\DAV\Events\SabrePluginAuthInitEvent;
|
2024-10-30 07:25:26 -04:00
|
|
|
use OCA\DAV\Files\BrowserErrorPagePlugin;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCA\DAV\Files\FileSearchBackend;
|
2018-06-28 08:53:44 -04:00
|
|
|
use OCA\DAV\Files\LazySearchBackend;
|
2024-10-10 03:48:53 -04:00
|
|
|
use OCA\DAV\Paginate\PaginatePlugin;
|
2022-03-31 09:34:57 -04:00
|
|
|
use OCA\DAV\Profiler\ProfilerPlugin;
|
2017-10-19 06:57:20 -04:00
|
|
|
use OCA\DAV\Provisioning\Apple\AppleProvisioningPlugin;
|
2016-09-23 13:57:07 -04:00
|
|
|
use OCA\DAV\SystemTag\SystemTagPlugin;
|
2017-07-31 16:46:19 -04:00
|
|
|
use OCA\DAV\Upload\ChunkingPlugin;
|
2021-05-06 12:26:42 -04:00
|
|
|
use OCA\DAV\Upload\ChunkingV2Plugin;
|
2025-06-19 08:41:08 -04:00
|
|
|
use OCA\DAV\Upload\UploadAutoMkcolPlugin;
|
2024-09-06 08:39:32 -04:00
|
|
|
use OCA\Theming\ThemingDefaults;
|
2025-04-29 10:42:09 -04:00
|
|
|
use OCP\Accounts\IAccountManager;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\App\IAppManager;
|
2022-03-31 09:34:57 -04:00
|
|
|
use OCP\AppFramework\Http\Response;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\Comments\ICommentsManager;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCP\Defaults;
|
2022-03-31 09:34:57 -04:00
|
|
|
use OCP\Diagnostics\IEventLogger;
|
2020-10-27 10:23:27 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2024-08-27 06:59:06 -04:00
|
|
|
use OCP\Files\IFilenameValidator;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\Files\IRootFolder;
|
2023-11-06 20:21:29 -05:00
|
|
|
use OCP\FilesMetadata\IFilesMetadataManager;
|
2024-09-17 07:45:44 -04:00
|
|
|
use OCP\IAppConfig;
|
2021-05-06 12:26:42 -04:00
|
|
|
use OCP\ICacheFactory;
|
2024-08-27 06:59:06 -04:00
|
|
|
use OCP\IConfig;
|
2025-08-14 04:01:33 -04:00
|
|
|
use OCP\IDateTimeZone;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\IGroupManager;
|
2024-08-27 06:59:06 -04:00
|
|
|
use OCP\IPreview;
|
2015-10-21 09:06:48 -04:00
|
|
|
use OCP\IRequest;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\ISession;
|
|
|
|
|
use OCP\ITagManager;
|
|
|
|
|
use OCP\IURLGenerator;
|
2024-08-27 06:59:06 -04:00
|
|
|
use OCP\IUserSession;
|
2024-10-10 06:40:31 -04:00
|
|
|
use OCP\Mail\IMailer;
|
2022-03-31 09:34:57 -04:00
|
|
|
use OCP\Profiler\IProfiler;
|
2015-12-04 06:11:07 -05:00
|
|
|
use OCP\SabrePluginEvent;
|
2025-02-03 09:34:01 -05:00
|
|
|
use OCP\Security\Bruteforce\IThrottler;
|
|
|
|
|
use OCP\SystemTag\ISystemTagManager;
|
|
|
|
|
use OCP\SystemTag\ISystemTagObjectMapper;
|
2022-03-31 09:34:57 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2016-04-10 06:43:15 -04:00
|
|
|
use Sabre\CardDAV\VCFExportPlugin;
|
2015-10-21 09:06:48 -04:00
|
|
|
use Sabre\DAV\Auth\Plugin;
|
2017-10-19 06:57:20 -04:00
|
|
|
use Sabre\DAV\UUIDUtil;
|
2017-02-02 12:20:08 -05:00
|
|
|
use SearchDAV\DAV\SearchPlugin;
|
2015-10-21 09:06:48 -04:00
|
|
|
|
|
|
|
|
class Server {
|
2022-01-19 17:30:34 -05:00
|
|
|
public Connector\Sabre\Server $server;
|
|
|
|
|
private IProfiler $profiler;
|
|
|
|
|
|
2024-10-18 06:04:22 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private IRequest $request,
|
|
|
|
|
private string $baseUri,
|
|
|
|
|
) {
|
2025-07-29 11:07:08 -04:00
|
|
|
$debugEnabled = \OCP\Server::get(IConfig::class)->getSystemValue('debug', false);
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->profiler = \OCP\Server::get(IProfiler::class);
|
2022-01-19 17:30:34 -05:00
|
|
|
if ($this->profiler->isEnabled()) {
|
|
|
|
|
/** @var IEventLogger $eventLogger */
|
2025-02-03 09:34:01 -05:00
|
|
|
$eventLogger = \OCP\Server::get(IEventLogger::class);
|
2022-01-19 17:30:34 -05:00
|
|
|
$eventLogger->start('runtime', 'DAV Runtime');
|
|
|
|
|
}
|
2015-10-21 09:06:48 -04:00
|
|
|
|
2024-09-28 16:16:42 -04:00
|
|
|
$logger = \OCP\Server::get(LoggerInterface::class);
|
|
|
|
|
$eventDispatcher = \OCP\Server::get(IEventDispatcher::class);
|
2015-11-16 10:09:04 -05:00
|
|
|
|
2015-10-21 09:06:48 -04:00
|
|
|
$root = new RootCollection();
|
2017-06-14 12:11:55 -04:00
|
|
|
$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
|
2025-07-29 11:07:08 -04:00
|
|
|
$this->server->setLogger($logger);
|
2015-10-21 09:06:48 -04:00
|
|
|
|
2017-04-10 18:57:31 -04:00
|
|
|
// Add maintenance plugin
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->server->addPlugin(new MaintenancePlugin(\OCP\Server::get(IConfig::class), \OC::$server->getL10N('dav')));
|
2017-04-10 18:57:31 -04:00
|
|
|
|
2024-10-10 06:40:31 -04:00
|
|
|
$this->server->addPlugin(new AppleQuirksPlugin());
|
2023-02-21 15:17:34 -05:00
|
|
|
|
2015-10-21 09:06:48 -04:00
|
|
|
// Backends
|
2015-10-26 08:02:10 -04:00
|
|
|
$authBackend = new Auth(
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(ISession::class),
|
|
|
|
|
\OCP\Server::get(IUserSession::class),
|
|
|
|
|
\OCP\Server::get(IRequest::class),
|
|
|
|
|
\OCP\Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
|
2025-07-11 11:07:44 -04:00
|
|
|
\OCP\Server::get(IThrottler::class)
|
2015-10-26 08:02:10 -04:00
|
|
|
);
|
2015-10-21 09:06:48 -04:00
|
|
|
|
|
|
|
|
// Set URL explicitly due to reverse-proxy situations
|
|
|
|
|
$this->server->httpRequest->setUrl($this->request->getRequestUri());
|
|
|
|
|
$this->server->setBaseUri($this->baseUri);
|
|
|
|
|
|
2022-01-19 17:30:34 -05:00
|
|
|
$this->server->addPlugin(new ProfilerPlugin($this->request));
|
2024-09-06 08:39:32 -04:00
|
|
|
$this->server->addPlugin(new BlockLegacyClientPlugin(
|
|
|
|
|
\OCP\Server::get(IConfig::class),
|
|
|
|
|
\OCP\Server::get(ThemingDefaults::class),
|
|
|
|
|
));
|
2018-05-22 07:40:54 -04:00
|
|
|
$this->server->addPlugin(new AnonymousOptionsPlugin());
|
2016-10-20 06:51:54 -04:00
|
|
|
$authPlugin = new Plugin();
|
|
|
|
|
$authPlugin->addBackend(new PublicAuth());
|
|
|
|
|
$this->server->addPlugin($authPlugin);
|
2015-12-04 06:11:07 -05:00
|
|
|
|
|
|
|
|
// allow setup of additional auth backends
|
|
|
|
|
$event = new SabrePluginEvent($this->server);
|
2024-09-28 16:16:42 -04:00
|
|
|
$eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
|
2015-12-04 06:11:07 -05:00
|
|
|
|
2020-10-28 08:24:17 -04:00
|
|
|
$newAuthEvent = new SabrePluginAuthInitEvent($this->server);
|
2024-09-28 16:16:42 -04:00
|
|
|
$eventDispatcher->dispatchTyped($newAuthEvent);
|
2020-10-27 10:23:27 -04:00
|
|
|
|
2017-05-18 14:09:51 -04:00
|
|
|
$bearerAuthBackend = new BearerAuth(
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IUserSession::class),
|
|
|
|
|
\OCP\Server::get(ISession::class),
|
2025-02-17 08:34:01 -05:00
|
|
|
\OCP\Server::get(IRequest::class),
|
|
|
|
|
\OCP\Server::get(IConfig::class),
|
2017-05-18 14:09:51 -04:00
|
|
|
);
|
|
|
|
|
$authPlugin->addBackend($bearerAuthBackend);
|
2016-07-14 10:19:31 -04:00
|
|
|
// because we are throwing exceptions this plugin has to be the last one
|
|
|
|
|
$authPlugin->addBackend($authBackend);
|
|
|
|
|
|
2016-03-17 11:51:19 -04:00
|
|
|
// debugging
|
2025-07-29 11:07:08 -04:00
|
|
|
if ($debugEnabled) {
|
|
|
|
|
$this->server->debugEnabled = true;
|
|
|
|
|
$this->server->addPlugin(new PropFindMonitorPlugin());
|
2016-03-17 11:51:19 -04:00
|
|
|
$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
|
|
|
|
|
} else {
|
|
|
|
|
$this->server->addPlugin(new DummyGetResponsePlugin());
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 06:40:31 -04:00
|
|
|
$this->server->addPlugin(new ExceptionLoggerPlugin('webdav', $logger));
|
|
|
|
|
$this->server->addPlugin(new LockPlugin());
|
2015-11-23 07:53:57 -05:00
|
|
|
$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
|
2015-10-21 09:06:48 -04:00
|
|
|
|
2015-11-24 05:15:31 -05:00
|
|
|
// acl
|
2016-02-29 11:30:02 -05:00
|
|
|
$acl = new DavAclPlugin();
|
2016-05-02 08:19:10 -04:00
|
|
|
$acl->principalCollectionSet = [
|
2019-08-06 07:40:52 -04:00
|
|
|
'principals/users',
|
|
|
|
|
'principals/groups',
|
2018-05-28 14:12:13 -04:00
|
|
|
'principals/calendar-resources',
|
|
|
|
|
'principals/calendar-rooms',
|
2016-05-02 08:19:10 -04:00
|
|
|
];
|
2015-11-24 05:15:31 -05:00
|
|
|
$this->server->addPlugin($acl);
|
|
|
|
|
|
2015-10-30 20:28:21 -04:00
|
|
|
// calendar plugins
|
2018-05-28 14:12:13 -04:00
|
|
|
if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) {
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class)));
|
2018-04-23 03:50:13 -04:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->server->addPlugin(new ICSExportPlugin(\OCP\Server::get(IConfig::class), $logger));
|
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OCP\Server::get(IConfig::class), \OCP\Server::get(LoggerInterface::class), \OCP\Server::get(DefaultCalendarValidator::class)));
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->server->addPlugin(\OCP\Server::get(\OCA\DAV\CalDAV\Trashbin\Plugin::class));
|
2024-10-18 06:04:22 -04:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($this->request));
|
2025-02-03 09:34:01 -05:00
|
|
|
if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') {
|
2022-10-02 10:38:01 -04:00
|
|
|
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
|
|
|
|
|
}
|
2018-06-28 07:07:33 -04:00
|
|
|
|
2018-04-23 03:50:13 -04:00
|
|
|
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
|
2024-10-10 06:40:31 -04:00
|
|
|
$this->server->addPlugin(new PublishPlugin(
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IConfig::class),
|
|
|
|
|
\OCP\Server::get(IURLGenerator::class)
|
2018-04-23 03:50:13 -04:00
|
|
|
));
|
2023-08-11 10:36:10 -04:00
|
|
|
|
|
|
|
|
$this->server->addPlugin(\OCP\Server::get(RateLimitingPlugin::class));
|
2024-07-04 18:56:27 -04:00
|
|
|
$this->server->addPlugin(\OCP\Server::get(CalDavValidatePlugin::class));
|
2017-10-11 07:14:56 -04:00
|
|
|
}
|
2015-11-09 07:27:19 -05:00
|
|
|
|
2015-10-30 20:28:21 -04:00
|
|
|
// addressbook plugins
|
2018-04-23 07:54:58 -04:00
|
|
|
if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class)));
|
2018-04-23 03:50:13 -04:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
|
|
|
|
|
$this->server->addPlugin(new VCFExportPlugin());
|
2018-10-24 02:22:31 -04:00
|
|
|
$this->server->addPlugin(new MultiGetExportPlugin());
|
2019-02-26 11:19:26 -05:00
|
|
|
$this->server->addPlugin(new HasPhotoPlugin());
|
2025-05-15 11:08:41 -04:00
|
|
|
$this->server->addPlugin(new ImageExportPlugin(\OCP\Server::get(PhotoCache::class)));
|
2024-04-04 18:00:49 -04:00
|
|
|
|
|
|
|
|
$this->server->addPlugin(\OCP\Server::get(CardDavRateLimitingPlugin::class));
|
2024-06-28 10:37:24 -04:00
|
|
|
$this->server->addPlugin(\OCP\Server::get(CardDavValidatePlugin::class));
|
2018-04-23 03:50:13 -04:00
|
|
|
}
|
2015-11-10 01:27:34 -05:00
|
|
|
|
2015-11-27 06:54:31 -05:00
|
|
|
// system tags plugins
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->server->addPlugin(\OCP\Server::get(SystemTagPlugin::class));
|
2015-11-27 06:54:31 -05:00
|
|
|
|
2016-01-11 12:09:00 -05:00
|
|
|
// comments plugin
|
2016-09-23 13:57:07 -04:00
|
|
|
$this->server->addPlugin(new CommentsPlugin(
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(ICommentsManager::class),
|
|
|
|
|
\OCP\Server::get(IUserSession::class)
|
2016-01-11 12:09:00 -05:00
|
|
|
));
|
|
|
|
|
|
2025-08-05 07:12:00 -04:00
|
|
|
// performance improvement plugins
|
2016-09-23 13:57:07 -04:00
|
|
|
$this->server->addPlugin(new CopyEtagHeaderPlugin());
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->server->addPlugin(new RequestIdHeaderPlugin(\OCP\Server::get(IRequest::class)));
|
2025-06-19 08:41:08 -04:00
|
|
|
$this->server->addPlugin(new UploadAutoMkcolPlugin());
|
2021-05-06 12:26:42 -04:00
|
|
|
$this->server->addPlugin(new ChunkingV2Plugin(\OCP\Server::get(ICacheFactory::class)));
|
2017-07-31 16:46:19 -04:00
|
|
|
$this->server->addPlugin(new ChunkingPlugin());
|
2024-09-16 06:51:18 -04:00
|
|
|
$this->server->addPlugin(new ZipFolderPlugin(
|
|
|
|
|
$this->server->tree,
|
|
|
|
|
$logger,
|
2024-09-28 16:16:42 -04:00
|
|
|
$eventDispatcher,
|
2025-08-14 04:01:33 -04:00
|
|
|
\OCP\Server::get(IDateTimeZone::class),
|
2024-09-16 06:51:18 -04:00
|
|
|
));
|
2024-10-10 03:48:53 -04:00
|
|
|
$this->server->addPlugin(\OCP\Server::get(PaginatePlugin::class));
|
2025-08-05 07:12:00 -04:00
|
|
|
$this->server->addPlugin(new PropFindPreloadNotifyPlugin());
|
2016-09-23 13:57:07 -04:00
|
|
|
|
2017-08-30 06:15:01 -04:00
|
|
|
// allow setup of additional plugins
|
2024-09-28 16:16:42 -04:00
|
|
|
$eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
|
2023-07-11 05:50:07 -04:00
|
|
|
$typedEvent = new SabrePluginAddEvent($this->server);
|
2024-09-28 16:16:42 -04:00
|
|
|
$eventDispatcher->dispatchTyped($typedEvent);
|
2017-08-30 06:15:01 -04:00
|
|
|
|
2016-01-26 11:31:01 -05:00
|
|
|
// Some WebDAV clients do require Class 2 WebDAV support (locking), since
|
|
|
|
|
// we do not provide locking we emulate it using a fake locking plugin.
|
2024-10-18 06:04:22 -04:00
|
|
|
if ($this->request->isUserAgent([
|
2016-01-26 11:31:01 -05:00
|
|
|
'/WebDAVFS/',
|
2018-03-26 15:32:12 -04:00
|
|
|
'/OneNote/',
|
2017-03-07 11:24:26 -05:00
|
|
|
'/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
|
2016-01-26 11:31:01 -05:00
|
|
|
])) {
|
2016-09-23 13:57:07 -04:00
|
|
|
$this->server->addPlugin(new FakeLockerPlugin());
|
2015-11-13 05:47:32 -05:00
|
|
|
}
|
|
|
|
|
|
2024-10-30 07:25:26 -04:00
|
|
|
if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
|
|
|
|
|
$this->server->addPlugin(new BrowserErrorPagePlugin());
|
|
|
|
|
}
|
2016-03-24 09:29:55 -04:00
|
|
|
|
2018-06-28 08:53:44 -04:00
|
|
|
$lazySearchBackend = new LazySearchBackend();
|
|
|
|
|
$this->server->addPlugin(new SearchPlugin($lazySearchBackend));
|
|
|
|
|
|
2015-10-21 09:06:48 -04:00
|
|
|
// wait with registering these until auth is handled and the filesystem is setup
|
2024-09-20 11:38:36 -04:00
|
|
|
$this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger): void {
|
2024-02-26 10:57:30 -05:00
|
|
|
// Allow view-only plugin for webdav requests
|
|
|
|
|
$this->server->addPlugin(new ViewOnlyPlugin(
|
|
|
|
|
\OC::$server->getUserFolder(),
|
|
|
|
|
));
|
|
|
|
|
|
2015-10-21 09:06:48 -04:00
|
|
|
// custom properties plugin must be the last one
|
2025-02-03 09:34:01 -05:00
|
|
|
$userSession = \OCP\Server::get(IUserSession::class);
|
2016-10-04 10:08:22 -04:00
|
|
|
$user = $userSession->getUser();
|
2016-11-08 04:03:25 -05:00
|
|
|
if ($user !== null) {
|
2024-10-10 06:40:31 -04:00
|
|
|
$view = Filesystem::getView();
|
2024-08-27 06:59:06 -04:00
|
|
|
$config = \OCP\Server::get(IConfig::class);
|
2016-04-18 05:18:50 -04:00
|
|
|
$this->server->addPlugin(
|
|
|
|
|
new FilesPlugin(
|
|
|
|
|
$this->server->tree,
|
2024-08-27 06:59:06 -04:00
|
|
|
$config,
|
2016-06-09 05:29:20 -04:00
|
|
|
$this->request,
|
2024-08-27 06:59:06 -04:00
|
|
|
\OCP\Server::get(IPreview::class),
|
|
|
|
|
\OCP\Server::get(IUserSession::class),
|
|
|
|
|
\OCP\Server::get(IFilenameValidator::class),
|
2025-04-29 10:42:09 -04:00
|
|
|
\OCP\Server::get(IAccountManager::class),
|
2016-04-18 05:18:50 -04:00
|
|
|
false,
|
2024-08-27 06:59:06 -04:00
|
|
|
$config->getSystemValueBool('debug', false) === false,
|
2016-04-18 05:18:50 -04:00
|
|
|
)
|
|
|
|
|
);
|
2021-06-04 10:22:39 -04:00
|
|
|
$this->server->addPlugin(new ChecksumUpdatePlugin());
|
2016-02-18 14:11:59 -05:00
|
|
|
|
2015-10-21 09:06:48 -04:00
|
|
|
$this->server->addPlugin(
|
|
|
|
|
new \Sabre\DAV\PropertyStorage\Plugin(
|
|
|
|
|
new CustomPropertiesBackend(
|
2024-02-21 16:29:09 -05:00
|
|
|
$this->server,
|
2015-10-21 09:06:48 -04:00
|
|
|
$this->server->tree,
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IDBConnection::class),
|
|
|
|
|
\OCP\Server::get(IUserSession::class)->getUser(),
|
2025-08-13 05:03:40 -04:00
|
|
|
\OCP\Server::get(PropertyMapper::class),
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(DefaultCalendarValidator::class),
|
2015-10-21 09:06:48 -04:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
2016-11-08 04:03:25 -05:00
|
|
|
if ($view !== null) {
|
|
|
|
|
$this->server->addPlugin(
|
2021-07-21 11:06:03 -04:00
|
|
|
new QuotaPlugin($view));
|
2016-11-08 04:03:25 -05:00
|
|
|
}
|
2016-09-12 10:20:49 -04:00
|
|
|
$this->server->addPlugin(
|
|
|
|
|
new TagsPlugin(
|
2025-02-03 09:34:01 -05:00
|
|
|
$this->server->tree, \OCP\Server::get(ITagManager::class), \OCP\Server::get(IEventDispatcher::class), \OCP\Server::get(IUserSession::class)
|
2016-09-12 10:20:49 -04:00
|
|
|
)
|
|
|
|
|
);
|
2024-06-06 12:55:33 -04:00
|
|
|
|
2016-10-04 10:08:22 -04:00
|
|
|
// TODO: switch to LazyUserFolder
|
|
|
|
|
$userFolder = \OC::$server->getUserFolder();
|
2024-06-06 12:55:33 -04:00
|
|
|
$shareManager = \OCP\Server::get(\OCP\Share\IManager::class);
|
2016-11-08 04:03:25 -05:00
|
|
|
$this->server->addPlugin(new SharesPlugin(
|
2016-10-04 10:08:22 -04:00
|
|
|
$this->server->tree,
|
|
|
|
|
$userSession,
|
|
|
|
|
$userFolder,
|
2024-06-06 12:55:33 -04:00
|
|
|
$shareManager,
|
2016-10-04 10:08:22 -04:00
|
|
|
));
|
2016-11-08 04:03:25 -05:00
|
|
|
$this->server->addPlugin(new CommentPropertiesPlugin(
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(ICommentsManager::class),
|
2016-10-04 10:08:22 -04:00
|
|
|
$userSession
|
|
|
|
|
));
|
2025-02-03 09:34:01 -05:00
|
|
|
if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
|
2024-04-29 14:29:17 -04:00
|
|
|
$this->server->addPlugin(new IMipPlugin(
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IAppConfig::class),
|
|
|
|
|
\OCP\Server::get(IMailer::class),
|
|
|
|
|
\OCP\Server::get(LoggerInterface::class),
|
|
|
|
|
\OCP\Server::get(ITimeFactory::class),
|
|
|
|
|
\OCP\Server::get(Defaults::class),
|
2024-04-30 10:30:12 -04:00
|
|
|
$userSession,
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IMipService::class),
|
|
|
|
|
\OCP\Server::get(EventComparisonService::class),
|
|
|
|
|
\OCP\Server::get(\OCP\Mail\Provider\IManager::class)
|
2024-04-29 14:29:17 -04:00
|
|
|
));
|
|
|
|
|
}
|
2017-03-25 06:56:40 -04:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
|
2016-11-08 04:03:25 -05:00
|
|
|
if ($view !== null) {
|
|
|
|
|
$this->server->addPlugin(new FilesReportPlugin(
|
|
|
|
|
$this->server->tree,
|
|
|
|
|
$view,
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(ISystemTagManager::class),
|
|
|
|
|
\OCP\Server::get(ISystemTagObjectMapper::class),
|
|
|
|
|
\OCP\Server::get(ITagManager::class),
|
2016-11-08 04:03:25 -05:00
|
|
|
$userSession,
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IGroupManager::class),
|
2019-03-12 19:42:39 -04:00
|
|
|
$userFolder,
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IAppManager::class)
|
2016-11-08 04:03:25 -05:00
|
|
|
));
|
2024-10-10 06:40:31 -04:00
|
|
|
$lazySearchBackend->setBackend(new FileSearchBackend(
|
2025-05-20 07:12:56 -04:00
|
|
|
$this->server,
|
2017-02-02 12:20:08 -05:00
|
|
|
$this->server->tree,
|
|
|
|
|
$user,
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IRootFolder::class),
|
2024-06-06 12:55:33 -04:00
|
|
|
$shareManager,
|
2023-11-06 20:21:29 -05:00
|
|
|
$view,
|
|
|
|
|
\OCP\Server::get(IFilesMetadataManager::class)
|
2018-06-28 08:53:44 -04:00
|
|
|
));
|
2021-09-16 13:09:38 -04:00
|
|
|
$this->server->addPlugin(
|
2022-08-29 04:37:08 -04:00
|
|
|
new BulkUploadPlugin(
|
|
|
|
|
$userFolder,
|
|
|
|
|
$logger
|
|
|
|
|
)
|
2021-09-16 13:09:38 -04:00
|
|
|
);
|
2016-11-08 04:03:25 -05:00
|
|
|
}
|
2024-10-10 06:40:31 -04:00
|
|
|
$this->server->addPlugin(new EnablePlugin(
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IConfig::class),
|
|
|
|
|
\OCP\Server::get(BirthdayService::class),
|
2023-08-18 03:02:59 -04:00
|
|
|
$user
|
2017-10-20 10:53:02 -04:00
|
|
|
));
|
2017-10-19 06:57:20 -04:00
|
|
|
$this->server->addPlugin(new AppleProvisioningPlugin(
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IUserSession::class),
|
|
|
|
|
\OCP\Server::get(IURLGenerator::class),
|
|
|
|
|
\OCP\Server::get(ThemingDefaults::class),
|
|
|
|
|
\OCP\Server::get(IRequest::class),
|
2017-10-19 06:57:20 -04:00
|
|
|
\OC::$server->getL10N('dav'),
|
2020-04-09 07:53:40 -04:00
|
|
|
function () {
|
2017-10-19 06:57:20 -04:00
|
|
|
return UUIDUtil::getUUID();
|
|
|
|
|
}
|
|
|
|
|
));
|
2015-10-21 09:06:48 -04:00
|
|
|
}
|
2016-12-06 18:19:14 -05:00
|
|
|
|
|
|
|
|
// register plugins from apps
|
|
|
|
|
$pluginManager = new PluginManager(
|
|
|
|
|
\OC::$server,
|
2025-02-03 09:34:01 -05:00
|
|
|
\OCP\Server::get(IAppManager::class)
|
2016-12-06 18:19:14 -05:00
|
|
|
);
|
|
|
|
|
foreach ($pluginManager->getAppPlugins() as $appPlugin) {
|
|
|
|
|
$this->server->addPlugin($appPlugin);
|
|
|
|
|
}
|
|
|
|
|
foreach ($pluginManager->getAppCollections() as $appCollection) {
|
|
|
|
|
$root->addChild($appCollection);
|
|
|
|
|
}
|
2015-10-21 09:06:48 -04:00
|
|
|
});
|
2020-04-02 09:17:04 -04:00
|
|
|
|
|
|
|
|
$this->server->addPlugin(
|
|
|
|
|
new PropfindCompressionPlugin()
|
|
|
|
|
);
|
2015-10-21 09:06:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function exec() {
|
2022-02-22 04:53:13 -05:00
|
|
|
/** @var IEventLogger $eventLogger */
|
2025-02-03 09:34:01 -05:00
|
|
|
$eventLogger = \OCP\Server::get(IEventLogger::class);
|
2022-02-22 04:53:13 -05:00
|
|
|
$eventLogger->start('dav_server_exec', '');
|
2024-07-22 13:35:45 -04:00
|
|
|
$this->server->start();
|
2022-02-22 04:53:13 -05:00
|
|
|
$eventLogger->end('dav_server_exec');
|
2022-01-19 17:30:34 -05:00
|
|
|
if ($this->profiler->isEnabled()) {
|
|
|
|
|
$eventLogger->end('runtime');
|
2025-02-03 09:34:01 -05:00
|
|
|
$profile = $this->profiler->collect(\OCP\Server::get(IRequest::class), new Response());
|
2022-01-19 17:30:34 -05:00
|
|
|
$this->profiler->saveProfile($profile);
|
|
|
|
|
}
|
2015-10-21 09:06:48 -04:00
|
|
|
}
|
2018-04-23 03:50:13 -04:00
|
|
|
|
2018-04-23 07:54:58 -04:00
|
|
|
private function requestIsForSubtree(array $subTrees): bool {
|
|
|
|
|
foreach ($subTrees as $subTree) {
|
|
|
|
|
$subTree = trim($subTree, ' /');
|
2023-06-02 08:08:19 -04:00
|
|
|
if (str_starts_with($this->server->getRequestUri(), $subTree . '/')) {
|
2018-04-23 07:54:58 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2018-04-23 03:50:13 -04:00
|
|
|
}
|
2023-11-08 07:26:56 -05:00
|
|
|
|
2015-10-21 09:06:48 -04:00
|
|
|
}
|