add proftp create user class

This commit is contained in:
wlx 2010-11-06 09:41:02 +00:00
parent 4508a97b12
commit fb2e7c3008
1 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,58 @@
<?php
class Proftp
{
public $db;
public $pwd;
public $time;
function __construct()
{
}
function createuser($user)
{
//只插入到users表中
$sql=$this->db->quoteInto("select * from proftpusers where userid=?",$user->username);
$u=$this->db->fetchRow($sql);
if (empty($u))
{
$sql=$this->db->quoteInto("insert into proftpusers (userid,passwd,uid,gid,homedir) values(?,?,109,1002,?)",$user->username,$user->userpass,'/home/ftp/'.$user->username);
$this->db->query($sql);
$sql=$this->db->quoteInto("select pkid from proftpusers where userid=?",$user->username);
$a=$this->db->fetchRow($sql);
$userid = $a['pkid'];
} else $userid=$u['id'];//g6ftp中的用户ID非系统的用户ID
$this->pwd=$user->password;//初始化
$this->time=$user->time;
//判断用户密码是否失效,或用户一次下载数据已经达到上限
$sql=$this->db->quoteInto("select * from ftpuser where userid=?",$user->id);
$u=$this->db->fetchRow($sql);
if (empty($u)) {
//插入ftpuser信息
$sql="insert into ftpuser (userid,pwd,ts_created,ts_invalid,datacount) values(?,?,now(),?,1)";
$this->db->query($sql,array($user->id,$user->password,$user->time));
//todo: create users home directory
return true;
} elseif (strtotime($u['ts_invalid'])<=time() or $u['datacount']<1) {
//更新用户密码、数据地址和数据计数
//数据地址覆盖原来的信息
//todo: 重置用户目录下的可用文件/目录。
$sql=$this->db->quoteInto("update proftpusers set passwd=? where userid=?",$user->password,$user->username);
$this->db->query($sql);
$sql="update ftpuser set pwd=?,ts_created=now(),ts_invalid=?,datacount=1 where userid=?";
$this->db->query($sql,array($user->password,$user->time,$user->id));
return true;
} elseif (strtotime($u['ts_invalid'])>time() && $u['datacount']<$user->maxdata) {
//更新数据地址和数据计数
//数据地址要追加在原来的后面
//需要判断数据是否已经在下载进程中
$sql="update ftpuser set ts_invalid=?,datacount=? where userid=?";
$this->db->query($sql,array($user->time,$user->datacount+1,$user->id));
$sql="select pwd,ts_invalid from ftpuser where userid=?";
$u=$this->db->fetchRow($sql,array($user->id));
$this->pwd=$u['pwd'];
$this->time=$u['ts_invalid'];
return true;
} else //同时下载数据数超过限制
return false;
}
}
?>