2015-10-21 16:06:48 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\DAV;
|
|
|
|
|
2015-12-18 13:56:25 +03:00
|
|
|
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
|
2015-12-03 18:22:18 +03:00
|
|
|
use OCA\DAV\Connector\FedAuth;
|
2015-10-21 16:06:48 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\Auth;
|
|
|
|
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
|
|
|
|
use OCA\DAV\Files\CustomPropertiesBackend;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use Sabre\DAV\Auth\Plugin;
|
|
|
|
|
|
|
|
class Server {
|
|
|
|
|
|
|
|
/** @var IRequest */
|
|
|
|
private $request;
|
|
|
|
|
|
|
|
public function __construct(IRequest $request, $baseUri) {
|
|
|
|
$this->request = $request;
|
|
|
|
$this->baseUri = $baseUri;
|
2015-11-16 18:09:04 +03:00
|
|
|
$logger = \OC::$server->getLogger();
|
|
|
|
$dispatcher = \OC::$server->getEventDispatcher();
|
2015-12-18 13:56:25 +03:00
|
|
|
$mailer = \OC::$server->getMailer();
|
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(),
|
|
|
|
\OC::$server->getUserSession()
|
|
|
|
);
|
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()));
|
2015-12-03 18:22:18 +03:00
|
|
|
$authPlugin = new Plugin($authBackend, 'ownCloud');
|
|
|
|
$authPlugin->addBackend(new FedAuth(\OC::$server->getDatabaseConnection()));
|
|
|
|
$this->server->addPlugin($authPlugin);
|
2015-11-16 18:09:04 +03: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());
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ListenerPlugin($dispatcher));
|
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
|
|
|
|
$acl = new \Sabre\DAVACL\Plugin();
|
|
|
|
$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\SharingPlugin());
|
|
|
|
$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
|
|
|
|
$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
|
2015-11-10 09:54:35 +03:00
|
|
|
$this->server->addPlugin(new CardDAV\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());
|
2015-11-10 09:27:34 +03:00
|
|
|
|
2015-11-27 14:54:31 +03:00
|
|
|
// system tags plugins
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\SystemTag\SystemTagPlugin(\OC::$server->getSystemTagManager()));
|
|
|
|
|
2015-11-13 13:47:32 +03:00
|
|
|
// Finder on OS X requires Class 2 WebDAV support (locking), since we do
|
|
|
|
// not provide locking we emulate it using a fake locking plugin.
|
|
|
|
if($request->isUserAgent(['/WebDAVFS/'])) {
|
|
|
|
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin());
|
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
}
|