summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib
diff options
context:
space:
mode:
authorJesus Macias Portela <jesus.macias.portela@gmail.com>2015-12-03 12:35:49 +0100
committerJesus Macias Portela <jesus.macias.portela@gmail.com>2015-12-03 12:35:49 +0100
commitdcfbbe4737e9939b6c038f8e48b49957c66a52e8 (patch)
tree8163f2d7537708d7d5486a093bb3dab9cc63f9d2 /apps/files_external/lib
parenta79ae4ae086c08c75a6d974966458251e2167347 (diff)
parente62b6c1617886b2cdd7553ea9b119c431e4eb363 (diff)
downloadnextcloud-server-dcfbbe4737e9939b6c038f8e48b49957c66a52e8.tar.gz
nextcloud-server-dcfbbe4737e9939b6c038f8e48b49957c66a52e8.zip
Merge branch 'master' into issue_20427
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r--apps/files_external/lib/config.php56
-rw-r--r--apps/files_external/lib/config/configadapter.php1
-rw-r--r--apps/files_external/lib/etagpropagator.php141
-rw-r--r--apps/files_external/lib/sftp.php40
-rw-r--r--apps/files_external/lib/storageconfig.php19
5 files changed, 56 insertions, 201 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 6c900f0f224..7a869847a63 100644
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -33,10 +33,10 @@
use phpseclib\Crypt\AES;
use \OCA\Files_External\Appinfo\Application;
-use \OCA\Files_External\Lib\BackendConfig;
-use \OCA\Files_External\Service\BackendService;
use \OCA\Files_External\Lib\Backend\LegacyBackend;
use \OCA\Files_External\Lib\StorageConfig;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCP\Files\StorageNotAvailableException;
/**
* Class to configure mount.json globally and for users
@@ -49,11 +49,6 @@ class OC_Mount_Config {
const MOUNT_TYPE_USER = 'user';
const MOUNT_TYPE_PERSONAL = 'personal';
- // getBackendStatus return types
- const STATUS_SUCCESS = 0;
- const STATUS_ERROR = 1;
- const STATUS_INDETERMINATE = 2;
-
// whether to skip backend test (for unit tests, as this static class is not mockable)
public static $skipTest = false;
@@ -75,36 +70,6 @@ class OC_Mount_Config {
return true;
}
- /*
- * Hook that mounts the given user's visible mount points
- *
- * @param array $data
- */
- public static function initMountPointsHook($data) {
- if ($data['user']) {
- $user = \OC::$server->getUserManager()->get($data['user']);
- if (!$user) {
- \OC::$server->getLogger()->warning(
- 'Cannot init external mount points for non-existant user "' . $data['user'] . '".',
- ['app' => 'files_external']
- );
- return;
- }
- $userView = new \OC\Files\View('/' . $user->getUID() . '/files');
- $changePropagator = new \OC\Files\Cache\ChangePropagator($userView);
- $etagPropagator = new \OCA\Files_External\EtagPropagator($user, $changePropagator, \OC::$server->getConfig());
- $etagPropagator->propagateDirtyMountPoints();
- \OCP\Util::connectHook(
- \OC\Files\Filesystem::CLASSNAME,
- \OC\Files\Filesystem::signal_create_mount,
- $etagPropagator, 'updateHook');
- \OCP\Util::connectHook(
- \OC\Files\Filesystem::CLASSNAME,
- \OC\Files\Filesystem::signal_delete_mount,
- $etagPropagator, 'updateHook');
- }
- }
-
/**
* Returns the mount points for the given user.
* The mount point is relative to the data directory.
@@ -244,24 +209,27 @@ class OC_Mount_Config {
*
* @param string $class backend class name
* @param array $options backend configuration options
+ * @param boolean $isPersonal
* @return int see self::STATUS_*
+ * @throws Exception
*/
public static function getBackendStatus($class, $options, $isPersonal) {
if (self::$skipTest) {
- return self::STATUS_SUCCESS;
+ return StorageNotAvailableException::STATUS_SUCCESS;
}
foreach ($options as &$option) {
$option = self::setUserVars(OCP\User::getUser(), $option);
}
if (class_exists($class)) {
try {
+ /** @var \OC\Files\Storage\Common $storage */
$storage = new $class($options);
try {
$result = $storage->test($isPersonal);
$storage->setAvailability($result);
if ($result) {
- return self::STATUS_SUCCESS;
+ return StorageNotAvailableException::STATUS_SUCCESS;
}
} catch (\Exception $e) {
$storage->setAvailability(false);
@@ -272,7 +240,7 @@ class OC_Mount_Config {
throw $exception;
}
}
- return self::STATUS_ERROR;
+ return StorageNotAvailableException::STATUS_ERROR;
}
/**
@@ -322,7 +290,7 @@ class OC_Mount_Config {
* Get backend dependency message
* TODO: move into AppFramework along with templates
*
- * @param BackendConfig[] $backends
+ * @param Backend[] $backends
* @return string
*/
public static function dependencyMessage($backends) {
@@ -361,11 +329,11 @@ class OC_Mount_Config {
private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) {
switch (strtolower($module)) {
case 'curl':
- return $l->t('<b>Note:</b> The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
+ return (string)$l->t('<b>Note:</b> The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
case 'ftp':
- return $l->t('<b>Note:</b> The FTP support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
+ return (string)$l->t('<b>Note:</b> The FTP support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
default:
- return $l->t('<b>Note:</b> "%s" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it.', array($module, $backend));
+ return (string)$l->t('<b>Note:</b> "%s" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it.', array($module, $backend));
}
}
diff --git a/apps/files_external/lib/config/configadapter.php b/apps/files_external/lib/config/configadapter.php
index 3a04512e8a8..f9640d53377 100644
--- a/apps/files_external/lib/config/configadapter.php
+++ b/apps/files_external/lib/config/configadapter.php
@@ -32,7 +32,6 @@ use OCP\IUser;
use OCA\Files_external\Service\UserStoragesService;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Lib\StorageConfig;
-use OCP\Files\StorageNotAvailableException;
use OCA\Files_External\Lib\FailedStorage;
/**
diff --git a/apps/files_external/lib/etagpropagator.php b/apps/files_external/lib/etagpropagator.php
deleted file mode 100644
index 772a11ea36f..00000000000
--- a/apps/files_external/lib/etagpropagator.php
+++ /dev/null
@@ -1,141 +0,0 @@
-<?php
-/**
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OCA\Files_External;
-
-use OC\Files\Filesystem;
-
-/**
- * Updates the etag of parent folders whenever a new external storage mount
- * point has been created or deleted. Updates need to be triggered using
- * the updateHook() method.
- *
- * There are two modes of operation:
- * - for personal mount points, the etag is propagated directly
- * - for system mount points, a dirty flag is saved in the configuration and
- * the etag will be updated the next time propagateDirtyMountPoints() is called
- */
-class EtagPropagator {
- /**
- * @var \OCP\IUser
- */
- protected $user;
-
- /**
- * @var \OC\Files\Cache\ChangePropagator
- */
- protected $changePropagator;
-
- /**
- * @var \OCP\IConfig
- */
- protected $config;
-
- /**
- * @param \OCP\IUser $user current user, must match the propagator's
- * user
- * @param \OC\Files\Cache\ChangePropagator $changePropagator change propagator
- * initialized with a view for $user
- * @param \OCP\IConfig $config
- */
- public function __construct($user, $changePropagator, $config) {
- $this->user = $user;
- $this->changePropagator = $changePropagator;
- $this->config = $config;
- }
-
- /**
- * Propagate the etag changes for all mountpoints marked as dirty and mark the mountpoints as clean
- *
- * @param int $time
- */
- public function propagateDirtyMountPoints($time = null) {
- if ($time === null) {
- $time = time();
- }
- $mountPoints = $this->getDirtyMountPoints();
- foreach ($mountPoints as $mountPoint) {
- $this->changePropagator->addChange($mountPoint);
- $this->config->setUserValue($this->user->getUID(), 'files_external', $mountPoint, $time);
- }
- if (count($mountPoints)) {
- $this->changePropagator->propagateChanges($time);
- }
- }
-
- /**
- * Get all mountpoints we need to update the etag for
- *
- * @return string[]
- */
- protected function getDirtyMountPoints() {
- $dirty = array();
- $mountPoints = $this->config->getAppKeys('files_external');
- foreach ($mountPoints as $mountPoint) {
- if (substr($mountPoint, 0, 1) === '/') {
- $updateTime = $this->config->getAppValue('files_external', $mountPoint);
- $userTime = $this->config->getUserValue($this->user->getUID(), 'files_external', $mountPoint);
- if ($updateTime > $userTime) {
- $dirty[] = $mountPoint;
- }
- }
- }
- return $dirty;
- }
-
- /**
- * @param string $mountPoint
- * @param int $time
- */
- protected function markDirty($mountPoint, $time = null) {
- if ($time === null) {
- $time = time();
- }
- $this->config->setAppValue('files_external', $mountPoint, $time);
- }
-
- /**
- * Update etags for mount points for known user
- * For global or group mount points, updating the etag for every user is not feasible
- * instead we mark the mount point as dirty and update the etag when the filesystem is loaded for the user
- * For personal mount points, the change is propagated directly
- *
- * @param array $params hook parameters
- * @param int $time update time to use when marking a mount point as dirty
- */
- public function updateHook($params, $time = null) {
- if ($time === null) {
- $time = time();
- }
- $users = $params[Filesystem::signal_param_users];
- $type = $params[Filesystem::signal_param_mount_type];
- $mountPoint = $params[Filesystem::signal_param_path];
- $mountPoint = Filesystem::normalizePath($mountPoint);
- if ($type === \OC_Mount_Config::MOUNT_TYPE_GROUP or $users === 'all') {
- $this->markDirty($mountPoint, $time);
- } else {
- $this->changePropagator->addChange($mountPoint);
- $this->changePropagator->propagateChanges($time);
- }
- }
-}
diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php
index 5dcc7686ca3..bcf3143736e 100644
--- a/apps/files_external/lib/sftp.php
+++ b/apps/files_external/lib/sftp.php
@@ -52,27 +52,37 @@ class SFTP extends \OC\Files\Storage\Common {
protected $client;
/**
+ * @param string $host protocol://server:port
+ * @return array [$server, $port]
+ */
+ private function splitHost($host) {
+ $input = $host;
+ if (strpos($host, '://') === false) {
+ // add a protocol to fix parse_url behavior with ipv6
+ $host = 'http://' . $host;
+ }
+
+ $parsed = parse_url($host);
+ if(is_array($parsed) && isset($parsed['port'])) {
+ return [$parsed['host'], $parsed['port']];
+ } else if (is_array($parsed)) {
+ return [$parsed['host'], 22];
+ } else {
+ return [$input, 22];
+ }
+ }
+
+ /**
* {@inheritdoc}
*/
public function __construct($params) {
// Register sftp://
Stream::register();
- $this->host = $params['host'];
+ $parsedHost = $this->splitHost($params['host']);
- //deals with sftp://server example
- $proto = strpos($this->host, '://');
- if ($proto != false) {
- $this->host = substr($this->host, $proto+3);
- }
-
- //deals with server:port
- $hasPort = strpos($this->host,':');
- if($hasPort != false) {
- $pieces = explode(":", $this->host);
- $this->host = $pieces[0];
- $this->port = $pieces[1];
- }
+ $this->host = $parsedHost[0];
+ $this->port = $parsedHost[1];
$this->user = $params['user'];
@@ -185,7 +195,7 @@ class SFTP extends \OC\Files\Storage\Common {
}
/**
- * @return bool|string
+ * @return string|false
*/
private function hostKeysPath() {
try {
diff --git a/apps/files_external/lib/storageconfig.php b/apps/files_external/lib/storageconfig.php
index 86a7e6ffa12..97e0386be73 100644
--- a/apps/files_external/lib/storageconfig.php
+++ b/apps/files_external/lib/storageconfig.php
@@ -302,6 +302,25 @@ class StorageConfig implements \JsonSerializable {
}
/**
+ * @param string $key
+ * @return mixed
+ */
+ public function getMountOption($key) {
+ if (isset($this->mountOptions[$key])) {
+ return $this->mountOptions[$key];
+ }
+ return null;
+ }
+
+ /**
+ * @param string $key
+ * @param mixed $value
+ */
+ public function setMountOption($key, $value) {
+ $this->mountOptions[$key] = $value;
+ }
+
+ /**
* Gets the storage status, whether the config worked last time
*
* @return int $status status