summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Lib
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2016-05-13 11:42:01 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2016-05-24 08:41:21 +0200
commit6ea54e73e82fb02bb6bfa3a189a861f90c00d105 (patch)
tree5ba453b1469a326cd0b216e771debb2972ace172 /apps/files_external/lib/Lib
parent6d7a1b9bd42637bd3cd1b1307082f010ab8b11ba (diff)
downloadnextcloud-server-6ea54e73e82fb02bb6bfa3a189a861f90c00d105.tar.gz
nextcloud-server-6ea54e73e82fb02bb6bfa3a189a861f90c00d105.zip
Move Lib\Backend to PSR-4
Diffstat (limited to 'apps/files_external/lib/Lib')
-rw-r--r--apps/files_external/lib/Lib/Backend/AmazonS3.php61
-rw-r--r--apps/files_external/lib/Lib/Backend/Backend.php165
-rw-r--r--apps/files_external/lib/Lib/Backend/DAV.php55
-rw-r--r--apps/files_external/lib/Lib/Backend/Dropbox.php52
-rw-r--r--apps/files_external/lib/Lib/Backend/FTP.php55
-rw-r--r--apps/files_external/lib/Lib/Backend/Google.php52
-rw-r--r--apps/files_external/lib/Lib/Backend/LegacyBackend.php104
-rw-r--r--apps/files_external/lib/Lib/Backend/Local.php49
-rw-r--r--apps/files_external/lib/Lib/Backend/OwnCloud.php52
-rw-r--r--apps/files_external/lib/Lib/Backend/SFTP.php51
-rw-r--r--apps/files_external/lib/Lib/Backend/SFTP_Key.php50
-rw-r--r--apps/files_external/lib/Lib/Backend/SMB.php69
-rw-r--r--apps/files_external/lib/Lib/Backend/SMB_OC.php72
-rw-r--r--apps/files_external/lib/Lib/Backend/Swift.php62
14 files changed, 949 insertions, 0 deletions
diff --git a/apps/files_external/lib/Lib/Backend/AmazonS3.php b/apps/files_external/lib/Lib/Backend/AmazonS3.php
new file mode 100644
index 00000000000..449b6c0379d
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/AmazonS3.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
+
+use \OCA\Files_External\Lib\Auth\AmazonS3\AccessKey;
+
+class AmazonS3 extends Backend {
+
+ use LegacyDependencyCheckPolyfill;
+
+ public function __construct(IL10N $l, AccessKey $legacyAuth) {
+ $this
+ ->setIdentifier('amazons3')
+ ->addIdentifierAlias('\OC\Files\Storage\AmazonS3') // legacy compat
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\AmazonS3')
+ ->setText($l->t('Amazon S3'))
+ ->addParameters([
+ (new DefinitionParameter('bucket', $l->t('Bucket'))),
+ (new DefinitionParameter('hostname', $l->t('Hostname')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('port', $l->t('Port')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('region', $l->t('Region')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('use_ssl', $l->t('Enable SSL')))
+ ->setType(DefinitionParameter::VALUE_BOOLEAN),
+ (new DefinitionParameter('use_path_style', $l->t('Enable Path Style')))
+ ->setType(DefinitionParameter::VALUE_BOOLEAN),
+ ])
+ ->addAuthScheme(AccessKey::SCHEME_AMAZONS3_ACCESSKEY)
+ ->setLegacyAuthMechanism($legacyAuth)
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/Backend.php b/apps/files_external/lib/Lib/Backend/Backend.php
new file mode 100644
index 00000000000..8fb84b0e835
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/Backend.php
@@ -0,0 +1,165 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCA\Files_External\Lib\StorageConfig;
+use \OCA\Files_External\Lib\VisibilityTrait;
+use \OCA\Files_External\Lib\FrontendDefinitionTrait;
+use \OCA\Files_External\Lib\PriorityTrait;
+use \OCA\Files_External\Lib\DependencyTrait;
+use \OCA\Files_External\Lib\StorageModifierTrait;
+use \OCA\Files_External\Lib\IdentifierTrait;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+
+/**
+ * Storage backend
+ *
+ * A backend can have services injected during construction,
+ * such as \OCP\IDB for database operations. This allows a backend
+ * to perform advanced operations based on provided information.
+ *
+ * An authenication scheme defines the parameter interface, common to the
+ * storage implementation, the backend and the authentication mechanism.
+ * A storage implementation expects parameters according to the authentication
+ * scheme, which are provided from the authentication mechanism.
+ *
+ * This class uses the following traits:
+ * - VisibilityTrait
+ * Restrict usage to admin-only/none
+ * - FrontendDefinitionTrait
+ * Specify configuration parameters and other definitions
+ * - PriorityTrait
+ * Allow objects to prioritize over others with the same mountpoint
+ * - DependencyTrait
+ * The object requires certain dependencies to be met
+ * - StorageModifierTrait
+ * Object can affect storage mounting
+ */
+class Backend implements \JsonSerializable {
+
+ use VisibilityTrait;
+ use FrontendDefinitionTrait;
+ use PriorityTrait;
+ use DependencyTrait;
+ use StorageModifierTrait;
+ use IdentifierTrait;
+
+ /** @var string storage class */
+ private $storageClass;
+
+ /** @var array 'scheme' => true, supported authentication schemes */
+ private $authSchemes = [];
+
+ /** @var AuthMechanism|callable authentication mechanism fallback */
+ private $legacyAuthMechanism;
+
+ /**
+ * @return string
+ */
+ public function getStorageClass() {
+ return $this->storageClass;
+ }
+
+ /**
+ * @param string $class
+ * @return self
+ */
+ public function setStorageClass($class) {
+ $this->storageClass = $class;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function getAuthSchemes() {
+ if (empty($this->authSchemes)) {
+ return [AuthMechanism::SCHEME_NULL => true];
+ }
+ return $this->authSchemes;
+ }
+
+ /**
+ * @param string $scheme
+ * @return self
+ */
+ public function addAuthScheme($scheme) {
+ $this->authSchemes[$scheme] = true;
+ return $this;
+ }
+
+ /**
+ * @param array $parameters storage parameters, for dynamic mechanism selection
+ * @return AuthMechanism
+ */
+ public function getLegacyAuthMechanism(array $parameters = []) {
+ if (is_callable($this->legacyAuthMechanism)) {
+ return call_user_func($this->legacyAuthMechanism, $parameters);
+ }
+ return $this->legacyAuthMechanism;
+ }
+
+ /**
+ * @param AuthMechanism $authMechanism
+ * @return self
+ */
+ public function setLegacyAuthMechanism(AuthMechanism $authMechanism) {
+ $this->legacyAuthMechanism = $authMechanism;
+ return $this;
+ }
+
+ /**
+ * @param callable $callback dynamic auth mechanism selection
+ * @return self
+ */
+ public function setLegacyAuthMechanismCallback(callable $callback) {
+ $this->legacyAuthMechanism = $callback;
+ }
+
+ /**
+ * Serialize into JSON for client-side JS
+ *
+ * @return array
+ */
+ public function jsonSerialize() {
+ $data = $this->jsonSerializeDefinition();
+ $data += $this->jsonSerializeIdentifier();
+
+ $data['backend'] = $data['name']; // legacy compat
+ $data['priority'] = $this->getPriority();
+ $data['authSchemes'] = $this->getAuthSchemes();
+
+ return $data;
+ }
+
+ /**
+ * Check if parameters are satisfied in a StorageConfig
+ *
+ * @param StorageConfig $storage
+ * @return bool
+ */
+ public function validateStorage(StorageConfig $storage) {
+ return $this->validateStorageDefinition($storage);
+ }
+
+}
+
diff --git a/apps/files_external/lib/Lib/Backend/DAV.php b/apps/files_external/lib/Lib/Backend/DAV.php
new file mode 100644
index 00000000000..c6e9630be9e
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/DAV.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
+
+use \OCA\Files_External\Lib\Auth\Password\Password;
+
+class DAV extends Backend {
+
+ use LegacyDependencyCheckPolyfill;
+
+ public function __construct(IL10N $l, Password $legacyAuth) {
+ $this
+ ->setIdentifier('dav')
+ ->addIdentifierAlias('\OC\Files\Storage\DAV') // legacy compat
+ ->setStorageClass('\OC\Files\Storage\DAV')
+ ->setText($l->t('WebDAV'))
+ ->addParameters([
+ (new DefinitionParameter('host', $l->t('URL'))),
+ (new DefinitionParameter('root', $l->t('Remote subfolder')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('secure', $l->t('Secure https://')))
+ ->setType(DefinitionParameter::VALUE_BOOLEAN),
+ ])
+ ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
+ ->setLegacyAuthMechanism($legacyAuth)
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/Dropbox.php b/apps/files_external/lib/Lib/Backend/Dropbox.php
new file mode 100644
index 00000000000..2133c274996
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/Dropbox.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
+
+use \OCA\Files_External\Lib\Auth\OAuth1\OAuth1;
+
+class Dropbox extends Backend {
+
+ use LegacyDependencyCheckPolyfill;
+
+ public function __construct(IL10N $l, OAuth1 $legacyAuth) {
+ $this
+ ->setIdentifier('dropbox')
+ ->addIdentifierAlias('\OC\Files\Storage\Dropbox') // legacy compat
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\Dropbox')
+ ->setText($l->t('Dropbox'))
+ ->addParameters([
+ // all parameters handled in OAuth1 mechanism
+ ])
+ ->addAuthScheme(AuthMechanism::SCHEME_OAUTH1)
+ ->addCustomJs('dropbox')
+ ->setLegacyAuthMechanism($legacyAuth)
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/FTP.php b/apps/files_external/lib/Lib/Backend/FTP.php
new file mode 100644
index 00000000000..3960592d0bc
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/FTP.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
+
+use \OCA\Files_External\Lib\Auth\Password\Password;
+
+class FTP extends Backend {
+
+ use LegacyDependencyCheckPolyfill;
+
+ public function __construct(IL10N $l, Password $legacyAuth) {
+ $this
+ ->setIdentifier('ftp')
+ ->addIdentifierAlias('\OC\Files\Storage\FTP') // legacy compat
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\FTP')
+ ->setText($l->t('FTP'))
+ ->addParameters([
+ (new DefinitionParameter('host', $l->t('Host'))),
+ (new DefinitionParameter('root', $l->t('Remote subfolder')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('secure', $l->t('Secure ftps://')))
+ ->setType(DefinitionParameter::VALUE_BOOLEAN),
+ ])
+ ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
+ ->setLegacyAuthMechanism($legacyAuth)
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/Google.php b/apps/files_external/lib/Lib/Backend/Google.php
new file mode 100644
index 00000000000..b18b7bdb348
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/Google.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
+
+use \OCA\Files_External\Lib\Auth\OAuth2\OAuth2;
+
+class Google extends Backend {
+
+ use LegacyDependencyCheckPolyfill;
+
+ public function __construct(IL10N $l, OAuth2 $legacyAuth) {
+ $this
+ ->setIdentifier('googledrive')
+ ->addIdentifierAlias('\OC\Files\Storage\Google') // legacy compat
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\Google')
+ ->setText($l->t('Google Drive'))
+ ->addParameters([
+ // all parameters handled in OAuth2 mechanism
+ ])
+ ->addAuthScheme(AuthMechanism::SCHEME_OAUTH2)
+ ->addCustomJs('gdrive')
+ ->setLegacyAuthMechanism($legacyAuth)
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/LegacyBackend.php b/apps/files_external/lib/Lib/Backend/LegacyBackend.php
new file mode 100644
index 00000000000..752c501e1ec
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/LegacyBackend.php
@@ -0,0 +1,104 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\Auth\Builtin;
+use \OCA\Files_External\Lib\MissingDependency;
+use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
+
+/**
+ * Legacy compatibility for OC_Mount_Config::registerBackend()
+ */
+class LegacyBackend extends Backend {
+
+ use LegacyDependencyCheckPolyfill {
+ LegacyDependencyCheckPolyfill::checkDependencies as doCheckDependencies;
+ }
+
+ /** @var bool */
+ protected $hasDependencies = false;
+
+ /**
+ * @param string $class
+ * @param array $definition
+ * @param Builtin $authMechanism
+ */
+ public function __construct($class, array $definition, Builtin $authMechanism) {
+ $this
+ ->setIdentifier($class)
+ ->setStorageClass($class)
+ ->setText($definition['backend'])
+ ->addAuthScheme(Builtin::SCHEME_BUILTIN)
+ ->setLegacyAuthMechanism($authMechanism)
+ ;
+
+ foreach ($definition['configuration'] as $name => $placeholder) {
+ $flags = DefinitionParameter::FLAG_NONE;
+ $type = DefinitionParameter::VALUE_TEXT;
+ if ($placeholder[0] === '&') {
+ $flags = DefinitionParameter::FLAG_OPTIONAL;
+ $placeholder = substr($placeholder, 1);
+ }
+ switch ($placeholder[0]) {
+ case '!':
+ $type = DefinitionParameter::VALUE_BOOLEAN;
+ $placeholder = substr($placeholder, 1);
+ break;
+ case '*':
+ $type = DefinitionParameter::VALUE_PASSWORD;
+ $placeholder = substr($placeholder, 1);
+ break;
+ case '#':
+ $type = DefinitionParameter::VALUE_HIDDEN;
+ $placeholder = substr($placeholder, 1);
+ break;
+ }
+ $this->addParameter((new DefinitionParameter($name, $placeholder))
+ ->setType($type)
+ ->setFlags($flags)
+ );
+ }
+
+ if (isset($definition['priority'])) {
+ $this->setPriority($definition['priority']);
+ }
+ if (isset($definition['custom'])) {
+ $this->addCustomJs($definition['custom']);
+ }
+ if (isset($definition['has_dependencies']) && $definition['has_dependencies']) {
+ $this->hasDependencies = true;
+ }
+ }
+
+ /**
+ * @return MissingDependency[]
+ */
+ public function checkDependencies() {
+ if ($this->hasDependencies) {
+ return $this->doCheckDependencies();
+ }
+ return [];
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/Local.php b/apps/files_external/lib/Lib/Backend/Local.php
new file mode 100644
index 00000000000..1db707e7247
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/Local.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\Auth\NullMechanism;
+
+class Local extends Backend {
+
+ public function __construct(IL10N $l, NullMechanism $legacyAuth) {
+ $this
+ ->setIdentifier('local')
+ ->addIdentifierAlias('\OC\Files\Storage\Local') // legacy compat
+ ->setStorageClass('\OC\Files\Storage\Local')
+ ->setText($l->t('Local'))
+ ->addParameters([
+ (new DefinitionParameter('datadir', $l->t('Location'))),
+ ])
+ ->setAllowedVisibility(BackendService::VISIBILITY_ADMIN)
+ ->setPriority(BackendService::PRIORITY_DEFAULT + 50)
+ ->addAuthScheme(AuthMechanism::SCHEME_NULL)
+ ->setLegacyAuthMechanism($legacyAuth)
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/OwnCloud.php b/apps/files_external/lib/Lib/Backend/OwnCloud.php
new file mode 100644
index 00000000000..e92288b1354
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/OwnCloud.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+
+use \OCA\Files_External\Lib\Auth\Password\Password;
+
+class OwnCloud extends Backend {
+
+ public function __construct(IL10N $l, Password $legacyAuth) {
+ $this
+ ->setIdentifier('owncloud')
+ ->addIdentifierAlias('\OC\Files\Storage\OwnCloud') // legacy compat
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\OwnCloud')
+ ->setText($l->t('ownCloud'))
+ ->addParameters([
+ (new DefinitionParameter('host', $l->t('URL'))),
+ (new DefinitionParameter('root', $l->t('Remote subfolder')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('secure', $l->t('Secure https://')))
+ ->setType(DefinitionParameter::VALUE_BOOLEAN),
+ ])
+ ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
+ ->setLegacyAuthMechanism($legacyAuth)
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/SFTP.php b/apps/files_external/lib/Lib/Backend/SFTP.php
new file mode 100644
index 00000000000..fa33caeb576
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/SFTP.php
@@ -0,0 +1,51 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+
+use \OCA\Files_External\Lib\Auth\Password\Password;
+
+class SFTP extends Backend {
+
+ public function __construct(IL10N $l, Password $legacyAuth) {
+ $this
+ ->setIdentifier('sftp')
+ ->addIdentifierAlias('\OC\Files\Storage\SFTP') // legacy compat
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP')
+ ->setText($l->t('SFTP'))
+ ->addParameters([
+ (new DefinitionParameter('host', $l->t('Host'))),
+ (new DefinitionParameter('root', $l->t('Root')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ ])
+ ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
+ ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY)
+ ->setLegacyAuthMechanism($legacyAuth)
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/SFTP_Key.php b/apps/files_external/lib/Lib/Backend/SFTP_Key.php
new file mode 100644
index 00000000000..838cf6c52b2
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/SFTP_Key.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\Auth\PublicKey\RSA;
+use \OCA\Files_External\Lib\Backend\SFTP;
+
+class SFTP_Key extends Backend {
+
+ public function __construct(IL10N $l, RSA $legacyAuth, SFTP $sftpBackend) {
+ $this
+ ->setIdentifier('\OC\Files\Storage\SFTP_Key')
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\SFTP')
+ ->setText($l->t('SFTP with secret key login'))
+ ->addParameters([
+ (new DefinitionParameter('host', $l->t('Host'))),
+ (new DefinitionParameter('root', $l->t('Remote subfolder')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ ])
+ ->addAuthScheme(AuthMechanism::SCHEME_PUBLICKEY)
+ ->setLegacyAuthMechanism($legacyAuth)
+ ->deprecateTo($sftpBackend)
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/SMB.php b/apps/files_external/lib/Lib/Backend/SMB.php
new file mode 100644
index 00000000000..7ea30dd11bd
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/SMB.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\StorageConfig;
+use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
+
+use \OCA\Files_External\Lib\Auth\Password\Password;
+use OCP\IUser;
+
+class SMB extends Backend {
+
+ use LegacyDependencyCheckPolyfill;
+
+ public function __construct(IL10N $l, Password $legacyAuth) {
+ $this
+ ->setIdentifier('smb')
+ ->addIdentifierAlias('\OC\Files\Storage\SMB') // legacy compat
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB')
+ ->setText($l->t('SMB / CIFS'))
+ ->addParameters([
+ (new DefinitionParameter('host', $l->t('Host'))),
+ (new DefinitionParameter('share', $l->t('Share'))),
+ (new DefinitionParameter('root', $l->t('Remote subfolder')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('domain', $l->t('Domain')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ ])
+ ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
+ ->setLegacyAuthMechanism($legacyAuth)
+ ;
+ }
+
+ /**
+ * @param StorageConfig $storage
+ * @param IUser $user
+ */
+ public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
+ $user = $storage->getBackendOption('user');
+ if ($domain = $storage->getBackendOption('domain')) {
+ $storage->setBackendOption('user', $domain.'\\'.$user);
+ }
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/SMB_OC.php b/apps/files_external/lib/Lib/Backend/SMB_OC.php
new file mode 100644
index 00000000000..c543a19bdd8
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/SMB_OC.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\Auth\Password\SessionCredentials;
+use \OCA\Files_External\Lib\StorageConfig;
+use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
+use \OCA\Files_External\Lib\Backend\SMB;
+use OCP\IUser;
+
+/**
+ * Deprecated SMB_OC class - use SMB with the password::sessioncredentials auth mechanism
+ */
+class SMB_OC extends Backend {
+
+ use LegacyDependencyCheckPolyfill;
+
+ public function __construct(IL10N $l, SessionCredentials $legacyAuth, SMB $smbBackend) {
+ $this
+ ->setIdentifier('\OC\Files\Storage\SMB_OC')
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB')
+ ->setText($l->t('SMB / CIFS using OC login'))
+ ->addParameters([
+ (new DefinitionParameter('host', $l->t('Host'))),
+ (new DefinitionParameter('username_as_share', $l->t('Username as share')))
+ ->setType(DefinitionParameter::VALUE_BOOLEAN),
+ (new DefinitionParameter('share', $l->t('Share')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('root', $l->t('Remote subfolder')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ ])
+ ->setPriority(BackendService::PRIORITY_DEFAULT - 10)
+ ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
+ ->setLegacyAuthMechanism($legacyAuth)
+ ->deprecateTo($smbBackend)
+ ;
+ }
+
+ public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
+ $username_as_share = ($storage->getBackendOption('username_as_share') === true);
+
+ if ($username_as_share) {
+ $share = '/' . $storage->getBackendOption('user');
+ $storage->setBackendOption('share', $share);
+ }
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/Backend/Swift.php b/apps/files_external/lib/Lib/Backend/Swift.php
new file mode 100644
index 00000000000..58677575f52
--- /dev/null
+++ b/apps/files_external/lib/Lib/Backend/Swift.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, 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\Lib\Backend;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\Auth\OpenStack\OpenStack;
+use \OCA\Files_External\Lib\Auth\OpenStack\Rackspace;
+use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
+
+class Swift extends Backend {
+
+ use LegacyDependencyCheckPolyfill;
+
+ public function __construct(IL10N $l, OpenStack $openstackAuth, Rackspace $rackspaceAuth) {
+ $this
+ ->setIdentifier('swift')
+ ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat
+ ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift')
+ ->setText($l->t('OpenStack Object Storage'))
+ ->addParameters([
+ (new DefinitionParameter('service_name', $l->t('Service name')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('region', $l->t('Region')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ (new DefinitionParameter('bucket', $l->t('Bucket'))),
+ (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)')))
+ ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
+ ])
+ ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK)
+ ->setLegacyAuthMechanismCallback(function(array $params) use ($openstackAuth, $rackspaceAuth) {
+ if (isset($params['options']['key']) && $params['options']['key']) {
+ return $rackspaceAuth;
+ }
+ return $openstackAuth;
+ })
+ ;
+ }
+
+}