Skip to content
Snippets Groups Projects
Commit ad14d67c authored by Robin Appelman's avatar Robin Appelman
Browse files

ftp user backend

parent b357a968
No related branches found
No related tags found
No related merge requests found
<?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';
<?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;
}
}
......@@ -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',
......
<?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'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment