server/apps/dav/lib/Server.php

191 lines
6.1 KiB
PHP
Raw Normal View History

<?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/>
*
*/
namespace OCA\DAV;
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\CardDAV\ImageExportPlugin;
use OCA\DAV\Connector\Sabre\Auth;
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
use OCA\DAV\Connector\Sabre\DavAclPlugin;
use OCA\DAV\Connector\Sabre\DummyGetResponsePlugin;
2016-02-18 19:11:59 +00:00
use OCA\DAV\Connector\Sabre\FilesPlugin;
use OCA\DAV\Files\BrowserErrorPagePlugin;
use OCA\DAV\Files\CustomPropertiesBackend;
use OCP\IRequest;
use OCP\SabrePluginEvent;
2016-04-10 10:43:15 +00:00
use Sabre\CardDAV\VCFExportPlugin;
use Sabre\DAV\Auth\Plugin;
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
public function __construct(IRequest $request, $baseUri) {
$this->request = $request;
$this->baseUri = $baseUri;
$logger = \OC::$server->getLogger();
$mailer = \OC::$server->getMailer();
2016-01-13 10:54:42 +00:00
$dispatcher = \OC::$server->getEventDispatcher();
$root = new RootCollection();
$this->server = new \OCA\DAV\Connector\Sabre\Server($root);
// Backends
$authBackend = new Auth(
\OC::$server->getSession(),
\OC::$server->getUserSession(),
\OC::$server->getRequest(),
\OC::$server->getTwoFactorAuthManager(),
\OC::$server->getBruteForceThrottler()
);
// 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()));
$authPlugin = new Plugin();
2015-12-03 15:22:18 +00:00
$this->server->addPlugin($authPlugin);
// allow setup of additional auth backends
$event = new SabrePluginEvent($this->server);
$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
// because we are throwing exceptions this plugin has to be the last one
$authPlugin->addBackend($authBackend);
// debugging
if(\OC::$server->getConfig()->getSystemValue('debug', false)) {
$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
} else {
$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 \Sabre\DAV\Sync\Plugin());
// acl
$acl = new DavAclPlugin();
$acl->principalCollectionSet = [
'principals/users', 'principals/groups'
];
$acl->defaultUsernamePath = 'principals/users';
$this->server->addPlugin($acl);
2015-10-31 00:28:21 +00:00
// calendar plugins
$this->server->addPlugin(new \Sabre\CalDAV\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
$this->server->addPlugin(new \Sabre\CalDAV\Schedule\Plugin());
$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());
$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
$this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
\OC::$server->getConfig(),
\OC::$server->getUrlGenerator()
));
2015-10-31 00:28:21 +00:00
// addressbook plugins
$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
2016-04-10 10:43:15 +00:00
$this->server->addPlugin(new VCFExportPlugin());
$this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger()));
2015-11-27 11:54:31 +00:00
// system tags plugins
$this->server->addPlugin(new \OCA\DAV\SystemTag\SystemTagPlugin(
\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
$this->server->addPlugin(new \OCA\DAV\Comments\CommentsPlugin(
\OC::$server->getCommentsManager(),
\OC::$server->getUserSession()
));
// 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/',
])) {
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
}
if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
$this->server->addPlugin(new BrowserErrorPagePlugin());
}
// 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
$user = \OC::$server->getUserSession()->getUser();
if (!is_null($user)) {
2016-02-18 19:11:59 +00:00
$view = \OC\Files\Filesystem::getView();
$this->server->addPlugin(
new FilesPlugin(
$this->server->tree,
$view,
\OC::$server->getConfig(),
$this->request,
\OC::$server->getPreviewManager(),
false,
!\OC::$server->getConfig()->getSystemValue('debug', false)
)
);
2016-02-18 19:11:59 +00:00
$this->server->addPlugin(
new \Sabre\DAV\PropertyStorage\Plugin(
new CustomPropertiesBackend(
$this->server->tree,
\OC::$server->getDatabaseConnection(),
\OC::$server->getUserSession()->getUser()
)
)
);
$this->server->addPlugin(
new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
}
});
}
public function exec() {
$this->server->exec();
}
}