diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-13 18:25:04 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-02-13 18:25:04 +0100 |
commit | 11707dffcee6ecf1d8e2931c3cb2144e585d0eac (patch) | |
tree | 76267d8868a157e7c19c73e630cf5aad9bae2c52 /apps/files_sharing/api | |
parent | 198d23406873aeda6fed68a80220abc08be5d8e0 (diff) | |
parent | 862e28f006801b13565f99253976fe973a09e657 (diff) | |
download | nextcloud-server-11707dffcee6ecf1d8e2931c3cb2144e585d0eac.tar.gz nextcloud-server-11707dffcee6ecf1d8e2931c3cb2144e585d0eac.zip |
Merge pull request #22351 from owncloud/fix_22277
show remote server on federated share auto-complete
Diffstat (limited to 'apps/files_sharing/api')
-rw-r--r-- | apps/files_sharing/api/sharees.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/apps/files_sharing/api/sharees.php b/apps/files_sharing/api/sharees.php index 85cea2e4238..5b7bbb11e84 100644 --- a/apps/files_sharing/api/sharees.php +++ b/apps/files_sharing/api/sharees.php @@ -279,6 +279,7 @@ class Sharees { $cloudIds = [$cloudIds]; } foreach ($cloudIds as $cloudId) { + list(, $serverUrl) = $this->splitUserRemote($cloudId); if (strtolower($contact['FN']) === $search || strtolower($cloudId) === $search) { if (strtolower($cloudId) === $search) { $foundRemoteById = true; @@ -288,6 +289,7 @@ class Sharees { 'value' => [ 'shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $cloudId, + 'server' => $serverUrl, ], ]; } else { @@ -296,6 +298,7 @@ class Sharees { 'value' => [ 'shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $cloudId, + 'server' => $serverUrl, ], ]; } @@ -321,6 +324,74 @@ class Sharees { } /** + * split user and remote from federated cloud id + * + * @param string $address federated share address + * @return array [user, remoteURL] + * @throws \Exception + */ + public function splitUserRemote($address) { + if (strpos($address, '@') === false) { + throw new \Exception('Invalid Federated Cloud ID'); + } + + // Find the first character that is not allowed in user names + $id = str_replace('\\', '/', $address); + $posSlash = strpos($id, '/'); + $posColon = strpos($id, ':'); + + if ($posSlash === false && $posColon === false) { + $invalidPos = strlen($id); + } else if ($posSlash === false) { + $invalidPos = $posColon; + } else if ($posColon === false) { + $invalidPos = $posSlash; + } else { + $invalidPos = min($posSlash, $posColon); + } + + // Find the last @ before $invalidPos + $pos = $lastAtPos = 0; + while ($lastAtPos !== false && $lastAtPos <= $invalidPos) { + $pos = $lastAtPos; + $lastAtPos = strpos($id, '@', $pos + 1); + } + + if ($pos !== false) { + $user = substr($id, 0, $pos); + $remote = substr($id, $pos + 1); + $remote = $this->fixRemoteURL($remote); + if (!empty($user) && !empty($remote)) { + return array($user, $remote); + } + } + + throw new \Exception('Invalid Federated Cloud ID'); + } + + /** + * Strips away a potential file names and trailing slashes: + * - http://localhost + * - http://localhost/ + * - http://localhost/index.php + * - http://localhost/index.php/s/{shareToken} + * + * all return: http://localhost + * + * @param string $remote + * @return string + */ + protected function fixRemoteURL($remote) { + $remote = str_replace('\\', '/', $remote); + if ($fileNamePosition = strpos($remote, '/index.php')) { + $remote = substr($remote, 0, $fileNamePosition); + } + $remote = rtrim($remote, '/'); + + return $remote; + } + + /** * @return \OC_OCS_Result */ public function search() { |