summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/connector/publicauth.php1
-rw-r--r--apps/files_sharing/lib/external/cache.php47
-rw-r--r--apps/files_sharing/lib/external/manager.php140
-rw-r--r--apps/files_sharing/lib/external/mount.php53
-rw-r--r--apps/files_sharing/lib/external/scanner.php54
-rw-r--r--apps/files_sharing/lib/external/storage.php103
-rw-r--r--apps/files_sharing/lib/helper.php22
-rw-r--r--apps/files_sharing/lib/isharedstorage.php13
-rw-r--r--apps/files_sharing/lib/readonlycache.php27
-rw-r--r--apps/files_sharing/lib/readonlywrapper.php56
-rw-r--r--apps/files_sharing/lib/sharedstorage.php24
11 files changed, 532 insertions, 8 deletions
diff --git a/apps/files_sharing/lib/connector/publicauth.php b/apps/files_sharing/lib/connector/publicauth.php
index ec7b68ba69c..c9d545180b3 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;
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 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * 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..70a0e98ebd5
--- /dev/null
+++ b/apps/files_sharing/lib/external/manager.php
@@ -0,0 +1,140 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * 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;
+
+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 addShare($remote, $token, $password, $name, $owner) {
+ $user = $this->userSession->getUser();
+ if ($user) {
+ $query = $this->connection->prepare('INSERT INTO *PREFIX*share_external(`remote`, `share_token`, `password`,
+ `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`) VALUES(?, ?, ?, ?, ?, ?, ?, ?)');
+ $mountPoint = Filesystem::normalizePath('/' . $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
+ );
+ return $this->mountShare($options);
+ }
+ }
+
+ 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`
+ FROM *PREFIX*share_external WHERE `user` = ?');
+ $query->execute(array($user->getUID()));
+
+ while ($row = $query->fetch()) {
+ $row['manager'] = $this;
+ $row['token'] = $row['share_token'];
+ $this->mountShare($row);
+ }
+ }
+ }
+
+ 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, $this->storageLoader);
+ $this->mountManager->addMount($mount);
+ return $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) {
+ $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` = ? 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` = ? AND `user` = ?');
+ return (bool)$query->execute(array($hash, $user->getUID()));
+ }
+}
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 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * 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/scanner.php b/apps/files_sharing/lib/external/scanner.php
new file mode 100644
index 00000000000..8921dd1a4c0
--- /dev/null
+++ b/apps/files_sharing/lib/external/scanner.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * 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 scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) {
+ $this->scanAll();
+ }
+
+ 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);
+ 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 (isset($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
new file mode 100644
index 00000000000..cd04841bb09
--- /dev/null
+++ b/apps/files_sharing/lib/external/storage.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * 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 OC\Files\Storage\DAV;
+use OCA\Files_Sharing\ISharedStorage;
+
+class Storage extends DAV implements ISharedStorage {
+ /**
+ * @var string
+ */
+ private $remoteUser;
+
+ /**
+ * @var string
+ */
+ private $remote;
+
+ /**
+ * @var string
+ */
+ private $mountPoint;
+
+ /**
+ * @var string
+ */
+ private $token;
+
+ public function __construct($options) {
+ $this->remote = $options['remote'];
+ $this->remoteUser = $options['owner'];
+ list($protocol, $remote) = explode('://', $this->remote);
+ list($host, $root) = explode('/', $remote);
+ $secure = $protocol === 'https';
+ $root .= '/public.php/webdav';
+ $this->mountPoint = $options['mountpoint'];
+ $this->token = $options['token'];
+ 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;
+ }
+
+ public function getToken() {
+ return $this->token;
+ }
+
+ public function getPassword() {
+ return $this->password;
+ }
+
+ /**
+ * @brief get id of the mount point
+ * @return string
+ */
+ public function getId() {
+ return 'shared::' . md5($this->token . '@' . $this->remote);
+ }
+
+ public function getCache($path = '', $storage = null) {
+ if (!$storage) {
+ $this->cache = new Cache($this, $this->remote, $this->remoteUser);
+ }
+ return $this->cache;
+ }
+
+ /**
+ * @param string $path
+ * @param \OC\Files\Storage\Storage $storage
+ * @return \OCA\Files_Sharing\External\Scanner
+ */
+ public function getScanner($path = '', $storage = null) {
+ if (!$storage) {
+ $storage = $this;
+ }
+ if (!isset($this->scanner)) {
+ $this->scanner = new Scanner($storage);
+ }
+ return $this->scanner;
+ }
+}
diff --git a/apps/files_sharing/lib/helper.php b/apps/files_sharing/lib/helper.php
index 49546f012a6..34de3a915ab 100644
--- a/apps/files_sharing/lib/helper.php
+++ b/apps/files_sharing/lib/helper.php
@@ -16,7 +16,7 @@ class Helper {
public static function setupFromToken($token, $relativePath = null, $password = null) {
\OC_User::setIncognitoMode(true);
- $linkItem = \OCP\Share::getShareByToken($token);
+ $linkItem = \OCP\Share::getShareByToken($token, !$password);
if($linkItem === false || ($linkItem['item_type'] !== 'file' && $linkItem['item_type'] !== 'folder')) {
\OC_Response::setStatus(404);
\OC_Log::write('core-preview', 'Passed token parameter is not valid', \OC_Log::DEBUG);
@@ -202,4 +202,24 @@ class Helper {
return $path;
}
+
+ /**
+ * allow users from other ownCloud instances to mount public links share by this instance
+ * @return bool
+ */
+ public static function isOutgoingServer2serverShareEnabled() {
+ $appConfig = \OC::$server->getAppConfig();
+ $result = $appConfig->getValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes');
+ return ($result === 'yes') ? true : false;
+ }
+
+ /**
+ * allow user to mount public links from onther ownClouds
+ * @return bool
+ */
+ public static function isIncomingServer2serverShareEnabled() {
+ $appConfig = \OC::$server->getAppConfig();
+ $result = $appConfig->getValue('files_sharing', 'incoming_server2server_share_enabled', 'yes');
+ return ($result === 'yes') ? true : false;
+ }
}
diff --git a/apps/files_sharing/lib/isharedstorage.php b/apps/files_sharing/lib/isharedstorage.php
new file mode 100644
index 00000000000..75e0afef394
--- /dev/null
+++ b/apps/files_sharing/lib/isharedstorage.php
@@ -0,0 +1,13 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * 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/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 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * 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 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * 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/lib/sharedstorage.php b/apps/files_sharing/lib/sharedstorage.php
index 59de2dfa4c4..8d5b22dc283 100644
--- a/apps/files_sharing/lib/sharedstorage.php
+++ b/apps/files_sharing/lib/sharedstorage.php
@@ -23,12 +23,13 @@
namespace OC\Files\Storage;
use OC\Files\Filesystem;
+use OCA\Files_Sharing\ISharedStorage;
use OCA\Files_Sharing\SharedMount;
/**
* Convert target path to source path and pass the function call to the correct storage provider
*/
-class Shared extends \OC\Files\Storage\Common {
+class Shared extends \OC\Files\Storage\Common implements ISharedStorage {
private $share; // the shared resource
private $files = array();
@@ -488,16 +489,25 @@ class Shared extends \OC\Files\Storage\Common {
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) {