2014-10-15 09:58:44 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Björn Schießle <schiessle@owncloud.com>
|
|
|
|
* @author Georg Ehrke <georg@owncloud.com>
|
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
2014-10-15 09:58:44 +00:00
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
|
|
|
* @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
|
2015-10-26 12:54:55 +00:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-03-26 10:44:34 +00:00
|
|
|
*
|
2016-01-12 14:02:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2015-03-26 10:44:34 +00: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/>
|
2014-10-15 09:58:44 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2014-10-15 09:58:44 +00:00
|
|
|
namespace OCA\Files_Sharing\Controllers;
|
|
|
|
|
|
|
|
use OC;
|
|
|
|
use OC\Files\Filesystem;
|
|
|
|
use OC_Files;
|
|
|
|
use OC_Util;
|
|
|
|
use OCP;
|
|
|
|
use OCP\Template;
|
|
|
|
use OCP\Share;
|
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
use OCP\AppFramework\Http\RedirectResponse;
|
2015-03-24 10:21:58 +00:00
|
|
|
use OCP\AppFramework\Http\NotFoundResponse;
|
2016-01-15 08:41:51 +00:00
|
|
|
use OCP\IURLGenerator;
|
|
|
|
use OCP\IConfig;
|
2014-10-15 09:58:44 +00:00
|
|
|
use OCP\ILogger;
|
2016-01-15 08:41:51 +00:00
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\ISession;
|
|
|
|
use OCP\IPreview;
|
2014-10-15 09:58:44 +00:00
|
|
|
use OCA\Files_Sharing\Helper;
|
|
|
|
use OCP\Util;
|
2014-12-22 11:35:50 +00:00
|
|
|
use OCA\Files_Sharing\Activity;
|
2015-09-30 11:32:20 +00:00
|
|
|
use \OCP\Files\NotFoundException;
|
2016-01-15 07:11:11 +00:00
|
|
|
use \OC\Share20\IShare;
|
2016-01-15 10:49:50 +00:00
|
|
|
use OCP\Files\IRootFolder;
|
2014-10-15 09:58:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ShareController
|
|
|
|
*
|
|
|
|
* @package OCA\Files_Sharing\Controllers
|
|
|
|
*/
|
|
|
|
class ShareController extends Controller {
|
|
|
|
|
2016-01-15 08:41:51 +00:00
|
|
|
/** @var IConfig */
|
2014-10-15 09:58:44 +00:00
|
|
|
protected $config;
|
2016-01-15 08:41:51 +00:00
|
|
|
/** @var IURLGenerator */
|
2014-10-15 09:58:44 +00:00
|
|
|
protected $urlGenerator;
|
2016-01-15 08:41:51 +00:00
|
|
|
/** @var IUserManager */
|
2014-10-15 09:58:44 +00:00
|
|
|
protected $userManager;
|
2016-01-15 08:41:51 +00:00
|
|
|
/** @var ILogger */
|
2014-10-15 09:58:44 +00:00
|
|
|
protected $logger;
|
2014-12-22 11:35:50 +00:00
|
|
|
/** @var OCP\Activity\IManager */
|
|
|
|
protected $activityManager;
|
2016-01-15 07:11:11 +00:00
|
|
|
/** @var OC\Share20\Manager */
|
|
|
|
protected $shareManager;
|
2016-01-15 08:41:51 +00:00
|
|
|
/** @var ISession */
|
2016-01-15 07:11:11 +00:00
|
|
|
protected $session;
|
2016-01-15 08:41:51 +00:00
|
|
|
/** @var IPreview */
|
2016-01-15 07:11:11 +00:00
|
|
|
protected $previewManager;
|
2016-01-15 10:49:50 +00:00
|
|
|
/** @var IRootFolder */
|
|
|
|
protected $rootFolder;
|
2014-10-15 09:58:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
2016-01-15 08:41:51 +00:00
|
|
|
* @param IConfig $config
|
|
|
|
* @param IURLGenerator $urlGenerator
|
|
|
|
* @param IUserManager $userManager
|
2014-10-15 09:58:44 +00:00
|
|
|
* @param ILogger $logger
|
2014-12-22 11:35:50 +00:00
|
|
|
* @param OCP\Activity\IManager $activityManager
|
2016-01-15 07:11:11 +00:00
|
|
|
* @param \OC\Share20\Manager $shareManager
|
2016-01-15 08:41:51 +00:00
|
|
|
* @param ISession $session
|
|
|
|
* @param IPreview $previewManager
|
2014-10-15 09:58:44 +00:00
|
|
|
*/
|
|
|
|
public function __construct($appName,
|
|
|
|
IRequest $request,
|
2016-01-15 08:41:51 +00:00
|
|
|
IConfig $config,
|
|
|
|
IURLGenerator $urlGenerator,
|
|
|
|
IUserManager $userManager,
|
2014-12-22 11:35:50 +00:00
|
|
|
ILogger $logger,
|
2016-01-15 08:41:51 +00:00
|
|
|
\OCP\Activity\IManager $activityManager,
|
2016-01-15 07:11:11 +00:00
|
|
|
\OC\Share20\Manager $shareManager,
|
2016-01-15 08:41:51 +00:00
|
|
|
ISession $session,
|
2016-01-15 10:49:50 +00:00
|
|
|
IPreview $previewManager,
|
|
|
|
IRootFolder $rootFolder) {
|
2014-10-15 09:58:44 +00:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
|
|
|
$this->config = $config;
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
$this->userManager = $userManager;
|
|
|
|
$this->logger = $logger;
|
2014-12-22 11:35:50 +00:00
|
|
|
$this->activityManager = $activityManager;
|
2016-01-15 07:11:11 +00:00
|
|
|
$this->shareManager = $shareManager;
|
|
|
|
$this->session = $session;
|
|
|
|
$this->previewManager = $previewManager;
|
2016-01-15 10:49:50 +00:00
|
|
|
$this->rootFolder = $rootFolder;
|
2014-10-15 09:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param string $token
|
|
|
|
* @return TemplateResponse|RedirectResponse
|
|
|
|
*/
|
|
|
|
public function showAuthenticate($token) {
|
2016-01-15 07:11:11 +00:00
|
|
|
$share = $this->shareManager->getShareByToken($token);
|
2014-10-15 09:58:44 +00:00
|
|
|
|
2016-01-15 07:11:11 +00:00
|
|
|
if($this->linkShareAuth($share)) {
|
2014-10-15 09:58:44 +00:00
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $token)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new TemplateResponse($this->appName, 'authenticate', array(), 'guest');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
2014-11-17 12:10:15 +00:00
|
|
|
* @UseSession
|
2014-10-15 09:58:44 +00:00
|
|
|
*
|
|
|
|
* Authenticates against password-protected shares
|
2015-12-07 12:05:27 +00:00
|
|
|
* @param string $token
|
2014-10-15 09:58:44 +00:00
|
|
|
* @param string $password
|
|
|
|
* @return RedirectResponse|TemplateResponse
|
|
|
|
*/
|
|
|
|
public function authenticate($token, $password = '') {
|
2016-01-15 07:11:11 +00:00
|
|
|
|
|
|
|
// Check whether share exists
|
|
|
|
try {
|
|
|
|
$share = $this->shareManager->getShareByToken($token);
|
|
|
|
} catch (\OC\Share20\Exception\ShareNotFound $e) {
|
2015-03-24 10:21:58 +00:00
|
|
|
return new NotFoundResponse();
|
2014-10-15 09:58:44 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 07:11:11 +00:00
|
|
|
$authenticate = $this->linkShareAuth($share, $password);
|
2014-10-15 09:58:44 +00:00
|
|
|
|
|
|
|
if($authenticate === true) {
|
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.showShare', array('token' => $token)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new TemplateResponse($this->appName, 'authenticate', array('wrongpw' => true), 'guest');
|
|
|
|
}
|
|
|
|
|
2016-01-15 07:11:11 +00:00
|
|
|
/**
|
|
|
|
* Authenticate a link item with the given password.
|
|
|
|
* Or use the session if no password is provided.
|
|
|
|
*
|
|
|
|
* This is a modified version of Helper::authenticate
|
|
|
|
* TODO: Try to merge back eventually with Helper::authenticate
|
|
|
|
*
|
|
|
|
* @param IShare $share
|
|
|
|
* @param string|null $password
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function linkShareAuth(IShare $share, $password = null) {
|
|
|
|
if ($password !== null) {
|
|
|
|
if ($this->shareManager->checkPassword($share, $password)) {
|
|
|
|
$this->session->set('public_link_authenticated', (string)$share->getId());
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// not authenticated ?
|
|
|
|
if ( ! $this->session->exists('public_link_authenticated')
|
|
|
|
|| $this->session->get('public_link_authenticated') !== (string)$share->getId()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-15 09:58:44 +00:00
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param string $token
|
|
|
|
* @param string $path
|
2015-01-16 18:31:15 +00:00
|
|
|
* @return TemplateResponse|RedirectResponse
|
2015-09-30 11:32:20 +00:00
|
|
|
* @throws NotFoundException
|
2014-10-15 09:58:44 +00:00
|
|
|
*/
|
|
|
|
public function showShare($token, $path = '') {
|
|
|
|
\OC_User::setIncognitoMode(true);
|
|
|
|
|
|
|
|
// Check whether share exists
|
2016-01-15 07:11:11 +00:00
|
|
|
try {
|
|
|
|
$share = $this->shareManager->getShareByToken($token);
|
|
|
|
} catch (\OC\Share20\Exception\ShareNotFound $e) {
|
2015-03-24 10:21:58 +00:00
|
|
|
return new NotFoundResponse();
|
2014-10-15 09:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Share is password protected - check whether the user is permitted to access the share
|
2016-01-15 07:11:11 +00:00
|
|
|
if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
|
2014-10-15 09:58:44 +00:00
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate',
|
|
|
|
array('token' => $token)));
|
|
|
|
}
|
|
|
|
|
2016-01-15 07:11:11 +00:00
|
|
|
// We can't get the path of a file share
|
|
|
|
if ($share->getPath() instanceof \OCP\Files\File && $path !== '') {
|
2015-09-30 11:32:20 +00:00
|
|
|
throw new NotFoundException();
|
2014-10-15 09:58:44 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 07:11:11 +00:00
|
|
|
$rootFolder = null;
|
|
|
|
if ($share->getPath() instanceof \OCP\Files\Folder) {
|
|
|
|
/** @var \OCP\Files\Folder $rootFolder */
|
|
|
|
$rootFolder = $share->getPath();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$path = $rootFolder->get($path);
|
|
|
|
} catch (\OCP\Files\NotFoundException $e) {
|
|
|
|
throw new NotFoundException();
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 09:58:44 +00:00
|
|
|
|
2015-03-24 10:21:58 +00:00
|
|
|
$shareTmpl = [];
|
2016-01-15 07:11:11 +00:00
|
|
|
$shareTmpl['displayName'] = $share->getShareOwner()->getDisplayName();
|
|
|
|
$shareTmpl['owner'] = $share->getShareOwner()->getUID();
|
|
|
|
$shareTmpl['filename'] = $share->getPath()->getName();
|
|
|
|
$shareTmpl['directory_path'] = $share->getTarget();
|
|
|
|
$shareTmpl['mimetype'] = $share->getPath()->getMimetype();
|
|
|
|
$shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getPath()->getMimetype());
|
|
|
|
$shareTmpl['dirToken'] = $token;
|
2014-10-15 09:58:44 +00:00
|
|
|
$shareTmpl['sharingToken'] = $token;
|
|
|
|
$shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled();
|
2016-01-15 07:11:11 +00:00
|
|
|
$shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
|
2014-11-18 13:54:08 +00:00
|
|
|
$shareTmpl['dir'] = '';
|
2016-01-15 07:11:11 +00:00
|
|
|
$shareTmpl['nonHumanFileSize'] = $share->getPath()->getSize();
|
|
|
|
$shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getPath()->getSize());
|
2014-10-15 09:58:44 +00:00
|
|
|
|
|
|
|
// Show file list
|
2016-01-15 07:11:11 +00:00
|
|
|
if ($share->getPath() instanceof \OCP\Files\Folder) {
|
|
|
|
$shareTmpl['dir'] = $rootFolder->getRelativePath($path->getPath());
|
2016-01-19 09:17:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The OC_Util methods require a view. This just uses the node API
|
|
|
|
*/
|
|
|
|
$freeSpace = $share->getPath()->getStorage()->free_space($share->getPath()->getInternalPath());
|
|
|
|
if ($freeSpace !== \OCP\Files\FileInfo::SPACE_UNKNOWN) {
|
|
|
|
$freeSpace = max($freeSpace, 0);
|
|
|
|
} else {
|
|
|
|
$freeSpace = (INF > 0) ? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
|
|
|
|
}
|
|
|
|
|
2014-10-15 09:58:44 +00:00
|
|
|
$uploadLimit = Util::uploadLimit();
|
2016-01-19 09:17:29 +00:00
|
|
|
$maxUploadFilesize = min($freeSpace, $uploadLimit);
|
|
|
|
|
2014-10-15 09:58:44 +00:00
|
|
|
$folder = new Template('files', 'list', '');
|
2016-01-15 07:11:11 +00:00
|
|
|
$folder->assign('dir', $rootFolder->getRelativePath($path->getPath()));
|
|
|
|
$folder->assign('dirToken', $token);
|
2014-11-25 15:28:41 +00:00
|
|
|
$folder->assign('permissions', \OCP\Constants::PERMISSION_READ);
|
2014-10-15 09:58:44 +00:00
|
|
|
$folder->assign('isPublic', true);
|
|
|
|
$folder->assign('publicUploadEnabled', 'no');
|
|
|
|
$folder->assign('uploadMaxFilesize', $maxUploadFilesize);
|
|
|
|
$folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
|
|
|
|
$folder->assign('freeSpace', $freeSpace);
|
|
|
|
$folder->assign('uploadLimit', $uploadLimit); // PHP upload limit
|
|
|
|
$folder->assign('usedSpacePercent', 0);
|
|
|
|
$folder->assign('trash', false);
|
|
|
|
$shareTmpl['folder'] = $folder->fetchPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
$shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
|
2015-01-17 11:11:52 +00:00
|
|
|
$shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
|
2015-06-09 14:33:26 +00:00
|
|
|
$shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
|
2014-10-15 09:58:44 +00:00
|
|
|
|
2015-03-10 09:06:15 +00:00
|
|
|
$csp = new OCP\AppFramework\Http\ContentSecurityPolicy();
|
|
|
|
$csp->addAllowedFrameDomain('\'self\'');
|
|
|
|
$response = new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
|
|
|
|
$response->setContentSecurityPolicy($csp);
|
|
|
|
|
|
|
|
return $response;
|
2014-10-15 09:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @PublicPage
|
|
|
|
* @NoCSRFRequired
|
2014-11-24 14:02:49 +00:00
|
|
|
*
|
2014-10-15 09:58:44 +00:00
|
|
|
* @param string $token
|
|
|
|
* @param string $files
|
|
|
|
* @param string $path
|
2015-10-08 09:21:17 +00:00
|
|
|
* @param string $downloadStartSecret
|
2014-10-15 09:58:44 +00:00
|
|
|
* @return void|RedirectResponse
|
|
|
|
*/
|
2015-10-08 09:21:17 +00:00
|
|
|
public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') {
|
2014-10-15 09:58:44 +00:00
|
|
|
\OC_User::setIncognitoMode(true);
|
|
|
|
|
2016-01-15 10:49:50 +00:00
|
|
|
$share = $this->shareManager->getShareByToken($token);
|
2014-10-15 09:58:44 +00:00
|
|
|
|
|
|
|
// Share is password protected - check whether the user is permitted to access the share
|
2016-01-15 10:49:50 +00:00
|
|
|
if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
|
|
|
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate',
|
|
|
|
['token' => $token]));
|
2014-10-15 09:58:44 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 14:08:16 +00:00
|
|
|
$files_list = null;
|
|
|
|
if (!is_null($files)) { // download selected files
|
|
|
|
$files_list = json_decode($files);
|
|
|
|
// in case we get only a single file
|
|
|
|
if ($files_list === null) {
|
2016-01-15 10:49:50 +00:00
|
|
|
$files_list = [$files];
|
2015-02-17 14:08:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-15 10:49:50 +00:00
|
|
|
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID());
|
|
|
|
$originalSharePath = $userFolder->getRelativePath($share->getPath()->getPath());
|
|
|
|
|
|
|
|
// Single file share
|
|
|
|
if ($share->getPath() instanceof \OCP\Files\File) {
|
|
|
|
$this->activityManager->publishActivity(
|
|
|
|
'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$originalSharePath], '', [],
|
|
|
|
$originalSharePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Directory share
|
|
|
|
else {
|
|
|
|
/** @var \OCP\Files\Folder $node */
|
|
|
|
$node = $share->getPath();
|
|
|
|
|
|
|
|
// Try to get the path
|
|
|
|
if ($path !== '') {
|
|
|
|
try {
|
|
|
|
$node = $node->get($path);
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
return new NotFoundResponse();
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 09:58:44 +00:00
|
|
|
|
2016-01-15 10:49:50 +00:00
|
|
|
$originalSharePath = $userFolder->getRelativePath($node->getPath());
|
2014-10-15 09:58:44 +00:00
|
|
|
|
2016-01-15 10:49:50 +00:00
|
|
|
if ($node instanceof \OCP\Files\File) {
|
|
|
|
// Single file download
|
|
|
|
$this->activityManager->publishActivity(
|
|
|
|
'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$originalSharePath], '', [],
|
|
|
|
$originalSharePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
|
|
|
|
);
|
2015-02-17 14:08:16 +00:00
|
|
|
} else if (!empty($files_list)) {
|
2016-01-15 10:49:50 +00:00
|
|
|
/** @var \OCP\Files\Folder $node */
|
|
|
|
|
|
|
|
// Subset of files is downloaded
|
2015-02-17 14:08:16 +00:00
|
|
|
foreach ($files_list as $file) {
|
2016-01-15 10:49:50 +00:00
|
|
|
$subNode = $node->get($file);
|
2016-01-20 08:04:22 +00:00
|
|
|
$nodePath = $userFolder->getRelativePath($subNode->getPath());
|
2016-01-15 10:49:50 +00:00
|
|
|
if ($subNode instanceof \OCP\Files\File) {
|
|
|
|
$this->activityManager->publishActivity(
|
|
|
|
'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$nodePath], '', [],
|
|
|
|
$nodePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->activityManager->publishActivity(
|
|
|
|
'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$nodePath], '', [],
|
|
|
|
$nodePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
|
|
|
|
);
|
|
|
|
}
|
2015-02-17 14:08:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The folder is downloaded
|
|
|
|
$this->activityManager->publishActivity(
|
2016-01-15 10:49:50 +00:00
|
|
|
'files_sharing', Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$originalSharePath], '', [],
|
|
|
|
$originalSharePath, '', $share->getShareOwner()->getUID(), Activity::TYPE_PUBLIC_LINKS, Activity::PRIORITY_MEDIUM
|
2015-02-17 14:08:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-15 10:49:50 +00:00
|
|
|
/* FIXME: We should do this all nicely in OCP */
|
|
|
|
OC_Util::tearDownFS();
|
|
|
|
OC_Util::setupFS($share->getShareOwner()->getUID());
|
|
|
|
|
2015-10-08 09:21:17 +00: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
|
|
|
|
*/
|
|
|
|
if (!empty($downloadStartSecret)
|
|
|
|
&& !isset($downloadStartSecret[32])
|
|
|
|
&& preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) {
|
|
|
|
|
|
|
|
// FIXME: set on the response once we use an actual app framework response
|
|
|
|
setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/');
|
|
|
|
}
|
|
|
|
|
2015-02-17 14:08:16 +00:00
|
|
|
// download selected files
|
|
|
|
if (!is_null($files)) {
|
2014-10-15 09:58:44 +00:00
|
|
|
// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
|
2014-11-25 09:17:31 +00:00
|
|
|
// after dispatching the request which results in a "Cannot modify header information" notice.
|
2014-10-15 09:58:44 +00:00
|
|
|
OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');
|
|
|
|
exit();
|
|
|
|
} else {
|
|
|
|
// FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
|
|
|
|
// after dispatching the request which results in a "Cannot modify header information" notice.
|
|
|
|
OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $_SERVER['REQUEST_METHOD'] == 'HEAD');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|