summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/appinfo/app.php142
-rw-r--r--apps/files_external/appinfo/application.php33
-rw-r--r--apps/files_external/appinfo/routes.php20
-rw-r--r--apps/files_external/controller/ajaxcontroller.php48
-rw-r--r--apps/files_external/js/dropbox.js5
-rw-r--r--apps/files_external/js/google.js5
-rw-r--r--apps/files_external/js/sftp_key.js53
-rw-r--r--apps/files_external/l10n/bg_BG.js2
-rw-r--r--apps/files_external/l10n/bg_BG.json2
-rw-r--r--apps/files_external/l10n/en_GB.json2
-rw-r--r--apps/files_external/l10n/eu.js3
-rw-r--r--apps/files_external/l10n/eu.json3
-rw-r--r--apps/files_external/l10n/fr.js2
-rw-r--r--apps/files_external/l10n/fr.json2
-rw-r--r--apps/files_external/l10n/ja.js2
-rw-r--r--apps/files_external/l10n/ja.json2
-rw-r--r--apps/files_external/l10n/nb_NO.js1
-rw-r--r--apps/files_external/l10n/nb_NO.json1
-rw-r--r--apps/files_external/lib/sftp.php21
-rw-r--r--apps/files_external/lib/sftp_key.php194
-rw-r--r--apps/files_external/tests/README.md58
-rw-r--r--apps/files_external/tests/backends/sftp_key.php85
-rw-r--r--apps/files_external/tests/config.php10
23 files changed, 628 insertions, 68 deletions
diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php
index 9b5994338a1..70f6b0159a6 100644
--- a/apps/files_external/appinfo/app.php
+++ b/apps/files_external/appinfo/app.php
@@ -18,6 +18,7 @@ OC::$CLASSPATH['OC\Files\Storage\SMB_OC'] = 'files_external/lib/smb_oc.php';
OC::$CLASSPATH['OC\Files\Storage\AmazonS3'] = 'files_external/lib/amazons3.php';
OC::$CLASSPATH['OC\Files\Storage\Dropbox'] = 'files_external/lib/dropbox.php';
OC::$CLASSPATH['OC\Files\Storage\SFTP'] = 'files_external/lib/sftp.php';
+OC::$CLASSPATH['OC\Files\Storage\SFTP_Key'] = 'files_external/lib/sftp_key.php';
OC::$CLASSPATH['OC_Mount_Config'] = 'files_external/lib/config.php';
OC::$CLASSPATH['OCA\Files\External\Api'] = 'files_external/lib/api.php';
@@ -26,39 +27,41 @@ if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == '
OCP\App::registerPersonal('files_external', 'personal');
}
-\OCA\Files\App::getNavigationManager()->add(
- array(
- "id" => 'extstoragemounts',
- "appname" => 'files_external',
- "script" => 'list.php',
- "order" => 30,
- "name" => $l->t('External storage')
- )
-);
+\OCA\Files\App::getNavigationManager()->add([
+ "id" => 'extstoragemounts',
+ "appname" => 'files_external',
+ "script" => 'list.php',
+ "order" => 30,
+ "name" => $l->t('External storage')
+]);
// connecting hooks
OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook');
OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_OC', 'login');
-OC_Mount_Config::registerBackend('\OC\Files\Storage\Local', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\Local', [
'backend' => (string)$l->t('Local'),
'priority' => 150,
- 'configuration' => array(
- 'datadir' => (string)$l->t('Location'))));
+ 'configuration' => [
+ 'datadir' => (string)$l->t('Location')
+ ],
+]);
-OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', [
'backend' => (string)$l->t('Amazon S3'),
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'key' => (string)$l->t('Key'),
'secret' => '*'.$l->t('Secret'),
- 'bucket' => (string)$l->t('Bucket')),
- 'has_dependencies' => true));
+ 'bucket' => (string)$l->t('Bucket'),
+ ],
+ 'has_dependencies' => true,
+]);
-OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', [
'backend' => (string)$l->t('Amazon S3 and compliant'),
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'key' => (string)$l->t('Access Key'),
'secret' => '*'.$l->t('Secret Key'),
'bucket' => (string)$l->t('Bucket'),
@@ -66,48 +69,56 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', array(
'port' => '&'.$l->t('Port'),
'region' => '&'.$l->t('Region'),
'use_ssl' => '!'.$l->t('Enable SSL'),
- 'use_path_style' => '!'.$l->t('Enable Path Style')),
- 'has_dependencies' => true));
+ 'use_path_style' => '!'.$l->t('Enable Path Style')
+ ],
+ 'has_dependencies' => true,
+]);
-OC_Mount_Config::registerBackend('\OC\Files\Storage\Dropbox', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\Dropbox', [
'backend' => 'Dropbox',
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'configured' => '#configured',
'app_key' => (string)$l->t('App key'),
'app_secret' => '*'.$l->t('App secret'),
'token' => '#token',
- 'token_secret' => '#token_secret'),
+ 'token_secret' => '#token_secret'
+ ],
'custom' => 'dropbox',
- 'has_dependencies' => true));
+ 'has_dependencies' => true,
+]);
-OC_Mount_Config::registerBackend('\OC\Files\Storage\FTP', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\FTP', [
'backend' => 'FTP',
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
'root' => '&'.$l->t('Remote subfolder'),
- 'secure' => '!'.$l->t('Secure ftps://')),
- 'has_dependencies' => true));
+ 'secure' => '!'.$l->t('Secure ftps://')
+ ],
+ 'has_dependencies' => true,
+]);
-OC_Mount_Config::registerBackend('\OC\Files\Storage\Google', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\Google', [
'backend' => 'Google Drive',
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'configured' => '#configured',
'client_id' => (string)$l->t('Client ID'),
'client_secret' => '*'.$l->t('Client secret'),
- 'token' => '#token'),
+ 'token' => '#token',
+ ],
'custom' => 'google',
- 'has_dependencies' => true));
+ 'has_dependencies' => true,
+]);
-OC_Mount_Config::registerBackend('\OC\Files\Storage\Swift', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\Swift', [
'backend' => (string)$l->t('OpenStack Object Storage'),
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'user' => (string)$l->t('Username'),
'bucket' => (string)$l->t('Bucket'),
'region' => '&'.$l->t('Region (optional for OpenStack Object Storage)'),
@@ -117,63 +128,86 @@ OC_Mount_Config::registerBackend('\OC\Files\Storage\Swift', array(
'service_name' => '&'.$l->t('Service Name (required for OpenStack Object Storage)'),
'url' => '&'.$l->t('URL of identity endpoint (required for OpenStack Object Storage)'),
'timeout' => '&'.$l->t('Timeout of HTTP requests in seconds'),
- ),
- 'has_dependencies' => true));
+ ],
+ 'has_dependencies' => true,
+]);
if (!OC_Util::runningOnWindows()) {
- OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB', array(
+ OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB', [
'backend' => 'SMB / CIFS',
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
'share' => (string)$l->t('Share'),
- 'root' => '&'.$l->t('Remote subfolder')),
- 'has_dependencies' => true));
+ 'root' => '&'.$l->t('Remote subfolder'),
+ ],
+ 'has_dependencies' => true,
+ ]);
- OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB_OC', array(
+ OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB_OC', [
'backend' => (string)$l->t('SMB / CIFS using OC login'),
'priority' => 90,
- 'configuration' => array(
+ 'configuration' => [
'host' => (string)$l->t('Host'),
'username_as_share' => '!'.$l->t('Username as share'),
'share' => '&'.$l->t('Share'),
- 'root' => '&'.$l->t('Remote subfolder')),
- 'has_dependencies' => true));
+ 'root' => '&'.$l->t('Remote subfolder'),
+ ],
+ 'has_dependencies' => true,
+ ]);
}
-OC_Mount_Config::registerBackend('\OC\Files\Storage\DAV', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\DAV', [
'backend' => 'WebDAV',
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'host' => (string)$l->t('URL'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
'root' => '&'.$l->t('Remote subfolder'),
- 'secure' => '!'.$l->t('Secure https://')),
- 'has_dependencies' => true));
+ 'secure' => '!'.$l->t('Secure https://'),
+ ],
+ 'has_dependencies' => true,
+]);
-OC_Mount_Config::registerBackend('\OC\Files\Storage\OwnCloud', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\OwnCloud', [
'backend' => 'ownCloud',
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'host' => (string)$l->t('URL'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
'root' => '&'.$l->t('Remote subfolder'),
- 'secure' => '!'.$l->t('Secure https://'))));
+ 'secure' => '!'.$l->t('Secure https://'),
+ ],
+]);
-OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP', array(
+OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP', [
'backend' => 'SFTP',
'priority' => 100,
- 'configuration' => array(
+ 'configuration' => [
'host' => (string)$l->t('Host'),
'user' => (string)$l->t('Username'),
'password' => '*'.$l->t('Password'),
- 'root' => '&'.$l->t('Remote subfolder'))));
+ 'root' => '&'.$l->t('Remote subfolder'),
+ ],
+]);
+OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP_Key', [
+ 'backend' => 'SFTP with secret key login',
+ 'priority' => 100,
+ 'configuration' => array(
+ 'host' => (string)$l->t('Host'),
+ 'user' => (string)$l->t('Username'),
+ 'public_key' => (string)$l->t('Public key'),
+ 'private_key' => '#private_key',
+ 'root' => '&'.$l->t('Remote subfolder')),
+ 'custom' => 'sftp_key',
+ ]
+);
$mountProvider = new \OCA\Files_External\Config\ConfigAdapter();
\OC::$server->getMountProviderCollection()->registerProvider($mountProvider);
diff --git a/apps/files_external/appinfo/application.php b/apps/files_external/appinfo/application.php
new file mode 100644
index 00000000000..b1605bb98a8
--- /dev/null
+++ b/apps/files_external/appinfo/application.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Copyright (c) 2015 University of Edinburgh <Ross.Nicoll@ed.ac.uk>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\Files_External\Appinfo;
+
+use \OCA\Files_External\Controller\AjaxController;
+use \OCP\AppFramework\App;
+use \OCP\IContainer;
+
+ /**
+ * @package OCA\Files_External\Appinfo
+ */
+class Application extends App {
+ public function __construct(array $urlParams=array()) {
+ parent::__construct('files_external', $urlParams);
+ $container = $this->getContainer();
+
+ /**
+ * Controllers
+ */
+ $container->registerService('AjaxController', function (IContainer $c) {
+ return new AjaxController(
+ $c->query('AppName'),
+ $c->query('Request')
+ );
+ });
+ }
+}
diff --git a/apps/files_external/appinfo/routes.php b/apps/files_external/appinfo/routes.php
index b852b34c5d3..5c7c4eca909 100644
--- a/apps/files_external/appinfo/routes.php
+++ b/apps/files_external/appinfo/routes.php
@@ -20,6 +20,23 @@
*
*/
+namespace OCA\Files_External\Appinfo;
+
+$application = new Application();
+$application->registerRoutes(
+ $this,
+ array(
+ 'routes' => array(
+ array(
+ 'name' => 'Ajax#getSshKeys',
+ 'url' => '/ajax/sftp_key.php',
+ 'verb' => 'POST',
+ 'requirements' => array()
+ )
+ )
+ )
+);
+
/** @var $this OC\Route\Router */
$this->create('files_external_add_mountpoint', 'ajax/addMountPoint.php')
@@ -37,10 +54,11 @@ $this->create('files_external_dropbox', 'ajax/dropbox.php')
$this->create('files_external_google', 'ajax/google.php')
->actionInclude('files_external/ajax/google.php');
+
$this->create('files_external_list_applicable', '/applicable')
->actionInclude('files_external/ajax/applicable.php');
-OC_API::register('get',
+\OC_API::register('get',
'/apps/files_external/api/v1/mounts',
array('\OCA\Files\External\Api', 'getUserMounts'),
'files_external');
diff --git a/apps/files_external/controller/ajaxcontroller.php b/apps/files_external/controller/ajaxcontroller.php
new file mode 100644
index 00000000000..141fc7817d2
--- /dev/null
+++ b/apps/files_external/controller/ajaxcontroller.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Copyright (c) 2015 University of Edinburgh <Ross.Nicoll@ed.ac.uk>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCA\Files_External\Controller;
+
+use OCP\AppFramework\Controller;
+use OCP\IRequest;
+use OCP\AppFramework\Http\JSONResponse;
+
+class AjaxController extends Controller {
+ public function __construct($appName, IRequest $request) {
+ parent::__construct($appName, $request);
+ }
+
+ private function generateSshKeys() {
+ $rsa = new \Crypt_RSA();
+ $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
+ $rsa->setPassword(\OC::$server->getConfig()->getSystemValue('secret', ''));
+
+ $key = $rsa->createKey();
+ // Replace the placeholder label with a more meaningful one
+ $key['publicKey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']);
+
+ return $key;
+ }
+
+ /**
+ * Generates an SSH public/private key pair.
+ *
+ * @NoAdminRequired
+ */
+ public function getSshKeys() {
+ $key = $this->generateSshKeys();
+ return new JSONResponse(
+ array('data' => array(
+ 'private_key' => $key['privatekey'],
+ 'public_key' => $key['publickey']
+ ),
+ 'status' => 'success'
+ ));
+ }
+
+}
diff --git a/apps/files_external/js/dropbox.js b/apps/files_external/js/dropbox.js
index 6baaabe11b6..2880e910f2c 100644
--- a/apps/files_external/js/dropbox.js
+++ b/apps/files_external/js/dropbox.js
@@ -65,7 +65,10 @@ $(document).ready(function() {
|| $(tr).find('.chzn-select').val() != null))
{
if ($(tr).find('.dropbox').length == 0) {
- $(config).append('<a class="button dropbox">'+t('files_external', 'Grant access')+'</a>');
+ $(config).append($(document.createElement('input'))
+ .addClass('button dropbox')
+ .attr('type', 'button')
+ .attr('value', t('files_external', 'Grant access')));
} else {
$(tr).find('.dropbox').show();
}
diff --git a/apps/files_external/js/google.js b/apps/files_external/js/google.js
index 068c2c13c66..b9a5e66b800 100644
--- a/apps/files_external/js/google.js
+++ b/apps/files_external/js/google.js
@@ -85,8 +85,9 @@ $(document).ready(function() {
|| $(tr).find('.chzn-select').val() != null))
{
if ($(tr).find('.google').length == 0) {
- $(config).append($('<a/>').addClass('button google')
- .text(t('files_external', 'Grant access')));
+ $(config).append($(document.createElement('input')).addClass('button google')
+ .attr('type', 'button')
+ .attr('value', t('files_external', 'Grant access')));
} else {
$(tr).find('.google').show();
}
diff --git a/apps/files_external/js/sftp_key.js b/apps/files_external/js/sftp_key.js
new file mode 100644
index 00000000000..2b39628247c
--- /dev/null
+++ b/apps/files_external/js/sftp_key.js
@@ -0,0 +1,53 @@
+$(document).ready(function() {
+
+ $('#externalStorage tbody tr.\\\\OC\\\\Files\\\\Storage\\\\SFTP_Key').each(function() {
+ var tr = $(this);
+ var config = $(tr).find('.configuration');
+ if ($(config).find('.sftp_key').length === 0) {
+ setupTableRow(tr, config);
+ }
+ });
+
+ // We can't catch the DOM elements being added, but we can pick up when
+ // they receive focus
+ $('#externalStorage').on('focus', 'tbody tr.\\\\OC\\\\Files\\\\Storage\\\\SFTP_Key', function() {
+ var tr = $(this);
+ var config = $(tr).find('.configuration');
+
+ if ($(config).find('.sftp_key').length === 0) {
+ setupTableRow(tr, config);
+ }
+ });
+
+ $('#externalStorage').on('click', '.sftp_key', function(event) {
+ event.preventDefault();
+ var tr = $(this).parent().parent();
+ generateKeys(tr);
+ });
+
+ function setupTableRow(tr, config) {
+ $(config).append($(document.createElement('input')).addClass('button sftp_key')
+ .attr('type', 'button')
+ .attr('value', t('files_external', 'Generate keys')));
+ // If there's no private key, build one
+ if (0 === $(config).find('[data-parameter="private_key"]').val().length) {
+ generateKeys(tr);
+ }
+ }
+
+ function generateKeys(tr) {
+ var config = $(tr).find('.configuration');
+
+ $.post(OC.filePath('files_external', 'ajax', 'sftp_key.php'), {}, function(result) {
+ if (result && result.status === 'success') {
+ $(config).find('[data-parameter="public_key"]').val(result.data.public_key);
+ $(config).find('[data-parameter="private_key"]').val(result.data.private_key);
+ OC.MountConfig.saveStorage(tr, function() {
+ // Nothing to do
+ });
+ } else {
+ OC.dialogs.alert(result.data.message, t('files_external', 'Error generating key pair') );
+ }
+ });
+ }
+});
diff --git a/apps/files_external/l10n/bg_BG.js b/apps/files_external/l10n/bg_BG.js
index dabf8715e82..f1a773b21f9 100644
--- a/apps/files_external/l10n/bg_BG.js
+++ b/apps/files_external/l10n/bg_BG.js
@@ -56,6 +56,8 @@ OC.L10N.register(
"<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." : "<b>Note:</b> PHP подръжката на cURL не е включена или инсталирана. Прикачването на %s не е възможно. Моля, поискай системния администратор да я инсталира.",
"<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." : "<b>Note:</b> PHP подръжката на FTP не е включена или инсталирана. Прикачването на %s не е възможно. Моля, поискай системния администратор да я инсталира.",
"<b>Note:</b> \"%s\" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it." : "<b>Note:</b> \"%s\" не е инсталиран. Прикачването на %s не е възможно. Моля, поискай системния администратор да я инсталира.",
+ "No external storage configured" : "Няма настроено външно дисково пространство",
+ "You can configure external storages in the personal settings" : "Можеш да промениш виншните дискови пространства в личните си настройки",
"Name" : "Име",
"Storage type" : "Тип дисково пространство",
"Scope" : "Обхват",
diff --git a/apps/files_external/l10n/bg_BG.json b/apps/files_external/l10n/bg_BG.json
index 5dc9e8d60a2..b404afdae5e 100644
--- a/apps/files_external/l10n/bg_BG.json
+++ b/apps/files_external/l10n/bg_BG.json
@@ -54,6 +54,8 @@
"<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." : "<b>Note:</b> PHP подръжката на cURL не е включена или инсталирана. Прикачването на %s не е възможно. Моля, поискай системния администратор да я инсталира.",
"<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." : "<b>Note:</b> PHP подръжката на FTP не е включена или инсталирана. Прикачването на %s не е възможно. Моля, поискай системния администратор да я инсталира.",
"<b>Note:</b> \"%s\" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it." : "<b>Note:</b> \"%s\" не е инсталиран. Прикачването на %s не е възможно. Моля, поискай системния администратор да я инсталира.",
+ "No external storage configured" : "Няма настроено външно дисково пространство",
+ "You can configure external storages in the personal settings" : "Можеш да промениш виншните дискови пространства в личните си настройки",
"Name" : "Име",
"Storage type" : "Тип дисково пространство",
"Scope" : "Обхват",
diff --git a/apps/files_external/l10n/en_GB.json b/apps/files_external/l10n/en_GB.json
index 21a5881c94e..4b4da2f2cb5 100644
--- a/apps/files_external/l10n/en_GB.json
+++ b/apps/files_external/l10n/en_GB.json
@@ -69,4 +69,4 @@
"Enable User External Storage" : "Enable User External Storage",
"Allow users to mount the following external storage" : "Allow users to mount the following external storage"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
-} \ No newline at end of file
+}
diff --git a/apps/files_external/l10n/eu.js b/apps/files_external/l10n/eu.js
index 8da8ca68263..0127452f697 100644
--- a/apps/files_external/l10n/eu.js
+++ b/apps/files_external/l10n/eu.js
@@ -52,9 +52,12 @@ OC.L10N.register(
"(group)" : "(taldea)",
"Saved" : "Gordeta",
"<b>Note:</b> " : "<b>Oharra:</b>",
+ "and" : "eta",
"<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." : "<b>Oharra:</b> :PHPko cURL euskarria ez dago instalatuta edo gaitua. Ezinezko da %s muntatzea. Mesedez eskatu sistema administratzaleari instala dezan. ",
"<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." : "<b>Oharra:</b> :PHPko FTP euskarria ez dago instalatuta edo gaitua. Ezinezko da %s muntatzea. Mesedez eskatu sistema administratzaleari instala dezan. ",
"<b>Note:</b> \"%s\" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it." : "<b>Oharra:</b>\"%s\" euskarria ez dago instalatuta Ezinezko da %s muntatzea. Mesedez eskatu sistema administratzaleari instala dezan. ",
+ "No external storage configured" : "Ez da kanpo biltegiratzerik konfiguratu",
+ "You can configure external storages in the personal settings" : "Ezarpen pertsonaletan kanpo biltegiratzeak konfigura ditzazkezu",
"Name" : "Izena",
"Storage type" : "Biltegiratze mota",
"External Storage" : "Kanpoko biltegiratzea",
diff --git a/apps/files_external/l10n/eu.json b/apps/files_external/l10n/eu.json
index 7ae84c8dbd3..af7f8e4016b 100644
--- a/apps/files_external/l10n/eu.json
+++ b/apps/files_external/l10n/eu.json
@@ -50,9 +50,12 @@
"(group)" : "(taldea)",
"Saved" : "Gordeta",
"<b>Note:</b> " : "<b>Oharra:</b>",
+ "and" : "eta",
"<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." : "<b>Oharra:</b> :PHPko cURL euskarria ez dago instalatuta edo gaitua. Ezinezko da %s muntatzea. Mesedez eskatu sistema administratzaleari instala dezan. ",
"<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." : "<b>Oharra:</b> :PHPko FTP euskarria ez dago instalatuta edo gaitua. Ezinezko da %s muntatzea. Mesedez eskatu sistema administratzaleari instala dezan. ",
"<b>Note:</b> \"%s\" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it." : "<b>Oharra:</b>\"%s\" euskarria ez dago instalatuta Ezinezko da %s muntatzea. Mesedez eskatu sistema administratzaleari instala dezan. ",
+ "No external storage configured" : "Ez da kanpo biltegiratzerik konfiguratu",
+ "You can configure external storages in the personal settings" : "Ezarpen pertsonaletan kanpo biltegiratzeak konfigura ditzazkezu",
"Name" : "Izena",
"Storage type" : "Biltegiratze mota",
"External Storage" : "Kanpoko biltegiratzea",
diff --git a/apps/files_external/l10n/fr.js b/apps/files_external/l10n/fr.js
index 23c31636fce..cec7d16d752 100644
--- a/apps/files_external/l10n/fr.js
+++ b/apps/files_external/l10n/fr.js
@@ -58,7 +58,7 @@ OC.L10N.register(
"<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." : "<b>Attention : </b> La prise en charge du FTP par PHP n'est pas activée ou installée. Le montage de %s n'est pas possible. Contactez votre administrateur système pour l'installer.",
"<b>Note:</b> \"%s\" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it." : "<b>Attention : </b> \"%s\" n'est pas installé. Le montage de %s n'est pas possible. Contactez votre administrateur système pour l'installer.",
"No external storage configured" : "Aucun stockage externe configuré",
- "You can configure external storages in the personal settings" : "Vous pouvez configurer vos stockages externes dans les paramètres personnels.",
+ "You can configure external storages in the personal settings" : "Vous pouvez configurer des stockages externes dans vos paramètres personnels",
"Name" : "Nom",
"Storage type" : "Type de support de stockage",
"Scope" : "Portée",
diff --git a/apps/files_external/l10n/fr.json b/apps/files_external/l10n/fr.json
index e29f032fc4e..af1e7c22cd3 100644
--- a/apps/files_external/l10n/fr.json
+++ b/apps/files_external/l10n/fr.json
@@ -56,7 +56,7 @@
"<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." : "<b>Attention : </b> La prise en charge du FTP par PHP n'est pas activée ou installée. Le montage de %s n'est pas possible. Contactez votre administrateur système pour l'installer.",
"<b>Note:</b> \"%s\" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it." : "<b>Attention : </b> \"%s\" n'est pas installé. Le montage de %s n'est pas possible. Contactez votre administrateur système pour l'installer.",
"No external storage configured" : "Aucun stockage externe configuré",
- "You can configure external storages in the personal settings" : "Vous pouvez configurer vos stockages externes dans les paramètres personnels.",
+ "You can configure external storages in the personal settings" : "Vous pouvez configurer des stockages externes dans vos paramètres personnels",
"Name" : "Nom",
"Storage type" : "Type de support de stockage",
"Scope" : "Portée",
diff --git a/apps/files_external/l10n/ja.js b/apps/files_external/l10n/ja.js
index 4c343daf902..f981ff6535f 100644
--- a/apps/files_external/l10n/ja.js
+++ b/apps/files_external/l10n/ja.js
@@ -65,7 +65,7 @@ OC.L10N.register(
"External Storage" : "外部ストレージ",
"Folder name" : "フォルダー名",
"Configuration" : "設定",
- "Available for" : "以下が利用可能",
+ "Available for" : "利用可能",
"Add storage" : "ストレージを追加",
"Delete" : "削除",
"Enable User External Storage" : "ユーザーの外部ストレージを有効にする",
diff --git a/apps/files_external/l10n/ja.json b/apps/files_external/l10n/ja.json
index 77aff58b9f7..d2cb64ad528 100644
--- a/apps/files_external/l10n/ja.json
+++ b/apps/files_external/l10n/ja.json
@@ -63,7 +63,7 @@
"External Storage" : "外部ストレージ",
"Folder name" : "フォルダー名",
"Configuration" : "設定",
- "Available for" : "以下が利用可能",
+ "Available for" : "利用可能",
"Add storage" : "ストレージを追加",
"Delete" : "削除",
"Enable User External Storage" : "ユーザーの外部ストレージを有効にする",
diff --git a/apps/files_external/l10n/nb_NO.js b/apps/files_external/l10n/nb_NO.js
index 19e0051e1e3..1fa2f9a8c6e 100644
--- a/apps/files_external/l10n/nb_NO.js
+++ b/apps/files_external/l10n/nb_NO.js
@@ -57,6 +57,7 @@ OC.L10N.register(
"<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." : "<b>Merk:</b> Støtte for cURL i PHP er ikke aktivert eller installert. Oppkobling av %s er ikke mulig. Be systemadministratoren om å installere det.",
"<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." : "<b>Merk:</b> FTP-støtte i PHP er ikke slått på eller installert. Kan ikke koble opp %s. Ta kontakt med systemadministratoren for å installere det.",
"<b>Note:</b> \"%s\" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it." : "<b>Merk:</b> \"%s\" er ikke installert. Oppkobling av %s er ikke mulig. Spør systemadministratoren om å installere det.",
+ "No external storage configured" : "Eksternt lager er ikke konfigurert",
"You can configure external storages in the personal settings" : "Du kan konfigurerer eksterne lagre i personlige innstillinger",
"Name" : "Navn",
"Storage type" : "Lagringstype",
diff --git a/apps/files_external/l10n/nb_NO.json b/apps/files_external/l10n/nb_NO.json
index 0b707decbea..6ff246ee2ef 100644
--- a/apps/files_external/l10n/nb_NO.json
+++ b/apps/files_external/l10n/nb_NO.json
@@ -55,6 +55,7 @@
"<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." : "<b>Merk:</b> Støtte for cURL i PHP er ikke aktivert eller installert. Oppkobling av %s er ikke mulig. Be systemadministratoren om å installere det.",
"<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." : "<b>Merk:</b> FTP-støtte i PHP er ikke slått på eller installert. Kan ikke koble opp %s. Ta kontakt med systemadministratoren for å installere det.",
"<b>Note:</b> \"%s\" is not installed. Mounting of %s is not possible. Please ask your system administrator to install it." : "<b>Merk:</b> \"%s\" er ikke installert. Oppkobling av %s er ikke mulig. Spør systemadministratoren om å installere det.",
+ "No external storage configured" : "Eksternt lager er ikke konfigurert",
"You can configure external storages in the personal settings" : "Du kan konfigurerer eksterne lagre i personlige innstillinger",
"Name" : "Navn",
"Storage type" : "Lagringstype",
diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php
index f6c56669734..2a762ad068f 100644
--- a/apps/files_external/lib/sftp.php
+++ b/apps/files_external/lib/sftp.php
@@ -20,7 +20,7 @@ class SFTP extends \OC\Files\Storage\Common {
/**
* @var \Net_SFTP
*/
- private $client;
+ protected $client;
private static $tempFiles = array();
@@ -42,7 +42,8 @@ class SFTP extends \OC\Files\Storage\Common {
$this->host = substr($this->host, $proto+3);
}
$this->user = $params['user'];
- $this->password = $params['password'];
+ $this->password
+ = isset($params['password']) ? $params['password'] : '';
$this->root
= isset($params['root']) ? $this->cleanPath($params['root']) : '/';
@@ -101,6 +102,18 @@ class SFTP extends \OC\Files\Storage\Common {
return 'sftp::' . $this->user . '@' . $this->host . '/' . $this->root;
}
+ public function getHost() {
+ return $this->host;
+ }
+
+ public function getRoot() {
+ return $this->root;
+ }
+
+ public function getUser() {
+ return $this->user;
+ }
+
/**
* @param string $path
*/
@@ -121,7 +134,7 @@ class SFTP extends \OC\Files\Storage\Common {
return false;
}
- private function writeHostKeys($keys) {
+ protected function writeHostKeys($keys) {
try {
$keyPath = $this->hostKeysPath();
if ($keyPath && file_exists($keyPath)) {
@@ -137,7 +150,7 @@ class SFTP extends \OC\Files\Storage\Common {
return false;
}
- private function readHostKeys() {
+ protected function readHostKeys() {
try {
$keyPath = $this->hostKeysPath();
if (file_exists($keyPath)) {
diff --git a/apps/files_external/lib/sftp_key.php b/apps/files_external/lib/sftp_key.php
new file mode 100644
index 00000000000..6113f88a8ff
--- /dev/null
+++ b/apps/files_external/lib/sftp_key.php
@@ -0,0 +1,194 @@
+<?php
+/**
+ * Copyright (c) 2014, 2015 University of Edinburgh <Ross.Nicoll@ed.ac.uk>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Files\Storage;
+
+/**
+* Uses phpseclib's Net_SFTP class and the Net_SFTP_Stream stream wrapper to
+* provide access to SFTP servers.
+*/
+class SFTP_Key extends \OC\Files\Storage\SFTP {
+ private $publicKey;
+ private $privateKey;
+
+ public function __construct($params) {
+ parent::__construct($params);
+ $this->publicKey = $params['public_key'];
+ $this->privateKey = $params['private_key'];
+ }
+
+ /**
+ * Returns the connection.
+ *
+ * @return \Net_SFTP connected client instance
+ * @throws \Exception when the connection failed
+ */
+ public function getConnection() {
+ if (!is_null($this->client)) {
+ return $this->client;
+ }
+
+ $hostKeys = $this->readHostKeys();
+ $this->client = new \Net_SFTP($this->getHost());
+
+ // The SSH Host Key MUST be verified before login().
+ $currentHostKey = $this->client->getServerPublicHostKey();
+ if (array_key_exists($this->getHost(), $hostKeys)) {
+ if ($hostKeys[$this->getHost()] !== $currentHostKey) {
+ throw new \Exception('Host public key does not match known key');
+ }
+ } else {
+ $hostKeys[$this->getHost()] = $currentHostKey;
+ $this->writeHostKeys($hostKeys);
+ }
+
+ $key = $this->getPrivateKey();
+ if (is_null($key)) {
+ throw new \Exception('Secret key could not be loaded');
+ }
+ if (!$this->client->login($this->getUser(), $key)) {
+ throw new \Exception('Login failed');
+ }
+ return $this->client;
+ }
+
+ /**
+ * Returns the private key to be used for authentication to the remote server.
+ *
+ * @return \Crypt_RSA instance or null in case of a failure to load the key.
+ */
+ private function getPrivateKey() {
+ $key = new \Crypt_RSA();
+ $key->setPassword(\OC::$server->getConfig()->getSystemValue('secret', ''));
+ if (!$key->loadKey($this->privateKey)) {
+ // Should this exception rather than return null?
+ return null;
+ }
+ return $key;
+ }
+
+ /**
+ * Throws an exception if the provided host name/address is invalid (cannot be resolved
+ * and is not an IPv4 address).
+ *
+ * @return true; never returns in case of a problem, this return value is used just to
+ * make unit tests happy.
+ */
+ public function assertHostAddressValid($hostname) {
+ // TODO: Should handle IPv6 addresses too
+ if (!preg_match('/^\d+\.\d+\.\d+\.\d+$/', $hostname) && gethostbyname($hostname) === $hostname) {
+ // Hostname is not an IPv4 address and cannot be resolved via DNS
+ throw new \InvalidArgumentException('Cannot resolve hostname.');
+ }
+ return true;
+ }
+
+ /**
+ * Throws an exception if the provided port number is invalid (cannot be resolved
+ * and is not an IPv4 address).
+ *
+ * @return true; never returns in case of a problem, this return value is used just to
+ * make unit tests happy.
+ */
+ public function assertPortNumberValid($port) {
+ if (!preg_match('/^\d+$/', $port)) {
+ throw new \InvalidArgumentException('Port number must be a number.');
+ }
+ if ($port < 0 || $port > 65535) {
+ throw new \InvalidArgumentException('Port number must be between 0 and 65535 inclusive.');
+ }
+ return true;
+ }
+
+ /**
+ * Replaces anything that's not an alphanumeric character or "." in a hostname
+ * with "_", to make it safe for use as part of a file name.
+ */
+ protected function sanitizeHostName($name) {
+ return preg_replace('/[^\d\w\._]/', '_', $name);
+ }
+
+ /**
+ * Replaces anything that's not an alphanumeric character or "_" in a username
+ * with "_", to make it safe for use as part of a file name.
+ */
+ protected function sanitizeUserName($name) {
+ return preg_replace('/[^\d\w_]/', '_', $name);
+ }
+
+ public function test() {
+ if (empty($this->getHost())) {
+ \OC::$server->getLogger()->warning('Hostname has not been specified');
+ return false;
+ }
+ if (empty($this->getUser())) {
+ \OC::$server->getLogger()->warning('Username has not been specified');
+ return false;
+ }
+ if (!isset($this->privateKey)) {
+ \OC::$server->getLogger()->warning('Private key was missing from the request');
+ return false;
+ }
+
+ // Sanity check the host
+ $hostParts = explode(':', $this->getHost());
+ try {
+ if (count($hostParts) == 1) {
+ $hostname = $hostParts[0];
+ $this->assertHostAddressValid($hostname);
+ } else if (count($hostParts) == 2) {
+ $hostname = $hostParts[0];
+ $this->assertHostAddressValid($hostname);
+ $this->assertPortNumberValid($hostParts[1]);
+ } else {
+ throw new \Exception('Host connection string is invalid.');
+ }
+ } catch(\Exception $e) {
+ \OC::$server->getLogger()->warning($e->getMessage());
+ return false;
+ }
+
+ // Validate the key
+ $key = $this->getPrivateKey();
+ if (is_null($key)) {
+ \OC::$server->getLogger()->warning('Secret key could not be loaded');
+ return false;
+ }
+
+ try {
+ if ($this->getConnection()->nlist() === false) {
+ return false;
+ }
+ } catch(\Exception $e) {
+ // We should be throwing a more specific error, so we're not just catching
+ // Exception here
+ \OC::$server->getLogger()->warning($e->getMessage());
+ return false;
+ }
+
+ // Save the key somewhere it can easily be extracted later
+ if (\OC::$server->getUserSession()->getUser()) {
+ $view = new \OC\Files\View('/'.\OC::$server->getUserSession()->getUser()->getUId().'/files_external/sftp_keys');
+ if (!$view->is_dir('')) {
+ if (!$view->mkdir('')) {
+ \OC::$server->getLogger()->warning('Could not create secret key directory.');
+ return false;
+ }
+ }
+ $key_filename = $this->sanitizeUserName($this->getUser()).'@'.$this->sanitizeHostName($hostname).'.pub';
+ $key_file = $view->fopen($key_filename, "w");
+ if ($key_file) {
+ fwrite($key_file, $this->publicKey);
+ fclose($key_file);
+ } else {
+ \OC::$server->getLogger()->warning('Could not write secret key file.');
+ }
+ }
+
+ return true;
+ }
+}
diff --git a/apps/files_external/tests/README.md b/apps/files_external/tests/README.md
new file mode 100644
index 00000000000..35a0232434e
--- /dev/null
+++ b/apps/files_external/tests/README.md
@@ -0,0 +1,58 @@
+# How to run the files external unit tests
+
+## Components
+
+The files_external relies - as the name already says - on external file system
+providers. To test easily against such a provider we use some scripts to setup
+a provider (and of course also cleanup that provider). Those scripts can be
+found in the `tests/env` folder of the files_external app.
+
+### Naming Conventions
+
+The current implementation supports a script that starts with `start-` for the
+setup step which is executed before the PHPUnit run and an optional script
+starting with `stop-` (and have the same ending as the start script) to cleanup
+the provider. For example: `start-webdav-ownCloud.sh` and
+`stop-webdav-ownCloud.sh`. As a second requirement after this prefix there has
+to be the name of the backend test suite. In the above example the test suite
+`tests/backends/webdav.php` is used. The last part is a name that can be chosen
+freely.
+
+## Hands-on way of unit test execution
+
+Run all files_external unit tests by invoking the following in the ownCloud
+core root folder:
+
+ ./autotest-external.sh
+
+This script supports to get passed a database as first argument:
+
+ ./autotest-external.sh sqlite
+
+You can also pass the name of the external file system provider as a second
+argument that should be executed. This is the name of the script without the
+prefix `start-` (or `stop-`) and without the extension `.sh` from the above
+mentioned components in `test/env`. So if you want to start the WebDAV backend
+tests against an ownCloud instance you can run following:
+
+ ./autotest-external.sh sqlite webdav-ownCloud
+
+This runs the script `start-webdav-ownCloud.sh` from the `tests/env` folder,
+then runs the unit test suite from `backends/webdav.php` (because the middle part of
+the name of the script is `webdav`) and finally tries to call
+`stop-webdav-ownCloud.sh` for cleanup purposes.
+
+## The more manual way of unit test execution
+
+If you want to debug your external storage provider, you maybe don't want to
+fire it up, execute the unit tests and clean everything up for each debugging
+step. In this case you can simply start the external storage provider instance
+and run the unit test multiple times against the instance for debugging purposes.
+To do this you just need to follow these steps (from within
+`apps/files_external/tests`):
+
+ 1. run the start step (`env/start-BACKEND-NAME.sh`) or start the environment by
+ hand (i.e. setting up an instance manually in a virtual box)
+ 2. run the unit tests with following command (you can repeat that step multiple times):
+ `phpunit --configuration ../../../tests/phpunit-autotest-external.xml backends/BACKEND.php`
+ 3. call the cleanup script (`env/stop-BACKEND-NAME.sh`) or cleanup by hand
diff --git a/apps/files_external/tests/backends/sftp_key.php b/apps/files_external/tests/backends/sftp_key.php
new file mode 100644
index 00000000000..4e55cc37ca3
--- /dev/null
+++ b/apps/files_external/tests/backends/sftp_key.php
@@ -0,0 +1,85 @@
+<?php
+
+/**
+ * ownCloud
+ *
+ * @author Henrik Kjölhede
+ * @copyright 2013 Henrik Kjölhede hkjolhede@gmail.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Test\Files\Storage;
+
+class SFTP_Key extends Storage {
+ private $config;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $id = $this->getUniqueID();
+ $this->config = include('files_external/tests/config.php');
+ if ( ! is_array($this->config) or ! isset($this->config['sftp_key']) or ! $this->config['sftp_key']['run']) {
+ $this->markTestSkipped('SFTP with key backend not configured');
+ }
+ $this->config['sftp_key']['root'] .= '/' . $id; //make sure we have an new empty folder to work in
+ $this->instance = new \OC\Files\Storage\SFTP_Key($this->config['sftp_key']);
+ $this->instance->mkdir('/');
+ }
+
+ protected function tearDown() {
+ if ($this->instance) {
+ $this->instance->rmdir('/');
+ }
+
+ parent::tearDown();
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testInvalidAddressShouldThrowException() {
+ # I'd use example.com for this, but someone decided to break the spec and make it resolve
+ $this->instance->assertHostAddressValid('notarealaddress...');
+ }
+
+ public function testValidAddressShouldPass() {
+ $this->assertTrue($this->instance->assertHostAddressValid('localhost'));
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testNegativePortNumberShouldThrowException() {
+ $this->instance->assertPortNumberValid('-1');
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testNonNumericalPortNumberShouldThrowException() {
+ $this->instance->assertPortNumberValid('a');
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testHighPortNumberShouldThrowException() {
+ $this->instance->assertPortNumberValid('65536');
+ }
+
+ public function testValidPortNumberShouldPass() {
+ $this->assertTrue($this->instance->assertPortNumberValid('22222'));
+ }
+}
diff --git a/apps/files_external/tests/config.php b/apps/files_external/tests/config.php
index 62aff4d1bc1..cf9cdfeead8 100644
--- a/apps/files_external/tests/config.php
+++ b/apps/files_external/tests/config.php
@@ -88,5 +88,13 @@ return array(
'user'=>'test',
'password'=>'test',
'root'=>'/test'
- )
+ ),
+ 'sftp_key' => array (
+ 'run'=>false,
+ 'host'=>'localhost',
+ 'user'=>'test',
+ 'public_key'=>'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDJPTvz3OLonF2KSGEKP/nd4CPmRYvemG2T4rIiNYjDj0U5y+2sKEWbjiUlQl2bsqYuVoJ+/UNJlGQbbZ08kQirFeo1GoWBzqioaTjUJfbLN6TzVVKXxR9YIVmH7Ajg2iEeGCndGgbmnPfj+kF9TR9IH8vMVvtubQwf7uEwB0ALhw== phpseclib-generated-key',
+ 'private_key'=>'test',
+ 'root'=>'/test'
+ ),
);