From 65f3b2fad235417d3f653c9e11aa8d72e8944d28 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 29 Apr 2014 15:14:48 +0200 Subject: Add server<->server sharing backend --- apps/files_sharing/lib/external/cache.php | 47 +++++++++++++++ apps/files_sharing/lib/external/manager.php | 90 ++++++++++++++++++++++++++++ apps/files_sharing/lib/external/storage.php | 91 +++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+) 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 (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/cache.php b/apps/files_sharing/lib/external/cache.php new file mode 100644 index 00000000000..cd06bfb1272 --- /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 00000000000..ffb673723aa --- /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 00000000000..2683a6a6902 --- /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; + } + } +} -- cgit v1.2.3 From a44baaf8eb9584c3525584ff893bad47adb0d375 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 2 May 2014 11:27:40 +0200 Subject: add remote/add external shares to manager --- apps/files_sharing/lib/external/manager.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index ffb673723aa..d82cb83a6e7 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)); + } } -- cgit v1.2.3 From 0156ef816650ec73d033ebba2107cf237d6301e3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 7 May 2014 13:19:41 +0200 Subject: 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(-) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml index b9c0d881fc6..e55688240b2 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 d82cb83a6e7..fa0005389a7 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)); -- cgit v1.2.3 From d7de35376d7e068abdfb49e8336feab25e313662 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 9 May 2014 17:06:08 +0200 Subject: 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 (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php new file mode 100644 index 00000000000..e7bf903f705 --- /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 9ea969f4cf3..db4e042faeb 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 7c2834dc9c2..2d214c879c4 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 00000000000..0fa99a1652b --- /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 fa0005389a7..47fc220f7de 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; } } -- cgit v1.2.3 From a900c7aa94ad6527cb3bdf2600b6b1e9e6b497ac Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 15 May 2014 12:13:46 +0200 Subject: Fix removing remote shares --- apps/files_sharing/lib/external/storage.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 2683a6a6902..0e799a0e9e3 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); + } + } } -- cgit v1.2.3 From 87b0021e5606888642b5798ba39b0525bf3f3e14 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 19 May 2014 16:39:57 +0200 Subject: 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 (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index e7bf903f705..c25b34ab552 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 00000000000..4aefdbe7b15 --- /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 00000000000..1f32d79b149 --- /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 0e799a0e9e3..741e219eff7 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)) { -- cgit v1.2.3 From 64ced76bebfab1607cbd44819b03242efdc17a9c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 4 Jun 2014 17:20:00 +0200 Subject: Save mountpoints relative to the user --- apps/files_sharing/lib/external/manager.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index 47fc220f7de..75edf73059c 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 */ -- cgit v1.2.3 From ce0aa7d4a895849a90e1ec5ea97bd699a8a4ad3f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Jun 2014 16:14:43 +0200 Subject: Use the movable mount system for external shares --- apps/files_sharing/lib/external/manager.php | 19 ++++++----- apps/files_sharing/lib/external/mount.php | 53 +++++++++++++++++++++++++++++ apps/files_sharing/lib/external/storage.php | 33 ++---------------- 3 files changed, 66 insertions(+), 39 deletions(-) create mode 100644 apps/files_sharing/lib/external/mount.php (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index 75edf73059c..a1a97126506 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -9,7 +9,6 @@ namespace OCA\Files_Sharing\External; use OC\Files\Filesystem; -use OC\Files\Mount\Mount; class Manager { const STORAGE = '\OCA\Files_Sharing\External\Storage'; @@ -83,13 +82,18 @@ class Manager { } } + protected function stripPath($path) { + $prefix = '/' . $this->userSession->getUser()->getUID() . '/files'; + return rtrim(substr($path, strlen($prefix)), '/'); + } + /** * @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); + $mount = new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); $this->mountManager->addMount($mount); return $mount; } @@ -107,22 +111,21 @@ class Manager { * @return bool */ public function setMountPoint($source, $target) { + $source = $this->stripPath($source); + $target = $this->stripPath($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)); + $result = (bool)$query->execute(array($target, $targetHash, $sourceHash)); - $mount = $this->mountManager->find($source); - $mount->setMountPoint($target . '/'); - $this->mountManager->addMount($mount); - $this->mountManager->removeMount($source . '/'); + return $result; } public function removeShare($mountPoint) { $hash = md5($mountPoint); $query = $this->connection->prepare('DELETE FROM *PREFIX*share_external WHERE `mountpoint_hash` = ?'); - $query->execute(array($hash)); + return (bool)$query->execute(array($hash)); } } diff --git a/apps/files_sharing/lib/external/mount.php b/apps/files_sharing/lib/external/mount.php new file mode 100644 index 00000000000..a42a12f9b9a --- /dev/null +++ b/apps/files_sharing/lib/external/mount.php @@ -0,0 +1,53 @@ + + * 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\MoveableMount; + +class Mount extends \OC\Files\Mount\Mount implements MoveableMount { + + /** + * @var \OCA\Files_Sharing\External\Manager + */ + protected $manager; + + /** + * @param string|\OC\Files\Storage\Storage $storage + * @param string $mountpoint + * @param array $options + * @param \OCA\Files_Sharing\External\Manager $manager + * @param \OC\Files\Storage\Loader $loader + */ + public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { + parent::__construct($storage, $mountpoint, $options, $loader); + $this->manager = $manager; + } + + /** + * Move the mount point to $target + * + * @param string $target the target mount point + * @return bool + */ + public function moveMount($target) { + $result = $this->manager->setMountPoint($this->mountPoint, $target); + $this->setMountPoint($target); + return $result; + } + + /** + * Remove the mount points + * + * @return mixed + * @return bool + */ + public function removeMount() { + return $this->manager->removeShare($this->mountPoint); + } +} diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 741e219eff7..89d2f5e6669 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -9,9 +9,10 @@ namespace OCA\Files_Sharing\External; use OC\Files\Filesystem; +use OC\Files\Storage\DAV; use OCA\Files_Sharing\ISharedStorage; -class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { +class Storage extends DAV implements ISharedStorage { /** * @var string */ @@ -101,34 +102,4 @@ class Storage extends \OC\Files\Storage\DAV implements ISharedStorage { } 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)) { - $this->manager->setMountPoint($path1, $path2); - $this->mountPoint = $path2; - return true; - } else { - // read only shares - 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); - } - } } -- cgit v1.2.3 From c8c81061684ccf671b22e48906a0abd04c6898cc Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Jun 2014 16:15:01 +0200 Subject: generate better storage ids --- apps/files_sharing/lib/external/storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 89d2f5e6669..e25777d60e3 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -82,7 +82,7 @@ class Storage extends DAV implements ISharedStorage { * @return string */ public function getId() { - return 'shared::' . md5($this->user . '@' . $this->remote); + return 'shared::' . md5($this->token . '@' . $this->remote); } public function getCache($path = '') { -- cgit v1.2.3 From decb51aee64d024059cf9f66b88e802270f8da09 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Jun 2014 16:20:35 +0200 Subject: Fix deleting of external shares --- apps/files_sharing/lib/external/manager.php | 1 + 1 file changed, 1 insertion(+) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index a1a97126506..53e8121b7f6 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -124,6 +124,7 @@ class Manager { } public function removeShare($mountPoint) { + $mountPoint = $this->stripPath($mountPoint); $hash = md5($mountPoint); $query = $this->connection->prepare('DELETE FROM *PREFIX*share_external WHERE `mountpoint_hash` = ?'); return (bool)$query->execute(array($hash)); -- cgit v1.2.3 From 87e311b99628858ddb974cd35ae381a26b4bcdb5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Jun 2014 17:23:34 +0200 Subject: Fix storage being passed to cache/watcher and scanner when using storage wrappers --- apps/files_sharing/lib/external/storage.php | 12 ++++++++---- apps/files_sharing/lib/sharedstorage.php | 21 ++++++++++++++------ lib/private/files/storage/common.php | 28 +++++++++++++++++++-------- lib/private/files/storage/home.php | 7 +++++-- lib/private/files/storage/storage.php | 9 ++++++--- lib/private/files/storage/wrapper/wrapper.php | 26 +++++++++++++++++++------ 6 files changed, 74 insertions(+), 29 deletions(-) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index e25777d60e3..7eac7f02c27 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -85,8 +85,8 @@ class Storage extends DAV implements ISharedStorage { return 'shared::' . md5($this->token . '@' . $this->remote); } - public function getCache($path = '') { - if (!isset($this->cache)) { + public function getCache($path = '', $storage = null) { + if (!$storage) { $this->cache = new Cache($this, $this->remote, $this->remoteUser); } return $this->cache; @@ -94,11 +94,15 @@ class Storage extends DAV implements ISharedStorage { /** * @param string $path + * @param \OC\Files\Storage\Storage $storage * @return \OCA\Files_Sharing\External\Scanner */ - public function getScanner($path = '') { + public function getScanner($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } if (!isset($this->scanner)) { - $this->scanner = new Scanner($this); + $this->scanner = new Scanner($storage); } return $this->scanner; } diff --git a/apps/files_sharing/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php index 6760538f510..8d5b22dc283 100644 --- a/apps/files_sharing/lib/sharedstorage.php +++ b/apps/files_sharing/lib/sharedstorage.php @@ -489,16 +489,25 @@ class Shared extends \OC\Files\Storage\Common implements ISharedStorage { return $this->filemtime($path) > $time; } - public function getCache($path = '') { - return new \OC\Files\Cache\Shared_Cache($this); + public function getCache($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } + return new \OC\Files\Cache\Shared_Cache($storage); } - public function getScanner($path = '') { - return new \OC\Files\Cache\Scanner($this); + public function getScanner($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } + return new \OC\Files\Cache\Scanner($storage); } - public function getWatcher($path = '') { - return new \OC\Files\Cache\Shared_Watcher($this); + public function getWatcher($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } + return new \OC\Files\Cache\Shared_Watcher($storage); } public function getOwner($path) { diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index 4d5a2078ef7..ecc75298b66 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -287,31 +287,43 @@ abstract class Common implements \OC\Files\Storage\Storage { return $this->filemtime($path) > $time; } - public function getCache($path = '') { + public function getCache($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } if (!isset($this->cache)) { - $this->cache = new \OC\Files\Cache\Cache($this); + $this->cache = new \OC\Files\Cache\Cache($storage); } return $this->cache; } - public function getScanner($path = '') { + public function getScanner($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } if (!isset($this->scanner)) { - $this->scanner = new \OC\Files\Cache\Scanner($this); + $this->scanner = new \OC\Files\Cache\Scanner($storage); } return $this->scanner; } - public function getWatcher($path = '') { + public function getWatcher($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } if (!isset($this->watcher)) { - $this->watcher = new \OC\Files\Cache\Watcher($this); + $this->watcher = new \OC\Files\Cache\Watcher($storage); $this->watcher->setPolicy(\OC::$server->getConfig()->getSystemValue('filesystem_check_changes', Watcher::CHECK_ONCE)); } return $this->watcher; } - public function getStorageCache() { + public function getStorageCache($storage = null) { + if (!$storage) { + $storage = $this; + } if (!isset($this->storageCache)) { - $this->storageCache = new \OC\Files\Cache\Storage($this); + $this->storageCache = new \OC\Files\Cache\Storage($storage); } return $this->storageCache; } diff --git a/lib/private/files/storage/home.php b/lib/private/files/storage/home.php index f66096f6d9c..214deede620 100644 --- a/lib/private/files/storage/home.php +++ b/lib/private/files/storage/home.php @@ -49,9 +49,12 @@ class Home extends Local { /** * @return \OC\Files\Cache\HomeCache */ - public function getCache($path = '') { + public function getCache($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } if (!isset($this->cache)) { - $this->cache = new \OC\Files\Cache\HomeCache($this); + $this->cache = new \OC\Files\Cache\HomeCache($storage); } return $this->cache; } diff --git a/lib/private/files/storage/storage.php b/lib/private/files/storage/storage.php index f085a0590b4..2139f464821 100644 --- a/lib/private/files/storage/storage.php +++ b/lib/private/files/storage/storage.php @@ -19,17 +19,19 @@ interface Storage extends \OCP\Files\Storage { * get a cache instance for the storage * * @param string $path + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache * @return \OC\Files\Cache\Cache */ - public function getCache($path = ''); + public function getCache($path = '', $storage = null); /** * get a scanner instance for the storage * * @param string $path + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner * @return \OC\Files\Cache\Scanner */ - public function getScanner($path = ''); + public function getScanner($path = '', $storage = null); /** @@ -44,9 +46,10 @@ interface Storage extends \OCP\Files\Storage { * get a watcher instance for the cache * * @param string $path + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher * @return \OC\Files\Cache\Watcher */ - public function getWatcher($path = ''); + public function getWatcher($path = '', $storage = null); /** * @return \OC\Files\Cache\Storage diff --git a/lib/private/files/storage/wrapper/wrapper.php b/lib/private/files/storage/wrapper/wrapper.php index 057c31c3cd8..d899c88363f 100644 --- a/lib/private/files/storage/wrapper/wrapper.php +++ b/lib/private/files/storage/wrapper/wrapper.php @@ -361,20 +361,28 @@ class Wrapper implements \OC\Files\Storage\Storage { * get a cache instance for the storage * * @param string $path + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache * @return \OC\Files\Cache\Cache */ - public function getCache($path = '') { - return $this->storage->getCache($path); + public function getCache($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } + return $this->storage->getCache($path, $storage); } /** * get a scanner instance for the storage * * @param string $path + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the scanner * @return \OC\Files\Cache\Scanner */ - public function getScanner($path = '') { - return $this->storage->getScanner($path); + public function getScanner($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } + return $this->storage->getScanner($path, $storage); } @@ -392,10 +400,14 @@ class Wrapper implements \OC\Files\Storage\Storage { * get a watcher instance for the cache * * @param string $path + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher * @return \OC\Files\Cache\Watcher */ - public function getWatcher($path = '') { - return $this->storage->getWatcher($path); + public function getWatcher($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } + return $this->storage->getWatcher($path, $storage); } /** @@ -417,6 +429,7 @@ class Wrapper implements \OC\Files\Storage\Storage { /** * Returns true + * * @return true */ public function test() { @@ -425,6 +438,7 @@ class Wrapper implements \OC\Files\Storage\Storage { /** * Returns the wrapped storage's value for isLocal() + * * @return bool wrapped storage's isLocal() value */ public function isLocal() { -- cgit v1.2.3 From e7b58ed2bdfe4bb56866e76b8fdd618946fa3c51 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 12 Jun 2014 17:53:56 +0200 Subject: Properly expose read only public shares as read only --- apps/files_sharing/ajax/shareinfo.php | 7 ++++ apps/files_sharing/lib/external/scanner.php | 4 +++ apps/files_sharing/lib/readonlycache.php | 27 ++++++++++++++ apps/files_sharing/lib/readonlywrapper.php | 56 +++++++++++++++++++++++++++++ apps/files_sharing/publicwebdav.php | 8 +++++ 5 files changed, 102 insertions(+) create mode 100644 apps/files_sharing/lib/readonlycache.php create mode 100644 apps/files_sharing/lib/readonlywrapper.php (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/ajax/shareinfo.php b/apps/files_sharing/ajax/shareinfo.php index 4aefdbe7b15..c5764867d56 100644 --- a/apps/files_sharing/ajax/shareinfo.php +++ b/apps/files_sharing/ajax/shareinfo.php @@ -33,6 +33,13 @@ $linkItem = $data['linkItem']; // Load the files $path = $data['realPath']; +$isWritable = $linkItem['permissions'] & \OCP\PERMISSION_CREATE; +if (!$isWritable) { + \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) { + return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage)); + }); +} + $rootInfo = \OC\Files\Filesystem::getFileInfo($path); $rootView = new \OC\Files\View(''); diff --git a/apps/files_sharing/lib/external/scanner.php b/apps/files_sharing/lib/external/scanner.php index 1f32d79b149..8fb8683ed92 100644 --- a/apps/files_sharing/lib/external/scanner.php +++ b/apps/files_sharing/lib/external/scanner.php @@ -14,6 +14,10 @@ class Scanner extends \OC\Files\Cache\Scanner { */ protected $storage; + public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) { + $this->scanAll(); + } + public function scanAll() { $remote = $this->storage->getRemote(); $token = $this->storage->getToken(); diff --git a/apps/files_sharing/lib/readonlycache.php b/apps/files_sharing/lib/readonlycache.php new file mode 100644 index 00000000000..f129ca49433 --- /dev/null +++ b/apps/files_sharing/lib/readonlycache.php @@ -0,0 +1,27 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing; + +use OC\Files\Cache\Cache; + +class ReadOnlyCache extends Cache { + public function get($path) { + $data = parent::get($path); + $data['permissions'] &= (\OCP\PERMISSION_READ | \OCP\PERMISSION_SHARE); + return $data; + } + + public function getFolderContents($path) { + $content = parent::getFolderContents($path); + foreach ($content as &$data) { + $data['permissions'] &= (\OCP\PERMISSION_READ | \OCP\PERMISSION_SHARE); + } + return $content; + } +} diff --git a/apps/files_sharing/lib/readonlywrapper.php b/apps/files_sharing/lib/readonlywrapper.php new file mode 100644 index 00000000000..45ed3fd68bb --- /dev/null +++ b/apps/files_sharing/lib/readonlywrapper.php @@ -0,0 +1,56 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCA\Files_Sharing; + +use OC\Files\Storage\Wrapper\Wrapper; + +class ReadOnlyWrapper extends Wrapper { + public function isUpdatable($path) { + return false; + } + + public function isCreatable($path) { + return false; + } + + public function isDeletable($path) { + return false; + } + + public function getPermissions($path) { + return $this->storage->getPermissions($path) & (\OCP\PERMISSION_READ | \OCP\PERMISSION_SHARE); + } + + public function rename($path1, $path2) { + return false; + } + + public function touch($path, $mtime = null) { + return false; + } + + public function mkdir($path) { + return false; + } + + public function rmdir($path) { + return false; + } + + public function unlink($path) { + return false; + } + + public function getCache($path = '', $storage = null) { + if (!$storage) { + $storage = $this; + } + return new ReadOnlyCache($storage); + } +} diff --git a/apps/files_sharing/publicwebdav.php b/apps/files_sharing/publicwebdav.php index b4f56eed89c..f33b920bc54 100644 --- a/apps/files_sharing/publicwebdav.php +++ b/apps/files_sharing/publicwebdav.php @@ -37,7 +37,15 @@ $server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav')); $server->subscribeEvent('beforeMethod', function () use ($server, $objectTree, $authBackend) { $share = $authBackend->getShare(); $owner = $share['uid_owner']; + $isWritable = $share['permissions']; $fileId = $share['file_source']; + + if (!$isWritable) { + \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) { + return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage)); + }); + } + OC_Util::setupFS($owner); $ownerView = \OC\Files\Filesystem::getView(); $path = $ownerView->getPath($fileId); -- cgit v1.2.3 From 3bf7b54cd59836165fd9ddb406cf1b56ded84923 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Fri, 13 Jun 2014 12:43:37 +0200 Subject: block server-to-server share if files_external is not activates, can be reverted once we moved to the webdav implementation in core --- apps/files_sharing/ajax/external.php | 5 ++++- apps/files_sharing/lib/external/manager.php | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index 5b4d4656d62..da73310c8df 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -12,7 +12,10 @@ OCP\JSON::checkLoggedIn(); $l = OC_L10N::get('files_sharing'); // check if server admin allows to mount public links from other servers -if (OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false) { +// check if files_external is enabled +// FIXME file_external check no longer needed if we use the webdav implementation from core +if (OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false || + \OC_App::isEnabled('files_external') === false) { \OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server')))); exit(); } diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index 53e8121b7f6..381651f8c6a 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -68,6 +68,12 @@ class Manager { } public function setup() { + // don't setup server-to-server shares if the file_external app is disabled + // FIXME no longer needed if we use the webdav implementation from core + if (\OC_App::isEnabled('files_external') === false) { + return false; + } + $user = $this->userSession->getUser(); if ($user) { $query = $this->connection->prepare('SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner` -- cgit v1.2.3 From 455fbafb484cb816307317f93a4d4018f8c2a429 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 13 Jun 2014 12:47:47 +0200 Subject: Fix undefined index error --- apps/files_sharing/lib/external/storage.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/storage.php b/apps/files_sharing/lib/external/storage.php index 7eac7f02c27..cd04841bb09 100644 --- a/apps/files_sharing/lib/external/storage.php +++ b/apps/files_sharing/lib/external/storage.php @@ -33,15 +33,9 @@ class Storage extends DAV implements ISharedStorage { */ private $token; - /** - * @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'; -- cgit v1.2.3 From 9670d3e98b2fdfb8a3865dcaf954b1fef5f1e574 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 13 Jun 2014 15:28:35 +0200 Subject: Always send a POST body --- apps/files_sharing/lib/external/scanner.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/scanner.php b/apps/files_sharing/lib/external/scanner.php index 8fb8683ed92..7381450521e 100644 --- a/apps/files_sharing/lib/external/scanner.php +++ b/apps/files_sharing/lib/external/scanner.php @@ -28,10 +28,8 @@ class Scanner extends \OC\Files\Cache\Scanner { 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_POSTFIELDS, + http_build_query(array('password' => $password))); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); -- cgit v1.2.3 From 0616eb4007b14d701ca3949c83bddf0a31507b56 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 16 Jun 2014 15:57:01 +0200 Subject: Fix multiple users having the same external share mountpoint --- apps/files_sharing/appinfo/database.xml | 4 ++++ apps/files_sharing/appinfo/version | 2 +- apps/files_sharing/lib/external/manager.php | 10 ++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/appinfo/database.xml b/apps/files_sharing/appinfo/database.xml index 159d6cb1c57..73d64c527b7 100644 --- a/apps/files_sharing/appinfo/database.xml +++ b/apps/files_sharing/appinfo/database.xml @@ -81,6 +81,10 @@ sh_external_mp true + + user + ascending + mountpoint_hash ascending diff --git a/apps/files_sharing/appinfo/version b/apps/files_sharing/appinfo/version index 4b9fcbec101..cb0c939a936 100644 --- a/apps/files_sharing/appinfo/version +++ b/apps/files_sharing/appinfo/version @@ -1 +1 @@ -0.5.1 +0.5.2 diff --git a/apps/files_sharing/lib/external/manager.php b/apps/files_sharing/lib/external/manager.php index 381651f8c6a..70a0e98ebd5 100644 --- a/apps/files_sharing/lib/external/manager.php +++ b/apps/files_sharing/lib/external/manager.php @@ -117,22 +117,24 @@ class Manager { * @return bool */ public function setMountPoint($source, $target) { + $user = $this->userSession->getUser(); $source = $this->stripPath($source); $target = $this->stripPath($target); $sourceHash = md5($source); $targetHash = md5($target); $query = $this->connection->prepare('UPDATE *PREFIX*share_external SET - `mountpoint` = ?, `mountpoint_hash` = ? WHERE `mountpoint_hash` = ?'); - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash)); + `mountpoint` = ?, `mountpoint_hash` = ? WHERE `mountpoint_hash` = ? AND `user` = ?'); + $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $user->getUID())); return $result; } public function removeShare($mountPoint) { + $user = $this->userSession->getUser(); $mountPoint = $this->stripPath($mountPoint); $hash = md5($mountPoint); - $query = $this->connection->prepare('DELETE FROM *PREFIX*share_external WHERE `mountpoint_hash` = ?'); - return (bool)$query->execute(array($hash)); + $query = $this->connection->prepare('DELETE FROM *PREFIX*share_external WHERE `mountpoint_hash` = ? AND `user` = ?'); + return (bool)$query->execute(array($hash, $user->getUID())); } } -- cgit v1.2.3 From 3ed4e5b26b4b1b253506525aedd9b8d0b8bd649b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 16 Jun 2014 16:12:32 +0200 Subject: Prevent warning --- apps/files_sharing/lib/external/scanner.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/files_sharing/lib/external') diff --git a/apps/files_sharing/lib/external/scanner.php b/apps/files_sharing/lib/external/scanner.php index 7381450521e..8921dd1a4c0 100644 --- a/apps/files_sharing/lib/external/scanner.php +++ b/apps/files_sharing/lib/external/scanner.php @@ -45,7 +45,7 @@ class Scanner extends \OC\Files\Cache\Scanner { private function addResult($data, $path) { $this->cache->put($path, $data); - if ($data['children']) { + if (isset($data['children'])) { foreach ($data['children'] as $child) { $this->addResult($child, ltrim($path . '/' . $child['name'], '/')); } -- cgit v1.2.3