diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 084f5711..e199295d 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -2693,8 +2693,130 @@ 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; + $submd=$this->view->config->sub->metadata; + + 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 $submd where uuid=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($uuid)); + $row=$sth->fetch(); + if (empty($row)) + { + $data = array( + 'error'=>"参数错误" + ); + $this->jsonexit($data); + return true; + } + + //ftp admin 用户名 + $auth = Zend_Auth::getInstance(); + $uid=$auth->getIdentity()->id; + $uname = $submd.'admin'.$uid; + + //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 @@ -2717,5 +2839,27 @@ class Admin_DataController extends Zend_Controller_Action public function jsonexit($data){ $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); 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; + } } diff --git a/application/admin/views/scripts/data/left.phtml b/application/admin/views/scripts/data/left.phtml index 8ec3a7f9..480b898b 100644 --- a/application/admin/views/scripts/data/left.phtml +++ b/application/admin/views/scripts/data/left.phtml @@ -3,12 +3,10 @@
临时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 diff --git a/application/default/views/scripts/archives/archive.phtml b/application/default/views/scripts/archives/archive.phtml index 9e39d78f..0b89c6ed 100644 --- a/application/default/views/scripts/archives/archive.phtml +++ b/application/default/views/scripts/archives/archive.phtml @@ -34,16 +34,16 @@ $this->headLink()->appendStylesheet('/css/news.css');