aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2016-07-12 14:03:29 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2016-07-14 16:39:48 +0200
commit33a685bc41628e1236015bd79cc8f82b9cb6cabf (patch)
treebe3b1a6cd391db7f48e1111b4b96960e9ce53c3a /apps/files_sharing
parent1394b0afb9b1d3d7c8952faea85873e731ccb801 (diff)
downloadnextcloud-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')
-rw-r--r--apps/files_sharing/ajax/external.php119
-rw-r--r--apps/files_sharing/js/external.js6
-rw-r--r--apps/files_sharing/js/public.js86
3 files changed, 94 insertions, 117 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.'))));
diff --git a/apps/files_sharing/js/external.js b/apps/files_sharing/js/external.js
index 0ca8213168e..be384818c3c 100644
--- a/apps/files_sharing/js/external.js
+++ b/apps/files_sharing/js/external.js
@@ -107,11 +107,7 @@
ownerDisplayName: share.ownerDisplayName || share.owner,
name: share.name,
password: password}, function(result) {
- if (result.status === 'error') {
- OC.Notification.showTemporary(result.data.message);
- } else {
- fileList.reload();
- }
+ OC.Notification.showTemporary(result.data.message);
});
}
};
diff --git a/apps/files_sharing/js/public.js b/apps/files_sharing/js/public.js
index d4f3bd36a63..4293c7b310b 100644
--- a/apps/files_sharing/js/public.js
+++ b/apps/files_sharing/js/public.js
@@ -244,8 +244,10 @@ OCA.Sharing.PublicApp = {
var remote = $(this).find('input[type="text"]').val();
var token = $('#sharingToken').val();
var owner = $('#save').data('owner');
+ var ownerDisplayName = $('#save').data('owner-display-name');
var name = $('#save').data('name');
- OCA.Sharing.PublicApp._saveToOwnCloud(remote, token);
+ var isProtected = $('#save').data('protected') ? 1 : 0;
+ OCA.Sharing.PublicApp._saveToOwnCloud(remote, token, owner, ownerDisplayName, name, isProtected);
});
$('#remote_address').on("keyup paste", function() {
@@ -293,7 +295,72 @@ OCA.Sharing.PublicApp = {
},
- _saveToOwnCloud: function (remote, token) {
+ /**
+ * fall back to old behaviour where we redirect the user to his server to mount
+ * the public link instead of creating a dedicated federated share
+ *
+ * @param remote
+ * @param token
+ * @param owner
+ * @param ownerDisplayName
+ * @param name
+ * @param isProtected
+ * @private
+ */
+ _legacySaveToOwnCloud: function (remote, token, owner, ownerDisplayName, name, isProtected) {
+
+ var location = window.location.protocol + '//' + window.location.host + OC.webroot;
+
+ if(remote.substr(-1) !== '/') {
+ remote += '/'
+ }
+
+ var url = remote + 'index.php/apps/files#' + 'remote=' + encodeURIComponent(location) // our location is the remote for the other server
+ + "&token=" + encodeURIComponent(token) + "&owner=" + encodeURIComponent(owner) +"&ownerDisplayName=" + encodeURIComponent(ownerDisplayName) + "&name=" + encodeURIComponent(name) + "&protected=" + isProtected;
+
+
+ if (remote.indexOf('://') > 0) {
+ OC.redirect(url);
+ } else {
+ // if no protocol is specified, we automatically detect it by testing https and http
+ // this check needs to happen on the server due to the Content Security Policy directive
+ $.get(OC.generateUrl('apps/files_sharing/testremote'), {remote: remote}).then(function (protocol) {
+ if (protocol !== 'http' && protocol !== 'https') {
+ OC.dialogs.alert(t('files_sharing', 'No compatible server found at {remote}', {remote: remote}),
+ t('files_sharing', 'Invalid server URL'));
+ } else {
+ OC.redirect(protocol + '://' + url);
+ }
+ });
+ }
+ },
+
+ _saveToOwnCloud: function (remote, token, owner, ownerDisplayName, name, isProtected) {
+
+ var toggleLoading = function() {
+ var iconClass = $('#save-button-confirm').attr('class');
+ var loading = iconClass.indexOf('icon-loading-small') !== -1;
+ if(loading) {
+ $('#save-button-confirm')
+ .removeClass("icon-loading-small")
+ .addClass("icon-confirm");
+
+ }
+ else {
+ $('#save-button-confirm')
+ .removeClass("icon-confirm")
+ .addClass("icon-loading-small");
+
+ }
+ };
+
+ toggleLoading();
+
+ if (remote.indexOf('@') == -1) {
+ this._legacySaveToOwnCloud(remote, token, owner, ownerDisplayName, name, isProtected);
+ toggleLoading();
+ return;
+ }
$.post(
OC.generateUrl('/apps/federatedfilesharing/saveToOwnCloud'),
@@ -308,17 +375,7 @@ OCA.Sharing.PublicApp = {
if (url.indexOf('://') > 0) {
OC.redirect(url);
} else {
- // if no protocol is specified, we automatically detect it by testing https and http
- // this check needs to happen on the server due to the Content Security Policy directive
- $.get(OC.generateUrl('apps/files_sharing/testremote'), {remote: remote}).then(function (protocol) {
- if (protocol !== 'http' && protocol !== 'https') {
- toggleLoading();
- OC.dialogs.alert(t('files_sharing', 'No Nextcloud installation (7 or higher) found at {remote}', {remote: remote}),
- t('files_sharing', 'Invalid ownCloud url'));
- } else {
- OC.redirect(protocol + '://' + url);
- }
- });
+ OC.redirect('http://' + url);
}
}
).fail(
@@ -326,7 +383,8 @@ OCA.Sharing.PublicApp = {
console.log("ERROR!");
console.log(jqXHR);
OC.dialogs.alert(JSON.parse(jqXHR.responseText).message,
- t('files_sharing', 'Failed to add the public link to your ownCloud'));
+ t('files_sharing', 'Failed to add the public link to your Nextcloud'));
+ toggleLoading();
}
);
}