将黑河上传的服务器切换为ftp1服务器

This commit is contained in:
wlx 2013-03-28 08:13:28 +00:00
parent f00639b9d2
commit 93e4f1859b
2 changed files with 30 additions and 82 deletions

View File

@ -508,73 +508,12 @@ class HeiheController extends DataController
// 2. 保存变化记录 save changelog & userid for the latest version // 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)"; $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'])); $this->db->query($sql,array($changelog,$u_id,$row['uuid']));
file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$row['uuid']."&filelist=1");
// 处理文件权限和数据信息
$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));
//自动添加数据分类为黑河 //自动添加数据分类为黑河
$sql="insert into datasource (uuid,sourceid) values(?,1)"; $sql="insert into datasource (uuid,sourceid) values(?,1)";
$sth=$this->db->prepare($sql); $sth=$this->db->prepare($sql);
try{$sth->execute(array($uuid));}catch(Exception $e) {} 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. 保存数据评审状态 // 3. 保存数据评审状态
//导入元数据 //导入元数据
$iso->saveDB($this->db); $iso->saveDB($this->db);
@ -637,7 +576,7 @@ class HeiheController extends DataController
}//unsubmit }//unsubmit
//FTP //FTP
if($ac == "ftp") else if($ac == "ftp")
{ {
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
@ -669,19 +608,24 @@ class HeiheController extends DataController
} }
//ftp 用户名 //ftp 用户名
$uname = 'heihe'.$u_id.'upload'; $uname = 'westdc'.$u_id.'upload';
//ftp路径 //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 = $this->db->prepare($sql);
$sth->execute(); $sth->execute();
$row = $sth->fetch(); $row = $sth->fetch();
$old=umask(0); //create directory for upload
@mkdir($homedir,0777); //server is not localhost, so we need a trick
umask($old); //$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'])) if(!empty($row['pkid']))
{ {
@ -697,13 +641,15 @@ class HeiheController extends DataController
return true; return true;
}else{ }else{
$uid = 1001; $uid = 109;
$gid = 1001; $gid = 1002;
$passwd = $this->genRandomString(16); $passwd = $this->genRandomString(16);
$sql = "UPDATE pureftp SET passwd=?,uid=?,gid=?,homedir=? WHERE userid=?"; //$sql = "UPDATE proftpusers SET passwd=?,uid=?,gid=?,homedir=? WHERE userid=?";
$sth = $this->db->prepare($sql); //$sth = $this->db->prepare($sql);
$rs = $sth->execute(array($passwd,$uid,$gid,$homedir,$uname)); //$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) if($rs)
{ {
$data = array( $data = array(
@ -724,13 +670,15 @@ class HeiheController extends DataController
} }
else{ else{
$uid = 1001; $uid = 109;
$gid = 1001; $gid = 1002;
$passwd = $this->genRandomString(16); $passwd = $this->genRandomString(16);
$sql = "INSERT INTO pureftp (userid,passwd,uid,gid,homedir) VALUES (?,?,?,?,?)"; //$sql = "INSERT INTO proftpusers (userid,passwd,uid,gid,homedir) VALUES (?,?,?,?,?)";
$sth = $this->db->prepare($sql); //$sth = $this->db->prepare($sql);
$rs = $sth->execute(array($uname,$passwd,$uid,$gid,$homedir)); //$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) if($rs)
{ {
$data = array( $data = array(

View File

@ -99,7 +99,7 @@ function getFtp(uuid){
{ {
if(data.statu > 0) if(data.statu > 0)
{ {
var html = '<p>临时FTP帐号信息<b>(此帐号仅对应当前数据集!)</b></p><p>ftp://westdc.westgis.ac.cn/</p>'+ var html = '<p>临时FTP帐号信息<b>(此帐号仅对应当前数据集!)</b></p><p>ftp://ftp1.westgis.ac.cn/</p>'+
'<p>用户名:'+data.user+ '<p>用户名:'+data.user+
'</p><p>密码:'+data.passwd+'</p>' '</p><p>密码:'+data.passwd+'</p>'
+'<p><a href="ftp://'+data.user+':'+data.passwd+'@westdc.westgis.ac.cn/">或直接点击此链接</a></p>'; +'<p><a href="ftp://'+data.user+':'+data.passwd+'@westdc.westgis.ac.cn/">或直接点击此链接</a></p>';