2014-05-09 19:06:08 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-02-26 13:37:37 +03:00
|
|
|
* 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.
|
2014-05-09 19:06:08 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2014-05-09 19:06:08 +04:00
|
|
|
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-08-31 12:05:59 +04:00
|
|
|
$l = \OC::$server->getL10N('files_sharing');
|
2014-06-12 21:49:52 +04:00
|
|
|
|
|
|
|
// check if server admin allows to mount public links from other servers
|
2014-06-30 14:34:49 +04:00
|
|
|
if (OCA\Files_Sharing\Helper::isIncomingServer2serverShareEnabled() === 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'];
|
|
|
|
|
2014-09-23 21:30:32 +04:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2014-05-09 19:06:08 +04:00
|
|
|
$externalManager = new \OCA\Files_Sharing\External\Manager(
|
2014-12-04 21:51:04 +03:00
|
|
|
\OC::$server->getDatabaseConnection(),
|
|
|
|
\OC\Files\Filesystem::getMountManager(),
|
|
|
|
\OC\Files\Filesystem::getLoader(),
|
2015-01-20 02:35:47 +03:00
|
|
|
\OC::$server->getHTTPHelper(),
|
|
|
|
\OC::$server->getUserSession()->getUser()->getUID()
|
2014-05-09 19:06:08 +04:00
|
|
|
);
|
|
|
|
|
2014-08-13 18:46:04 +04:00
|
|
|
// check for ssl cert
|
|
|
|
if (substr($remote, 0, 5) === 'https' and !OC_Util::getUrlContent($remote)) {
|
2015-01-20 21:45:32 +03:00
|
|
|
\OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate'))));
|
2014-08-13 18:46:04 +04:00
|
|
|
exit;
|
2014-06-12 21:49:52 +04:00
|
|
|
} else {
|
2014-12-04 21:51:04 +03:00
|
|
|
$mount = $externalManager->addShare($remote, $token, $password, $name, $owner, true);
|
2015-01-20 21:45:32 +03:00
|
|
|
|
2014-08-13 18:46:04 +04:00
|
|
|
/**
|
|
|
|
* @var \OCA\Files_Sharing\External\Storage $storage
|
|
|
|
*/
|
|
|
|
$storage = $mount->getStorage();
|
2015-01-20 21:45:32 +03:00
|
|
|
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')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
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'))));
|
2015-01-26 18:07:28 +03:00
|
|
|
exit();
|
2015-01-20 21:45:32 +03:00
|
|
|
}
|
2014-08-13 18:46:04 +04:00
|
|
|
$result = $storage->file_exists('');
|
|
|
|
if ($result) {
|
2015-01-20 21:45:32 +03:00
|
|
|
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'))));
|
|
|
|
}
|
2014-08-13 18:46:04 +04:00
|
|
|
} else {
|
|
|
|
$externalManager->removeShare($mount->getMountPoint());
|
2015-01-20 21:45:32 +03:00
|
|
|
\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'))));
|
2014-08-13 18:46:04 +04:00
|
|
|
}
|
2014-05-19 18:39:57 +04:00
|
|
|
}
|