SMB/CIFS mount using OwnCloud logon credentials
Selecting 'SMB/CIFS Auto' in the mounts configuration allows an SMB/CIFS mount to be configured that uses the credentials of the user logging in to authenticate to the server. Optionally, the username can be used as the share name, permitting home shares to be dynamically mounted.
This commit is contained in:
parent
b656c68ede
commit
ba63e46b5e
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
|
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
|
||||||
|
* Copyright (c) 2014 Robin McCorkell <rmccorkell@karoshi.org.uk>
|
||||||
* This file is licensed under the Affero General Public License version 3 or
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
* later.
|
* later.
|
||||||
* See the COPYING-README file.
|
* See the COPYING-README file.
|
||||||
|
@ -13,6 +14,7 @@ OC::$CLASSPATH['OC\Files\Storage\OwnCloud'] = 'files_external/lib/owncloud.php';
|
||||||
OC::$CLASSPATH['OC\Files\Storage\Google'] = 'files_external/lib/google.php';
|
OC::$CLASSPATH['OC\Files\Storage\Google'] = 'files_external/lib/google.php';
|
||||||
OC::$CLASSPATH['OC\Files\Storage\Swift'] = 'files_external/lib/swift.php';
|
OC::$CLASSPATH['OC\Files\Storage\Swift'] = 'files_external/lib/swift.php';
|
||||||
OC::$CLASSPATH['OC\Files\Storage\SMB'] = 'files_external/lib/smb.php';
|
OC::$CLASSPATH['OC\Files\Storage\SMB'] = 'files_external/lib/smb.php';
|
||||||
|
OC::$CLASSPATH['OC\Files\Storage\SMB_Auto'] = 'files_external/lib/smb_auto.php';
|
||||||
OC::$CLASSPATH['OC\Files\Storage\AmazonS3'] = 'files_external/lib/amazons3.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\Dropbox'] = 'files_external/lib/dropbox.php';
|
||||||
OC::$CLASSPATH['OC\Files\Storage\SFTP'] = 'files_external/lib/sftp.php';
|
OC::$CLASSPATH['OC\Files\Storage\SFTP'] = 'files_external/lib/sftp.php';
|
||||||
|
@ -27,4 +29,5 @@ if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == '
|
||||||
// connecting hooks
|
// connecting hooks
|
||||||
OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook');
|
OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook');
|
||||||
OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\iRODS', 'login');
|
OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\iRODS', 'login');
|
||||||
|
OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_Auto', 'login');
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
* @author Michael Gapczynski
|
* @author Michael Gapczynski
|
||||||
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
|
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
|
||||||
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
|
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
|
||||||
|
* @copyright 2014 Robin McCorkell <rmccorkell@karoshi.org.uk>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
@ -122,6 +123,13 @@ class OC_Mount_Config {
|
||||||
'password' => '*Password',
|
'password' => '*Password',
|
||||||
'share' => 'Share',
|
'share' => 'Share',
|
||||||
'root' => '&Root'));
|
'root' => '&Root'));
|
||||||
|
$backends['\OC\Files\Storage\SMB_Auto'] = array(
|
||||||
|
'backend' => 'SMB / CIFS Auto',
|
||||||
|
'configuration' => array(
|
||||||
|
'host' => 'URL',
|
||||||
|
'username_as_share' => '!Username as share',
|
||||||
|
'share' => '&Share',
|
||||||
|
'root' => '&Root'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2014 Robin McCorkell <rmccorkell@karoshi.org.uk>
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OC\Files\Storage;
|
||||||
|
|
||||||
|
class SMB_Auto extends \OC\Files\Storage\SMB{
|
||||||
|
public function __construct($params) {
|
||||||
|
if (isset($params['host']) && \OC::$session->exists('smb-credentials')) {
|
||||||
|
$host=$params['host'];
|
||||||
|
$username_as_share = ($params['username_as_share'] === 'true');
|
||||||
|
|
||||||
|
$params_auth = \OC::$session->get('smb-credentials');
|
||||||
|
$user = \OC_User::getDisplayName($params_auth['uid']);
|
||||||
|
$password = $params_auth['password'];
|
||||||
|
|
||||||
|
$root=isset($params['root'])?$params['root']:'/';
|
||||||
|
$share = '';
|
||||||
|
|
||||||
|
if ($username_as_share) {
|
||||||
|
$share = '/'.$user;
|
||||||
|
} elseif (isset($params['share'])) {
|
||||||
|
$share = $params['share'];
|
||||||
|
} else {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
parent::__construct(array(
|
||||||
|
"user" => $user,
|
||||||
|
"password" => $password,
|
||||||
|
"host" => $host,
|
||||||
|
"share" => $share,
|
||||||
|
"root" => $root
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function login( $params ) {
|
||||||
|
\OC::$session->set('smb-credentials', $params);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue