From 7a1e65b42d7786b65475d841c681af3a10d29337 Mon Sep 17 00:00:00 2001 From: wlx Date: Thu, 28 Mar 2013 09:00:27 +0000 Subject: [PATCH] merge trunk r3220 --- .../default/controllers/HeiheController.php | 110 +++++------------- .../views/scripts/heihe/submit-unsubmit.phtml | 2 +- 2 files changed, 30 insertions(+), 82 deletions(-) diff --git a/application/default/controllers/HeiheController.php b/application/default/controllers/HeiheController.php index a7cee7d7..5fa35b1c 100644 --- a/application/default/controllers/HeiheController.php +++ b/application/default/controllers/HeiheController.php @@ -508,72 +508,11 @@ class HeiheController extends DataController // 2. 保存变化记录 save changelog & userid for the latest version $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid=? order by ts_created desc limit 1)"; $this->db->query($sql,array($changelog,$u_id,$row['uuid'])); - - // 处理文件权限和数据信息 - $ftp_user = "heihe".$u_id."upload"; - $sql = "SELECT * FROM pureftp WHERE userid=? AND homedir LIKE ?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($ftp_user,'%'.$uuid.'%')); - $row1 = $sth->fetch(PDO::FETCH_ASSOC); - - if(!empty($row1['passwd'])) - { - $old=umask(0); - //$this->chmodr($row1['homedir'],1444); - umask($old); - } - - //$path = $row1['homedir']; - $path = '/var/www/westdc.westgis.ac.cn/data/heihe_upload/'.$uuid.'/'; - - //delete dataset & datafile records - $sql="delete from dataset where uuid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($uuid)); + file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$row['uuid']."&filelist=1"); //自动添加数据分类为黑河 $sql="insert into datasource (uuid,sourceid) values(?,1)"; $sth=$this->db->prepare($sql); try{$sth->execute(array($uuid));}catch(Exception $e) {} - - $sql = "INSERT INTO dataset (uuid,path) VALUES (?,?) RETURNING id"; - $sth = $this->db->prepare($sql); - $rs = $sth->execute(array($uuid,$path)); - - if(!$rs) - { - $messages[] = "元数据信息写入失败"; - /* - $data = array("error"=>'元数据信息写入失败'); - $this->jsonexit($data); - return true; - */ - } - - $temp = $sth->fetch(PDO::FETCH_ASSOC); - - $dsid = $temp['id']; - - $dir = new mydir(); - $files=$dir->recursive($path); - - foreach ($files as $k=>$v) - { - //$pathinfo = pathinfo($path.$v); - $filename = mb_substr($v,mb_strlen($path)+1); - $filesize = filesize($v); - $isdir=is_dir($v)?1:0; - $depth=substr_count($filename,"/")+1; - if (substr($filename,-1,1)=='/') $depth--; - //$this->chmodr($path.$v,0444); - $sql = "INSERT INTO datafile (dsid,filename,filesize,isdir,depth) VALUES (?,?,?,?,?)"; - $sth = $this->db->prepare($sql); - $rs = $sth->execute(array($dsid,$filename,$filesize,$isdir,$depth)); - if(!$rs) - { - $messages[] = "数据文件".$filename.'写入失败'; - } - } - // 3. 保存数据评审状态 //导入元数据 @@ -637,7 +576,7 @@ class HeiheController extends DataController }//unsubmit //FTP - if($ac == "ftp") + else if($ac == "ftp") { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); @@ -666,22 +605,27 @@ class HeiheController extends DataController ); $this->jsonexit($data); return true; - } + } //ftp 用户名 - $uname = 'heihe'.$u_id.'upload'; + $uname = 'westdc'.$u_id.'upload'; //ftp路径 - $homedir = "/var/www/westdc.westgis.ac.cn/data/heihe_upload/".$uuid."/"; + $homedir = "/disk1/WestDC/upload/".$uuid."/"; - $sql = "SELECT * FROM pureftp WHERE userid='$uname' ORDER BY pkid DESC"; + $sql = "SELECT * FROM proftpusers WHERE userid='$uname' ORDER BY pkid DESC"; $sth = $this->db->prepare($sql); $sth->execute(); $row = $sth->fetch(); - - $old=umask(0); - @mkdir($homedir,0777); - umask($old); + + //create directory for upload + //server is not localhost, so we need a trick + //$old=umask(0); + //@mkdir($homedir,0777); + //umask($old); + $page=file_get_contents('http://ftp1.westgis.ac.cn/proftp_upload.php?uuid='.$uuid); + if (!empty($page)) die($page);//there are errors in visit ftp page + if(!empty($row['pkid'])) { @@ -697,13 +641,15 @@ class HeiheController extends DataController return true; }else{ - $uid = 1001; - $gid = 1001; + $uid = 109; + $gid = 1002; $passwd = $this->genRandomString(16); - $sql = "UPDATE pureftp SET passwd=?,uid=?,gid=?,homedir=? WHERE userid=?"; - $sth = $this->db->prepare($sql); - $rs = $sth->execute(array($passwd,$uid,$gid,$homedir,$uname)); + //$sql = "UPDATE proftpusers SET passwd=?,uid=?,gid=?,homedir=? WHERE userid=?"; + //$sth = $this->db->prepare($sql); + //$rs = $sth->execute(array($passwd,$uid,$gid,$homedir,$uname)); + $sql="update proftpusers SET passwd='".$passwd."',uid=".$uid.",gid=".$gid.",homedir='".$homedir."' WHERE userid='".$uname."'"; + $rs=$this->db->query($sql); if($rs) { $data = array( @@ -724,13 +670,15 @@ class HeiheController extends DataController } else{ - $uid = 1001; - $gid = 1001; + $uid = 109; + $gid = 1002; $passwd = $this->genRandomString(16); - $sql = "INSERT INTO pureftp (userid,passwd,uid,gid,homedir) VALUES (?,?,?,?,?)"; - $sth = $this->db->prepare($sql); - $rs = $sth->execute(array($uname,$passwd,$uid,$gid,$homedir)); + //$sql = "INSERT INTO proftpusers (userid,passwd,uid,gid,homedir) VALUES (?,?,?,?,?)"; + //$sth = $this->db->prepare($sql); + //$rs = $sth->execute(array($uname,$passwd,$uid,$gid,$homedir)); + $sql="insert into proftpusers (userid,passwd,uid,gid,homedir) values('".$uname."','".$passwd."',109,1002,'".$homedir."')"; + $rs=$this->db->query($sql); if($rs) { $data = array( diff --git a/application/default/views/scripts/heihe/submit-unsubmit.phtml b/application/default/views/scripts/heihe/submit-unsubmit.phtml index 7e6f2b71..abcc417d 100644 --- a/application/default/views/scripts/heihe/submit-unsubmit.phtml +++ b/application/default/views/scripts/heihe/submit-unsubmit.phtml @@ -99,7 +99,7 @@ function getFtp(uuid){ { if(data.statu > 0) { - var html = '

临时FTP帐号信息(此帐号仅对应当前数据集!)

ftp://westdc.westgis.ac.cn/

'+ + var html = '

临时FTP帐号信息(此帐号仅对应当前数据集!)

ftp://ftp1.westgis.ac.cn/

'+ '

用户名:'+data.user+ '

密码:'+data.passwd+'

' +'

或直接点击此链接

';