diff --git a/application/admin/controllers/DownController.php b/application/admin/controllers/DownController.php index 19c05140..393b8421 100644 --- a/application/admin/controllers/DownController.php +++ b/application/admin/controllers/DownController.php @@ -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=?"; $rs=$this->db->fetchAll($sql,array($finish)); $has_ftp1=false; + $has_ftp2=false; foreach($rs as $data) { if ($data['host']=='ftp1.westgis.ac.cn') $has_ftp1=true; + if ($data['host']=='ftp2.westgis.ac.cn') + $has_ftp2=true; + // deal with ftp.westgis.ac.cn, use g6 to add path // todo ... } - //deal with ftp1 account - if ($has_ftp1) { - $user=(object)array("id"=>$row['userid'], + //deal with ftp1&ftp2 account, for offline data + if ($has_ftp1 || $has_ftp2) { + $password=md5('westdc'.$row['userid'].rand(1000,9999)); + if ($has_ftp1) + { + $user=(object)array("id"=>$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')), //"path"=>$path, "param"=>"offlineappid=".$finish, @@ -415,33 +422,70 @@ class Admin_DownController extends Zend_Controller_Action "maxdata"=>$this->view->config->download->max, "datacount"=>1 //represent one offline application ); - $proftp=new Proftp(); - $proftp->db=$this->db; - if (!$proftp->createuser($user)) - { - $user->datacount=0; //force this offline to be true - $proftp->createuser($user); - $data = array( - 'error' => "该用户申请的数据过多,请检查该用户之前已完成的申请", - ); + $proftp=new Proftp(); + $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; - //$this->messenger->addMessage('提示信息:该用户申请的数据过多,请检查该用户之前已完成的申请。'); - } - //发送用户邮件进行信息提示和说明 - $mail = new WestdcMailer($this->view->config->smtp); - //实例化EmailText - $mailtp=new EmailText($this->db,'offline-finish', - array('user'=>$row['username'],'datalist'=>str_replace(";","\n",$row['datalist']), - 'ftpuser'=>$user->username,'ftppwd'=>$proftp->pwd,'ftptime'=>$proftp->time)); - $mail->setBodyText($mailtp->getBody()); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($row['email']); - $mail->addCc($this->view->config->service->email,'西部数据中心服务组'); - $mail->setSubject($mailtp->getSubject()); - $mail->send(); - } //ftp1 deal + $this->jsonexit($data); + return true; + //$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); + //实例化EmailText + $mailtp=new EmailText($this->db,'offline-finish', + array('user'=>$row['username'],'datalist'=>str_replace(";","\n",$row['datalist']), + 'ftpuser'=>$user->username,'ftppwd'=>$proftp->pwd,'ftptime'=>$proftp->time,'ftphost'=>$ftphost)); + $mail->setBodyText($mailtp->getBody()); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mail->addTo($row['email']); + $mail->addCc($this->view->config->service->email,'西部数据中心服务组'); + $mail->setSubject($mailtp->getSubject()); + $mail->send(); + } //offline deal //$this->messenger->addMessage('提示信息:该离线数据已经处理完成。'); $data = array( diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 3fd5fb08..ee97c0f2 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -1297,7 +1297,7 @@ class DataController extends Zend_Controller_Action $testsql="select id,has_send_mail from onlineapp where userid='$userid' and uuid='$uuid' order by id desc"; $result=$this->db->query($testsql); $rows = $result->fetch(); - $has_send_mail=$rows['has_send_mail']; + $has_send_mail=$rows['has_send_mail']; if (empty($rows['id'])) { $this->_redirect('/data/'.$uuid); @@ -1323,109 +1323,83 @@ 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); - $rows=$this->db->fetchAll($sql); + + $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); + $data=$this->db->fetchRow($sql); $updateftp=$updateftp1=false; - $sql=$this->db->quoteInto("select * from metadata where uuid=?",$uuid); - $this->view->md=$this->db->fetchRow($sql); - $bigfile=($this->view->md['filesize']>5); + $this->view->md=$data; $this->view->userpass=md5('westdc'.rand(1000,9999)); $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']; - foreach ($rows as $row) { - $url=$row['linkage']; - $p=parse_url($url); - if ($p['scheme']=='ftp') - //if ($row['protocol']=="WWW:DOWNLOAD-1.0-ftp--download") - { - //判断FTP URL是否附带了用户名和密码 - 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; - $g6=new G6ftp(); - $g6->db=$this->db; - //不进行判断,每个元数据中的下载地址都对应一个虚拟路径 - //if (is_file($url)) $path=dirname($p['path']); else $path[]=$p['path']; - $path[]=$p['path']; - $uu=(object)array("id"=>$userid, - "username"=>$this->view->username, - "password"=>$this->view->userpass, - "path"=>$path, - "maxdata"=>$this->view->config->download->max, - "time"=>$this->view->ftptime, - "datacount"=>$datacount); - if ($g6->createuser($uu)) { - $this->view->userpass=$g6->pwd; - $this->view->ftptime=$g6->time; - } else { - $this->messenger->addMessage('错误:您正在进行下载的在线数据数已经超过系统允许的最大值,请在下面点击“完成”或“取消”对应的在线数据下载!'); - $this->_redirect('/data/order'); - } - } elseif (!$updateftp1 && $p['host']=='ftp1.westgis.ac.cn') - { - //添加FTP1帐号信息以及时间控制信息,只更新一次 - $updateftp1=true; - $proftp=new Proftp(); - $proftp->db=$this->db; - //proftp离线用户名和g6的用户名稍有不同 - $this->view->username='westdc_'.Zend_Auth::getInstance()->getIdentity()->id; - $uu=(object)array("id"=>$userid, - "username"=>$this->view->username, - "password"=>$this->view->userpass, - "host"=>'ftp1.westgis.ac.cn', - "param"=>"onlineappid=".$onlineappid, - "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; - } - } - if ($p['host']=='ftp.westgis.ac.cn') - { - //更新URL - $ftpurls[]='ftp://'.$this->view->username.'@ftp.westgis.ac.cn'.$p['path']; - } elseif ($p['host']=='ftp1.westgis.ac.cn') - $ftpurls[]='ftp://ftp1.westgis.ac.cn'.$p['path']; - else - $ftpurls[]=$url; - } - } else { - //若不清楚协议,只是列出来? - $links[]=$row; + if ($data['host']=='ftp.westgis.ac.cn') + { + //添加FTP帐号信息以及时间控制信息 + $updateftp=true; + $g6=new G6ftp(); + $g6->db=$this->db; + //不进行判断,每个元数据中的下载地址都对应一个虚拟路径 + $path[]=$data['path']; + $this->view->username='westdc'.$userid; + $uu=(object)array("id"=>$userid, + "username"=>$this->view->username, + "password"=>$this->view->userpass, + "path"=>$path, + "maxdata"=>$this->view->config->download->max, + "time"=>$this->view->ftptime, + "datacount"=>$datacount); + if ($g6->createuser($uu)) { + $this->view->userpass=$g6->pwd; + $this->view->ftptime=$g6->time; + } else { + $this->messenger->addMessage('错误:您正在进行下载的在线数据数已经超过系统允许的最大值,请在下面点击“完成”或“取消”对应的在线数据下载!'); + $this->_redirect('/data/order'); } - } + } elseif ($data['host']=='ftp1.westgis.ac.cn') + { + //添加FTP1帐号信息以及时间控制信息 + $proftp=new Proftp(); + $proftp->db=$this->db; + //proftp离线用户名和g6的用户名稍有不同 + $this->view->username='westdc_'.$userid; + $uu=(object)array("id"=>$userid, + "username"=>$this->view->username, + "password"=>$this->view->userpass, + "host"=>'ftp1.westgis.ac.cn', + "param"=>"onlineappid=".$onlineappid, + "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; + } + } elseif ($data['host']=='ftp2.westgis.ac.cn') + { + //添加FTP2帐号信息以及时间控制信息 + $proftp=new Pureftp(); + $proftp->db=$this->db; + $this->view->username='westdc_'.$userid; + $uu=(object)array("id"=>$userid, + "username"=>$this->view->username, + "password"=>$this->view->userpass, + "host"=>'ftp2.westgis.ac.cn', + "param"=>"onlineappid=".$onlineappid, + "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; - @$this->view->ftpurls=$ftpurls; - @$this->view->links=$links; - //更新下载记录 + $this->view->ftpurls=$ftpurl; + //更新下载记录 //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)"; $u=$this->db->fetchRow($sql,array($userid,$uuid)); @@ -1433,29 +1407,29 @@ class DataController extends Zend_Controller_Action $sql="insert into dataorder (userid,uuid,ts_created) values(?,?,now())"; $this->db->query($sql,array($userid,$uuid)); }*/ - if (!empty($ftpurls) && ($updateftp || $updateftp1) && !$has_send_mail) - { - $data = array( - "uuid"=>$uuid, - "title"=>$this->view->md['title']."(".$this->view->md['filesize']."MB)", - "user"=>$user->username, - "ftpuser"=>$this->view->username, - "ftppwd"=>$this->view->userpass, - "ftptime"=>$this->view->ftptime, - "ftpurl"=>$this->view->ftpurls[0], - "note"=>$updateftp?'BTW:请注意登陆后要手工进入对应的目录!':'' - ); - $mailtp=new EmailText($this->db,'online-download',$data); - $mail=new WestdcMailer($this->view->config->smtp); - $mail->setBodyText($mailtp->getBody()); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($user->email); - $mail->setSubject($mailtp->getSubject()); - @$mail->send(); - $sql="update onlineapp set has_send_mail=true where id=?"; - $sth=$this->db->prepare($sql); - $sth->execute(array($onlineappid)); - } + if (!empty($ftpurl) && !$has_send_mail) + { + $data = array( + "uuid"=>$uuid, + "title"=>$this->view->md['title']."(".$this->view->md['filesize']."MB)", + "user"=>$user->username, + "ftpuser"=>$this->view->username, + "ftppwd"=>$this->view->userpass, + "ftptime"=>$this->view->ftptime, + "ftpurl"=>$this->view->ftpurl, + "note"=>$updateftp?'BTW:请注意登陆后要手工进入对应的目录!':'' + ); + $mailtp=new EmailText($this->db,'online-download',$data); + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setBodyText($mailtp->getBody()); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mail->addTo($user->email); + $mail->setSubject($mailtp->getSubject()); + @$mail->send(); + $sql="update onlineapp set has_send_mail=true where id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($onlineappid)); + } } /* * 离线申请(可以包括在线数据),在无数据参数时,则显示已有列表 diff --git a/application/default/views/scripts/data/onlineapp-download.phtml b/application/default/views/scripts/data/onlineapp-download.phtml index a1f3bde8..008b4dcf 100644 --- a/application/default/views/scripts/data/onlineapp-download.phtml +++ b/application/default/views/scripts/data/onlineapp-download.phtml @@ -3,11 +3,9 @@ $this->headTitle('我的账户'); $this->headTitle()->setSeparator(' - '); $this->theme->AppendPlus($this,'jquery'); - $this->theme->AppendPlus($this,'bootstarp'); $this->theme->AppendPlus($this,'colorbox'); ?> -
-
+
+
\ No newline at end of file diff --git a/application/models/Pureftp.php b/application/models/Pureftp.php index 538ec8c6..a88d103e 100644 --- a/application/models/Pureftp.php +++ b/application/models/Pureftp.php @@ -17,6 +17,8 @@ class Pureftp { $this->insert_user($user); // add system link directory + // use for same web server & ftp server + /* if (is_array($user->path)) { foreach ($user->path as $path) @@ -25,6 +27,14 @@ class Pureftp //online path, only one path 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); }