2015-10-21 16:06:48 +03:00
|
|
|
<?php
|
2016-01-12 17:02:16 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 17:02:16 +03: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 16:06:48 +03:00
|
|
|
namespace OCA\DAV;
|
|
|
|
|
2015-12-18 13:56:25 +03:00
|
|
|
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
|
2016-06-21 16:25:44 +03:00
|
|
|
use OCA\DAV\CardDAV\ImageExportPlugin;
|
2015-10-21 16:06:48 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\Auth;
|
|
|
|
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
|
2016-02-29 19:30:02 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\DavAclPlugin;
|
2016-03-17 18:51:19 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\DummyGetResponsePlugin;
|
2016-02-18 22:11:59 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\FilesPlugin;
|
2016-03-24 16:29:55 +03:00
|
|
|
use OCA\DAV\Files\BrowserErrorPagePlugin;
|
2015-10-21 16:06:48 +03:00
|
|
|
use OCA\DAV\Files\CustomPropertiesBackend;
|
|
|
|
use OCP\IRequest;
|
2015-12-04 14:11:07 +03:00
|
|
|
use OCP\SabrePluginEvent;
|
2016-04-10 13:43:15 +03:00
|
|
|
use Sabre\CardDAV\VCFExportPlugin;
|
2015-10-21 16:06:48 +03:00
|
|
|
use Sabre\DAV\Auth\Plugin;
|
|
|
|
|
|
|
|
class Server {
|
|
|
|
|
|
|
|
/** @var IRequest */
|
|
|
|
private $request;
|
|
|
|
|
2016-07-05 23:45:05 +03:00
|
|
|
/** @var string */
|
|
|
|
private $baseUri;
|
|
|
|
|
|
|
|
/** @var Connector\Sabre\Server */
|
2016-07-07 17:56:28 +03:00
|
|
|
private $server;
|
2016-07-05 23:45:05 +03:00
|
|
|
|
2015-10-21 16:06:48 +03:00
|
|
|
public function __construct(IRequest $request, $baseUri) {
|
|
|
|
$this->request = $request;
|
|
|
|
$this->baseUri = $baseUri;
|
2015-11-16 18:09:04 +03:00
|
|
|
$logger = \OC::$server->getLogger();
|
2015-12-18 13:56:25 +03:00
|
|
|
$mailer = \OC::$server->getMailer();
|
2016-01-13 13:54:42 +03:00
|
|
|
$dispatcher = \OC::$server->getEventDispatcher();
|
2015-11-16 18:09:04 +03:00
|
|
|
|
2015-10-21 16:06:48 +03:00
|
|
|
$root = new RootCollection();
|
|
|
|
$this->server = new \OCA\DAV\Connector\Sabre\Server($root);
|
|
|
|
|
|
|
|
// Backends
|
2015-10-26 15:02:10 +03:00
|
|
|
$authBackend = new Auth(
|
|
|
|
\OC::$server->getSession(),
|
2016-02-16 15:16:52 +03:00
|
|
|
\OC::$server->getUserSession(),
|
2016-06-01 11:42:38 +03:00
|
|
|
\OC::$server->getRequest(),
|
2016-07-20 19:36:15 +03:00
|
|
|
\OC::$server->getTwoFactorAuthManager(),
|
|
|
|
\OC::$server->getBruteForceThrottler()
|
2015-10-26 15:02:10 +03:00
|
|
|
);
|
2015-10-21 16:06:48 +03: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-07-14 17:19:31 +03:00
|
|
|
$authPlugin = new Plugin();
|
2015-12-03 18:22:18 +03:00
|
|
|
$this->server->addPlugin($authPlugin);
|
2015-12-04 14:11:07 +03:00
|
|
|
|
|
|
|
// allow setup of additional auth backends
|
|
|
|
$event = new SabrePluginEvent($this->server);
|
|
|
|
$dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
|
|
|
|
|
2016-07-14 17:19:31 +03:00
|
|
|
// because we are throwing exceptions this plugin has to be the last one
|
|
|
|
$authPlugin->addBackend($authBackend);
|
|
|
|
|
2016-03-17 18:51:19 +03: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 18:09:04 +03:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger));
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin());
|
2015-11-23 15:53:57 +03:00
|
|
|
$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
|
2015-10-21 16:06:48 +03:00
|
|
|
|
2015-11-24 13:15:31 +03:00
|
|
|
// acl
|
2016-02-29 19:30:02 +03:00
|
|
|
$acl = new DavAclPlugin();
|
2016-05-02 15:19:10 +03:00
|
|
|
$acl->principalCollectionSet = [
|
|
|
|
'principals/users', 'principals/groups'
|
|
|
|
];
|
2015-11-24 13:15:31 +03:00
|
|
|
$acl->defaultUsernamePath = 'principals/users';
|
|
|
|
$this->server->addPlugin($acl);
|
|
|
|
|
2015-10-31 03:28:21 +03: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());
|
2015-12-18 13:56:25 +03:00
|
|
|
$this->server->addPlugin(new IMipPlugin($mailer, $logger));
|
2015-10-31 03:28:21 +03:00
|
|
|
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
|
|
|
|
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
|
2016-01-25 22:23:11 +03:00
|
|
|
$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
|
2015-11-09 15:27:19 +03:00
|
|
|
|
2015-10-31 03:28:21 +03:00
|
|
|
// addressbook plugins
|
2015-11-27 15:14:55 +03:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
|
2016-04-10 13:43:15 +03:00
|
|
|
$this->server->addPlugin(new VCFExportPlugin());
|
2016-06-21 16:25:44 +03:00
|
|
|
$this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger()));
|
2015-11-10 09:27:34 +03:00
|
|
|
|
2015-11-27 14:54:31 +03:00
|
|
|
// system tags plugins
|
2016-02-19 21:45:03 +03:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\SystemTag\SystemTagPlugin(
|
|
|
|
\OC::$server->getSystemTagManager(),
|
|
|
|
\OC::$server->getGroupManager(),
|
|
|
|
\OC::$server->getUserSession()
|
|
|
|
));
|
2015-11-27 14:54:31 +03:00
|
|
|
|
2016-01-11 20:09:00 +03:00
|
|
|
// comments plugin
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\Comments\CommentsPlugin(
|
|
|
|
\OC::$server->getCommentsManager(),
|
|
|
|
\OC::$server->getUserSession()
|
|
|
|
));
|
|
|
|
|
2016-01-26 19:31:01 +03: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/',
|
|
|
|
])) {
|
2015-11-13 13:47:32 +03:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
|
|
|
|
}
|
|
|
|
|
2016-03-24 16:29:55 +03:00
|
|
|
if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
|
|
|
|
$this->server->addPlugin(new BrowserErrorPagePlugin());
|
|
|
|
}
|
|
|
|
|
2015-10-21 16:06:48 +03: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
|
|
|
|
$user = \OC::$server->getUserSession()->getUser();
|
|
|
|
if (!is_null($user)) {
|
2016-02-18 22:11:59 +03:00
|
|
|
$view = \OC\Files\Filesystem::getView();
|
2016-04-18 12:18:50 +03:00
|
|
|
$this->server->addPlugin(
|
|
|
|
new FilesPlugin(
|
|
|
|
$this->server->tree,
|
|
|
|
$view,
|
|
|
|
\OC::$server->getConfig(),
|
2016-06-09 12:29:20 +03:00
|
|
|
$this->request,
|
2016-07-26 14:15:12 +03:00
|
|
|
\OC::$server->getPreviewManager(),
|
2016-04-18 12:18:50 +03:00
|
|
|
false,
|
|
|
|
!\OC::$server->getConfig()->getSystemValue('debug', false)
|
|
|
|
)
|
|
|
|
);
|
2016-02-18 22:11:59 +03:00
|
|
|
|
2015-10-21 16:06:48 +03:00
|
|
|
$this->server->addPlugin(
|
|
|
|
new \Sabre\DAV\PropertyStorage\Plugin(
|
|
|
|
new CustomPropertiesBackend(
|
|
|
|
$this->server->tree,
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
\OC::$server->getUserSession()->getUser()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2016-07-29 07:40:39 +03:00
|
|
|
$this->server->addPlugin(
|
|
|
|
new \OCA\DAV\Connector\Sabre\QuotaPlugin($view));
|
|
|
|
|
2015-10-21 16:06:48 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function exec() {
|
|
|
|
$this->server->exec();
|
|
|
|
}
|
|
|
|
}
|