From 65f3b2fad235417d3f653c9e11aa8d72e8944d28 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 29 Apr 2014 15:14:48 +0200 Subject: [PATCH 01/47] Add server<->server sharing backend --- apps/files_external/lib/webdav.php | 14 ++-- apps/files_sharing/appinfo/app.php | 9 ++ apps/files_sharing/appinfo/database.xml | 83 +++++++++++++++++++ apps/files_sharing/appinfo/version | 2 +- apps/files_sharing/lib/external/cache.php | 47 +++++++++++ apps/files_sharing/lib/external/manager.php | 90 ++++++++++++++++++++ apps/files_sharing/lib/external/storage.php | 91 +++++++++++++++++++++ apps/files_sharing/lib/isharedstorage.php | 13 +++ lib/private/connector/sabre/directory.php | 3 +- lib/private/connector/sabre/objecttree.php | 2 +- lib/private/files/cache/cache.php | 10 +-- lib/private/helper.php | 2 +- lib/private/share/share.php | 2 +- 13 files changed, 351 insertions(+), 17 deletions(-) create mode 100644 apps/files_sharing/appinfo/database.xml create mode 100644 apps/files_sharing/lib/external/cache.php create mode 100644 apps/files_sharing/lib/external/manager.php create mode 100644 apps/files_sharing/lib/external/storage.php create mode 100644 apps/files_sharing/lib/isharedstorage.php diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 525f41c127..3614b05e97 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -9,13 +9,13 @@ namespace OC\Files\Storage; class DAV extends \OC\Files\Storage\Common { - private $password; - private $user; - private $host; - private $secure; - private $root; - private $certPath; - private $ready; + protected $password; + protected $user; + protected $host; + protected $secure; + protected $root; + protected $certPath; + protected $ready; /** * @var \Sabre\DAV\Client */ diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 6b40ba921c..9ea969f4cf 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -11,6 +11,15 @@ OC::$CLASSPATH['OC\Files\Cache\Shared_Watcher'] = 'files_sharing/lib/watcher.php OC::$CLASSPATH['OCA\Files\Share\Api'] = 'files_sharing/lib/api.php'; OC::$CLASSPATH['OCA\Files\Share\Maintainer'] = 'files_sharing/lib/maintainer.php'; OC::$CLASSPATH['OCA\Files\Share\Proxy'] = 'files_sharing/lib/proxy.php'; + +$externalManager = new \OCA\Files_Sharing\External\Manager( + \OC::$server->getDatabaseConnection(), + \OC\Files\Filesystem::getMountManager(), + \OC\Files\Filesystem::getLoader(), + \OC::$server->getUserSession() +); +$externalManager->setup(); + OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file'); diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml new file mode 100644 index 0000000000..b9c0d881fc --- /dev/null +++ b/apps/files_sharing/appinfo/database.xml @@ -0,0 +1,83 @@ + + + *dbname* + true + false + utf8 + + *dbprefix*share_external + + + id + integer + 0 + true + 1 + 4 + + + remote + text + true + 128 + + + token + text + true + 64 + + + password + text + true + 64 + + + name + text + true + 64 + + + owner + text + true + 64 + + + user + text + true + 64 + + + mountpoint + text + true + 512 + + + mountpoint_hash + text + true + 32 + + + sh_external_user + + user + ascending + + + + sh_external_mp + true + + mountpoint_hash + ascending + + + +
+
diff --git a/apps/files_sharing/appinfo/version b/apps/files_sharing/appinfo/version index 2eb3c4fe4e..4b9fcbec10 100644 --- a/apps/files_sharing/appinfo/version +++ b/apps/files_sharing/appinfo/version @@ -1 +1 @@ -0.5 +0.5.1 diff --git a/apps/files_sharing/lib/external/cache.php b/apps/files_sharing/lib/external/cache.php new file mode 100644 index 0000000000..cd06bfb127 --- /dev/null +++ b/apps/files_sharing/lib/external/cache.php @@ -0,0 +1,47 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing\External; + +class Cache extends \OC\Files\Cache\Cache { + private $remote; + private $remoteUser; + private $storage; + + /** + * @param \OCA\Files_Sharing\External\Storage $storage + * @param string $remote + * @param string $remoteUser + */ + public function __construct($storage, $remote, $remoteUser) { + $this->storage = $storage; + list(, $remote) = explode('://', $remote, 2); + $this->remote = $remote; + $this->remoteUser = $remoteUser; + parent::__construct($storage); + } + + public function get($file) { + $result = parent::get($file); + $result['displayname_owner'] = $this->remoteUser . '@' . $this->remote; + if (!$file || $file === '') { + $result['is_share_mount_point'] = true; + $mountPoint = rtrim($this->storage->getMountPoint()); + $result['name'] = basename($mountPoint); + } + return $result; + } + + public function getFolderContentsById($id) { + $results = parent::getFolderContentsById($id); + foreach ($results as &$file) { + $file['displayname_owner'] = $this->remoteUser . '@' . $this->remote; + } + return $results; + } +} diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php new file mode 100644 index 0000000000..ffb673723a --- /dev/null +++ b/apps/files_sharing/lib/external/manager.php @@ -0,0 +1,90 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing\External; + +use OC\Files\Mount\Mount; + +class Manager { + const STORAGE = '\OCA\Files_Sharing\External\Storage'; + + /** + * @var \OCP\IDBConnection + */ + private $connection; + + /** + * @var \OC\Files\Mount\Manager + */ + private $mountManager; + + /** + * @var \OC\Files\Storage\Loader + */ + private $storageLoader; + + /** + * @var \OC\User\Session + */ + private $userSession; + + /** + * @param \OCP\IDBConnection $connection + * @param \OC\Files\Mount\Manager $mountManager + * @param \OC\User\Session $userSession + * @param \OC\Files\Storage\Loader $storageLoader + */ + public function __construct(\OCP\IDBConnection $connection, \OC\Files\Mount\Manager $mountManager, + \OC\Files\Storage\Loader $storageLoader, \OC\User\Session $userSession) { + $this->connection = $connection; + $this->mountManager = $mountManager; + $this->userSession = $userSession; + $this->storageLoader = $storageLoader; + } + + public function setup() { + $user = $this->userSession->getUser(); + if ($user) { + $query = $this->connection->prepare('SELECT `remote`, `token`, `password`, `mountpoint`, `owner` + FROM *PREFIX*share_external WHERE `user` = ?'); + $query->execute(array($user->getUID())); + + while ($row = $query->fetch()) { + $row['manager'] = $this; + $mount = new Mount(self::STORAGE, $row['mountpoint'], $row, $this->storageLoader); + $this->mountManager->addMount($mount); + } + } + } + + /** + * @return \OC\Files\Mount\Manager + */ + public function getMountManager() { + return $this->mountManager; + } + + /** + * @param string $source + * @param string $target + * @return bool + */ + public function setMountPoint($source, $target) { + $sourceHash = md5($source); + $targetHash = md5($target); + + $query = $this->connection->prepare('UPDATE *PREFIX*share_external SET + `mountpoint` = ?, `mountpoint_hash` = ? WHERE `mountpoint_hash` = ?'); + $query->execute(array($target, $targetHash, $sourceHash)); + + $mount = $this->mountManager->find($source); + $mount->setMountPoint($target . '/'); + $this->mountManager->addMount($mount); + $this->mountManager->removeMount($source . '/'); + } +} diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php new file mode 100644 index 0000000000..2683a6a690 --- /dev/null +++ b/apps/files_sharing/lib/external/storage.php @@ -0,0 +1,91 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing\External; + +use OC\Files\Filesystem; +use OCA\Files_Sharing\ISharedStorage; + +class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { + /** + * @var string + */ + private $remoteUser; + + /** + * @var string + */ + private $remote; + + /** + * @var string + */ + private $mountPoint; + + /** + * @var \OCA\Files_Sharing\External\Manager + */ + private $manager; + + public function __construct($options) { + $this->remote = $options['remote']; + $this->remoteUser = $options['owner']; + $this->manager = $options['manager']; + list($protocol, $remote) = explode('://', $this->remote); + list($host, $root) = explode('/', $remote); + $secure = $protocol === 'https'; + $root .= '/public.php/webdav'; + $this->mountPoint = $options['mountpoint']; + parent::__construct(array( + 'secure' => $secure, + 'host' => $host, + 'root' => $root, + 'user' => $options['token'], + 'password' => $options['password'] + )); + } + + public function getRemoteUser() { + return $this->remoteUser; + } + + public function getRemote() { + return $this->remote; + } + + public function getMountPoint() { + return $this->mountPoint; + } + + /** + * @brief get id of the mount point + * @return string + */ + public function getId() { + return 'shared::' . md5($this->user . '@' . $this->remote); + } + + public function getCache($path = '') { + if (!isset($this->cache)) { + $this->cache = new Cache($this, $this->remote, $this->remoteUser); + } + return $this->cache; + } + + public function rename($path1, $path2) { + // if we renamed the mount point we need to adjust the mountpoint in the database + if (Filesystem::normalizePath($this->mountPoint) === Filesystem::normalizePath($path1)) { + $this->manager->setMountPoint($path1, $path2); + $this->mountPoint = $path2; + return true; + } else { + // read only shares + return false; + } + } +} diff --git a/apps/files_sharing/lib/isharedstorage.php b/apps/files_sharing/lib/isharedstorage.php new file mode 100644 index 0000000000..75e0afef39 --- /dev/null +++ b/apps/files_sharing/lib/isharedstorage.php @@ -0,0 +1,13 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing; + +interface ISharedStorage{ + +} diff --git a/lib/private/connector/sabre/directory.php b/lib/private/connector/sabre/directory.php index aa467cec53..9904c3525c 100644 --- a/lib/private/connector/sabre/directory.php +++ b/lib/private/connector/sabre/directory.php @@ -202,7 +202,8 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node * @return array */ public function getQuotaInfo() { - $storageInfo = OC_Helper::getStorageInfo($this->path); + $path = \OC\Files\Filesystem::getView()->getRelativePath($this->info->getPath()); + $storageInfo = OC_Helper::getStorageInfo($path); return array( $storageInfo['used'], $storageInfo['free'] diff --git a/lib/private/connector/sabre/objecttree.php b/lib/private/connector/sabre/objecttree.php index c55a392bca..2cadb5af52 100644 --- a/lib/private/connector/sabre/objecttree.php +++ b/lib/private/connector/sabre/objecttree.php @@ -117,7 +117,7 @@ class ObjectTree extends \Sabre\DAV\ObjectTree { $isShareMountPoint = false; list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath( '/' . \OCP\User::getUser() . '/files/' . $sourcePath); - if ($storage instanceof \OC\Files\Storage\Shared && !$internalPath) { + if ($storage instanceof \OCA\Files_Sharing\ISharedStorage && !$internalPath) { $isShareMountPoint = true; } diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index bfd280a91a..48c57e2e43 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -22,20 +22,20 @@ class Cache { /** * @var array partial data for the cache */ - private $partial = array(); + protected $partial = array(); /** * @var string */ - private $storageId; + protected $storageId; /** * @var Storage $storageCache */ - private $storageCache; + protected $storageCache; - private static $mimetypeIds = array(); - private static $mimetypes = array(); + protected static $mimetypeIds = array(); + protected static $mimetypes = array(); /** * @param \OC\Files\Storage\Storage|string $storage diff --git a/lib/private/helper.php b/lib/private/helper.php index 3e2c1db79d..243baa4694 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -940,7 +940,7 @@ class OC_Helper { // return storage info without adding mount points $includeExtStorage = \OC_Config::getValue('quota_include_external_storage', false); - if (is_null($rootInfo)) { + if (!$rootInfo) { $rootInfo = \OC\Files\Filesystem::getFileInfo($path, false); } $used = $rootInfo->getSize(); diff --git a/lib/private/share/share.php b/lib/private/share/share.php index a3de8ebc0e..0a4d9a913e 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -510,7 +510,7 @@ class Share extends \OC\Share\Constants { $mountManager = \OC\Files\Filesystem::getMountManager(); $mounts = $mountManager->getAll(); foreach ($mounts as $mountPoint => $mount) { - if ($mount->getStorage() instanceof \OC\Files\Storage\Shared && strpos($mountPoint, $path) === 0) { + if ($mount->getStorage() instanceof \OCA\Files_Sharing\ISharedStorage && strpos($mountPoint, $path) === 0) { $message = 'Sharing "' . $itemSourceName . '" failed, because it contains files shared with you!'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); From a44baaf8eb9584c3525584ff893bad47adb0d375 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 2 May 2014 11:27:40 +0200 Subject: [PATCH 02/47] add remote/add external shares to manager --- apps/files_sharing/lib/external/manager.php | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index ffb673723a..d82cb83a6e 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -47,6 +47,27 @@ class Manager { $this->storageLoader = $storageLoader; } + public function addShare($remote, $token, $password, $name, $owner) { + $user = $this->userSession->getUser(); + if ($user) { + $query = $this->connection->prepare('INSERT INTO *PREFIX*share_external(`remote`, `token`, `password`, + `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`) VALUES(?, ?, ?, ?, ?, ?, ?, ?)'); + $mountPoint = '/' . $user->getUID() . '/files/' . $name; + $hash = md5($mountPoint); + $query->execute(array($remote, $token, $password, $name, $owner, $user->getUID(), $mountPoint, $hash)); + + $options = array( + 'remote' => $remote, + 'token' => $token, + 'password' => $password, + 'mountpoint' => $mountPoint, + 'owner' => $owner + ); + $mount = new Mount(self::STORAGE, $mountPoint, $options, $this->storageLoader); + $this->mountManager->addMount($mount); + } + } + public function setup() { $user = $this->userSession->getUser(); if ($user) { @@ -87,4 +108,10 @@ class Manager { $this->mountManager->addMount($mount); $this->mountManager->removeMount($source . '/'); } + + public function remoteShare($mountPoint) { + $hash = md5($mountPoint); + $query = $this->connection->prepare('DELETE FROM *PREFIX*share_external WHERE `mountpoint_hash` = ?'); + $query->execute(array($hash)); + } } From 0156ef816650ec73d033ebba2107cf237d6301e3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 7 May 2014 13:19:41 +0200 Subject: [PATCH 03/47] Add coments to database and dont use sql keywords as table names --- apps/files_sharing/appinfo/database.xml | 12 ++++++++++-- apps/files_sharing/lib/external/manager.php | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml index b9c0d881fc..e55688240b 100644 --- a/apps/files_sharing/appinfo/database.xml +++ b/apps/files_sharing/appinfo/database.xml @@ -19,49 +19,57 @@ remote text true - 128 + 512 + Url of the remove owncloud instance - token + share_token text true 64 + Public share token password text true 64 + Optional password for the public share name text true 64 + Original name on the remote server owner text true 64 + User that owns the public share on the remote server user text true 64 + Local user which added the external share mountpoint text true 512 + Full path where the share is mounted mountpoint_hash text true 32 + md5 hash of the mountpoint sh_external_user diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index d82cb83a6e..fa0005389a 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -50,7 +50,7 @@ class Manager { public function addShare($remote, $token, $password, $name, $owner) { $user = $this->userSession->getUser(); if ($user) { - $query = $this->connection->prepare('INSERT INTO *PREFIX*share_external(`remote`, `token`, `password`, + $query = $this->connection->prepare('INSERT INTO *PREFIX*share_external(`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`) VALUES(?, ?, ?, ?, ?, ?, ?, ?)'); $mountPoint = '/' . $user->getUID() . '/files/' . $name; $hash = md5($mountPoint); @@ -71,12 +71,13 @@ class Manager { public function setup() { $user = $this->userSession->getUser(); if ($user) { - $query = $this->connection->prepare('SELECT `remote`, `token`, `password`, `mountpoint`, `owner` + $query = $this->connection->prepare('SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner` FROM *PREFIX*share_external WHERE `user` = ?'); $query->execute(array($user->getUID())); while ($row = $query->fetch()) { $row['manager'] = $this; + $row['token'] = $row['share_token']; $mount = new Mount(self::STORAGE, $row['mountpoint'], $row, $this->storageLoader); $this->mountManager->addMount($mount); } @@ -109,7 +110,7 @@ class Manager { $this->mountManager->removeMount($source . '/'); } - public function remoteShare($mountPoint) { + public function removeShare($mountPoint) { $hash = md5($mountPoint); $query = $this->connection->prepare('DELETE FROM *PREFIX*share_external WHERE `mountpoint_hash` = ?'); $query->execute(array($hash)); From d7de35376d7e068abdfb49e8336feab25e313662 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 9 May 2014 17:06:08 +0200 Subject: [PATCH 04/47] Add interface for accpeting external shares --- apps/files_sharing/ajax/external.php | 28 +++++++++++ apps/files_sharing/appinfo/app.php | 3 ++ apps/files_sharing/appinfo/routes.php | 2 + apps/files_sharing/js/external.js | 53 +++++++++++++++++++++ apps/files_sharing/lib/external/manager.php | 1 + 5 files changed, 87 insertions(+) create mode 100644 apps/files_sharing/ajax/external.php create mode 100644 apps/files_sharing/js/external.js diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php new file mode 100644 index 0000000000..e7bf903f70 --- /dev/null +++ b/apps/files_sharing/ajax/external.php @@ -0,0 +1,28 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +OCP\JSON::callCheck(); +OCP\JSON::checkLoggedIn(); + +$token = $_POST['token']; +$remote = $_POST['remote']; +$owner = $_POST['owner']; +$name = $_POST['name']; +$password = $_POST['password']; + +$externalManager = new \OCA\Files_Sharing\External\Manager( + \OC::$server->getDatabaseConnection(), + \OC\Files\Filesystem::getMountManager(), + \OC\Files\Filesystem::getLoader(), + \OC::$server->getUserSession() +); + +$mount = $externalManager->addShare($remote, $token, $password, $name, $owner); +$result = $mount->getStorage()->file_exists(''); + +echo json_encode($result); diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 9ea969f4cf..db4e042fae 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -23,7 +23,10 @@ $externalManager->setup(); OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); OCP\Share::registerBackend('file', 'OC_Share_Backend_File'); OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file'); + OCP\Util::addScript('files_sharing', 'share'); +OCP\Util::addScript('files_sharing', 'external'); + \OC_Hook::connect('OC_Filesystem', 'post_write', '\OC\Files\Cache\Shared_Updater', 'writeHook'); \OC_Hook::connect('OC_Filesystem', 'post_delete', '\OC\Files\Cache\Shared_Updater', 'postDeleteHook'); \OC_Hook::connect('OC_Filesystem', 'delete', '\OC\Files\Cache\Shared_Updater', 'deleteHook'); diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 7c2834dc9c..2d214c879c 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -5,6 +5,8 @@ $this->create('core_ajax_public_preview', '/publicpreview')->action( require_once __DIR__ . '/../ajax/publicpreview.php'; }); +$this->create('sharing_external_add', '/external')->actionInclude('files_sharing/ajax/external.php'); + // OCS API //TODO: SET: mail notification, waiting for PR #4689 to be accepted diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js new file mode 100644 index 0000000000..0fa99a1652 --- /dev/null +++ b/apps/files_sharing/js/external.js @@ -0,0 +1,53 @@ +$(document).ready(function () { + var getParameterByName = function (query, name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\#&]" + name + "=([^&#]*)"), + results = regex.exec(query); + return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); + }; + + var addExternalShare = function (remote, token, owner, name, password) { + return $.post(OC.generateUrl('apps/files_sharing/external'), { + remote : remote, + token : token, + owner : owner, + name : name, + password: password + }); + }; + + var showAddExternalDialog = function (remote, token, owner, name, passwordProtected) { + var remoteClean = (remote.substr(0, 8) === 'https://') ? remote.substr(8) : remote.substr(7); + var callback = function (add, password) { + password = password || ''; + if (add) { + addExternalShare(remote, token, owner, name, password).then(function (result) { + if (result) { + FileList.reload(); + } else { + OC.dialogs.alert('Error adding ' + name, 'Error adding share'); + } + }); + } + }; + if (!passwordProtected) { + OC.dialogs.confirm('Add ' + name + ' from ' + owner + '@' + remoteClean, 'Add Share', callback, true); + } else { + OC.dialogs.prompt('Add ' + name + ' from ' + owner + '@' + remoteClean, 'Add Share', callback, true, 'Password', true); + } + }; + + if (window.FileList) {// only run in the files app + var hash = location.hash; + location.hash = ''; + var remote = getParameterByName(hash, 'remote'); + var owner = getParameterByName(hash, 'owner'); + var name = getParameterByName(hash, 'name'); + var token = getParameterByName(hash, 'token'); + var passwordProtected = parseInt(getParameterByName(hash, 'protected'), 10); + + if (remote && token && owner && name) { + showAddExternalDialog(remote, token, owner, name, passwordProtected); + } + } +}); diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index fa0005389a..47fc220f7d 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -65,6 +65,7 @@ class Manager { ); $mount = new Mount(self::STORAGE, $mountPoint, $options, $this->storageLoader); $this->mountManager->addMount($mount); + return $mount; } } From cf5a72c10398bb18817cff8ca4dfba4429a97123 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 14 May 2014 13:29:03 +0200 Subject: [PATCH 05/47] Add interface for adding a public share to a different ownCloud instance --- apps/files_sharing/ajax/testremote.php | 17 ++++++++++++ apps/files_sharing/appinfo/routes.php | 1 + apps/files_sharing/css/public.css | 14 ++++++++++ apps/files_sharing/js/external.js | 4 +-- apps/files_sharing/js/public.js | 36 +++++++++++++++++++++++++ apps/files_sharing/templates/public.php | 18 ++++++++++--- 6 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 apps/files_sharing/ajax/testremote.php diff --git a/apps/files_sharing/ajax/testremote.php b/apps/files_sharing/ajax/testremote.php new file mode 100644 index 0000000000..10ea3075ed --- /dev/null +++ b/apps/files_sharing/ajax/testremote.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +$remote = $_GET['remote']; + +if (file_get_contents('https://' . $remote . '/status.php')) { + echo 'https'; +} elseif (file_get_contents('http://' . $remote . '/status.php')) { + echo 'http'; +}else{ + echo 'false'; +} diff --git a/apps/files_sharing/appinfo/routes.php b/apps/files_sharing/appinfo/routes.php index 2d214c879c..8ec4382180 100644 --- a/apps/files_sharing/appinfo/routes.php +++ b/apps/files_sharing/appinfo/routes.php @@ -6,6 +6,7 @@ $this->create('core_ajax_public_preview', '/publicpreview')->action( }); $this->create('sharing_external_add', '/external')->actionInclude('files_sharing/ajax/external.php'); +$this->create('sharing_external_test_remote', '/testremote')->actionInclude('files_sharing/ajax/testremote.php'); // OCS API diff --git a/apps/files_sharing/css/public.css b/apps/files_sharing/css/public.css index 1bafb78074..52b8481140 100644 --- a/apps/files_sharing/css/public.css +++ b/apps/files_sharing/css/public.css @@ -87,3 +87,17 @@ thead { width: 300px; max-width: 90%; } + +.header-right { + transition: opacity 500ms ease 0s; + -moz-transition: opacity 500ms ease 0s; + -ms-transition: opacity 500ms ease 0s; + -o-transition: opacity 500ms ease 0s; + -webkit-transition: opacity 500ms ease 0s; +} + +.header-right:hover, .header-right.active { + opacity: 1; + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)"; + filter: alpha(opacity=100); +} diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js index 0fa99a1652..1e46b35c53 100644 --- a/apps/files_sharing/js/external.js +++ b/apps/files_sharing/js/external.js @@ -22,7 +22,7 @@ $(document).ready(function () { password = password || ''; if (add) { addExternalShare(remote, token, owner, name, password).then(function (result) { - if (result) { + if (result && result !== 'false') { FileList.reload(); } else { OC.dialogs.alert('Error adding ' + name, 'Error adding share'); @@ -37,7 +37,7 @@ $(document).ready(function () { } }; - if (window.FileList) {// only run in the files app + if (window.FileList && window.FileList.appName === 'Files') {// only run in the files app var hash = location.hash; location.hash = ''; var remote = getParameterByName(hash, 'remote'); diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index a2248405d2..48db89532b 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -186,5 +186,41 @@ $(document).ready(function() { }); }; } + + $('.save-form').submit(function (event) { + event.preventDefault(); + + var remote = $(this).find('input[type="text"]').val(); + var token = $('#sharingToken').val(); + var location = window.location.protocol + '//' + window.location.host + OC.webroot; + var owner = $('#save').data('owner'); + var name = $('#save').data('name'); + + var url = remote + '/index.php/apps/files#' + 'remote=' + encodeURIComponent(location) // our location is the remote for the other server + + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) + "&name=" + encodeURIComponent(name); + + + if (remote.indexOf('://') > 0) { + window.location = url; + } else { + // if no protocol is specified, we automatically detect it by testing https and http + // this check needs to happen on the server due to the Content Security Policy directive + $.get(OC.generateUrl('apps/files_sharing/testremote'), {remote: remote}).then(function (protocol) { + if (protocol !== 'http' && protocol !== 'https') { + OC.dialogs.alert(t('files_sharing', 'No ownCloud installation found at {remote}', {remote: remote}), + t('files_sharing', 'Invalid ownCloud url')); + } else { + window.location = protocol + '://' + url; + } + }); + } + }); + + $('#save > button').click(function () { + $(this).hide(); + $('.header-right').addClass('active'); + $('.save-form').css('display', 'inline'); + $('#remote_address').focus(); + }); }); diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 7b5f603a10..1c0570cb01 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -15,10 +15,20 @@ src="" alt="getName()); ?>" />
- - "/> - t('Download'))?> - + + + + + + + "/> + t('Download'))?> + + t('shared by %s', array($_['displayName']))) ?> +
From c6a83b2f1740936ba39acc13b6f0f9b9d619ca07 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 14 May 2014 23:08:45 +0200 Subject: [PATCH 06/47] Fix exposing single files over webdav --- apps/files_sharing/publicwebdav.php | 8 ++++++-- lib/private/connector/sabre/file.php | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/files_sharing/publicwebdav.php b/apps/files_sharing/publicwebdav.php index df2c04cf45..b4f56eed89 100644 --- a/apps/files_sharing/publicwebdav.php +++ b/apps/files_sharing/publicwebdav.php @@ -47,8 +47,12 @@ $server->subscribeEvent('beforeMethod', function () use ($server, $objectTree, $ $rootInfo = $view->getFileInfo(''); // Create ownCloud Dir - $rootDir = new OC_Connector_Sabre_Directory($view, $rootInfo); - $objectTree->init($rootDir, $view); + if ($rootInfo->getType() === 'dir') { + $root = new OC_Connector_Sabre_Directory($view, $rootInfo); + } else { + $root = new OC_Connector_Sabre_File($view, $rootInfo); + } + $objectTree->init($root, $view); $server->addPlugin(new OC_Connector_Sabre_AbortedUploadDetectionPlugin($view)); $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin($view)); diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 4e90d46ad4..7591cc5c06 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -140,7 +140,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements \Sabre\ if (\OC_Util::encryptedFiles()) { throw new \Sabre\DAV\Exception\ServiceUnavailable(); } else { - return $this->fileView->fopen($this->path, 'rb'); + return $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); } } From 1c149da52f7b742b51dcd2b71035506a0a149eaa Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 14 May 2014 23:19:29 +0200 Subject: [PATCH 07/47] Support path lengths up to 4000 chars --- apps/files_sharing/appinfo/database.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml index e55688240b..159d6cb1c5 100644 --- a/apps/files_sharing/appinfo/database.xml +++ b/apps/files_sharing/appinfo/database.xml @@ -61,7 +61,7 @@ mountpoint text true - 512 + 4000 Full path where the share is mounted From a900c7aa94ad6527cb3bdf2600b6b1e9e6b497ac Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 15 May 2014 12:13:46 +0200 Subject: [PATCH 08/47] Fix removing remote shares --- apps/files_sharing/lib/external/storage.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 2683a6a690..0e799a0e9e 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -88,4 +88,22 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { return false; } } + + public function unlink($path) { + if ($path === '' || $path === false) { + $this->manager->removeShare($this->mountPoint); + return true; + } else { + return parent::unlink($path); + } + } + + public function rmdir($path) { + if ($path === '' || $path === false) { + $this->manager->removeShare($this->mountPoint); + return true; + } else { + return parent::rmdir($path); + } + } } From 21ced89beb3cdb6614597c29d0c6de304325185c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 16 May 2014 12:30:08 +0200 Subject: [PATCH 09/47] Dont return false for internalPath --- apps/files_external/lib/webdav.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 3614b05e97..948a462074 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -355,6 +355,9 @@ class DAV extends \OC\Files\Storage\Common { * @param string $path */ public function cleanPath($path) { + if ($path === ""){ + return $path; + } $path = \OC\Files\Filesystem::normalizePath($path); // remove leading slash return substr($path, 1); From 30f5b2bd7cdb9dde211dd0d897f798190c8d3947 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 19 May 2014 15:39:14 +0200 Subject: [PATCH 10/47] Improve detection of whether we're in the files app --- apps/files_sharing/js/external.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js index 1e46b35c53..5e133db2f5 100644 --- a/apps/files_sharing/js/external.js +++ b/apps/files_sharing/js/external.js @@ -37,7 +37,7 @@ $(document).ready(function () { } }; - if (window.FileList && window.FileList.appName === 'Files') {// only run in the files app + if (OCA.Files) {// only run in the files app var hash = location.hash; location.hash = ''; var remote = getParameterByName(hash, 'remote'); From 87b0021e5606888642b5798ba39b0525bf3f3e14 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 19 May 2014 16:39:57 +0200 Subject: [PATCH 11/47] Scan the entire remote share at once by requesting the full file tree from the remote server --- apps/files_sharing/ajax/external.php | 9 ++- apps/files_sharing/ajax/shareinfo.php | 62 +++++++++++++++++++++ apps/files_sharing/lib/external/scanner.php | 52 +++++++++++++++++ apps/files_sharing/lib/external/storage.php | 25 +++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 apps/files_sharing/ajax/shareinfo.php create mode 100644 apps/files_sharing/lib/external/scanner.php diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index e7bf903f70..c25b34ab55 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -23,6 +23,13 @@ $externalManager = new \OCA\Files_Sharing\External\Manager( ); $mount = $externalManager->addShare($remote, $token, $password, $name, $owner); -$result = $mount->getStorage()->file_exists(''); +/** + * @var \OCA\Files_Sharing\External\Storage $storage + */ +$storage = $mount->getStorage(); +$result = $storage->file_exists(''); +if($result){ + $storage->getScanner()->scanAll(); +} echo json_encode($result); diff --git a/apps/files_sharing/ajax/shareinfo.php b/apps/files_sharing/ajax/shareinfo.php new file mode 100644 index 0000000000..4aefdbe7b1 --- /dev/null +++ b/apps/files_sharing/ajax/shareinfo.php @@ -0,0 +1,62 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +if (!\OC_App::isEnabled('files_sharing')) { + exit; +} + +if (!isset($_GET['t'])) { + \OC_Response::setStatus(400); //400 Bad Request + exit; +} + +$token = $_GET['t']; + +$password = null; +if (isset($_POST['password'])) { + $password = $_POST['password']; +} + +$relativePath = null; +if (isset($_GET['dir'])) { + $relativePath = $_GET['dir']; +} + +$data = \OCA\Files_Sharing\Helper::setupFromToken($token, $relativePath, $password); + +$linkItem = $data['linkItem']; +// Load the files +$path = $data['realPath']; + +$rootInfo = \OC\Files\Filesystem::getFileInfo($path); +$rootView = new \OC\Files\View(''); + +/** + * @param \OCP\Files\FileInfo $dir + * @param \OC\Files\View $view + * @return array + */ +function getChildInfo($dir, $view) { + $children = $view->getDirectoryContent($dir->getPath()); + $result = array(); + foreach ($children as $child) { + $formated = \OCA\Files\Helper::formatFileInfo($child); + if ($child->getType() === 'dir') { + $formated['children'] = getChildInfo($child, $view); + } + $result[] = $formated; + } + return $result; +} + +$result = \OCA\Files\Helper::formatFileInfo($rootInfo); +if ($rootInfo->getType() === 'dir') { + $result['children'] = getChildInfo($rootInfo, $rootView); +} + +OCP\JSON::success(array('data' => $result)); diff --git a/apps/files_sharing/lib/external/scanner.php b/apps/files_sharing/lib/external/scanner.php new file mode 100644 index 0000000000..1f32d79b14 --- /dev/null +++ b/apps/files_sharing/lib/external/scanner.php @@ -0,0 +1,52 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing\External; + +class Scanner extends \OC\Files\Cache\Scanner { + /** + * @var \OCA\Files_Sharing\External\Storage + */ + protected $storage; + + public function scanAll() { + $remote = $this->storage->getRemote(); + $token = $this->storage->getToken(); + $password = $this->storage->getPassword(); + $url = $remote . '/index.php/apps/files_sharing/shareinfo?t=' . $token; + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + if ($password) { + curl_setopt($ch, CURLOPT_POSTFIELDS, + http_build_query(array('password' => $password))); + } + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + $result = curl_exec($ch); + curl_close($ch); + + $data = json_decode($result, true); + if ($data['status'] === 'success') { + $this->addResult($data['data'], ''); + } else { + throw new \Exception('Error while scanning remote share'); + } + } + + private function addResult($data, $path) { + $this->cache->put($path, $data); + if ($data['children']) { + foreach ($data['children'] as $child) { + $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); + } + } + } +} diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 0e799a0e9e..741e219eff 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -27,6 +27,11 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { */ private $mountPoint; + /** + * @var string + */ + private $token; + /** * @var \OCA\Files_Sharing\External\Manager */ @@ -41,6 +46,7 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { $secure = $protocol === 'https'; $root .= '/public.php/webdav'; $this->mountPoint = $options['mountpoint']; + $this->token = $options['token']; parent::__construct(array( 'secure' => $secure, 'host' => $host, @@ -62,6 +68,14 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { return $this->mountPoint; } + public function getToken() { + return $this->token; + } + + public function getPassword() { + return $this->password; + } + /** * @brief get id of the mount point * @return string @@ -77,6 +91,17 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { return $this->cache; } + /** + * @param string $path + * @return \OCA\Files_Sharing\External\Scanner + */ + public function getScanner($path = '') { + if (!isset($this->scanner)) { + $this->scanner = new Scanner($this); + } + return $this->scanner; + } + public function rename($path1, $path2) { // if we renamed the mount point we need to adjust the mountpoint in the database if (Filesystem::normalizePath($this->mountPoint) === Filesystem::normalizePath($path1)) { From 961317d9114afda53a381802880d6c94af7ccb47 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Tue, 20 May 2014 17:54:14 +0200 Subject: [PATCH 12/47] make sure to enable incognito mode when mounting a public link and update init status of the encryption app --- apps/files_encryption/lib/session.php | 2 ++ apps/files_sharing/lib/connector/publicauth.php | 1 + 2 files changed, 3 insertions(+) diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php index 93be6691f9..ef18b924dd 100644 --- a/apps/files_encryption/lib/session.php +++ b/apps/files_encryption/lib/session.php @@ -100,6 +100,8 @@ class Session { $privateKey = Crypt::decryptPrivateKey($encryptedKey, ''); $this->setPublicSharePrivateKey($privateKey); + $this->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL); + \OC_FileProxy::$enabled = $proxyStatus; } } diff --git a/apps/files_sharing/lib/connector/publicauth.php b/apps/files_sharing/lib/connector/publicauth.php index ec7b68ba69..c9d545180b 100644 --- a/apps/files_sharing/lib/connector/publicauth.php +++ b/apps/files_sharing/lib/connector/publicauth.php @@ -38,6 +38,7 @@ class PublicAuth extends \Sabre\DAV\Auth\Backend\AbstractBasic { */ protected function validateUserPass($username, $password) { $linkItem = \OCP\Share::getShareByToken($username, false); + \OC_User::setIncognitoMode(true); $this->share = $linkItem; if (!$linkItem) { return false; From c580aeb4550adab2ffaa25f9b844012d54f9f05f Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 21 May 2014 11:39:37 +0200 Subject: [PATCH 13/47] exclude mounted server-to-server shares from encryption --- apps/files_encryption/lib/proxy.php | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index fd91073b8d..51de8fc7e4 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -41,6 +41,30 @@ class Proxy extends \OC_FileProxy { private static $fopenMode = array(); // remember the fopen mode private static $enableEncryption = false; // Enable encryption for the given path + + /** + * check if path is excluded from encryption + * + * @param string $path relative to data/ + * @param string $uid user + * @return boolean + */ + private function isExcludedPath($path, $uid) { + + // files outside of the files-folder are excluded + if(strpos($path, '/' . $uid . '/files') !== 0) { + return true; + } + + // we don't encrypt server-to-server shares + list($storage, ) = \OC\Files\Filesystem::resolvePath($path); + if ($storage instanceof OCA\Files_Sharing\External\Storage) { + return true; + } + + return false; + } + /** * Check if a file requires encryption * @param string $path @@ -50,7 +74,7 @@ class Proxy extends \OC_FileProxy { * Tests if server side encryption is enabled, and if we should call the * crypt stream wrapper for the given file */ - private static function shouldEncrypt($path, $mode = 'w') { + private function shouldEncrypt($path, $mode = 'w') { $userId = Helper::getUser($path); $session = new Session(new \OC\Files\View()); @@ -59,7 +83,7 @@ class Proxy extends \OC_FileProxy { if ( $session->getInitialized() !== Session::INIT_SUCCESSFUL // encryption successful initialized || Crypt::mode() !== 'server' // we are not in server-side-encryption mode - || strpos($path, '/' . $userId . '/files') !== 0 // path is not in files/ + || $this->isExcludedPath($path, $userId) // if path is excluded from encryption || substr($path, 0, 8) === 'crypt://' // we are already in crypt mode ) { return false; @@ -85,7 +109,7 @@ class Proxy extends \OC_FileProxy { */ public function preFile_put_contents($path, &$data) { - if (self::shouldEncrypt($path)) { + if ($this->shouldEncrypt($path)) { if (!is_resource($data)) { @@ -219,7 +243,7 @@ class Proxy extends \OC_FileProxy { public function preFopen($path, $mode) { self::$fopenMode[$path] = $mode; - self::$enableEncryption = self::shouldEncrypt($path, $mode); + self::$enableEncryption = $this->shouldEncrypt($path, $mode); } From e6f3850890537f8407e4028258e9631d8a0feaf1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 4 Jun 2014 17:05:37 +0200 Subject: [PATCH 14/47] Update for changes in master --- apps/files_sharing/templates/public.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 1c0570cb01..92d561e18e 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -27,7 +27,6 @@ "/> t('Download'))?> - t('shared by %s', array($_['displayName']))) ?>
From 43c56fcd07f610196d2704158978acca566f5776 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 4 Jun 2014 17:19:49 +0200 Subject: [PATCH 15/47] Generate a unique name --- apps/files_sharing/ajax/external.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index c25b34ab55..3759559764 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -22,6 +22,8 @@ $externalManager = new \OCA\Files_Sharing\External\Manager( \OC::$server->getUserSession() ); +$name = OCP\Files::buildNotExistingFileName('/', $name); + $mount = $externalManager->addShare($remote, $token, $password, $name, $owner); /** * @var \OCA\Files_Sharing\External\Storage $storage From 64ced76bebfab1607cbd44819b03242efdc17a9c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 4 Jun 2014 17:20:00 +0200 Subject: [PATCH 16/47] Save mountpoints relative to the user --- apps/files_sharing/lib/external/manager.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index 47fc220f7d..75edf73059 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -8,6 +8,7 @@ namespace OCA\Files_Sharing\External; +use OC\Files\Filesystem; use OC\Files\Mount\Mount; class Manager { @@ -52,7 +53,7 @@ class Manager { if ($user) { $query = $this->connection->prepare('INSERT INTO *PREFIX*share_external(`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`) VALUES(?, ?, ?, ?, ?, ?, ?, ?)'); - $mountPoint = '/' . $user->getUID() . '/files/' . $name; + $mountPoint = Filesystem::normalizePath('/' . $name); $hash = md5($mountPoint); $query->execute(array($remote, $token, $password, $name, $owner, $user->getUID(), $mountPoint, $hash)); @@ -63,9 +64,7 @@ class Manager { 'mountpoint' => $mountPoint, 'owner' => $owner ); - $mount = new Mount(self::STORAGE, $mountPoint, $options, $this->storageLoader); - $this->mountManager->addMount($mount); - return $mount; + return $this->mountShare($options); } } @@ -79,12 +78,22 @@ class Manager { while ($row = $query->fetch()) { $row['manager'] = $this; $row['token'] = $row['share_token']; - $mount = new Mount(self::STORAGE, $row['mountpoint'], $row, $this->storageLoader); - $this->mountManager->addMount($mount); + $this->mountShare($row); } } } + /** + * @param array $data + * @return Mount + */ + protected function mountShare($data) { + $mountPoint = '/' . $this->userSession->getUser()->getUID() . '/files' . $data['mountpoint']; + $mount = new Mount(self::STORAGE, $mountPoint, $data, $this->storageLoader); + $this->mountManager->addMount($mount); + return $mount; + } + /** * @return \OC\Files\Mount\Manager */ From 2005c162bdfbe70f2690697eee82bcbd28ff57f5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 5 Jun 2014 11:29:01 +0200 Subject: [PATCH 17/47] Fix prompting for password --- apps/files_sharing/js/public.js | 31 +++++++++++++------------ apps/files_sharing/public.php | 1 + apps/files_sharing/templates/public.php | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js index 48db89532b..359087c0f9 100644 --- a/apps/files_sharing/js/public.js +++ b/apps/files_sharing/js/public.js @@ -19,7 +19,7 @@ if (!OCA.Files) { OCA.Sharing.PublicApp = { _initialized: false, - initialize: function($el) { + initialize: function ($el) { var self = this; var fileActions; if (this._initialized) { @@ -65,7 +65,7 @@ OCA.Sharing.PublicApp = { } // dynamically load image previews - if (mimetype.substr(0, mimetype.indexOf('/')) === 'image' ) { + if (mimetype.substr(0, mimetype.indexOf('/')) === 'image') { var params = { x: $(document).width() * window.devicePixelRatio, @@ -82,7 +82,7 @@ OCA.Sharing.PublicApp = { if (this.fileList) { // TODO: move this to a separate PublicFileList class that extends OCA.Files.FileList (+ unit tests) - this.fileList.getDownloadUrl = function(filename, dir) { + this.fileList.getDownloadUrl = function (filename, dir) { if ($.isArray(filename)) { filename = JSON.stringify(filename); } @@ -97,13 +97,13 @@ OCA.Sharing.PublicApp = { return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); }; - this.fileList.getAjaxUrl = function(action, params) { + this.fileList.getAjaxUrl = function (action, params) { params = params || {}; params.t = $('#sharingToken').val(); return OC.filePath('files_sharing', 'ajax', action + '.php') + '?' + OC.buildQueryString(params); }; - this.fileList.linkTo = function(dir) { + this.fileList.linkTo = function (dir) { var params = { service: 'files', t: $('#sharingToken').val(), @@ -112,15 +112,15 @@ OCA.Sharing.PublicApp = { return OC.filePath('', '', 'public.php') + '?' + OC.buildQueryString(params); }; - this.fileList.generatePreviewUrl = function(urlSpec) { + this.fileList.generatePreviewUrl = function (urlSpec) { urlSpec.t = $('#dirToken').val(); return OC.generateUrl('/apps/files_sharing/ajax/publicpreview.php?') + $.param(urlSpec); }; var file_upload_start = $('#file_upload_start'); - file_upload_start.on('fileuploadadd', function(e, data) { + file_upload_start.on('fileuploadadd', function (e, data) { var fileDirectory = ''; - if(typeof data.files[0].relativePath !== 'undefined') { + if (typeof data.files[0].relativePath !== 'undefined') { fileDirectory = data.files[0].relativePath; } @@ -143,7 +143,7 @@ OCA.Sharing.PublicApp = { OC.Util.History.addOnPopStateHandler(_.bind(this._onUrlChanged, this)); } - $(document).on('click', '#directLink', function() { + $(document).on('click', '#directLink', function () { $(this).focus(); $(this).select(); }); @@ -152,7 +152,7 @@ OCA.Sharing.PublicApp = { window.FileList = this.fileList; }, - _onDirectoryChanged: function(e) { + _onDirectoryChanged: function (e) { OC.Util.History.pushState({ service: 'files', t: $('#sharingToken').val(), @@ -161,21 +161,21 @@ OCA.Sharing.PublicApp = { }); }, - _onUrlChanged: function(params) { + _onUrlChanged: function (params) { this.fileList.changeDirectory(params.path || params.dir, false, true); } }; -$(document).ready(function() { +$(document).ready(function () { var App = OCA.Sharing.PublicApp; // defer app init, to give a chance to plugins to register file actions - _.defer(function() { + _.defer(function () { App.initialize($('#preview')); }); if (window.Files) { // HACK: for oc-dialogs previews that depends on Files: - Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) { + Files.lazyLoadPreview = function (path, mime, ready, width, height, etag) { return App.fileList.lazyLoadPreview({ path: path, mime: mime, @@ -195,9 +195,10 @@ $(document).ready(function() { var location = window.location.protocol + '//' + window.location.host + OC.webroot; var owner = $('#save').data('owner'); var name = $('#save').data('name'); + var isProtected = $('#save').data('protected') ? 1 : 0; var url = remote + '/index.php/apps/files#' + 'remote=' + encodeURIComponent(location) // our location is the remote for the other server - + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) + "&name=" + encodeURIComponent(name); + + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) + "&name=" + encodeURIComponent(name) + "&protected=" + isProtected; if (remote.indexOf('://') > 0) { diff --git a/apps/files_sharing/public.php b/apps/files_sharing/public.php index 4782c4dbe3..ec7c80f331 100644 --- a/apps/files_sharing/public.php +++ b/apps/files_sharing/public.php @@ -128,6 +128,7 @@ if (isset($path)) { $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path)); $tmpl->assign('dirToken', $linkItem['token']); $tmpl->assign('sharingToken', $token); + $tmpl->assign('protected', isset($linkItem['share_with']) ? 'true' : 'false'); $urlLinkIdentifiers= (isset($token)?'&t='.$token:'') .(isset($_GET['dir'])?'&dir='.$_GET['dir']:'') diff --git a/apps/files_sharing/templates/public.php b/apps/files_sharing/templates/public.php index 92d561e18e..c053aaabec 100644 --- a/apps/files_sharing/templates/public.php +++ b/apps/files_sharing/templates/public.php @@ -16,7 +16,7 @@
- +