add ftp2 support

This commit is contained in:
wlx 2013-05-26 03:58:38 +00:00
parent 9938873d23
commit 3ca45e3618
4 changed files with 185 additions and 160 deletions

View File

@ -397,17 +397,24 @@ class Admin_DownController extends Zend_Controller_Action
$sql="select * from dataorder left join dataset on dataset.uuid=dataorder.uuid where dataorder.offlineappid=?"; $sql="select * from dataorder left join dataset on dataset.uuid=dataorder.uuid where dataorder.offlineappid=?";
$rs=$this->db->fetchAll($sql,array($finish)); $rs=$this->db->fetchAll($sql,array($finish));
$has_ftp1=false; $has_ftp1=false;
$has_ftp2=false;
foreach($rs as $data) { foreach($rs as $data) {
if ($data['host']=='ftp1.westgis.ac.cn') if ($data['host']=='ftp1.westgis.ac.cn')
$has_ftp1=true; $has_ftp1=true;
if ($data['host']=='ftp2.westgis.ac.cn')
$has_ftp2=true;
// deal with ftp.westgis.ac.cn, use g6 to add path // deal with ftp.westgis.ac.cn, use g6 to add path
// todo ... // todo ...
} }
//deal with ftp1 account //deal with ftp1&ftp2 account, for offline data
if ($has_ftp1) { if ($has_ftp1 || $has_ftp2) {
$password=md5('westdc'.$row['userid'].rand(1000,9999));
if ($has_ftp1)
{
$user=(object)array("id"=>$row['userid'], $user=(object)array("id"=>$row['userid'],
"username"=>"westdc_".$row['userid'], "username"=>"westdc_".$row['userid'],
"password"=>md5('westdc'.$row['userid'].rand(1000,9999)), "password"=>$password,
"time"=>date('Y-m-d H:i:s', strtotime('+2 week')), "time"=>date('Y-m-d H:i:s', strtotime('+2 week')),
//"path"=>$path, //"path"=>$path,
"param"=>"offlineappid=".$finish, "param"=>"offlineappid=".$finish,
@ -429,19 +436,56 @@ class Admin_DownController extends Zend_Controller_Action
return true; return true;
//$this->messenger->addMessage('提示信息:该用户申请的数据过多,请检查该用户之前已完成的申请。'); //$this->messenger->addMessage('提示信息:该用户申请的数据过多,请检查该用户之前已完成的申请。');
} }
}
if ($has_ftp2)
{
$user=(object)array("id"=>$row['userid'],
"username"=>"westdc_".$row['userid'],
"password"=>$password,
"time"=>date('Y-m-d H:i:s', strtotime('+2 week')),
//"path"=>$path,
"param"=>"offlineappid=".$finish,
"host"=>'ftp2.westgis.ac.cn',
"maxdata"=>$this->view->config->download->max,
"datacount"=>1 //represent one offline application
);
$proftp=new Pureftp();
$proftp->db=$this->db;
if (!$proftp->createuser($user))
{
$user->datacount=0; //force this offline to be true
$proftp->createuser($user);
$data = array(
'error' => "该用户申请的数据过多,请检查该用户之前已完成的申请",
);
$this->jsonexit($data);
return true;
}
}
if ($has_ftp1 && !$has_ftp2)
{
$ftphost='ftp://ftp1.westgis.ac.cn';
} else if (!$has_ftp1 && $has_ftp2)
{
$ftphost='ftp://ftp2.westgis.ac.cn';
} else if ($has_ftp1 && $has_ftp2)
{
$ftphost='ftp://ftp1.westgis.ac.cn 以及 ftp://ftp2.westgis.ac.cn';
}
//发送用户邮件进行信息提示和说明 //发送用户邮件进行信息提示和说明
$mail = new WestdcMailer($this->view->config->smtp); $mail = new WestdcMailer($this->view->config->smtp);
//实例化EmailText //实例化EmailText
$mailtp=new EmailText($this->db,'offline-finish', $mailtp=new EmailText($this->db,'offline-finish',
array('user'=>$row['username'],'datalist'=>str_replace(";","\n",$row['datalist']), array('user'=>$row['username'],'datalist'=>str_replace(";","\n",$row['datalist']),
'ftpuser'=>$user->username,'ftppwd'=>$proftp->pwd,'ftptime'=>$proftp->time)); 'ftpuser'=>$user->username,'ftppwd'=>$proftp->pwd,'ftptime'=>$proftp->time,'ftphost'=>$ftphost));
$mail->setBodyText($mailtp->getBody()); $mail->setBodyText($mailtp->getBody());
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); $mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mail->addTo($row['email']); $mail->addTo($row['email']);
$mail->addCc($this->view->config->service->email,'西部数据中心服务组'); $mail->addCc($this->view->config->service->email,'西部数据中心服务组');
$mail->setSubject($mailtp->getSubject()); $mail->setSubject($mailtp->getSubject());
$mail->send(); $mail->send();
} //ftp1 deal } //offline deal
//$this->messenger->addMessage('提示信息:该离线数据已经处理完成。'); //$this->messenger->addMessage('提示信息:该离线数据已经处理完成。');
$data = array( $data = array(

View File

@ -1323,54 +1323,23 @@ class DataController extends Zend_Controller_Action
} }
} }
$this->view->username='westdc'.Zend_Auth::getInstance()->getIdentity()->id;
$sql=$this->db->quoteInto("select o.* from onlineresource o left join metadata m on o.uuid=m.uuid where m.datatype=0 and m.uuid=?",$uuid); $sql=$this->db->quoteInto("select * from dataset o left join metadata m on o.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>4 and m.datatype=0 and m.uuid=?",$uuid);
$rows=$this->db->fetchAll($sql); $data=$this->db->fetchRow($sql);
$updateftp=$updateftp1=false; $updateftp=$updateftp1=false;
$sql=$this->db->quoteInto("select * from metadata where uuid=?",$uuid); $this->view->md=$data;
$this->view->md=$this->db->fetchRow($sql);
$bigfile=($this->view->md['filesize']>5);
$this->view->userpass=md5('westdc'.rand(1000,9999)); $this->view->userpass=md5('westdc'.rand(1000,9999));
$this->view->ftptime=date('Y-m-d H:i:s', strtotime('+1 week')); $this->view->ftptime=date('Y-m-d H:i:s', strtotime('+1 week'));
$sql=$this->db->quoteInto("select * from ftpuser where userid=?",$userid);
$row=$this->db->fetchRow($sql);
$datacount=$row['datacount']; $datacount=$row['datacount'];
foreach ($rows as $row) { if ($data['host']=='ftp.westgis.ac.cn')
$url=$row['linkage'];
$p=parse_url($url);
if ($p['scheme']=='ftp')
//if ($row['protocol']=="WWW:DOWNLOAD-1.0-ftp--download")
{ {
//判断FTP URL是否附带了用户名和密码 //添加FTP帐号信息以及时间控制信息
if ($p['host']=='ftp.westgis.ac.cn')
$url='ftp://'.$this->view->config->ftp->user.':'.$this->view->config->ftp->password.'@ftp.westgis.ac.cn'.$p['path'];
/*if (!$bigfile &&is_file($url) && file_exists($url))
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$content=file_get_contents($url);
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
->setHeader('Content-Disposition','attachment; filename="'.basename($url).'"')
->setHeader('Content-Length', strlen($content))
->setHeader('Content-Type','application/force-download')
->setHeader('Content-Type','application/download')
->setHeader('Content-Description','File Transfer')
->setHeader('Content-Transfer-Encoding','binary')
->setHeader('Expires',0)
->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0')
->setHeader('Pragma','public')
->setBody($content);
} else */{
//是一个FTP返回用户名称和密码说明
if ($p['host']=='ftp.westgis.ac.cn')
{
//添加FTP帐号信息以及时间控制信息只更新一次
$updateftp=true; $updateftp=true;
$g6=new G6ftp(); $g6=new G6ftp();
$g6->db=$this->db; $g6->db=$this->db;
//不进行判断,每个元数据中的下载地址都对应一个虚拟路径 //不进行判断,每个元数据中的下载地址都对应一个虚拟路径
//if (is_file($url)) $path=dirname($p['path']); else $path[]=$p['path']; $path[]=$data['path'];
$path[]=$p['path']; $this->view->username='westdc'.$userid;
$uu=(object)array("id"=>$userid, $uu=(object)array("id"=>$userid,
"username"=>$this->view->username, "username"=>$this->view->username,
"password"=>$this->view->userpass, "password"=>$this->view->userpass,
@ -1385,14 +1354,13 @@ class DataController extends Zend_Controller_Action
$this->messenger->addMessage('错误:您正在进行下载的在线数据数已经超过系统允许的最大值,请在下面点击“完成”或“取消”对应的在线数据下载!'); $this->messenger->addMessage('错误:您正在进行下载的在线数据数已经超过系统允许的最大值,请在下面点击“完成”或“取消”对应的在线数据下载!');
$this->_redirect('/data/order'); $this->_redirect('/data/order');
} }
} elseif (!$updateftp1 && $p['host']=='ftp1.westgis.ac.cn') } elseif ($data['host']=='ftp1.westgis.ac.cn')
{ {
//添加FTP1帐号信息以及时间控制信息只更新一次 //添加FTP1帐号信息以及时间控制信息
$updateftp1=true;
$proftp=new Proftp(); $proftp=new Proftp();
$proftp->db=$this->db; $proftp->db=$this->db;
//proftp离线用户名和g6的用户名稍有不同 //proftp离线用户名和g6的用户名稍有不同
$this->view->username='westdc_'.Zend_Auth::getInstance()->getIdentity()->id; $this->view->username='westdc_'.$userid;
$uu=(object)array("id"=>$userid, $uu=(object)array("id"=>$userid,
"username"=>$this->view->username, "username"=>$this->view->username,
"password"=>$this->view->userpass, "password"=>$this->view->userpass,
@ -1406,25 +1374,31 @@ class DataController extends Zend_Controller_Action
$this->view->userpass=$proftp->pwd; $this->view->userpass=$proftp->pwd;
$this->view->ftptime=$proftp->time; $this->view->ftptime=$proftp->time;
} }
} } elseif ($data['host']=='ftp2.westgis.ac.cn')
if ($p['host']=='ftp.westgis.ac.cn')
{ {
//更新URL //添加FTP2帐号信息以及时间控制信息
$ftpurls[]='ftp://'.$this->view->username.'@ftp.westgis.ac.cn'.$p['path']; $proftp=new Pureftp();
} elseif ($p['host']=='ftp1.westgis.ac.cn') $proftp->db=$this->db;
$ftpurls[]='ftp://ftp1.westgis.ac.cn'.$p['path']; $this->view->username='westdc_'.$userid;
else $uu=(object)array("id"=>$userid,
$ftpurls[]=$url; "username"=>$this->view->username,
} "password"=>$this->view->userpass,
} else { "host"=>'ftp2.westgis.ac.cn',
//若不清楚协议,只是列出来? "param"=>"onlineappid=".$onlineappid,
$links[]=$row; "maxdata"=>$this->view->config->download->max,
"time"=>$this->view->ftptime,
"datacount"=>$datacount);
if ($proftp->createuser($uu))
{
$this->view->userpass=$proftp->pwd;
$this->view->ftptime=$proftp->time;
} }
} }
$ftpurl='ftp://'.$this->view->username.'@'.$data['host'].$data['path'];
//设置输出 //设置输出
//if ($updateftp || $updateftp1) $this->view->userpass=$password; //if ($updateftp || $updateftp1) $this->view->userpass=$password;
@$this->view->ftpurls=$ftpurls; $this->view->ftpurls=$ftpurl;
@$this->view->links=$links;
//更新下载记录 //更新下载记录
//todo: 尝试添加一个RULE若有对应数据存在则不插入 userid,uuid,status=0,ts_approved:null) //todo: 尝试添加一个RULE若有对应数据存在则不插入 userid,uuid,status=0,ts_approved:null)
/*$sql="select * from dataorder where userid=? and uuid=? and status=0 and (ts_approved is null)"; /*$sql="select * from dataorder where userid=? and uuid=? and status=0 and (ts_approved is null)";
@ -1433,7 +1407,7 @@ class DataController extends Zend_Controller_Action
$sql="insert into dataorder (userid,uuid,ts_created) values(?,?,now())"; $sql="insert into dataorder (userid,uuid,ts_created) values(?,?,now())";
$this->db->query($sql,array($userid,$uuid)); $this->db->query($sql,array($userid,$uuid));
}*/ }*/
if (!empty($ftpurls) && ($updateftp || $updateftp1) && !$has_send_mail) if (!empty($ftpurl) && !$has_send_mail)
{ {
$data = array( $data = array(
"uuid"=>$uuid, "uuid"=>$uuid,
@ -1442,7 +1416,7 @@ class DataController extends Zend_Controller_Action
"ftpuser"=>$this->view->username, "ftpuser"=>$this->view->username,
"ftppwd"=>$this->view->userpass, "ftppwd"=>$this->view->userpass,
"ftptime"=>$this->view->ftptime, "ftptime"=>$this->view->ftptime,
"ftpurl"=>$this->view->ftpurls[0], "ftpurl"=>$this->view->ftpurl,
"note"=>$updateftp?'BTW请注意登陆后要手工进入对应的目录':'' "note"=>$updateftp?'BTW请注意登陆后要手工进入对应的目录':''
); );
$mailtp=new EmailText($this->db,'online-download',$data); $mailtp=new EmailText($this->db,'online-download',$data);

View File

@ -3,11 +3,9 @@
$this->headTitle('我的账户'); $this->headTitle('我的账户');
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->theme->AppendPlus($this,'jquery'); $this->theme->AppendPlus($this,'jquery');
$this->theme->AppendPlus($this,'bootstarp');
$this->theme->AppendPlus($this,'colorbox'); $this->theme->AppendPlus($this,'colorbox');
?> ?>
<div class="container-fluid"> <div class="row">
<div class="row-fluid">
<div class="span3"> <div class="span3">
<div class="well sidebar-nav"> <div class="well sidebar-nav">
<?= $this->partial('account/left.phtml'); ?> <?= $this->partial('account/left.phtml'); ?>
@ -50,13 +48,13 @@
<div class="control-group "> <div class="control-group ">
<label class="control-label">工作单位</label> <label class="control-label">工作单位</label>
<div class="controls"> <div class="controls">
<input type="text" name="unit" value="<?php echo empty($this->info['unit']) ? "":$this->info['unit']; ?>" class="span8" /> <input type="text" name="unit" value="<?php echo empty($this->info['unit']) ? "":$this->info['unit']; ?>" />
</div> </div>
</div> </div>
<div class="control-group "> <div class="control-group ">
<label class="control-label">联系地址</label> <label class="control-label">联系地址</label>
<div class="controls"> <div class="controls">
<input type="text" name="address" value="<?php echo empty($this->info['address']) ? "":$this->info['address']; ?>" class="span8" /> <input type="text" name="address" value="<?php echo empty($this->info['address']) ? "":$this->info['address']; ?>" />
</div> </div>
</div> </div>
<div class="control-group "> <div class="control-group ">
@ -110,13 +108,13 @@
<div class="control-group "> <div class="control-group ">
<label class="control-label">项目名称</label> <label class="control-label">项目名称</label>
<div class="controls"> <div class="controls">
<input type="text" name="project_title" value="<?php echo empty($this->info['project_title']) ? "":$this->info['project_title']; ?>" class="span8" /> <input type="text" name="project_title" value="<?php echo empty($this->info['project_title']) ? "":$this->info['project_title']; ?>" />
</div> </div>
</div> </div>
<div class="control-group "> <div class="control-group ">
<label class="control-label">项目简介</label> <label class="control-label">数据用途</label>
<div class="controls"> <div class="controls">
<textarea name="project" class="span8"><?php echo empty($this->info['project']) ? "":$this->info['project']; ?></textarea> <textarea name="project"><?php echo empty($this->info['project']) ? "":$this->info['project']; ?></textarea>
</div> </div>
</div> </div>
<div class="control-group "> <div class="control-group ">
@ -146,4 +144,3 @@
<?php }?> <?php }?>
</div><!--/span--> </div><!--/span-->
</div><!--/row--> </div><!--/row-->
</div>

View File

@ -17,6 +17,8 @@ class Pureftp
{ {
$this->insert_user($user); $this->insert_user($user);
// add system link directory // add system link directory
// use for same web server & ftp server
/*
if (is_array($user->path)) if (is_array($user->path))
{ {
foreach ($user->path as $path) foreach ($user->path as $path)
@ -25,6 +27,14 @@ class Pureftp
//online path, only one path //online path, only one path
symlink($this->data_path.$user->path,'/home/ftp/'.$user->username.'/'.str_replace('/','-',substr($user->path,1))); symlink($this->data_path.$user->path,'/home/ftp/'.$user->username.'/'.str_replace('/','-',substr($user->path,1)));
} }
*/
//处理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); return $this->update_pwd($user);
} }