From bcc7146f812c1c19155c84f5df16d8b890145d15 Mon Sep 17 00:00:00 2001
From: Li Jianxuan
Date: Wed, 16 Jul 2014 02:28:38 +0000
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8E=E5=8F=B0ftp?=
=?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=95=B0=E6=8D=AE=E7=9A=84=E6=93=8D=E4=BD=9C?=
=?UTF-8?q?=E6=8C=89=E9=92=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../admin/controllers/DataController.php | 123 +++++++++++++++++-
application/admin/views/scripts/data/md.phtml | 35 ++++-
2 files changed, 155 insertions(+), 3 deletions(-)
diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php
index 084f5711..cd31e0a6 100755
--- a/application/admin/controllers/DataController.php
+++ b/application/admin/controllers/DataController.php
@@ -2693,8 +2693,127 @@ class Admin_DataController extends Zend_Controller_Action
return;
}
-
-
+ public function ftpAction()
+ {
+ $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 = 'sjy'.$u_id.'upload';
+
+ //ftp路径
+ $homedir = "/data/upload/".$uuid."/";
+ //ftp用户表
+ $ftptable=' pureftp ';//ftp2.westgis.ac.cn
+ $uid = 1002;
+ $gid = 1002;
+
+ $sql = "SELECT * FROM $ftptable 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://ftp.sanjiangyuan.org.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{
+ $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 ".$ftptable." 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{
+ $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 ".$ftptable." (userid,passwd,uid,gid,homedir) values('".$uname."','".$passwd."',".$uid.",".$gid.",'".$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
+ }
+
/*
获得单个文件的信息
return array row
diff --git a/application/admin/views/scripts/data/md.phtml b/application/admin/views/scripts/data/md.phtml
index e437e616..0cdfa305 100644
--- a/application/admin/views/scripts/data/md.phtml
+++ b/application/admin/views/scripts/data/md.phtml
@@ -73,7 +73,8 @@
邮件通知 |
支持项目 |
- 数据可视化
+ 数据可视化 |
+ FTP数据上传
@@ -89,4 +90,36 @@ $(".inline").colorbox({inline:true, width:"50%"});
function Alert(html){
$.colorbox({'innerWidth':'50%','html':''+html+'
'});
}
+function getFtp(uuid){
+ $.ajax({
+ 'type':"POST",
+ 'url':'/admin/data/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 = '临时FTP帐号信息(此帐号仅对应当前数据集!)
ftp://ftp.sanjiangyuan.org.cn/
'+
+ '用户名:'+data.user+
+ '
密码:'+data.passwd+'
'
+ +'或直接点击此链接
';
+ Alert(html);
+ }
+ }
+ }
+ else{
+ Alert('出现错误,请稍候再试');
+ }
+ },
+ 'timeout': 30000,
+ 'error': function(){
+ Alert('处理中出现错误,请刷新页面后重试');
+ }
+ });
+}
\ No newline at end of file