From 56f317030e755c59ae7397d6d142075f94ca400b Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 25 Jun 2012 14:25:48 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3proftp=E7=B1=BB=E5=B9=B6?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=AE=9E=E6=97=B6FTP=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DownController.php | 8 +++-- application/models/Proftp.php | 32 ++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/application/admin/controllers/DownController.php b/application/admin/controllers/DownController.php index 388b904f..be450f63 100644 --- a/application/admin/controllers/DownController.php +++ b/application/admin/controllers/DownController.php @@ -370,8 +370,8 @@ class Admin_DownController extends Zend_Controller_Action $rs=$this->db->fetchAll($sql,array($finish)); $has_ftp1=false; foreach($rs as $data) { - if ($data['host']=='ftp1.westgis.ac.cn') - $has_ftp1=true; + if ($data['host']=='ftp1.westgis.ac.cn') + $has_ftp1=true; // deal with ftp.westgis.ac.cn, use g6 to add path // todo ... } @@ -381,7 +381,9 @@ class Admin_DownController extends Zend_Controller_Action "username"=>"westdc_".$row['userid'], "password"=>md5('westdc'.$row['userid'].rand(1000,9999)), "time"=>date('Y-m-d H:i:s', strtotime('+2 week')), - //"path"=>$path, + //"path"=>$path, + "param"=>"offlineappid=".$finish, + "host"=>'ftp1.westgis.ac.cn', "maxdata"=>$this->view->config->download->max, "datacount"=>1 //represent one offline application ); diff --git a/application/models/Proftp.php b/application/models/Proftp.php index efc04392..ee7e65eb 100644 --- a/application/models/Proftp.php +++ b/application/models/Proftp.php @@ -7,7 +7,29 @@ class Proftp function __construct() { } + + // deal with online & offline user + // online user, $user->param is 'onlineappid=xx', xx is number + // offline user, $user->param is 'offlineid=xx', xx is number function createuser($user) + { + $this->insert_user($user); + //处理FTP用户目录 + if (!empty($user->host)) + { + //vist $user->host web + $page=file_get_contents('http://'.$user->host.'/proftp.php?'.$user->param); + if (!empty($page) die($page);//there are errors in visit ftp page + } + return $this->update_pwd($user); + } + + /* + * insert user into pureftp table + * param $user: username, + * return null + */ + private function insert_user($user) { //只插入到users表中 $sql=$this->db->quoteInto("select * from proftpusers where userid=?",$user->username); @@ -19,6 +41,14 @@ class Proftp $sql="insert into proftpusers (userid,passwd,uid,gid,homedir) values('".$user->username."','".$user->password."',109,1002,'".'/home/ftp/'.$user->username."')"; $this->db->query($sql); } + } + /* + * update password in the table used by pureftp + * param $user: password,id,time,username + * return: bool + */ + private function update_pwd($user) + { $this->pwd=$user->password;//初始化 $this->time=$user->time; //判断用户密码是否失效,或用户一次下载数据已经达到上限 @@ -49,7 +79,7 @@ class Proftp $this->time=$u['ts_invalid']; return true; } else //同时下载数据数超过限制 - return false; + return false; } } ?> \ No newline at end of file