From 07fddff440bcbde0da298ae6d704794c300fb943 Mon Sep 17 00:00:00 2001 From: Jonas Sulzer Date: Wed, 22 May 2019 20:17:06 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20thanks=20to=20@DavieD?= =?UTF-8?q?avieDave=20(nextcloud/apps#56):=20SSH=20password=20authenticati?= =?UTF-8?q?on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Sulzer --- README.md | 22 +++++++++++++++++++++ appinfo/app.php | 1 + lib/ssh.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 lib/ssh.php diff --git a/README.md b/README.md index 38f477f..98ffa07 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,28 @@ Add the following to your `config.php`: [BasicAuth_0]: https://en.wikipedia.org/wiki/Basic_access_authentication +SSH +--- + +Authenticates users via SSH. You can use any SSH2 server, but it must accept password authentication. + +### Configuration +The only supported parameter is the hostname of the remote machine. + +Add the following to your `config.php`: + + 'user_backends' => array( + array( + 'class' => 'OC_User_SSH', + 'arguments' => array('127.0.0.1'), + ), + ), + + +### Dependencies +Requires the php-ssh2 PECL module installed. + + XMPP (Prosody) ---- Authenticate Nextcloud users against a Prosody XMPP MySQL database. diff --git a/appinfo/app.php b/appinfo/app.php index c5b2519..6c3b095 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -3,4 +3,5 @@ OC::$CLASSPATH['OC_User_IMAP']='user_external/lib/imap.php'; OC::$CLASSPATH['OC_User_SMB']='user_external/lib/smb.php'; OC::$CLASSPATH['OC_User_FTP']='user_external/lib/ftp.php'; OC::$CLASSPATH['OC_User_BasicAuth']='user_external/lib/basicauth.php'; +OC::$CLASSPATH['OC_User_SSH']='user_external/lib/ssh.php'; OC::$CLASSPATH['OC_User_XMPP']='user_external/lib/xmpp.php'; diff --git a/lib/ssh.php b/lib/ssh.php new file mode 100644 index 0000000..ae575ba --- /dev/null +++ b/lib/ssh.php @@ -0,0 +1,51 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +/** + * User authentication against a FTP/FTPS server + * + * @category Apps + * @package UserExternal + * @author David Fullard + * @license http://www.gnu.org/licenses/agpl AGPL + * @link http://github.com/owncloud/apps + */ + + +class OC_User_SSH extends \OCA\user_external\Base { + private $host; + + /** + * Create a new SSH authentication provider + * + * @param string $host Hostname or IP address of SSH servr + */ + public function __construct($host) { + parent::__construct($host); + $this->host =$host; + } + + /** + * Check if the password is correct without logging in + * Requires the php-ssh2 pecl extension + * + * @param string $uid The username + * @param string $password The password + * + * @return true/false + */ + public function checkPassword($uid, $password) { + $connection = ssh2_connect($this->host); + if (ssh2_auth_password($connection, $uid, $password)) { + $this->storeUser($uid); + return $uid; + } else { + return false; + } + } +} From 8e1261004ce399d72b078d44f8899a7d93fcec7f Mon Sep 17 00:00:00 2001 From: Jonas Sulzer Date: Wed, 22 May 2019 20:49:00 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20add=20SSH=20port?= =?UTF-8?q?=20as=20possible=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Sulzer --- README.md | 4 ++-- lib/ssh.php | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 98ffa07..4d11c1b 100644 --- a/README.md +++ b/README.md @@ -156,14 +156,14 @@ SSH Authenticates users via SSH. You can use any SSH2 server, but it must accept password authentication. ### Configuration -The only supported parameter is the hostname of the remote machine. +The supported parameters are the hostname and the port (default `22`) of the remote machine. Add the following to your `config.php`: 'user_backends' => array( array( 'class' => 'OC_User_SSH', - 'arguments' => array('127.0.0.1'), + 'arguments' => array('127.0.0.1', '22'), ), ), diff --git a/lib/ssh.php b/lib/ssh.php index ae575ba..6948645 100644 --- a/lib/ssh.php +++ b/lib/ssh.php @@ -16,18 +16,20 @@ * @link http://github.com/owncloud/apps */ - + class OC_User_SSH extends \OCA\user_external\Base { private $host; + private $port; /** * Create a new SSH authentication provider * * @param string $host Hostname or IP address of SSH servr */ - public function __construct($host) { + public function __construct($host, $port = 22) { parent::__construct($host); - $this->host =$host; + $this->host = $host; + $this->port = $port; } /** @@ -40,7 +42,7 @@ class OC_User_SSH extends \OCA\user_external\Base { * @return true/false */ public function checkPassword($uid, $password) { - $connection = ssh2_connect($this->host); + $connection = ssh2_connect($this->host, $this->port); if (ssh2_auth_password($connection, $uid, $password)) { $this->storeUser($uid); return $uid; From 1d2a662669d3530ae289d6a5133ec182f99c7d7c Mon Sep 17 00:00:00 2001 From: Jonas Sulzer Date: Wed, 22 May 2019 20:50:47 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=85=20TEST:=20check=20if=20ssh2=20mod?= =?UTF-8?q?ule=20is=20installed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Sulzer --- lib/ssh.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ssh.php b/lib/ssh.php index 6948645..14e771f 100644 --- a/lib/ssh.php +++ b/lib/ssh.php @@ -42,6 +42,13 @@ class OC_User_SSH extends \OCA\user_external\Base { * @return true/false */ public function checkPassword($uid, $password) { + if (!extension_loaded('ssh2')) { + OC::$server->getLogger()->error( + 'ERROR: php-ssh2 PECL module missing', + ['app' => 'user_external'] + ); + return false; + } $connection = ssh2_connect($this->host, $this->port); if (ssh2_auth_password($connection, $uid, $password)) { $this->storeUser($uid); From e7b9800df8c0f182e1a76a95f6f131bbf96bebf6 Mon Sep 17 00:00:00 2001 From: Jonas Sulzer Date: Wed, 22 May 2019 21:13:18 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20spaces/tabs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Sulzer --- lib/ssh.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/ssh.php b/lib/ssh.php index 14e771f..617c4fe 100644 --- a/lib/ssh.php +++ b/lib/ssh.php @@ -22,33 +22,33 @@ class OC_User_SSH extends \OCA\user_external\Base { private $port; /** - * Create a new SSH authentication provider - * - * @param string $host Hostname or IP address of SSH servr - */ + * Create a new SSH authentication provider + * + * @param string $host Hostname or IP address of SSH servr + */ public function __construct($host, $port = 22) { parent::__construct($host); $this->host = $host; - $this->port = $port; + $this->port = $port; } /** - * Check if the password is correct without logging in - * Requires the php-ssh2 pecl extension - * - * @param string $uid The username - * @param string $password The password - * - * @return true/false - */ + * Check if the password is correct without logging in + * Requires the php-ssh2 pecl extension + * + * @param string $uid The username + * @param string $password The password + * + * @return true/false + */ public function checkPassword($uid, $password) { - if (!extension_loaded('ssh2')) { - OC::$server->getLogger()->error( - 'ERROR: php-ssh2 PECL module missing', - ['app' => 'user_external'] - ); - return false; - } + if (!extension_loaded('ssh2')) { + OC::$server->getLogger()->error( + 'ERROR: php-ssh2 PECL module missing', + ['app' => 'user_external'] + ); + return false; + } $connection = ssh2_connect($this->host, $this->port); if (ssh2_auth_password($connection, $uid, $password)) { $this->storeUser($uid);