Remove old code to be compatible with Nextcloud 9 and before
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
af89db3407
commit
4cbcf6f920
1 changed files with 2 additions and 114 deletions
|
@ -227,119 +227,7 @@ class MountPublicLinkController extends Controller {
|
|||
|
||||
// if we doesn't get the expected response we assume that we try to add
|
||||
// a federated share from a Nextcloud <= 9 server
|
||||
return $this->legacyMountPublicLink($token, $remote, $password, $name, $owner, $ownerDisplayName);
|
||||
$message = $this->l->t("Couldn't establish a federated share, it looks like the server to federate with is too old (Nextcloud <= 9).");
|
||||
return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow Nextcloud to mount a public link directly
|
||||
*
|
||||
* This code was copied from the apps/files_sharing/ajax/external.php with
|
||||
* minimal changes, just to guarantee backward compatibility
|
||||
*
|
||||
* ToDo: Remove this method once Nextcloud 9 reaches end of life
|
||||
*
|
||||
* @param string $token
|
||||
* @param string $remote
|
||||
* @param string $password
|
||||
* @param string $name
|
||||
* @param string $owner
|
||||
* @param string $ownerDisplayName
|
||||
* @return JSONResponse
|
||||
*/
|
||||
private function legacyMountPublicLink($token, $remote, $password, $name, $owner, $ownerDisplayName) {
|
||||
|
||||
// Check for invalid name
|
||||
if (!Util::isValidFileName($name)) {
|
||||
return new JSONResponse(['message' => $this->l->t('The mountpoint name contains invalid characters.')], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
$currentUser = $this->userSession->getUser()->getUID();
|
||||
$currentServer = $this->addressHandler->generateRemoteURL();
|
||||
if (Helper::isSameUserOnSameServer($owner, $remote, $currentUser, $currentServer)) {
|
||||
return new JSONResponse(['message' => $this->l->t('Not allowed to create a federated share with the owner.')], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
$externalManager = new Manager(
|
||||
\OC::$server->getDatabaseConnection(),
|
||||
Filesystem::getMountManager(),
|
||||
Filesystem::getLoader(),
|
||||
\OC::$server->getHTTPClientService(),
|
||||
\OC::$server->getNotificationManager(),
|
||||
\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
|
||||
\OC::$server->getUserSession()->getUser()->getUID()
|
||||
);
|
||||
|
||||
// check for ssl cert
|
||||
|
||||
if (strpos($remote, 'https') === 0) {
|
||||
try {
|
||||
$client = $this->clientService->newClient();
|
||||
$client->get($remote, [
|
||||
'timeout' => 10,
|
||||
'connect_timeout' => 10,
|
||||
])->getBody();
|
||||
} catch (\Exception $e) {
|
||||
return new JSONResponse(['message' => $this->l->t('Invalid or untrusted SSL certificate')], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
$mount = $externalManager->addShare($remote, $token, $password, $name, $ownerDisplayName, true);
|
||||
/**
|
||||
* @var \OCA\Files_Sharing\External\Storage $storage
|
||||
*/
|
||||
$storage = $mount->getStorage();
|
||||
try {
|
||||
// check if storage exists
|
||||
$storage->checkStorageAvailability();
|
||||
} catch (StorageInvalidException $e) {
|
||||
// note: checkStorageAvailability will already remove the invalid share
|
||||
\OC::$server->getLogger()->logException($e, [
|
||||
'message' => 'Invalid remote storage.',
|
||||
'level' => \OCP\Util::DEBUG,
|
||||
'app' => 'federatedfilesharing'
|
||||
]);
|
||||
return new JSONResponse(['message' => $this->l->t('Could not authenticate to remote share, password might be wrong')], Http::STATUS_BAD_REQUEST);
|
||||
} catch (\Exception $e) {
|
||||
\OC::$server->getLogger()->logException($e, [
|
||||
'message' => 'Invalid remote storage.',
|
||||
'level' => \OCP\Util::DEBUG,
|
||||
'app' => 'federatedfilesharing'
|
||||
]);
|
||||
$externalManager->removeShare($mount->getMountPoint());
|
||||
return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
$result = $storage->file_exists('');
|
||||
if ($result) {
|
||||
try {
|
||||
$storage->getScanner()->scanAll();
|
||||
return new JSONResponse(
|
||||
[
|
||||
'message' => $this->l->t('Federated share added'),
|
||||
'legacyMount' => '1'
|
||||
]
|
||||
);
|
||||
} catch (StorageInvalidException $e) {
|
||||
\OC::$server->getLogger()->logException($e, [
|
||||
'message' => 'Invalid remote storage.',
|
||||
'level' => \OCP\Util::DEBUG,
|
||||
'app' => 'federatedfilesharing'
|
||||
]);
|
||||
return new JSONResponse(['message' => $this->l->t('Storage not valid')], Http::STATUS_BAD_REQUEST);
|
||||
} catch (\Exception $e) {
|
||||
\OC::$server->getLogger()->logException($e, [
|
||||
'message' => 'Invalid remote storage.',
|
||||
'level' => \OCP\Util::DEBUG,
|
||||
'app' => 'federatedfilesharing'
|
||||
]);
|
||||
return new JSONResponse(['message' => $this->l->t('Couldn\'t add remote share')], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
} else {
|
||||
$externalManager->removeShare($mount->getMountPoint());
|
||||
Util::writeLog(
|
||||
'federatedfilesharing',
|
||||
'Couldn\'t add remote share',
|
||||
Util::DEBUG
|
||||
);
|
||||
return new JSONResponse(['message' => $this->l->t('Couldn\'t add remote share')], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue