Merge pull request #15470 from rullzer/files_sharing_getUrlContent

Move away from private static function OC_Util::getUrlContent
This commit is contained in:
Vincent Petry 2015-07-03 17:47:46 +02:00
commit cc373ab89a
2 changed files with 58 additions and 52 deletions

View File

@ -56,71 +56,76 @@ $externalManager = new \OCA\Files_Sharing\External\Manager(
);
// check for ssl cert
if (substr($remote, 0, 5) === 'https' and !OC_Util::getUrlContent($remote)) {
\OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate'))));
exit;
} else {
$mount = $externalManager->addShare($remote, $token, $password, $name, $owner, true);
/**
* @var \OCA\Files_Sharing\External\Storage $storage
*/
$storage = $mount->getStorage();
if (substr($remote, 0, 5) === 'https') {
try {
// check if storage exists
$storage->checkStorageAvailability();
\OC::$server->getHTTPClientService()->newClient()->get($remote)->getBody();
} catch (\Exception $e) {
\OCP\JSON::error(array('data' => array('message' => $l->t('Invalid or untrusted SSL certificate'))));
exit;
}
}
$mount = $externalManager->addShare($remote, $token, $password, $name, $owner, true);
/**
* @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')
)
)
);
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) {
// 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();
\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
);
$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'))));
}
} 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'))));
}
} 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'))));
}

View File

@ -1245,6 +1245,7 @@ class OC_Util {
* @return string of the response or false on error
* This function get the content of a page via curl, if curl is enabled.
* If not, file_get_contents is used.
* @deprecated Use \OCP\Http\Client\IClientService
*/
public static function getUrlContent($url) {
try {