diff options
author | Bjoern Schiessle <bjoern@schiessle.org> | 2016-07-12 14:03:29 +0200 |
---|---|---|
committer | Bjoern Schiessle <bjoern@schiessle.org> | 2016-07-14 16:39:48 +0200 |
commit | 33a685bc41628e1236015bd79cc8f82b9cb6cabf (patch) | |
tree | be3b1a6cd391db7f48e1111b4b96960e9ce53c3a /apps/files_sharing/ajax | |
parent | 1394b0afb9b1d3d7c8952faea85873e731ccb801 (diff) | |
download | nextcloud-server-33a685bc41628e1236015bd79cc8f82b9cb6cabf.tar.gz nextcloud-server-33a685bc41628e1236015bd79cc8f82b9cb6cabf.zip |
continue to accept the URL of the remote server instead of the federated cloud id
Diffstat (limited to 'apps/files_sharing/ajax')
-rw-r--r-- | apps/files_sharing/ajax/external.php | 119 |
1 files changed, 21 insertions, 98 deletions
diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index 4a7a6096c91..d57d333c7ee 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -42,112 +42,35 @@ if ($federatedShareProvider->isIncomingServer2serverShareEnabled() === false) { $token = $_POST['token']; $remote = $_POST['remote']; -$owner = $_POST['owner']; -$ownerDisplayName = $_POST['ownerDisplayName']; -$name = $_POST['name']; -$password = $_POST['password']; +$password = isset($_POST['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(); -} +$urlGenerator = \OC::$server->getURLGenerator(); -$discoveryManager = new \OCA\FederatedFileSharing\DiscoveryManager( - \OC::$server->getMemCacheFactory(), - \OC::$server->getHTTPClientService() -); -$externalManager = new \OCA\Files_Sharing\External\Manager( - \OC::$server->getDatabaseConnection(), - \OC\Files\Filesystem::getMountManager(), - \OC\Files\Filesystem::getLoader(), - \OC::$server->getHTTPHelper(), - \OC::$server->getNotificationManager(), - $discoveryManager, - \OC::$server->getUserSession()->getUser()->getUID() -); +$shareWith = \OCP\User::getUser() . '@' . $urlGenerator->getAbsoluteURL('/'); -// check for ssl cert -if (substr($remote, 0, 5) === 'https') { - try { - \OC::$server->getHTTPClientService()->newClient()->get($remote, [ - 'timeout' => 10, - 'connect_timeout' => 10, - ])->getBody(); - } catch (\Exception $e) { - \OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate')))); - exit; - } -} +$httpClient = \OC::$server->getHTTPClientService()->newClient(); -$mount = $externalManager->addShare($remote, $token, $password, $name, $ownerDisplayName, true); +error_log("do th post"); -/** - * @var \OCA\Files_Sharing\External\Storage $storage - */ -$storage = $mount->getStorage(); try { - // check if storage exists - $storage->checkStorageAvailability(); -} catch (\OCP\Files\StorageInvalidException $e) { - // note: checkStorageAvailability will already remove the invalid share - \OCP\Util::writeLog( - 'files_sharing', - 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), - \OCP\Util::DEBUG - ); - \OCP\JSON::error( - array( - 'data' => array( - 'message' => $l->t('Could not authenticate to remote share, password might be wrong') - ) - ) + $response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/saveToOwnCloud', + [ + 'body' => + [ + 'token' => $token, + 'shareWith' => rtrim($shareWith, '/'), + 'password' => $password + ] + ] ); - exit(); } catch (\Exception $e) { - \OCP\Util::writeLog( - 'files_sharing', - 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), - \OCP\Util::DEBUG - ); - $externalManager->removeShare($mount->getMountPoint()); - \OCP\JSON::error(array('data' => array('message' => $l->t('Storage not valid')))); - exit(); -} -$result = $storage->file_exists(''); -if ($result) { - try { - $storage->getScanner()->scanAll(); - \OCP\JSON::success(); - } catch (\OCP\Files\StorageInvalidException $e) { - \OCP\Util::writeLog( - 'files_sharing', - 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), - \OCP\Util::DEBUG - ); - \OCP\JSON::error(array('data' => array('message' => $l->t('Storage not valid')))); - } catch (\Exception $e) { - \OCP\Util::writeLog( - 'files_sharing', - 'Invalid remote storage: ' . get_class($e) . ': ' . $e->getMessage(), - \OCP\Util::DEBUG - ); - \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t add remote share')))); + if (empty($password)) { + $message = $l->t("Couldn't establish a federated share."); + } else { + $message = $l->t("Couldn't establish a federated share, maybe the password was wrong."); } -} else { - $externalManager->removeShare($mount->getMountPoint()); - \OCP\Util::writeLog( - 'files_sharing', - 'Couldn\'t add remote share', - \OCP\Util::DEBUG - ); - \OCP\JSON::error(array('data' => array('message' => $l->t('Couldn\'t add remote share')))); + \OCP\JSON::error(array('data' => array('message' => $message))); + exit(); } +\OCP\JSON::success(array('data' => array('message' => $l->t('Federated Share request was successful, you will receive a invitation. Check your notifications.')))); |