2015-10-21 13:06:48 +00:00
|
|
|
<?php
|
2016-01-12 14:02:16 +00:00
|
|
|
/**
|
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
* @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;
|
2015-12-03 15:22:18 +00:00
|
|
|
use OCA\DAV\Connector\FedAuth;
|
2015-10-21 13:06:48 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\Auth;
|
|
|
|
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
|
|
|
|
use OCA\DAV\Files\CustomPropertiesBackend;
|
|
|
|
use OCP\IRequest;
|
2015-12-04 11:11:07 +00:00
|
|
|
use OCP\SabrePluginEvent;
|
2015-10-21 13:06:48 +00:00
|
|
|
use Sabre\DAV\Auth\Plugin;
|
2015-10-26 23:53:54 +00:00
|
|
|
use Sabre\DAV\IFile;
|
|
|
|
use Sabre\HTTP\RequestInterface;
|
|
|
|
use Sabre\HTTP\ResponseInterface;
|
|
|
|
use Sabre\HTTP\Util;
|
2015-10-21 13:06:48 +00:00
|
|
|
|
|
|
|
class Server {
|
|
|
|
|
|
|
|
/** @var IRequest */
|
|
|
|
private $request;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Backends
|
2015-10-26 12:02:10 +00:00
|
|
|
$authBackend = new Auth(
|
|
|
|
\OC::$server->getSession(),
|
|
|
|
\OC::$server->getUserSession()
|
|
|
|
);
|
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()));
|
2015-12-03 15:22:18 +00:00
|
|
|
$authPlugin = new Plugin($authBackend, 'ownCloud');
|
|
|
|
$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);
|
|
|
|
|
2015-11-16 15:09:04 +00:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin());
|
|
|
|
$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
|
|
|
|
$acl = new \Sabre\DAVACL\Plugin();
|
|
|
|
$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());
|
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()));
|
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());
|
2015-11-10 06:27:34 +00:00
|
|
|
|
2015-11-27 11:54:31 +00:00
|
|
|
// system tags plugins
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\SystemTag\SystemTagPlugin(\OC::$server->getSystemTagManager()));
|
|
|
|
|
2016-01-11 17:09:00 +00:00
|
|
|
// comments plugin
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\Comments\CommentsPlugin(
|
|
|
|
\OC::$server->getCommentsManager(),
|
|
|
|
\OC::$server->getUserSession()
|
|
|
|
));
|
|
|
|
|
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/',
|
|
|
|
])) {
|
2015-11-13 10:47:32 +00:00
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
|
|
|
|
}
|
|
|
|
|
2015-10-26 23:53:54 +00:00
|
|
|
// Serve all files with an Content-Disposition of type "attachment"
|
|
|
|
$this->server->on('beforeMethod', function (RequestInterface $requestInterface, ResponseInterface $responseInterface) {
|
2016-02-08 16:49:25 +00:00
|
|
|
if ($requestInterface->getMethod() === 'GET') {
|
|
|
|
$path = $requestInterface->getPath();
|
|
|
|
if ($this->server->tree->nodeExists($path)) {
|
|
|
|
$node = $this->server->tree->getNodeForPath($path);
|
|
|
|
if (($node instanceof IFile)) {
|
|
|
|
$responseInterface->addHeader('Content-Disposition', 'attachment');
|
|
|
|
}
|
2015-10-26 23:53:54 +00:00
|
|
|
}
|
2016-02-08 16:49:25 +00:00
|
|
|
}
|
2015-10-26 23:53:54 +00:00
|
|
|
});
|
|
|
|
|
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
|
|
|
|
$user = \OC::$server->getUserSession()->getUser();
|
|
|
|
if (!is_null($user)) {
|
|
|
|
$this->server->addPlugin(
|
|
|
|
new \Sabre\DAV\PropertyStorage\Plugin(
|
|
|
|
new CustomPropertiesBackend(
|
|
|
|
$this->server->tree,
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
\OC::$server->getUserSession()->getUser()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function exec() {
|
|
|
|
$this->server->exec();
|
|
|
|
}
|
|
|
|
}
|