2015-10-21 13:06:48 +00:00
|
|
|
<?php
|
2016-01-12 14:02:16 +00:00
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-07-21 16:13:36 +00:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2015-10-21 13:06:48 +00:00
|
|
|
namespace OCA\DAV;
|
|
|
|
|
2015-12-18 10:56:25 +00:00
|
|
|
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
|
2016-06-21 13:25:44 +00:00
|
|
|
use OCA\DAV\CardDAV\ImageExportPlugin;
|
2017-05-03 12:22:02 +00:00
|
|
|
use OCA\DAV\CardDAV\PhotoCache;
|
2016-09-23 17:57:07 +00:00
|
|
|
use OCA\DAV\Comments\CommentsPlugin;
|
2015-10-21 13:06:48 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\Auth;
|
2017-05-18 18:09:51 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\BearerAuth;
|
2015-10-21 13:06:48 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
|
2016-11-08 09:03:25 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\CommentPropertiesPlugin;
|
2016-09-23 17:57:07 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin;
|
2016-02-29 16:30:02 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\DavAclPlugin;
|
2016-03-17 15:51:19 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\DummyGetResponsePlugin;
|
2016-09-23 17:57:07 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\FakeLockerPlugin;
|
2016-02-18 19:11:59 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\FilesPlugin;
|
2016-11-08 09:03:25 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\FilesReportPlugin;
|
|
|
|
use OCA\DAV\Connector\Sabre\SharesPlugin;
|
2016-07-08 14:52:20 +00:00
|
|
|
use OCA\DAV\DAV\PublicAuth;
|
2017-03-27 17:15:51 +00:00
|
|
|
use OCA\DAV\DAV\CustomPropertiesBackend;
|
2016-09-23 17:57:07 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\QuotaPlugin;
|
2016-03-24 13:29:55 +00:00
|
|
|
use OCA\DAV\Files\BrowserErrorPagePlugin;
|
2016-09-23 17:57:07 +00:00
|
|
|
use OCA\DAV\SystemTag\SystemTagPlugin;
|
2015-10-21 13:06:48 +00:00
|
|
|
use OCP\IRequest;
|
2015-12-04 11:11:07 +00:00
|
|
|
use OCP\SabrePluginEvent;
|
2016-04-10 10:43:15 +00:00
|
|
|
use Sabre\CardDAV\VCFExportPlugin;
|
2015-10-21 13:06:48 +00:00
|
|
|
use Sabre\DAV\Auth\Plugin;
|
2016-09-12 14:20:49 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\TagsPlugin;
|
2017-05-18 18:09:51 +00:00
|
|
|
use Sabre\HTTP\Auth\Bearer;
|
2017-02-02 17:20:08 +00:00
|
|
|
use SearchDAV\DAV\SearchPlugin;
|
2015-10-21 13:06:48 +00:00
|
|
|
|
|
|
|
class Server {
|
|
|
|
|
|
|
|
/** @var IRequest */
|
|
|
|
private $request;
|
|
|
|
|
2016-07-05 20:45:05 +00:00
|
|
|
/** @var string */
|
|
|
|
private $baseUri;
|
|
|
|
|
|
|
|
/** @var Connector\Sabre\Server */
|
2016-07-07 14:56:28 +00:00
|
|
|
private $server;
|
2016-07-05 20:45:05 +00:00
|
|
|
|
2015-10-21 13:06:48 +00:00
|
|
|
public function __construct(IRequest $request, $baseUri) {
|
|
|
|
$this->request = $request;
|
|
|
|
$this->baseUri = $baseUri;
|
2015-11-16 15:09:04 +00:00
|
|
|
$logger = \OC::$server->getLogger();
|
2015-12-18 10:56:25 +00:00
|
|
|
$mailer = \OC::$server->getMailer();
|
2016-01-13 10:54:42 +00:00
|
|
|
$dispatcher = \OC::$server->getEventDispatcher();
|
2015-11-16 15:09:04 +00:00
|
|
|
|
2015-10-21 13:06:48 +00:00
|
|
|
$root = new RootCollection();
|
|
|
|
$this->server = new \OCA\DAV\Connector\Sabre\Server($root);
|
|
|
|
|
2017-04-10 22:57:31 +00:00
|
|
|
// Add maintenance plugin
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
|
|
|
|
|
2015-10-21 13:06:48 +00:00
|
|
|
// Backends
|
2015-10-26 12:02:10 +00:00
|
|
|
$authBackend = new Auth(
|
|
|
|
\OC::$server->getSession(),
|
2016-02-16 12:16:52 +00:00
|
|
|
\OC::$server->getUserSession(),
|
2016-06-01 08:42:38 +00:00
|
|
|
\OC::$server->getRequest(),
|
2016-07-20 16:36:15 +00:00
|
|
|
\OC::$server->getTwoFactorAuthManager(),
|
|
|
|
\OC::$server->getBruteForceThrottler()
|
2015-10-26 12:02:10 +00:00
|
|
|
);
|
2015-10-21 13:06:48 +00:00
|
|
|
|
|
|
|
// Set URL explicitly due to reverse-proxy situations
|
|
|
|
$this->server->httpRequest->setUrl($this->request->getRequestUri());
|
|
|
|
$this->server->setBaseUri($this->baseUri);
|
|
|
|
|
|
|
|
$this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig()));
|
2016-10-20 10:51:54 +00:00
|
|
|
$authPlugin = new Plugin();
|
|
|
|
$authPlugin->addBackend(new PublicAuth());
|
|
|
|
$this->server->addPlugin($authPlugin);
|
2015-12-04 11:11:07 +00:00
|
|
|
|
|
|
|
// allow setup of additional auth backends
|
|
|
|
$event = new SabrePluginEvent($this->server);
|
|
|
|
$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
|
|
|
|
|
2017-05-18 18:09:51 +00:00
|
|
|
$bearerAuthBackend = new BearerAuth(
|
|
|
|
\OC::$server->getUserSession(),
|
|
|
|
\OC::$server->getSession(),
|
|
|
|
\OC::$server->getRequest()
|
|
|
|
);
|
|
|
|
$authPlugin->addBackend($bearerAuthBackend);
|
2016-07-14 14:19:31 +00:00
|
|
|
// because we are throwing exceptions this plugin has to be the last one
|
|
|
|
$authPlugin->addBackend($authBackend);
|
|
|
|
|
2016-03-17 15:51:19 +00:00
|
|
|
// debugging
|
|
|
|
if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
|
|
|
|
$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
|
|
|
|
} else {
|
|
|
|
$this->server->addPlugin(new DummyGetResponsePlugin());
|
|
|
|
}
|
|
|
|
|
2015-11-16 15:09:04 +00:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
|
2015-11-23 12:53:57 +00:00
|
|
|
$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
|
2015-10-21 13:06:48 +00:00
|
|
|
|
2015-11-24 10:15:31 +00:00
|
|
|
// acl
|
2016-02-29 16:30:02 +00:00
|
|
|
$acl = new DavAclPlugin();
|
2016-05-02 12:19:10 +00:00
|
|
|
$acl->principalCollectionSet = [
|
|
|
|
'principals/users', 'principals/groups'
|
|
|
|
];
|
2015-11-24 10:15:31 +00:00
|
|
|
$acl->defaultUsernamePath = 'principals/users';
|
|
|
|
$this->server->addPlugin($acl);
|
|
|
|
|
2015-10-31 00:28:21 +00:00
|
|
|
// calendar plugins
|
2016-10-13 10:15:10 +00:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
|
2015-10-31 00:28:21 +00:00
|
|
|
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
|
2016-11-04 14:05:15 +00:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
|
2015-12-18 10:56:25 +00:00
|
|
|
$this->server->addPlugin(new IMipPlugin($mailer, $logger));
|
2015-10-31 00:28:21 +00:00
|
|
|
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
|
|
|
|
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
|
2016-01-25 19:23:11 +00:00
|
|
|
$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
|
2016-07-07 08:16:56 +00:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
|
|
|
|
\OC::$server->getConfig(),
|
2016-10-19 08:49:43 +00:00
|
|
|
\OC::$server->getURLGenerator()
|
2016-07-07 08:16:56 +00:00
|
|
|
));
|
2015-11-09 12:27:19 +00:00
|
|
|
|
2015-10-31 00:28:21 +00:00
|
|
|
// addressbook plugins
|
2015-11-27 12:14:55 +00:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
|
2016-04-10 10:43:15 +00:00
|
|
|
$this->server->addPlugin(new VCFExportPlugin());
|
2017-05-08 09:25:02 +00:00
|
|
|
$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
|
2015-11-10 06:27:34 +00:00
|
|
|
|
2015-11-27 11:54:31 +00:00
|
|
|
// system tags plugins
|
2016-09-23 17:57:07 +00:00
|
|
|
$this->server->addPlugin(new SystemTagPlugin(
|
2016-02-19 18:45:03 +00:00
|
|
|
\OC::$server->getSystemTagManager(),
|
|
|
|
\OC::$server->getGroupManager(),
|
|
|
|
\OC::$server->getUserSession()
|
|
|
|
));
|
2015-11-27 11:54:31 +00:00
|
|
|
|
2016-01-11 17:09:00 +00:00
|
|
|
// comments plugin
|
2016-09-23 17:57:07 +00:00
|
|
|
$this->server->addPlugin(new CommentsPlugin(
|
2016-01-11 17:09:00 +00:00
|
|
|
\OC::$server->getCommentsManager(),
|
|
|
|
\OC::$server->getUserSession()
|
|
|
|
));
|
|
|
|
|
2016-09-23 17:57:07 +00:00
|
|
|
$this->server->addPlugin(new CopyEtagHeaderPlugin());
|
|
|
|
|
2017-08-30 10:15:01 +00:00
|
|
|
// allow setup of additional plugins
|
|
|
|
$dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
|
|
|
|
|
2016-01-26 16:31:01 +00: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.
|
|
|
|
if($request->isUserAgent([
|
|
|
|
'/WebDAVFS/',
|
|
|
|
'/Microsoft Office OneNote 2013/',
|
2017-03-07 16:24:26 +00:00
|
|
|
'/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
|
2016-01-26 16:31:01 +00:00
|
|
|
])) {
|
2016-09-23 17:57:07 +00:00
|
|
|
$this->server->addPlugin(new FakeLockerPlugin());
|
2015-11-13 10:47:32 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 13:29:55 +00:00
|
|
|
if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
|
|
|
|
$this->server->addPlugin(new BrowserErrorPagePlugin());
|
|
|
|
}
|
|
|
|
|
2015-10-21 13:06:48 +00:00
|
|
|
// wait with registering these until auth is handled and the filesystem is setup
|
|
|
|
$this->server->on('beforeMethod', function () {
|
|
|
|
// custom properties plugin must be the last one
|
2016-10-04 14:08:22 +00:00
|
|
|
$userSession = \OC::$server->getUserSession();
|
|
|
|
$user = $userSession->getUser();
|
2016-11-08 09:03:25 +00:00
|
|
|
if ($user !== null) {
|
2016-02-18 19:11:59 +00:00
|
|
|
$view = \OC\Files\Filesystem::getView();
|
2016-04-18 09:18:50 +00:00
|
|
|
$this->server->addPlugin(
|
|
|
|
new FilesPlugin(
|
|
|
|
$this->server->tree,
|
|
|
|
\OC::$server->getConfig(),
|
2016-06-09 09:29:20 +00:00
|
|
|
$this->request,
|
2016-07-26 11:15:12 +00:00
|
|
|
\OC::$server->getPreviewManager(),
|
2016-04-18 09:18:50 +00:00
|
|
|
false,
|
|
|
|
!\OC::$server->getConfig()->getSystemValue('debug', false)
|
|
|
|
)
|
|
|
|
);
|
2016-02-18 19:11:59 +00:00
|
|
|
|
2015-10-21 13:06:48 +00:00
|
|
|
$this->server->addPlugin(
|
|
|
|
new \Sabre\DAV\PropertyStorage\Plugin(
|
|
|
|
new CustomPropertiesBackend(
|
|
|
|
$this->server->tree,
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
\OC::$server->getUserSession()->getUser()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2016-11-08 09:03:25 +00:00
|
|
|
if ($view !== null) {
|
|
|
|
$this->server->addPlugin(
|
|
|
|
new QuotaPlugin($view));
|
|
|
|
}
|
2016-09-12 14:20:49 +00:00
|
|
|
$this->server->addPlugin(
|
|
|
|
new TagsPlugin(
|
|
|
|
$this->server->tree, \OC::$server->getTagManager()
|
|
|
|
)
|
|
|
|
);
|
2016-10-04 14:08:22 +00:00
|
|
|
// TODO: switch to LazyUserFolder
|
|
|
|
$userFolder = \OC::$server->getUserFolder();
|
2016-11-08 09:03:25 +00:00
|
|
|
$this->server->addPlugin(new SharesPlugin(
|
2016-10-04 14:08:22 +00:00
|
|
|
$this->server->tree,
|
|
|
|
$userSession,
|
|
|
|
$userFolder,
|
|
|
|
\OC::$server->getShareManager()
|
|
|
|
));
|
2016-11-08 09:03:25 +00:00
|
|
|
$this->server->addPlugin(new CommentPropertiesPlugin(
|
2016-10-04 14:08:22 +00:00
|
|
|
\OC::$server->getCommentsManager(),
|
|
|
|
$userSession
|
|
|
|
));
|
2017-03-25 10:56:40 +00:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
|
2016-11-08 09:03:25 +00:00
|
|
|
if ($view !== null) {
|
|
|
|
$this->server->addPlugin(new FilesReportPlugin(
|
|
|
|
$this->server->tree,
|
|
|
|
$view,
|
|
|
|
\OC::$server->getSystemTagManager(),
|
|
|
|
\OC::$server->getSystemTagObjectMapper(),
|
|
|
|
\OC::$server->getTagManager(),
|
|
|
|
$userSession,
|
|
|
|
\OC::$server->getGroupManager(),
|
|
|
|
$userFolder
|
|
|
|
));
|
2017-02-02 17:20:08 +00:00
|
|
|
$this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend(
|
|
|
|
$this->server->tree,
|
|
|
|
$user,
|
|
|
|
\OC::$server->getRootFolder(),
|
|
|
|
\OC::$server->getShareManager(),
|
|
|
|
$view
|
|
|
|
)));
|
2016-11-08 09:03:25 +00:00
|
|
|
}
|
2015-10-21 13:06:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function exec() {
|
|
|
|
$this->server->exec();
|
|
|
|
}
|
|
|
|
}
|