diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index 34cd37641978f..4945e4fe17835 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -26,59 +26,92 @@ * */ // Backends +use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager; use OC\KnownUser\KnownUserService; +use OC\Security\Bruteforce\Throttler; use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\CalDAV\Proxy\ProxyMapper; +use OCA\DAV\CalDAV\Schedule\IMipPlugin; +use OCA\DAV\CalDAV\Schedule\Plugin as SchedulePlugin; use OCA\DAV\Connector\LegacyDAVACL; use OCA\DAV\CalDAV\CalendarRoot; use OCA\DAV\Connector\Sabre\Auth; use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin; use OCA\DAV\Connector\Sabre\MaintenancePlugin; use OCA\DAV\Connector\Sabre\Principal; +use OCP\App\IAppManager; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\IRequest; +use OCP\IUserManager; +use OCP\IUserSession; +use OCP\L10N\IFactory as IL10NFactory; +use OCP\Security\ISecureRandom; +use OCP\Share\IManager as IShareManager; +use Psr\Log\LoggerInterface; +use Sabre\CalDAV\ICSExportPlugin; +use Sabre\CalDAV\Plugin as CalDAVPlugin; +use Sabre\CalDAV\Principal\Collection; +use Sabre\DAV\Auth\Plugin as AuthPlugin; +use Sabre\DAV\Browser\Plugin as BrowserPlugin; +use Sabre\DAV\Server; +use Sabre\DAV\Sync\Plugin as SyncPlugin; + +/** @var IUserSession $userSession */ +$userSession = \OC::$server->get(IUserSession::class); +/** @var IRequest $request */ +$request = \OC::$server->get(IRequest::class); +/** @var IUserManager $userManager */ +$userManager = \OC::$server->get(IUserManager::class); +/** @var IGroupManager $groupManager */ +$groupManager = \OC::$server->get(IGroupManager::class); +/** @var IConfig $config */ +$config = \OC::$server->get(IConfig::class); +/** @var IL10NFactory $l10nFactory */ +$l10nFactory = \OC::$server->get(IL10NFactory::class); +/** @var LoggerInterface $logger */ +$logger = \OC::$server->get(LoggerInterface::class); $authBackend = new Auth( - \OC::$server->getSession(), - \OC::$server->getUserSession(), - \OC::$server->getRequest(), - \OC::$server->getTwoFactorAuthManager(), - \OC::$server->getBruteForceThrottler(), + $userSession->getSession(), + $userSession, + $request, + \OC::$server->get(TwoFactorAuthManager::class), + \OC::$server->get(Throttler::class), 'principals/' ); $principalBackend = new Principal( - \OC::$server->getUserManager(), - \OC::$server->getGroupManager(), - \OC::$server->getShareManager(), - \OC::$server->getUserSession(), - \OC::$server->getAppManager(), - \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class), + $userManager, + $groupManager, + \OC::$server->get(IShareManager::class), + $userSession, + \OC::$server->get(IAppManager::class), + \OC::$server->get(ProxyMapper::class), \OC::$server->get(KnownUserService::class), - \OC::$server->getConfig(), - \OC::$server->getL10NFactory(), + $config, + $l10nFactory, 'principals/' ); -$db = \OC::$server->getDatabaseConnection(); -$userManager = \OC::$server->getUserManager(); -$random = \OC::$server->getSecureRandom(); -$logger = \OC::$server->getLogger(); -$dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class); -$config = \OC::$server->get(\OCP\IConfig::class); $calDavBackend = new CalDavBackend( - $db, + \OC::$server->get(IDBConnection::class), $principalBackend, $userManager, - \OC::$server->getGroupManager(), - $random, + $groupManager, + \OC::$server->get(ISecureRandom::class), $logger, - $dispatcher, + \OC::$server->get(IEventDispatcher::class), $config, true ); -$debugging = \OC::$server->getConfig()->getSystemValue('debug', false); -$sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes'; +$debugging = $config->getSystemValue('debug', false); +$sendInvitations = $config->getAppValue('dav', 'sendInvitations', 'yes') === 'yes'; // Root nodes -$principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend); +$principalCollection = new Collection($principalBackend); $principalCollection->disableListing = !$debugging; // Disable listing $addressBookRoot = new CalendarRoot($principalBackend, $calDavBackend); @@ -90,29 +123,29 @@ ]; // Fire up server -$server = new \Sabre\DAV\Server($nodes); +$server = new Server($nodes); $server::$exposeVersion = false; -$server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri()); +$server->httpRequest->setUrl($request->getRequestUri()); $server->setBaseUri($baseuri); // Add plugins -$server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); -$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); -$server->addPlugin(new \Sabre\CalDAV\Plugin()); +$server->addPlugin(new MaintenancePlugin($config, $l10nFactory->get('dav'))); +$server->addPlugin(new AuthPlugin($authBackend)); +$server->addPlugin(new CalDAVPlugin()); $server->addPlugin(new LegacyDAVACL()); if ($debugging) { - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); + $server->addPlugin(new BrowserPlugin()); } -$server->addPlugin(new \Sabre\DAV\Sync\Plugin()); -$server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); -$server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig())); +$server->addPlugin(new SyncPlugin()); +$server->addPlugin(new ICSExportPlugin()); +$server->addPlugin(new SchedulePlugin($config)); if ($sendInvitations) { - $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); + $server->addPlugin(\OC::$server->get(IMipPlugin::class)); } -$server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger())); +$server->addPlugin(new ExceptionLoggerPlugin('caldav', $logger)); // And off we go! -$server->exec(); +$server->start(); diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php index 1b694f84d1db9..a5d96ccb320f8 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -8,6 +8,7 @@ * @author John Molakvoæ * @author Lukas Reschke * @author Morris Jobke + * @author Thomas Citharel * @author Thomas Müller * * @license AGPL-3.0 @@ -26,48 +27,85 @@ * */ // Backends +use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager; +use OC\Files\AppData\Factory as AppDataFactory; use OC\KnownUser\KnownUserService; +use OC\Security\Bruteforce\Throttler; use OCA\DAV\AppInfo\PluginManager; +use OCA\DAV\CalDAV\Proxy\ProxyMapper; use OCA\DAV\CardDAV\AddressBookRoot; use OCA\DAV\CardDAV\CardDavBackend; +use OCA\DAV\CardDAV\ImageExportPlugin; +use OCA\DAV\CardDAV\PhotoCache; use OCA\DAV\Connector\LegacyDAVACL; use OCA\DAV\Connector\Sabre\Auth; use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin; use OCA\DAV\Connector\Sabre\MaintenancePlugin; use OCA\DAV\Connector\Sabre\Principal; use OCP\App\IAppManager; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\IRequest; +use OCP\IUserManager; +use OCP\IUserSession; +use OCP\L10N\IFactory as IL10NFactory; +use OCP\Share\IManager as IShareManager; +use Psr\Log\LoggerInterface; +use Sabre\CalDAV\Principal\Collection; use Sabre\CardDAV\Plugin; +use Sabre\CardDAV\VCFExportPlugin; +use Sabre\DAV\Auth\Plugin as AuthPlugin; +use Sabre\DAV\Browser\Plugin as BrowserPlugin; +use Sabre\DAV\Server; +use Sabre\DAV\Sync\Plugin as SyncPlugin; + +/** @var IUserSession $userSession */ +$userSession = \OC::$server->get(IUserSession::class); +/** @var IRequest $request */ +$request = \OC::$server->get(IRequest::class); +/** @var IUserManager $userManager */ +$userManager = \OC::$server->get(IUserManager::class); +/** @var IGroupManager $groupManager */ +$groupManager = \OC::$server->get(IGroupManager::class); +/** @var IConfig $config */ +$config = \OC::$server->get(IConfig::class); +/** @var IL10NFactory $l10nFactory */ +$l10nFactory = \OC::$server->get(IL10NFactory::class); +/** @var LoggerInterface $logger */ +$logger = \OC::$server->get(LoggerInterface::class); $authBackend = new Auth( - \OC::$server->getSession(), - \OC::$server->getUserSession(), - \OC::$server->getRequest(), - \OC::$server->getTwoFactorAuthManager(), - \OC::$server->getBruteForceThrottler(), + $userSession->getSession(), + $userSession, + $request, + \OC::$server->get(TwoFactorAuthManager::class), + \OC::$server->get(Throttler::class), 'principals/' ); $principalBackend = new Principal( - \OC::$server->getUserManager(), - \OC::$server->getGroupManager(), - \OC::$server->getShareManager(), - \OC::$server->getUserSession(), - \OC::$server->getAppManager(), - \OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class), + $userManager, + $groupManager, + \OC::$server->get(IShareManager::class), + $userSession, + \OC::$server->get(IAppManager::class), + \OC::$server->get(ProxyMapper::class), \OC::$server->get(KnownUserService::class), - \OC::$server->getConfig(), - \OC::$server->getL10NFactory(), + $config, + $l10nFactory, 'principals/' ); -$db = \OC::$server->getDatabaseConnection(); -$cardDavBackend = new CardDavBackend($db, $principalBackend, \OC::$server->getUserManager(), \OC::$server->getGroupManager(), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class)); -$debugging = \OC::$server->getConfig()->getSystemValue('debug', false); +$cardDavBackend = new CardDavBackend(\OC::$server->get(IDBConnection::class), $principalBackend, $userManager, $groupManager, \OC::$server->get(IEventDispatcher::class)); + +$debugging = $config->getSystemValue('debug', false); // Root nodes -$principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend); +$principalCollection = new Collection($principalBackend); $principalCollection->disableListing = !$debugging; // Disable listing -$pluginManager = new PluginManager(\OC::$server, \OC::$server->query(IAppManager::class)); +$pluginManager = new PluginManager(\OC::$server, \OC::$server->get(IAppManager::class)); $addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend, $pluginManager); $addressBookRoot->disableListing = !$debugging; // Disable listing @@ -77,27 +115,27 @@ ]; // Fire up server -$server = new \Sabre\DAV\Server($nodes); +$server = new Server($nodes); $server::$exposeVersion = false; -$server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri()); +$server->httpRequest->setUrl($request->getRequestUri()); $server->setBaseUri($baseuri); // Add plugins -$server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); -$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); +$server->addPlugin(new MaintenancePlugin($config, $l10nFactory->get('dav'))); +$server->addPlugin(new AuthPlugin($authBackend)); $server->addPlugin(new Plugin()); $server->addPlugin(new LegacyDAVACL()); if ($debugging) { - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); + $server->addPlugin(new BrowserPlugin()); } -$server->addPlugin(new \Sabre\DAV\Sync\Plugin()); -$server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin()); -$server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache( - \OC::$server->getAppDataDir('dav-photocache'), - \OC::$server->getLogger() +$server->addPlugin(new SyncPlugin()); +$server->addPlugin(new VCFExportPlugin()); +$server->addPlugin(new ImageExportPlugin(new PhotoCache( + $this->get(AppDataFactory::class)->get('dav-photocache'), + $logger ))); -$server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger())); +$server->addPlugin(new ExceptionLoggerPlugin('carddav', $logger)); // And off we go! -$server->exec(); +$server->start(); diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index c99c5bcd83399..3585f490ca4da 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -11,6 +11,7 @@ * @author Morris Jobke * @author Robin Appelman * @author Roeland Jago Douma + * @author Thomas Citharel * @author Thomas Müller * @author Vincent Petry * @@ -29,68 +30,97 @@ * along with this program. If not, see * */ + +use OC\Files\Filesystem; +use OC\Files\Storage\Wrapper\PermissionsMask; +use OC\Files\View; +use OC\Security\Bruteforce\Throttler; +use OCA\DAV\Files\Sharing\FilesDropPlugin; +use OCA\DAV\Files\Sharing\PublicLinkCheckPlugin; +use OCA\DAV\Storage\PublicOwnerWrapper; +use OCA\FederatedFileSharing\FederatedShareProvider; +use OCP\Constants; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Mount\IMountManager; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IPreview; +use OCP\IRequest; +use OCP\ITagManager; +use OCP\IUserSession; +use OCP\L10N\IFactory as IL10NFactory; +use OCP\Share\IManager as IShareManager; +use Psr\Log\LoggerInterface; +use Sabre\DAV\Auth\Plugin as AuthPlugin; +use Sabre\DAV\Exception\NotAuthenticated; +use Sabre\DAV\Server; + // load needed apps $RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging']; +/** @var IUserSession $userSession */ +$userSession = \OC::$server->get(IUserSession::class); +/** @var IRequest $request */ +$request = \OC::$server->get(IRequest::class); + OC_App::loadApps($RUNTIME_APPTYPES); OC_Util::obEnd(); -\OC::$server->getSession()->close(); +$userSession->getSession()->close(); // Backends $authBackend = new OCA\DAV\Connector\PublicAuth( - \OC::$server->getRequest(), - \OC::$server->getShareManager(), - \OC::$server->getSession(), - \OC::$server->getBruteForceThrottler() + $request, + \OC::$server->get(IShareManager::class), + $userSession->getSession(), + \OC::$server->get(Throttler::class) ); -$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); +$authPlugin = new AuthPlugin($authBackend); $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( - \OC::$server->getConfig(), - \OC::$server->getLogger(), - \OC::$server->getDatabaseConnection(), - \OC::$server->getUserSession(), - \OC::$server->getMountManager(), - \OC::$server->getTagManager(), - \OC::$server->getRequest(), - \OC::$server->getPreviewManager(), - \OC::$server->getEventDispatcher(), - \OC::$server->getL10N('dav') + \OC::$server->get(IConfig::class), + \OC::$server->get(LoggerInterface::class), + \OC::$server->get(IDBConnection::class), + $userSession, + \OC::$server->get(IMountManager::class), + \OC::$server->get(ITagManager::class), + $request, + \OC::$server->get(IPreview::class), + \OC::$server->get(IEventDispatcher::class), + \OC::$server->get(IL10NFactory::class)->get('dav') ); -$requestUri = \OC::$server->getRequest()->getRequestUri(); -$linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin(); -$filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin(); +$linkCheckPlugin = new PublicLinkCheckPlugin(); +$filesDropPlugin = new FilesDropPlugin(); -$server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { +$server = $serverFactory->createServer($baseuri, $request->getRequestUri(), $authPlugin, function (Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); - /** @var \OCA\FederatedFileSharing\FederatedShareProvider $shareProvider */ - $federatedShareProvider = \OC::$server->query(\OCA\FederatedFileSharing\FederatedShareProvider::class); + /** @var FederatedShareProvider $shareProvider */ + $federatedShareProvider = \OC::$server->get(FederatedShareProvider::class); if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { // this is what is thrown when trying to access a non-existing share - throw new \Sabre\DAV\Exception\NotAuthenticated(); + throw new NotAuthenticated(); } $share = $authBackend->getShare(); $owner = $share->getShareOwner(); - $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ; + $isReadable = $share->getPermissions() & Constants::PERMISSION_READ; $fileId = $share->getNodeId(); // FIXME: should not add storage wrappers outside of preSetup, need to find a better way - $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); - \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { - return new \OC\Files\Storage\Wrapper\PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE]); + $previousLog = Filesystem::logWarningWhenAddingStorageWrapper(false); + Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { + return new PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | Constants::PERMISSION_SHARE]); }); - \OC\Files\Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) { - return new \OCA\DAV\Storage\PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]); + Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) { + return new PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]); }); - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); + Filesystem::logWarningWhenAddingStorageWrapper($previousLog); OC_Util::tearDownFS(); OC_Util::setupFS($owner); - $ownerView = new \OC\Files\View('/'. $owner . '/files'); + $ownerView = new View('/'. $owner . '/files'); $path = $ownerView->getPath($fileId); $fileInfo = $ownerView->getFileInfo($path); $linkCheckPlugin->setFileInfo($fileInfo); @@ -100,7 +130,7 @@ $filesDropPlugin->enable(); } - $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); + $view = new View($ownerView->getAbsolutePath($path)); $filesDropPlugin->setView($view); return $view; @@ -110,4 +140,4 @@ $server->addPlugin($filesDropPlugin); // And off we go! -$server->exec(); +$server->start(); diff --git a/apps/dav/appinfo/v1/webdav.php b/apps/dav/appinfo/v1/webdav.php index 44130da0f28e7..729cda1a7f737 100644 --- a/apps/dav/appinfo/v1/webdav.php +++ b/apps/dav/appinfo/v1/webdav.php @@ -10,6 +10,7 @@ * @author Morris Jobke * @author Robin Appelman * @author Roeland Jago Douma + * @author Thomas Citharel * @author Thomas Müller * @author Vincent Petry * @@ -29,7 +30,23 @@ * */ // no php execution timeout for webdav +use OC\Authentication\TwoFactorAuth\Manager; +use OC\Files\Filesystem; +use OC\Security\Bruteforce\Throttler; +use OCA\DAV\Connector\Sabre\BearerAuth; use OCA\DAV\Events\SabreAddPluginEvent; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Mount\IMountManager; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IPreview; +use OCP\IRequest; +use OCP\ITagManager; +use OCP\IUserSession; +use OCP\L10N\IFactory as IL10NFactory; +use OCP\SabrePluginEvent; +use Psr\Log\LoggerInterface; +use Sabre\DAV\Auth\Plugin as AuthPlugin; if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { @set_time_limit(0); @@ -39,49 +56,52 @@ // Turn off output buffering to prevent memory problems \OC_Util::obEnd(); -$serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory( - \OC::$server->getConfig(), - \OC::$server->getLogger(), - \OC::$server->getDatabaseConnection(), - \OC::$server->getUserSession(), - \OC::$server->getMountManager(), - \OC::$server->getTagManager(), - \OC::$server->getRequest(), - \OC::$server->getPreviewManager(), - \OC::$server->getEventDispatcher(), - \OC::$server->getL10N('dav') +/** @var IUserSession $userSession */ +$userSession = \OC::$server->get(IUserSession::class); +/** @var IRequest $request */ +$request = \OC::$server->get(IRequest::class); + +$serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( + \OC::$server->get(IConfig::class), + \OC::$server->get(LoggerInterface::class), + \OC::$server->get(IDBConnection::class), + $userSession, + \OC::$server->get(IMountManager::class), + \OC::$server->get(ITagManager::class), + $request, + \OC::$server->get(IPreview::class), + \OC::$server->get(IEventDispatcher::class), + \OC::$server->get(IL10NFactory::class)->get('dav') ); // Backends $authBackend = new \OCA\DAV\Connector\Sabre\Auth( - \OC::$server->getSession(), - \OC::$server->getUserSession(), - \OC::$server->getRequest(), - \OC::$server->getTwoFactorAuthManager(), - \OC::$server->getBruteForceThrottler(), + $userSession->getSession(), + $userSession, + $request, + \OC::$server->get(Manager::class), + \OC::$server->get(Throttler::class), 'principals/' ); -$authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); -$bearerAuthPlugin = new \OCA\DAV\Connector\Sabre\BearerAuth( - \OC::$server->getUserSession(), - \OC::$server->getSession(), - \OC::$server->getRequest() +$authPlugin = new AuthPlugin($authBackend); +$bearerAuthPlugin = new BearerAuth( + $userSession, + $userSession->getSession(), + $request ); $authPlugin->addBackend($bearerAuthPlugin); -$requestUri = \OC::$server->getRequest()->getRequestUri(); - -$server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function () { +$server = $serverFactory->createServer($baseuri, $request->getRequestUri(), $authPlugin, function () { // use the view for the logged in user - return \OC\Files\Filesystem::getView(); + return Filesystem::getView(); }); $dispatcher = \OC::$server->getEventDispatcher(); -$newDispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class); +$newDispatcher = \OC::$server->get(IEventDispatcher::class); // allow setup of additional plugins $newDispatcher->dispatchTyped(new SabreAddPluginEvent($server)); -$event = new \OCP\SabrePluginEvent($server); +$event = new SabrePluginEvent($server); $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); // And off we go! -$server->exec(); +$server->start(); diff --git a/apps/dav/appinfo/v2/direct.php b/apps/dav/appinfo/v2/direct.php index cab6109e5e62d..9073b561b1a13 100644 --- a/apps/dav/appinfo/v2/direct.php +++ b/apps/dav/appinfo/v2/direct.php @@ -7,6 +7,7 @@ * * @author Robin Appelman * @author Roeland Jago Douma + * @author Thomas Citharel * * @license GNU AGPL version 3 or any later version * @@ -24,7 +25,13 @@ * along with this program. If not, see . * */ -use \OCA\DAV\Direct\ServerFactory; + +use OC\Security\Bruteforce\Throttler; +use OCA\DAV\Db\DirectMapper; +use OCA\DAV\Direct\ServerFactory; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Files\IRootFolder; +use OCP\IRequest; // no php execution timeout for webdav if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { @@ -35,18 +42,19 @@ // Turn off output buffering to prevent memory problems \OC_Util::obEnd(); -$requestUri = \OC::$server->getRequest()->getRequestUri(); +/** @var IRequest $request */ +$request = \OC::$server->get(IRequest::class); /** @var ServerFactory $serverFactory */ -$serverFactory = \OC::$server->query(ServerFactory::class); +$serverFactory = \OC::$server->get(ServerFactory::class); $server = $serverFactory->createServer( $baseuri, - $requestUri, - \OC::$server->getRootFolder(), - \OC::$server->query(\OCA\DAV\Db\DirectMapper::class), - \OC::$server->query(\OCP\AppFramework\Utility\ITimeFactory::class), - \OC::$server->getBruteForceThrottler(), - \OC::$server->getRequest() + $request->getRequestUri(), + \OC::$server->get(IRootFolder::class), + \OC::$server->get(DirectMapper::class), + \OC::$server->get(ITimeFactory::class), + \OC::$server->get(Throttler::class), + $request ); -$server->exec(); +$server->start(); diff --git a/apps/dav/appinfo/v2/remote.php b/apps/dav/appinfo/v2/remote.php index de2ba989f8dab..9eb424c987167 100644 --- a/apps/dav/appinfo/v2/remote.php +++ b/apps/dav/appinfo/v2/remote.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Ko- + * @author Thomas Citharel * @author Thomas Müller * @author Vincent Petry * @@ -22,6 +23,9 @@ * */ // no php execution timeout for webdav +use OCA\DAV\Server; +use OCP\IRequest; + if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { @set_time_limit(0); } @@ -30,6 +34,5 @@ // Turn off output buffering to prevent memory problems \OC_Util::obEnd(); -$request = \OC::$server->getRequest(); -$server = new \OCA\DAV\Server($request, $baseuri); -$server->exec(); +$server = new Server(\OC::$server->get(IRequest::class), $baseuri); +$server->start(); diff --git a/apps/dav/bin/chunkperf.php b/apps/dav/bin/chunkperf.php index a8652654bca07..30726afbee23b 100644 --- a/apps/dav/bin/chunkperf.php +++ b/apps/dav/bin/chunkperf.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Christoph Wurst + * @author Thomas Citharel * @author Thomas Müller * * @license AGPL-3.0 @@ -20,6 +21,9 @@ * along with this program. If not, see * */ + +use Sabre\DAV\Client; + require '../../../../3rdparty/autoload.php'; if ($argc !== 6) { @@ -28,11 +32,14 @@ } /** - * @param \Sabre\DAV\Client $client - * @param $uploadUrl - * @return mixed + * @param Client $client + * @param string $method + * @param string $uploadUrl + * @param string|resource|null $data + * @param array $headers + * @return array */ -function request($client, $method, $uploadUrl, $data = null, $headers = []) { +function request(Client $client, string $method, string $uploadUrl, string $data = null, array $headers = []): array { echo "$method $uploadUrl ... "; $t0 = microtime(true); $result = $client->request($method, $uploadUrl, $data, $headers); @@ -50,7 +57,7 @@ function request($client, $method, $uploadUrl, $data = null, $headers = []) { $file = $argv[4]; $chunkSize = $argv[5] * 1024 * 1024; -$client = new \Sabre\DAV\Client([ +$client = new Client([ 'baseUri' => $baseUri, 'userName' => $userName, 'password' => $password diff --git a/apps/dav/lib/Connector/Sabre/Auth.php b/apps/dav/lib/Connector/Sabre/Auth.php index 1908f5e7a7aa4..d5c1b2009efaf 100644 --- a/apps/dav/lib/Connector/Sabre/Auth.php +++ b/apps/dav/lib/Connector/Sabre/Auth.php @@ -41,6 +41,7 @@ use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden; use OCP\IRequest; use OCP\ISession; +use OCP\IUserSession; use Psr\Log\LoggerInterface; use Sabre\DAV\Auth\Backend\AbstractBasic; use Sabre\DAV\Exception\NotAuthenticated; @@ -73,11 +74,11 @@ class Auth extends AbstractBasic { * @param string $principalPrefix */ public function __construct(ISession $session, - Session $userSession, + IUserSession $userSession, IRequest $request, Manager $twoFactorManager, Throttler $throttler, - $principalPrefix = 'principals/users/') { + string $principalPrefix = 'principals/users/') { $this->session = $session; $this->userSession = $userSession; $this->twoFactorManager = $twoFactorManager; diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 8706c8a444bd0..0f736fbffdfe4 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -35,8 +35,17 @@ namespace OCA\DAV; use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager; +use OC\EventDispatcher\SymfonyAdapter; use OC\Security\Bruteforce\Throttler; +use OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin; +use OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin; +use OCA\DAV\CalDAV\Publishing\PublishPlugin; +use OCA\DAV\CalDAV\Schedule\IMipPlugin; +use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin; +use OCA\DAV\Connector\Sabre\LockPlugin; +use OCA\DAV\Connector\Sabre\MaintenancePlugin; use OCA\DAV\Events\SabreAddPluginEvent; +use OCA\DAV\Files\FileSearchBackend; use OCP\App\IAppManager; use OCP\Comments\ICommentsManager; use OCP\Files\IRootFolder; @@ -48,6 +57,7 @@ use OCP\IURLGenerator; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\SabrePluginEvent; use OCP\Share\IManager; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagObjectMapper; @@ -106,15 +116,15 @@ public function __construct(IRequest $request, $baseUri) { $this->request = $request; $this->baseUri = $baseUri; $logger = \OC::$server->get(LoggerInterface::class); - $dispatcher = \OC::$server->get(\OC\EventDispatcher\SymfonyAdapter::class); + $dispatcher = \OC::$server->get(SymfonyAdapter::class); /** @var IEventDispatcher $newDispatcher */ $newDispatcher = \OC::$server->get(IEventDispatcher::class); $root = new RootCollection(); - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); + $this->server = new Connector\Sabre\Server(new CachingTree($root)); // Add maintenance plugin - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->get(IConfig::class), \OC::$server->get(IFactory::class)->get('dav'))); + $this->server->addPlugin(new MaintenancePlugin(\OC::$server->get(IConfig::class), \OC::$server->get(IFactory::class)->get('dav'))); // Backends $authBackend = new Auth( @@ -156,8 +166,8 @@ public function __construct(IRequest $request, $baseUri) { $this->server->addPlugin(new DummyGetResponsePlugin()); } - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); + $this->server->addPlugin(new ExceptionLoggerPlugin('webdav', $logger)); + $this->server->addPlugin(new LockPlugin()); $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); // acl @@ -173,20 +183,20 @@ public function __construct(IRequest $request, $baseUri) { // calendar plugins if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); - $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->get(IConfig::class), \OC::$server->get(LoggerInterface::class))); - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->get(IConfig::class))); + $this->server->addPlugin(new CalDAV\Plugin()); + $this->server->addPlugin(new ICSExportPlugin(\OC::$server->get(IConfig::class), \OC::$server->get(LoggerInterface::class))); + $this->server->addPlugin(new CalDAV\Schedule\Plugin(\OC::$server->get(IConfig::class))); if (\OC::$server->get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { - $this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); + $this->server->addPlugin(\OC::$server->get(IMipPlugin::class)); } - $this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class)); - $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($request)); + $this->server->addPlugin(\OC::$server->get(CalDAV\Trashbin\Plugin::class)); + $this->server->addPlugin(new CalDAV\WebcalCaching\Plugin($request)); $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->get(IRequest::class), \OC::$server->get(IConfig::class))); - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( + $this->server->addPlugin(new PublishPlugin( \OC::$server->get(IConfig::class), \OC::$server->get(IURLGenerator::class) )); @@ -195,7 +205,7 @@ public function __construct(IRequest $request, $baseUri) { // addressbook plugins if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->get(IRequest::class), \OC::$server->get(IConfig::class))); - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); + $this->server->addPlugin(new CardDAV\Plugin()); $this->server->addPlugin(new VCFExportPlugin()); $this->server->addPlugin(new MultiGetExportPlugin()); $this->server->addPlugin(new HasPhotoPlugin()); @@ -223,7 +233,7 @@ public function __construct(IRequest $request, $baseUri) { // allow setup of additional plugins $newDispatcher->dispatchTyped(new SabreAddPluginEvent($this->server)); - $event = new \OCP\SabrePluginEvent($this->server); + $event = new SabrePluginEvent($this->server); $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); // Some WebDAV clients do require Class 2 WebDAV support (locking), since @@ -292,7 +302,7 @@ public function __construct(IRequest $request, $baseUri) { \OC::$server->get(ICommentsManager::class), $userSession )); - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); + $this->server->addPlugin(new CalDAV\Search\SearchPlugin()); if ($view !== null) { $this->server->addPlugin(new FilesReportPlugin( $this->server->tree, @@ -305,7 +315,7 @@ public function __construct(IRequest $request, $baseUri) { $userFolder, \OC::$server->get(IAppManager::class) )); - $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( + $lazySearchBackend->setBackend(new FileSearchBackend( $this->server->tree, $user, \OC::$server->get(IRootFolder::class), @@ -317,14 +327,14 @@ public function __construct(IRequest $request, $baseUri) { new BulkUploadPlugin($userFolder, $logger) ); } - $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( + $this->server->addPlugin(new EnablePlugin( \OC::$server->get(IConfig::class), \OC::$server->get(BirthdayService::class) )); $this->server->addPlugin(new AppleProvisioningPlugin( \OC::$server->get(IUserSession::class), \OC::$server->get(IURLGenerator::class), - \OC::$server->getThemingDefaults(), + \OC::$server->get('ThemingDefaults'), \OC::$server->get(IRequest::class), \OC::$server->get(IFactory::class)->get('dav'), function () { @@ -351,8 +361,15 @@ function () { ); } + /** + * @deprecated + */ public function exec() { - $this->server->exec(); + $this->start(); + } + + public function start() { + $this->server->start(); } private function requestIsForSubtree(array $subTrees): bool {