58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
|
<?php
|
||
|
class Proftp
|
||
|
{
|
||
|
public $db;
|
||
|
public $pwd;
|
||
|
public $time;
|
||
|
function __construct()
|
||
|
{
|
||
|
}
|
||
|
function createuser($user)
|
||
|
{
|
||
|
//插入到pureftp表中
|
||
|
$sql=$this->db->quoteInto("select * from pureftp where userid=?",$user->username);
|
||
|
$u=$this->db->fetchRow($sql);
|
||
|
if (empty($u))
|
||
|
{
|
||
|
$sql="insert into pureftp (userid,passwd,homedir) values('".$user->username."','".$user->password."','".'/home/ftp/'.$user->username."')";
|
||
|
$this->db->query($sql);
|
||
|
//create user home dir
|
||
|
mkdir('/home/ftp/'.$user->username);
|
||
|
}
|
||
|
// add system link directory
|
||
|
symlink('/home/wlx/qhhdata'.$user->path,'/home/ftp/'.$user->username.$user->path);
|
||
|
|
||
|
$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));
|
||
|
return true;
|
||
|
} elseif (strtotime($u['ts_invalid'])<=time() or $u['datacount']<1) {
|
||
|
//更新用户密码和数据计数
|
||
|
$sql="update pureftp set passwd='".$user->password."' where userid='".$user->username."'";
|
||
|
//$this->db->query($sql,array($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*/) {
|
||
|
//更新数据计数
|
||
|
//同步ftpuser和pureftp用户密码
|
||
|
$sql="update ftpuser set ts_invalid=?,datacount=datacount+?,pwd=pureftp.passwd
|
||
|
from pureftp where ftpuser.userid=? and pureftp.userid=?";
|
||
|
$this->db->query($sql,array($user->time,$user->datacount,$user->id,$user->username));
|
||
|
$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;
|
||
|
}
|
||
|
}
|
||
|
?>
|