summaryrefslogtreecommitdiffstats
path: root/apps/user_external
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-07-19 23:03:02 +0200
committerRobin Appelman <icewind@owncloud.com>2012-07-19 23:03:02 +0200
commitad14d67c8dee81a343ff31fe6e510c588abbf46b (patch)
tree6dd5a57a8c479f7f2bf29e7e6c29ff3d725bc994 /apps/user_external
parentb357a968c07bdfe888c469ff261baff8f8ed4d51 (diff)
downloadnextcloud-server-ad14d67c8dee81a343ff31fe6e510c588abbf46b.tar.gz
nextcloud-server-ad14d67c8dee81a343ff31fe6e510c588abbf46b.zip
ftp user backend
Diffstat (limited to 'apps/user_external')
-rw-r--r--apps/user_external/appinfo/app.php1
-rw-r--r--apps/user_external/lib/ftp.php45
-rw-r--r--apps/user_external/tests/config.php8
-rw-r--r--apps/user_external/tests/ftp.php34
4 files changed, 87 insertions, 1 deletions
diff --git a/apps/user_external/appinfo/app.php b/apps/user_external/appinfo/app.php
index 66320da95bc..c7408ec30d9 100644
--- a/apps/user_external/appinfo/app.php
+++ b/apps/user_external/appinfo/app.php
@@ -1,3 +1,4 @@
<?php
OC::$CLASSPATH['OC_User_IMAP']='apps/user_external/lib/imap.php';
OC::$CLASSPATH['OC_User_SMB']='apps/user_external/lib/smb.php';
+OC::$CLASSPATH['OC_User_FTP']='apps/user_external/lib/ftp.php';
diff --git a/apps/user_external/lib/ftp.php b/apps/user_external/lib/ftp.php
new file mode 100644
index 00000000000..e03e17d2b6a
--- /dev/null
+++ b/apps/user_external/lib/ftp.php
@@ -0,0 +1,45 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class OC_User_FTP extends OC_User_Backend{
+ private $host;
+ private $secure;
+ private $protocol;
+
+ public function __construct($host,$secure=false){
+ $this->host=$host;
+ $this->secure=$secure;
+ $this->protocol='ftp';
+ if($this->secure){
+ $this->protocol.='s';
+ }
+ $this->protocol.='://';
+ }
+
+ /**
+ * @brief Check if the password is correct
+ * @param $uid The username
+ * @param $password The password
+ * @returns true/false
+ *
+ * Check if the password is correct without logging in the user
+ */
+ public function checkPassword($uid, $password){
+ $url=$this->protocol.$uid.':'.$password.'@'.$this->host.'/';
+ $result=@opendir($url);
+ if(is_resource($result)){
+ return $uid;
+ }else{
+ return false;
+ }
+ }
+
+ public function userExists($uid){
+ return true;
+ }
+}
diff --git a/apps/user_external/tests/config.php b/apps/user_external/tests/config.php
index a72b2bbce80..64ee141d32d 100644
--- a/apps/user_external/tests/config.php
+++ b/apps/user_external/tests/config.php
@@ -14,7 +14,13 @@ return array(
'password'=>'bar',
),
'smb'=>array(
- 'run'=>true,
+ 'run'=>false,
+ 'host'=>'localhost',
+ 'user'=>'test',//valid username/password combination
+ 'password'=>'test',
+ ),
+ 'ftp'=>array(
+ 'run'=>false,
'host'=>'localhost',
'user'=>'test',//valid username/password combination
'password'=>'test',
diff --git a/apps/user_external/tests/ftp.php b/apps/user_external/tests/ftp.php
new file mode 100644
index 00000000000..0cf7565f9c6
--- /dev/null
+++ b/apps/user_external/tests/ftp.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_User_FTP extends UnitTestCase{
+ /**
+ * @var OC_User_IMAP $instance
+ */
+ private $instance;
+
+ private function getConfig(){
+ return include(__DIR__.'/config.php');
+ }
+
+ function skip(){
+ $config=$this->getConfig();
+ $this->skipUnless($config['ftp']['run']);
+ }
+
+ function setUp(){
+ $config=$this->getConfig();
+ $this->instance=new OC_User_FTP($config['ftp']['host']);
+ }
+
+ function testLogin(){
+ $config=$this->getConfig();
+ $this->assertEqual($config['ftp']['user'],$this->instance->checkPassword($config['ftp']['user'],$config['ftp']['password']));
+ $this->assertFalse($this->instance->checkPassword($config['ftp']['user'],$config['ftp']['password'].'foo'));
+ }
+}