2013-10-23 18:03:57 +04:00
|
|
|
<?php
|
2015-02-26 13:37:37 +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 Björn Schießle <bjoern@schiessle.org>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-02-26 13:37:37 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @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-02-26 13:37:37 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-08-30 20:13:01 +03:00
|
|
|
namespace OCA\DAV\Connector\Sabre;
|
2015-02-12 14:29:01 +03:00
|
|
|
|
2016-03-21 14:27:13 +03:00
|
|
|
use OC\Files\View;
|
2016-06-01 17:17:57 +03:00
|
|
|
use OCP\Files\ForbiddenException;
|
2016-07-26 14:15:12 +03:00
|
|
|
use OCP\IPreview;
|
2016-03-21 14:27:13 +03:00
|
|
|
use Sabre\DAV\Exception\Forbidden;
|
2016-02-28 21:41:46 +03:00
|
|
|
use Sabre\DAV\Exception\NotFound;
|
2015-02-25 13:45:44 +03:00
|
|
|
use Sabre\DAV\IFile;
|
2015-02-12 14:29:01 +03:00
|
|
|
use \Sabre\DAV\PropFind;
|
|
|
|
use \Sabre\DAV\PropPatch;
|
2016-04-12 15:26:42 +03:00
|
|
|
use Sabre\DAV\ServerPlugin;
|
2016-03-21 14:27:13 +03:00
|
|
|
use Sabre\DAV\Tree;
|
2015-02-12 14:29:01 +03:00
|
|
|
use \Sabre\HTTP\RequestInterface;
|
|
|
|
use \Sabre\HTTP\ResponseInterface;
|
2015-12-09 19:31:14 +03:00
|
|
|
use OCP\Files\StorageNotAvailableException;
|
2016-04-18 12:18:50 +03:00
|
|
|
use OCP\IConfig;
|
2016-06-09 12:29:20 +03:00
|
|
|
use OCP\IRequest;
|
2017-03-30 12:30:37 +03:00
|
|
|
use OCA\DAV\Upload\FutureFile;
|
2015-02-12 14:29:01 +03:00
|
|
|
|
2016-04-12 15:26:42 +03:00
|
|
|
class FilesPlugin extends ServerPlugin {
|
2013-10-23 18:03:57 +04:00
|
|
|
|
|
|
|
// namespace
|
2013-10-24 16:40:43 +04:00
|
|
|
const NS_OWNCLOUD = 'http://owncloud.org/ns';
|
2016-07-26 14:15:12 +03:00
|
|
|
const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
|
2015-02-12 14:29:01 +03:00
|
|
|
const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
|
2015-11-18 13:41:04 +03:00
|
|
|
const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
|
2015-02-12 14:29:01 +03:00
|
|
|
const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
|
2016-04-15 11:06:00 +03:00
|
|
|
const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
|
2015-02-12 14:29:01 +03:00
|
|
|
const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
|
|
|
|
const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
|
|
|
|
const GETETAG_PROPERTYNAME = '{DAV:}getetag';
|
2015-10-13 13:51:21 +03:00
|
|
|
const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
|
2015-11-02 17:05:16 +03:00
|
|
|
const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
|
|
|
|
const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
|
2016-02-08 13:55:07 +03:00
|
|
|
const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
|
2016-04-18 12:18:50 +03:00
|
|
|
const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
|
2016-07-26 14:15:12 +03:00
|
|
|
const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
|
2017-04-26 15:53:11 +03:00
|
|
|
const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
|
2013-10-23 18:03:57 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to main server object
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* @var \Sabre\DAV\Server
|
2013-10-23 18:03:57 +04:00
|
|
|
*/
|
|
|
|
private $server;
|
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
/**
|
2016-03-21 14:27:13 +03:00
|
|
|
* @var Tree
|
2015-02-12 14:29:01 +03:00
|
|
|
*/
|
|
|
|
private $tree;
|
|
|
|
|
2015-07-13 15:20:35 +03:00
|
|
|
/**
|
|
|
|
* Whether this is public webdav.
|
|
|
|
* If true, some returned information will be stripped off.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $isPublic;
|
|
|
|
|
2015-10-06 16:36:54 +03:00
|
|
|
/**
|
2016-03-21 14:27:13 +03:00
|
|
|
* @var View
|
2015-10-06 16:36:54 +03:00
|
|
|
*/
|
|
|
|
private $fileView;
|
|
|
|
|
2015-02-25 13:45:44 +03:00
|
|
|
/**
|
2016-03-21 14:27:13 +03:00
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $downloadAttachment;
|
|
|
|
|
2016-04-18 12:18:50 +03:00
|
|
|
/**
|
|
|
|
* @var IConfig
|
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2016-06-09 12:29:20 +03:00
|
|
|
/**
|
|
|
|
* @var IRequest
|
|
|
|
*/
|
|
|
|
private $request;
|
|
|
|
|
2016-07-26 14:15:12 +03:00
|
|
|
/**
|
|
|
|
* @var IPreview
|
|
|
|
*/
|
|
|
|
private $previewManager;
|
|
|
|
|
2016-03-21 14:27:13 +03:00
|
|
|
/**
|
|
|
|
* @param Tree $tree
|
2016-06-09 12:29:20 +03:00
|
|
|
* @param IConfig $config
|
|
|
|
* @param IRequest $request
|
2016-07-26 14:15:12 +03:00
|
|
|
* @param IPreview $previewManager
|
2015-10-06 16:36:54 +03:00
|
|
|
* @param bool $isPublic
|
2016-03-21 14:27:13 +03:00
|
|
|
* @param bool $downloadAttachment
|
2015-02-25 13:45:44 +03:00
|
|
|
*/
|
2016-03-21 14:27:13 +03:00
|
|
|
public function __construct(Tree $tree,
|
2016-04-18 12:18:50 +03:00
|
|
|
IConfig $config,
|
2016-06-09 12:29:20 +03:00
|
|
|
IRequest $request,
|
2016-07-26 14:15:12 +03:00
|
|
|
IPreview $previewManager,
|
2016-03-21 14:27:13 +03:00
|
|
|
$isPublic = false,
|
|
|
|
$downloadAttachment = true) {
|
2015-02-12 14:29:01 +03:00
|
|
|
$this->tree = $tree;
|
2016-04-18 12:18:50 +03:00
|
|
|
$this->config = $config;
|
2016-06-09 12:29:20 +03:00
|
|
|
$this->request = $request;
|
2015-07-13 15:20:35 +03:00
|
|
|
$this->isPublic = $isPublic;
|
2016-03-21 14:27:13 +03:00
|
|
|
$this->downloadAttachment = $downloadAttachment;
|
2016-07-26 14:15:12 +03:00
|
|
|
$this->previewManager = $previewManager;
|
2015-02-12 14:29:01 +03:00
|
|
|
}
|
|
|
|
|
2013-10-23 18:03:57 +04:00
|
|
|
/**
|
|
|
|
* This initializes the plugin.
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* This function is called by \Sabre\DAV\Server, after
|
2013-10-23 18:03:57 +04:00
|
|
|
* addPlugin is called.
|
|
|
|
*
|
|
|
|
* This method should set up the required event subscriptions.
|
|
|
|
*
|
2014-01-09 17:25:48 +04:00
|
|
|
* @param \Sabre\DAV\Server $server
|
2013-10-23 18:03:57 +04:00
|
|
|
* @return void
|
|
|
|
*/
|
2014-01-09 17:25:48 +04:00
|
|
|
public function initialize(\Sabre\DAV\Server $server) {
|
2013-10-23 18:03:57 +04:00
|
|
|
|
2015-12-03 17:55:10 +03:00
|
|
|
$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
|
2016-07-26 14:15:12 +03:00
|
|
|
$server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
|
2015-02-12 14:29:01 +03:00
|
|
|
$server->protectedProperties[] = self::FILEID_PROPERTYNAME;
|
2015-11-18 13:41:04 +03:00
|
|
|
$server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
|
2015-02-12 14:29:01 +03:00
|
|
|
$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
|
2016-03-03 22:58:18 +03:00
|
|
|
$server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
|
2015-02-12 14:29:01 +03:00
|
|
|
$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
|
|
|
|
$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
|
2015-11-02 17:05:16 +03:00
|
|
|
$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
|
|
|
|
$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
|
2016-02-08 13:55:07 +03:00
|
|
|
$server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
|
2016-04-18 12:18:50 +03:00
|
|
|
$server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
|
2016-07-26 14:15:12 +03:00
|
|
|
$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
|
2017-04-26 15:53:11 +03:00
|
|
|
$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
|
2015-02-12 14:29:01 +03:00
|
|
|
|
|
|
|
// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
|
2015-10-13 13:51:21 +03:00
|
|
|
$allowedProperties = ['{DAV:}getetag'];
|
2015-02-12 14:29:01 +03:00
|
|
|
$server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
|
2013-10-23 18:03:57 +04:00
|
|
|
|
|
|
|
$this->server = $server;
|
2015-02-12 14:29:01 +03:00
|
|
|
$this->server->on('propFind', array($this, 'handleGetProperties'));
|
|
|
|
$this->server->on('propPatch', array($this, 'handleUpdateProperties'));
|
|
|
|
$this->server->on('afterBind', array($this, 'sendFileIdHeader'));
|
|
|
|
$this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
|
2015-02-25 13:45:44 +03:00
|
|
|
$this->server->on('afterMethod:GET', [$this,'httpGet']);
|
2015-11-19 14:01:55 +03:00
|
|
|
$this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
|
2015-05-21 18:52:13 +03:00
|
|
|
$this->server->on('afterResponse', function($request, ResponseInterface $response) {
|
|
|
|
$body = $response->getBody();
|
|
|
|
if (is_resource($body)) {
|
|
|
|
fclose($body);
|
|
|
|
}
|
|
|
|
});
|
2015-10-06 16:36:54 +03:00
|
|
|
$this->server->on('beforeMove', [$this, 'checkMove']);
|
2017-03-30 12:30:37 +03:00
|
|
|
$this->server->on('beforeMove', [$this, 'beforeMoveFutureFile']);
|
2015-10-06 16:36:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin that checks if a move can actually be performed.
|
2016-04-12 15:26:42 +03:00
|
|
|
*
|
2015-10-06 16:36:54 +03:00
|
|
|
* @param string $source source path
|
|
|
|
* @param string $destination destination path
|
2016-03-21 14:27:13 +03:00
|
|
|
* @throws Forbidden
|
2016-04-12 15:26:42 +03:00
|
|
|
* @throws NotFound
|
2015-10-06 16:36:54 +03:00
|
|
|
*/
|
|
|
|
function checkMove($source, $destination) {
|
2016-04-12 16:51:09 +03:00
|
|
|
$sourceNode = $this->tree->getNodeForPath($source);
|
2016-06-06 18:01:27 +03:00
|
|
|
if (!$sourceNode instanceof Node) {
|
2016-04-12 15:26:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-07-20 10:43:23 +03:00
|
|
|
list($sourceDir,) = \Sabre\Uri\split($source);
|
|
|
|
list($destinationDir,) = \Sabre\Uri\split($destination);
|
2015-10-06 16:36:54 +03:00
|
|
|
|
|
|
|
if ($sourceDir !== $destinationDir) {
|
2016-06-06 18:01:27 +03:00
|
|
|
$sourceNodeFileInfo = $sourceNode->getFileInfo();
|
2017-07-19 16:37:03 +03:00
|
|
|
if ($sourceNodeFileInfo !== null && !$sourceNodeFileInfo->isDeletable()) {
|
2016-03-21 14:27:13 +03:00
|
|
|
throw new Forbidden($source . " cannot be deleted");
|
2015-10-06 16:36:54 +03:00
|
|
|
}
|
2017-07-19 16:37:03 +03:00
|
|
|
|
|
|
|
throw new NotFound($source . ' does not exist');
|
2015-10-06 16:36:54 +03:00
|
|
|
}
|
2015-02-25 13:45:44 +03:00
|
|
|
}
|
|
|
|
|
2015-11-19 14:01:55 +03:00
|
|
|
/**
|
|
|
|
* This sets a cookie to be able to recognize the start of the download
|
|
|
|
* the content must not be longer than 32 characters and must only contain
|
|
|
|
* alphanumeric characters
|
|
|
|
*
|
|
|
|
* @param RequestInterface $request
|
|
|
|
* @param ResponseInterface $response
|
|
|
|
*/
|
|
|
|
function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
|
|
|
|
$queryParams = $request->getQueryParameters();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this sets a cookie to be able to recognize the start of the download
|
|
|
|
* the content must not be longer than 32 characters and must only contain
|
|
|
|
* alphanumeric characters
|
|
|
|
*/
|
|
|
|
if (isset($queryParams['downloadStartSecret'])) {
|
|
|
|
$token = $queryParams['downloadStartSecret'];
|
|
|
|
if (!isset($token[32])
|
|
|
|
&& preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
|
|
|
|
// FIXME: use $response->setHeader() instead
|
|
|
|
setcookie('ocDownloadStarted', $token, time() + 20, '/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 13:45:44 +03:00
|
|
|
/**
|
2016-01-29 23:50:48 +03:00
|
|
|
* Add headers to file download
|
|
|
|
*
|
2015-02-25 13:45:44 +03:00
|
|
|
* @param RequestInterface $request
|
|
|
|
* @param ResponseInterface $response
|
|
|
|
*/
|
|
|
|
function httpGet(RequestInterface $request, ResponseInterface $response) {
|
|
|
|
// Only handle valid files
|
2015-03-26 22:45:39 +03:00
|
|
|
$node = $this->tree->getNodeForPath($request->getPath());
|
2015-02-25 13:45:44 +03:00
|
|
|
if (!($node instanceof IFile)) return;
|
|
|
|
|
2016-12-14 19:35:27 +03:00
|
|
|
// adds a 'Content-Disposition: attachment' header in case no disposition
|
|
|
|
// header has been set before
|
|
|
|
if ($this->downloadAttachment &&
|
|
|
|
$response->getHeader('Content-Disposition') === null) {
|
2016-06-09 12:29:20 +03:00
|
|
|
$filename = $node->getName();
|
|
|
|
if ($this->request->isUserAgent(
|
|
|
|
[
|
|
|
|
\OC\AppFramework\Http\Request::USER_AGENT_IE,
|
|
|
|
\OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME,
|
|
|
|
\OC\AppFramework\Http\Request::USER_AGENT_FREEBOX,
|
|
|
|
])) {
|
|
|
|
$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
|
|
|
|
} else {
|
|
|
|
$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
|
|
|
|
. '; filename="' . rawurlencode($filename) . '"');
|
|
|
|
}
|
2016-03-21 14:27:13 +03:00
|
|
|
}
|
2016-01-29 23:50:48 +03:00
|
|
|
|
2016-02-19 12:56:43 +03:00
|
|
|
if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
|
|
|
|
//Add OC-Checksum header
|
|
|
|
/** @var $node File */
|
|
|
|
$checksum = $node->getChecksum();
|
2016-02-28 21:41:46 +03:00
|
|
|
if ($checksum !== null && $checksum !== '') {
|
2016-02-19 12:56:43 +03:00
|
|
|
$response->addHeader('OC-Checksum', $checksum);
|
|
|
|
}
|
2016-01-29 23:50:48 +03:00
|
|
|
}
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds all ownCloud-specific properties
|
|
|
|
*
|
2015-02-12 14:29:01 +03:00
|
|
|
* @param PropFind $propFind
|
2014-01-09 17:25:48 +04:00
|
|
|
* @param \Sabre\DAV\INode $node
|
2013-10-23 18:03:57 +04:00
|
|
|
* @return void
|
|
|
|
*/
|
2015-02-12 14:29:01 +03:00
|
|
|
public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
|
2013-10-23 18:03:57 +04:00
|
|
|
|
2016-04-13 18:31:01 +03:00
|
|
|
$httpRequest = $this->server->httpRequest;
|
|
|
|
|
2015-08-30 20:13:01 +03:00
|
|
|
if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
|
2017-05-26 13:36:42 +03:00
|
|
|
/**
|
|
|
|
* This was disabled, because it made dir listing throw an exception,
|
|
|
|
* so users were unable to navigate into folders where one subitem
|
|
|
|
* is blocked by the files_accesscontrol app, see:
|
|
|
|
* https://github.com/nextcloud/files_accesscontrol/issues/65
|
2017-02-24 13:56:29 +03:00
|
|
|
if (!$node->getFileInfo()->isReadable()) {
|
|
|
|
// avoid detecting files through this means
|
|
|
|
throw new NotFound();
|
|
|
|
}
|
2017-05-26 13:36:42 +03:00
|
|
|
*/
|
2013-10-23 18:03:57 +04:00
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
$propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
|
|
|
|
return $node->getFileId();
|
|
|
|
});
|
2013-10-23 18:03:57 +04:00
|
|
|
|
2015-11-18 13:41:04 +03:00
|
|
|
$propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
|
|
|
|
return $node->getInternalFileId();
|
|
|
|
});
|
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
|
2015-07-13 15:20:35 +03:00
|
|
|
$perms = $node->getDavPermissions();
|
|
|
|
if ($this->isPublic) {
|
|
|
|
// remove mount information
|
|
|
|
$perms = str_replace(['S', 'M'], '', $perms);
|
|
|
|
}
|
|
|
|
return $perms;
|
2015-02-12 14:29:01 +03:00
|
|
|
});
|
2014-05-02 19:37:16 +04:00
|
|
|
|
2016-04-13 18:31:01 +03:00
|
|
|
$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
|
|
|
|
return $node->getSharePermissions(
|
|
|
|
$httpRequest->getRawServerValue('PHP_AUTH_USER')
|
|
|
|
);
|
2016-03-03 22:58:18 +03:00
|
|
|
});
|
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
|
2016-03-21 14:27:13 +03:00
|
|
|
return $node->getETag();
|
2015-02-12 14:29:01 +03:00
|
|
|
});
|
2016-03-10 22:53:56 +03:00
|
|
|
|
|
|
|
$propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
|
|
|
|
$owner = $node->getOwner();
|
2017-03-02 17:26:00 +03:00
|
|
|
if (!$owner) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return $owner->getUID();
|
|
|
|
}
|
2016-03-10 22:53:56 +03:00
|
|
|
});
|
|
|
|
$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
|
|
|
|
$owner = $node->getOwner();
|
2017-03-02 17:26:00 +03:00
|
|
|
if (!$owner) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return $owner->getDisplayName();
|
|
|
|
}
|
2016-03-10 22:53:56 +03:00
|
|
|
});
|
2016-04-18 12:18:50 +03:00
|
|
|
|
2016-07-26 14:15:12 +03:00
|
|
|
$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
|
|
|
|
return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
|
|
|
|
});
|
2016-11-21 17:03:45 +03:00
|
|
|
$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
|
|
|
|
return $node->getSize();
|
|
|
|
});
|
2017-05-08 15:34:36 +03:00
|
|
|
$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
|
|
|
|
return $node->getFileInfo()->getMountPoint()->getMountType();
|
|
|
|
});
|
2016-04-18 12:18:50 +03:00
|
|
|
}
|
|
|
|
|
2016-09-08 13:56:48 +03:00
|
|
|
if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
|
2016-04-18 12:18:50 +03:00
|
|
|
$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
|
|
|
|
return $this->config->getSystemValue('data-fingerprint', '');
|
|
|
|
});
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|
|
|
|
|
2015-08-30 20:13:01 +03:00
|
|
|
if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
|
2015-02-12 14:29:01 +03:00
|
|
|
$propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
|
2015-08-30 20:13:01 +03:00
|
|
|
/** @var $node \OCA\DAV\Connector\Sabre\File */
|
2015-12-09 19:31:14 +03:00
|
|
|
try {
|
|
|
|
$directDownloadUrl = $node->getDirectDownload();
|
|
|
|
if (isset($directDownloadUrl['url'])) {
|
|
|
|
return $directDownloadUrl['url'];
|
|
|
|
}
|
|
|
|
} catch (StorageNotAvailableException $e) {
|
|
|
|
return false;
|
2016-06-01 17:17:57 +03:00
|
|
|
} catch (ForbiddenException $e) {
|
|
|
|
return false;
|
2015-02-12 14:29:01 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2016-01-29 23:50:48 +03:00
|
|
|
|
2016-02-08 13:55:07 +03:00
|
|
|
$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
|
2016-01-29 23:50:48 +03:00
|
|
|
$checksum = $node->getChecksum();
|
2016-02-28 21:41:46 +03:00
|
|
|
if ($checksum === NULL || $checksum === '') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-02-08 13:55:07 +03:00
|
|
|
return new ChecksumList($checksum);
|
2016-01-29 23:50:48 +03:00
|
|
|
});
|
|
|
|
|
2014-12-15 17:20:24 +03:00
|
|
|
}
|
|
|
|
|
2015-08-30 20:13:01 +03:00
|
|
|
if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
|
2015-02-12 14:29:01 +03:00
|
|
|
$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
|
|
|
|
return $node->getSize();
|
|
|
|
});
|
2014-08-29 13:39:02 +04:00
|
|
|
}
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|
|
|
|
|
2015-02-12 14:29:01 +03:00
|
|
|
/**
|
|
|
|
* Update ownCloud-specific properties
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param PropPatch $propPatch
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handleUpdateProperties($path, PropPatch $propPatch) {
|
2017-02-08 20:18:38 +03:00
|
|
|
$node = $this->tree->getNodeForPath($path);
|
|
|
|
if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
|
2015-02-12 14:29:01 +03:00
|
|
|
if (empty($time)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$node->touch($time);
|
|
|
|
return true;
|
|
|
|
});
|
2017-02-08 20:18:38 +03:00
|
|
|
$propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
|
2015-02-12 14:29:01 +03:00
|
|
|
if (empty($etag)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($node->setEtag($etag) !== -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:20:59 +04:00
|
|
|
/**
|
2014-05-12 00:51:30 +04:00
|
|
|
* @param string $filePath
|
2014-01-09 17:25:48 +04:00
|
|
|
* @param \Sabre\DAV\INode $node
|
|
|
|
* @throws \Sabre\DAV\Exception\BadRequest
|
2013-10-25 15:20:59 +04:00
|
|
|
*/
|
2014-01-09 17:25:48 +04:00
|
|
|
public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
|
2013-11-25 18:35:26 +04:00
|
|
|
// chunked upload handling
|
|
|
|
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
|
2017-07-20 10:43:23 +03:00
|
|
|
list($path, $name) = \Sabre\Uri\split($filePath);
|
2015-02-12 14:29:01 +03:00
|
|
|
$info = \OC_FileChunking::decodeName($name);
|
2013-11-25 18:35:26 +04:00
|
|
|
if (!empty($info)) {
|
|
|
|
$filePath = $path . '/' . $info['name'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 19:14:08 +04:00
|
|
|
// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
|
2013-11-25 18:35:26 +04:00
|
|
|
if (!$this->server->tree->nodeExists($filePath)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-20 19:14:08 +04:00
|
|
|
$node = $this->server->tree->getNodeForPath($filePath);
|
2015-08-30 20:13:01 +03:00
|
|
|
if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
|
2013-10-25 15:20:59 +04:00
|
|
|
$fileId = $node->getFileId();
|
|
|
|
if (!is_null($fileId)) {
|
|
|
|
$this->server->httpResponse->setHeader('OC-FileId', $fileId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-30 12:30:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Move handler for future file.
|
|
|
|
*
|
|
|
|
* This overrides the default move behavior to prevent Sabre
|
|
|
|
* to delete the target file before moving. Because deleting would
|
|
|
|
* lose the file id and metadata.
|
|
|
|
*
|
|
|
|
* @param string $path source path
|
|
|
|
* @param string $destination destination path
|
|
|
|
* @return bool|void false to stop handling, void to skip this handler
|
|
|
|
*/
|
|
|
|
public function beforeMoveFutureFile($path, $destination) {
|
|
|
|
$sourceNode = $this->tree->getNodeForPath($path);
|
|
|
|
if (!$sourceNode instanceof FutureFile) {
|
|
|
|
// skip handling as the source is not a chunked FutureFile
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->tree->nodeExists($destination)) {
|
|
|
|
// skip and let the default handler do its work
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do a move manually, skipping Sabre's default "delete" for existing nodes
|
|
|
|
$this->tree->move($path, $destination);
|
|
|
|
|
|
|
|
// trigger all default events (copied from CorePlugin::move)
|
|
|
|
$this->server->emit('afterMove', [$path, $destination]);
|
|
|
|
$this->server->emit('afterUnbind', [$path]);
|
|
|
|
$this->server->emit('afterBind', [$destination]);
|
|
|
|
|
|
|
|
$response = $this->server->httpResponse;
|
|
|
|
$response->setHeader('Content-Length', '0');
|
|
|
|
$response->setStatus(204);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-23 18:03:57 +04:00
|
|
|
}
|