2015-10-21 16:06:48 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\DAV;
|
|
|
|
|
|
|
|
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;
|
|
|
|
use Sabre\HTTP\Util;
|
|
|
|
|
|
|
|
class Server {
|
|
|
|
|
|
|
|
/** @var IRequest */
|
|
|
|
private $request;
|
|
|
|
|
|
|
|
public function __construct(IRequest $request, $baseUri) {
|
|
|
|
$this->request = $request;
|
|
|
|
$this->baseUri = $baseUri;
|
|
|
|
$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()));
|
|
|
|
$this->server->addPlugin(new Plugin($authBackend, 'ownCloud'));
|
|
|
|
|
2015-11-09 15:27:19 +03:00
|
|
|
$this->server->addPlugin(new \Sabre\DAVACL\Plugin());
|
|
|
|
|
2015-11-10 09:27:34 +03:00
|
|
|
$this->server->addPlugin(new \Sabre\CardDAV\Plugin());
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|