/** * @param IEvent $event * @param string $parameter The parameter to be formatted * @param bool $allowHtml Should HTML be used to format the parameter? * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ public function format(IEvent $event, $parameter, $allowHtml, $verbose = false) { $displayName = $parameter; try { list($user, $server) = Helper::splitUserRemote($parameter); } catch (HintException $e) { $user = $parameter; $server = ''; } if (!$verbose && $server !== '') { $displayName = $user . '@…'; } try { $displayName = $this->getDisplayNameFromContact($parameter); } catch (\OutOfBoundsException $e) { } if ($allowHtml === null) { return '<federated-cloud-id display-name="' . Util::sanitizeHTML($displayName) . '" user="******" server="' . $server . '">' . Util::sanitizeHTML($parameter) . '</federated-cloud-id>'; } if ($allowHtml) { $title = ' title="' . Util::sanitizeHTML($parameter) . '"'; return '<strong class="has-tooltip"' . $title . '>' . Util::sanitizeHTML($displayName) . '</strong>'; } else { return $displayName; } }
/** * @param IEvent $event * @param string $parameter The parameter to be formatted * @return string The formatted parameter */ public function format(IEvent $event, $parameter) { $displayName = $parameter; try { list($user, $server) = Helper::splitUserRemote($parameter); } catch (HintException $e) { $user = $parameter; $server = ''; } if ($server !== '') { $displayName = $user . '@…'; } try { $displayName = $this->getDisplayNameFromContact($parameter); } catch (\OutOfBoundsException $e) { } return '<federated-cloud-id display-name="' . Util::sanitizeHTML($displayName) . '" user="******" server="' . Util::sanitizeHTML($server) . '">' . Util::sanitizeHTML($parameter) . '</federated-cloud-id>'; }
/** * @param IEvent $event * @param string $parameter The parameter to be formatted * @param bool $allowHtml Should HTML be used to format the parameter? * @param bool $verbose Should paths, names, etc be shortened or full length * @return string The formatted parameter */ public function format(IEvent $event, $parameter, $allowHtml, $verbose = false) { $displayName = $parameter; if (!$verbose) { try { list($user, ) = Helper::splitUserRemote($parameter); $displayName = $user . '@…'; } catch (HintException $e) { } } try { $displayName = $this->getDisplayNameFromContact($parameter); } catch (\OutOfBoundsException $e) { } if ($allowHtml) { $title = ' title="' . Util::sanitizeHTML($parameter) . '"'; return '<strong class="has-tooltip"' . $title . '>' . Util::sanitizeHTML($displayName) . '</strong>'; } else { return $displayName; } }
/** * send server-to-server share to remote server * * @param string $token * @param string $shareWith * @param string $name * @param int $remote_id * @param string $owner * @return bool */ private static function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner) { list($user, $remote) = Helper::splitUserRemote($shareWith); if ($user && $remote) { $url = $remote . self::BASE_PATH_TO_SHARE_API . '?format=' . self::RESPONSE_FORMAT; $local = \OC::$server->getURLGenerator()->getAbsoluteURL('/'); $fields = array('shareWith' => $user, 'token' => $token, 'name' => $name, 'remoteId' => $remote_id, 'owner' => $owner, 'remote' => $local); $url = self::removeProtocolFromUrl($url); $result = self::tryHttpPost($url, $fields); $status = json_decode($result['result'], true); if ($result['success'] && $status['ocs']['meta']['statuscode'] === 100) { \OC_Hook::emit('OCP\\Share', 'federated_share_added', ['server' => $remote]); return true; } } return false; }
/** * Prepares a federated cloud id parameter for usage * * Search in contacts and do not output the remote in html * * @param string $federatedCloudId * @param bool $stripRemote Shall we remove the remote * @param bool $highlightParams * @return string */ protected function prepareFederatedCloudIDParam($federatedCloudId, $stripRemote, $highlightParams) { $displayName = $federatedCloudId; if ($stripRemote) { try { list($user, ) = Helper::splitUserRemote($federatedCloudId); $displayName = $user . '@…'; } catch (\OC\HintException $e) { } } try { $displayName = $this->getDisplayNameFromContact($federatedCloudId); } catch (\OutOfBoundsException $e) { } if ($highlightParams) { $title = ' title="' . Util::sanitizeHTML($federatedCloudId) . '"'; return '<strong class="has-tooltip"' . $title . '>' . Util::sanitizeHTML($displayName) . '</strong>'; } else { return $displayName; } }
/** * @dataProvider expireDateProvider */ public function testCalculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate, $expected) { $result = \OC\Share\Helper::calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate); $this->assertSame($expected, $result); }
exit; } $token = $_POST['token']; $remote = $_POST['remote']; $owner = $_POST['owner']; $ownerDisplayName = $_POST['ownerDisplayName']; $name = $_POST['name']; $password = $_POST['password']; // Check for invalid name if (!\OCP\Util::isValidFileName($name)) { \OCP\JSON::error(array('data' => array('message' => $l->t('The mountpoint name contains invalid characters.')))); exit; } $currentUser = \OC::$server->getUserSession()->getUser()->getUID(); $currentServer = \OC::$server->getURLGenerator()->getAbsoluteURL('/'); if (\OC\Share\Helper::isSameUserOnSameServer($owner, $remote, $currentUser, $currentServer)) { \OCP\JSON::error(array('data' => array('message' => $l->t('Not allowed to create a federated share with the same user server')))); exit; } $externalManager = new \OCA\Files_Sharing\External\Manager(\OC::$server->getDatabaseConnection(), \OC\Files\Filesystem::getMountManager(), \OC\Files\Filesystem::getLoader(), \OC::$server->getHTTPHelper(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession()->getUser()->getUID()); // check for ssl cert if (substr($remote, 0, 5) === 'https') { try { \OC::$server->getHTTPClientService()->newClient()->get($remote)->getBody(); } catch (\Exception $e) { \OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate')))); exit; } } $mount = $externalManager->addShare($remote, $token, $password, $name, $ownerDisplayName, true); /**
/** * @dataProvider dataTestSplitUserRemoteError * * @param string $id * @expectedException \OC\HintException */ public function testSplitUserRemoteError($id) { \OC\Share\Helper::splitUserRemote($id); }
/** * @dataProvider dataTestCompareServerAddresses * * @param string $server1 * @param string $server2 * @param bool $expected */ public function testIsSameUserOnSameServer($user1, $server1, $user2, $server2, $expected) { $this->assertSame($expected, \OC\Share\Helper::isSameUserOnSameServer($user1, $server1, $user2, $server2)); }
/** * Delete all shares with type SHARE_TYPE_LINK */ public static function removeAllLinkShares() { // Delete any link shares $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ?'); $result = $query->execute(array(self::SHARE_TYPE_LINK)); while ($item = $result->fetchRow()) { Helper::delete($item['id']); } }
/** * @dataProvider fixRemoteURLInShareWithData */ public function testFixRemoteURLInShareWith($remote, $expected) { $this->assertSame($expected, \OC\Share\Helper::fixRemoteURLInShareWith($remote)); }