实现数据作者的FTP上传功能 #357

This commit is contained in:
wlx 2012-11-16 15:51:28 +00:00
parent 9b220549cf
commit a97be47fed
2 changed files with 182 additions and 2 deletions

View File

@ -2337,6 +2337,129 @@ class AuthorController extends Zend_Controller_Action
return true; return true;
} }
} }
//FTP
else if($ac == "ftp")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$uuid = $this->_getParam('uuid');
$this->view->uuid = $uuid;
if(empty($uuid) || !preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
$data = array(
'error'=>"参数错误"
);
$this->jsonexit($data);
return true;
}
//安全检查: uuid必须是当前用户且为新建数据
$sql="select * from geonetworkmetadata where uuid=? and uuid not in (select uuid from metadata) and owner=?";
$sth=$this->db->prepare($sql);
$sth->execute(array($uuid,$u_id));
$row=$sth->fetch();
if (empty($row))
{
$data = array(
'error'=>"参数错误"
);
$this->jsonexit($data);
return true;
}
//ftp 用户名
$uname = 'westdc'.$u_id.'upload';
//ftp路径
$homedir = "/disk1/WestDC/upload/".$uuid."/";
$sql = "SELECT * FROM proftpusers WHERE userid='$uname' ORDER BY pkid DESC";
$sth = $this->db->prepare($sql);
$sth->execute();
$row = $sth->fetch();
//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']))
{
if(preg_match("/.*".$uuid.".*/",$row['homedir']))
{
$data = array(
'statu'=>1,
'user'=>$row['userid'],
'passwd'=>$row['passwd']
);
$this->jsonexit($data);
return true;
}else{
$uid = 109;
$gid = 1002;
$passwd = $this->genRandomString(16);
//$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(
'statu'=>1,
'user'=>$uname,
'passwd'=>$passwd
);
$this->jsonexit($data);
return true;
}else{
$data = array(
'error'=>"FTP信息更新失败请重试"
);
$this->jsonexit($data);
return true;
}
}
}
else{
$uid = 109;
$gid = 1002;
$passwd = $this->genRandomString(16);
//$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(
'statu'=>1,
'user'=>$uname,
'passwd'=>$passwd
);
$this->jsonexit($data);
return true;
}else{
$data = array(
'error'=>"FTP信息更新失败请重试"
);
$this->jsonexit($data);
return true;
}
}//end if
}//ftp
} }
//新建元数据 //新建元数据
@ -3280,6 +3403,27 @@ class AuthorController extends Zend_Controller_Action
return true; return true;
}//jsonexit() 退出并返回json数据 }//jsonexit() 退出并返回json数据
private function genRandomString($len)
{
$chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
"3", "4", "5", "6", "7", "8", "9"
);
$charsLen = count($chars) - 1;
shuffle($chars); // 将数组打乱
$output = "";
for ($i=0; $i<$len; $i++)
{
$output .= $chars[mt_rand(0, $charsLen)];
}
return $output;
}
//ajax 提示框 //ajax 提示框
public function alertbox($type='',$body){ public function alertbox($type='',$body){

View File

@ -43,6 +43,7 @@ $this->breadcrumb()->setSeparator(' > ');
<a href="/service/geonetwork?url=metadata.show?id=<?php echo $item['id']; ?>">在geonetwork里查看</a> <a href="/service/geonetwork?url=metadata.show?id=<?php echo $item['id']; ?>">在geonetwork里查看</a>
| <a href="/service/geonetwork?url=metadata.edit?id=<?php echo $item['id']; ?>">在geonetwork里修改</a> | <a href="/service/geonetwork?url=metadata.edit?id=<?php echo $item['id']; ?>">在geonetwork里修改</a>
| <a href="/service/geonetwork?url=metadata.delete?id=<?php echo $item['id']; ?>">删除此条数据</a> | <a href="/service/geonetwork?url=metadata.delete?id=<?php echo $item['id']; ?>">删除此条数据</a>
| <a href="javascript:;" onclick="getFtp('<?php echo $item['uuid'];?>')">FTP数据上传</a>
| <a onclick="$('#commit_submit').attr('onclick','commit(\'<?php echo $item['id'];?>\');');" href="#commitform" class="more inline">提交评审发布</a> | <a onclick="$('#commit_submit').attr('onclick','commit(\'<?php echo $item['id'];?>\');');" href="#commitform" class="more inline">提交评审发布</a>
</p> </p>
</li> </li>
@ -89,6 +90,41 @@ $(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
function commit(id){ function commit(id){
action('commit&changelog='+$('#changelog').val(),id); action('commit&changelog='+$('#changelog').val(),id);
} }
function getFtp(uuid){
$.ajax({
'type':"POST",
'url':'/author/newdata/ac/ftp/uuid/'+uuid,
'data':'',
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{Alert(data.error);return false;}
if(typeof(data.statu)!='undefined')
{
if(data.statu > 0)
{
var html = '<p>临时FTP帐号信息<b>(此帐号仅对应当前数据集!)</b></p><p>ftp://ftp1.westgis.ac.cn/</p>'+
'<p>用户名:'+data.user+
'</p><p>密码:'+data.passwd+'</p>'
+'<p><a href="ftp://'+data.user+':'+data.passwd+'@ftp1.westgis.ac.cn/">或直接点击此链接</a></p>';
Alert(html);
}
}
}
else{
Alert('出现错误,请稍候再试</h4>');
}
},
'timeout': 30000,
'error': function(){
Alert('处理中出现错误,请刷新页面后重试</h4>');
}
});
}
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4>'+html+'</h4>'});
}
</script> </script>
<div class="colorbox" style="display:none;"> <div class="colorbox" style="display:none;">
<div id="commitform"> <div id="commitform">