diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-07-03 17:47:46 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-07-03 17:47:46 +0200 |
commit | cc373ab89acd3d63e58b7323f0b128e988a6bba2 (patch) | |
tree | 91d5367475ee6c75c93ba14dd06b383aa32bd207 /apps/files_sharing/ajax | |
parent | dbb3dc1be72888c27c052070dde7c24985030be8 (diff) | |
parent | 9866066d3ef3b36da7e7d1d354d39ae3820873a4 (diff) | |
download | nextcloud-server-cc373ab89acd3d63e58b7323f0b128e988a6bba2.tar.gz nextcloud-server-cc373ab89acd3d63e58b7323f0b128e988a6bba2.zip |
Merge pull request #15470 from rullzer/files_sharing_getUrlContent
Move away from private static function OC_Util::getUrlContent
Diffstat (limited to 'apps/files_sharing/ajax')
-rw-r--r-- | apps/files_sharing/ajax/external.php | 107 |
1 files changed, 56 insertions, 51 deletions
diff --git a/apps/files_sharing/ajax/external.php b/apps/files_sharing/ajax/external.php index 7bef0c3197a..d26a64d3aec 100644 --- a/apps/files_sharing/ajax/external.php +++ b/apps/files_sharing/ajax/external.php @@ -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); +if (substr($remote, 0, 5) === 'https') { + try { + \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(); +/** + * @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 { - // check if storage exists - $storage->checkStorageAvailability(); + $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')))); } + |