2014-05-09 19:06:08 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
OCP\JSON::callCheck();
|
|
|
|
OCP\JSON::checkLoggedIn();
|
2014-06-16 14:42:28 +04:00
|
|
|
OCP\JSON::checkAppEnabled('files_sharing');
|
2014-05-09 19:06:08 +04:00
|
|
|
|
2014-06-12 21:49:52 +04:00
|
|
|
$l = OC_L10N::get('files_sharing');
|
|
|
|
|
|
|
|
// check if server admin allows to mount public links from other servers
|
2014-06-13 14:43:37 +04:00
|
|
|
// check if files_external is enabled
|
|
|
|
// FIXME file_external check no longer needed if we use the webdav implementation from core
|
|
|
|
if (OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === false ||
|
|
|
|
\OC_App::isEnabled('files_external') === false) {
|
2014-06-12 21:49:52 +04:00
|
|
|
\OCP\JSON::error(array('data' => array('message' => $l->t('Server to server sharing is not enabled on this server'))));
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2014-05-09 19:06:08 +04:00
|
|
|
$token = $_POST['token'];
|
|
|
|
$remote = $_POST['remote'];
|
|
|
|
$owner = $_POST['owner'];
|
|
|
|
$name = $_POST['name'];
|
|
|
|
$password = $_POST['password'];
|
|
|
|
|
|
|
|
$externalManager = new \OCA\Files_Sharing\External\Manager(
|
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
\OC\Files\Filesystem::getMountManager(),
|
|
|
|
\OC\Files\Filesystem::getLoader(),
|
|
|
|
\OC::$server->getUserSession()
|
|
|
|
);
|
|
|
|
|
2014-06-04 19:19:49 +04:00
|
|
|
$name = OCP\Files::buildNotExistingFileName('/', $name);
|
|
|
|
|
2014-05-09 19:06:08 +04:00
|
|
|
$mount = $externalManager->addShare($remote, $token, $password, $name, $owner);
|
2014-05-19 18:39:57 +04:00
|
|
|
/**
|
|
|
|
* @var \OCA\Files_Sharing\External\Storage $storage
|
|
|
|
*/
|
|
|
|
$storage = $mount->getStorage();
|
|
|
|
$result = $storage->file_exists('');
|
|
|
|
if($result){
|
|
|
|
$storage->getScanner()->scanAll();
|
2014-06-12 21:49:52 +04:00
|
|
|
\OCP\JSON::success();
|
|
|
|
} else {
|
|
|
|
$externalManager->removeShare($mount->getMountPoint());
|
|
|
|
\OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't add remote share"))));
|
2014-05-19 18:39:57 +04:00
|
|
|
}
|