标签:des style blog http color io os 使用 ar
file controller
<?php //include ‘env.php‘; class FileController extends Controller { public function addNode() { $dirname=$_POST[‘dirname‘]; $hadoop_home = Loader::loadConfigs(‘env‘,‘HADOOP_HOME‘); $cmd="$hadoop_home"."/bin/hadoop fs -mkdir ".$dirname; exec($cmd,$arr,$return_val); if($return_val==0) $state="success"; else $sate="error"; echo $state; } public function download() { $pathFrom=$_POST[‘pathFrom‘]; $pathTo=$_POST[‘pathTo‘]; $hadoop_home = Loader::loadConfigs(‘env‘,‘HADOOP_HOME‘); $cmd="$hadoop_home"."/bin/hadoop fs -get ".$pathFrom." ".$pathTo; exec($cmd,$arr,$return_val); if($return_val==0) $state="success"; else $sate="error"; echo $state; } public function remove() { $location=$_POST[‘location‘]; //$loaction="/home/hadoop/malmonitor_proj/readme.txt"; $hadoop_home = Loader::loadConfigs(‘env‘,‘HADOOP_HOME‘); $cmd="$hadoop_home"."/bin/hadoop fs -rmr ".$location; exec($cmd,$arr,$return_val); if($return_val==0) $state="success"; else $sate="error"; echo $state; } public function rename() { //args $location=$_POST[‘location‘]; $oldName=$_POST[‘oldName‘]; $newName=$_POST[‘newName‘]; //$location="/data2"; ///$newName="data"; //cmd $hadoop_home = Loader::loadConfigs(‘env‘,‘HADOOP_HOME‘); $cmd="$hadoop_home"."/bin/hadoop fs -mv ".$location." ".str_replace("//","/",dirname($location)."/").$newName; //echo $cmd."<br/>"; exec($cmd,$arr,$return_val); if($return_val==0) $state="success"; else $state="error"; echo $state; } public function upload() { $srcPath=$_POST[‘pathFrom‘]; $dstPath=$_POST[‘pathTo‘]; //$srcPath="/home/hadoop/malmonitor_proj/datacli/Basic5.16"; //$dstPath="/data"; //$HADOOP_HOME = Loader::loadConfigs(‘env‘,‘HADOOP_HOME‘); //$cmd="$HADOOP_HOME"."/bin/hadoop fs -put ".$srcPath." ".$dstPath; $upload_jar = Loader::loadConfigs(‘env‘,‘UPLOAD_JAR‘); $java_home = Loader::loadConfigs(‘env‘,‘JAVA_HOME‘); $hadoop_home = Loader::loadConfigs(‘env‘,‘HADOOP_HOME‘); $java_opts="-Djava.library.path=$hadoop_home/lib/native/Linux-amd64-64"; //$CLASSPATH="$CLASSPATH:$HADOOP_HOME/conf"; $classpath = "$hadoop_home/conf"; $cmd="$java_home" . "/bin/java -Xmx512m $java_opts -cp $classpath -Xbootclasspath/a:$hadoop_home/conf -jar " . $upload_jar . " " . $srcPath . " " . $dstPath; exec($cmd,$arr,$return_val); if($return_val==0) $state=array("isSuccess"=>"true"); else { foreach($arr as $v){ if(empty($v) or !isset($v)) $msg=$v; else $msg=$msg . $v; } $state=array("isSuccess"=>"false","msg"=>"$msg"); } echo json_encode($state); } public function getNodes() { $pId = "0"; //parent id $pName = "null"; //parent name $pLocation="/"; if(array_key_exists( ‘id‘,$_REQUEST)) { $pId=$_REQUEST[‘id‘]; } if(array_key_exists(‘name‘,$_REQUEST)) { $pName=$_REQUEST[‘name‘]; } if(array_key_exists(‘location‘,$_REQUEST)){ $pLocation=$_REQUEST[‘location‘]; } //$str = ‘[{"id":"0", "name":"java","type":"0","location":"hdfs"},{"id":"1", "name":"script","type":"1","location":"hdfs"}]‘; if(strcmp("$pId","0")==0) { $jsonStr=null; $jsonStr=array(‘id‘=>‘0‘,‘name‘=>‘Root‘,‘isParent‘=>‘true‘,‘location‘=>‘/‘); $jsonStr[‘id‘]=$pId.$jsonStr[‘id‘]; //echo $jsonStr[‘id‘]; echo json_encode($jsonStr); } else { unset($output); // $cmd="./getNodes.sh"." ".$pLocation; $cmd= "/bin/bash ".WEBMONITOR_BASE."/core/controller/getNodes.sh" . " " . $pLocation; exec($cmd, $output,$val); $filelist=(string)$output[0]; $filelist = json_decode($filelist); $len = count($filelist); for($i=0; $i<$len; $i++){ $filelist[$i]->id=$pId . $filelist[$i]->id; } echo json_encode($filelist); // $filelist=array(‘id‘=>‘0‘,‘name‘=>‘R‘,‘isParent‘=>‘true‘,‘location‘=>‘/‘); // echo json_encode($filelist); } } } ?>
user controller
<?php class UserController extends Controller{ public function loginAuth(){ $model = new UserModelManager(); session_start(); if(isset($_SESSION[‘user_name‘])){ // $this->loginSuccess(); if(isset($_SESSION[‘role‘])){ $role = $_SESSION[‘role‘]; $vc = new ViewController(); $vc->loginSuccess($role); }else{ $vc = new ViewController(); $vc->loginFail(); } }else if(strcmp($_SESSION[‘6_letters_code‘],$_POST[‘verifycode‘])==0 &&$model->userExist($this->params[‘user_name‘], $this->params[‘password‘])){ //保存用户名和密码信息到Session中,方便下次免登陆 $user=$model->getUsers($this->params[‘user_name‘], $this->params[‘password‘],1); $_SESSION[‘user_name‘]=$user->getUserName(); $_SESSION[‘password‘]= $user->getPassWord(); $_SESSION[‘email‘] = $user->getEmail(); $_SESSION[‘comment‘] = $user->getComment(); $_SESSION[‘role‘]=$user->getRole(); // $vc = new ViewController(); // $vc->loginSuccess(); $vc = new ViewController(); $role = $user->getRole(); $vc->loginSuccess($role); }else{ // header(‘location:‘.Server::getRootURL().‘login/fail‘); $vc = new ViewController(); $vc->loginFail(); } } public function userNameCheck(){ $model = new UserModelManager(); if($model->userNameAvailable($_POST[‘memberid‘])){ $jsonStr[‘isMemberIdUsed‘]=true; }else $jsonStr[‘isMemberIdUsed‘]=false; echo json_encode($jsonStr); } public function userRegist(){ $model = new UserModelManager(); if($model->addUser($this->params[‘user_name‘], $this->params[‘password‘], $this->params[‘role‘], $this->params[‘email‘], $this->params[‘comment‘])){ $vc = new ViewController(); $vc->registerSuccess(); }else{ $vc = new ViewController(); $vc->registerFail(); } } public function userBasicInfoUpdate(){ $model = new UserModelManager(); if($model->updateBasicInfo(‘‘,$this->params[‘email‘],$this->params[‘comment‘])) { $jsonStr[‘retval‘] =true; }else{ $jsonStr[‘retval‘] = false; } echo json_encode($jsonStr); } public function userPassUpdate(){ $model = new UserModelManager(); try{ $jsonStr[‘retval‘]=$model->passUpdate($this->params[‘password‘], $this->params[‘newpassword‘]); }catch(Exception $e){ $jsonStr[‘tips‘]=$e->getMessage(); } echo json_encode($jsonStr); } public function getUserInfo(){ $model = new UserModelManager(); session_start(); if(isset($_SESSION[‘user_name‘])){ $user_name=$_SESSION[‘user_name‘]; }else{ $user_name="null"; } if(isset($_SESSION[‘password‘])){ $password=$_SESSION[‘password‘]; }else{ $password="null"; } $user_info = $model->getUsers($user_name, $password); // echo $user_info; $name=$user_info->getUserName(); $role=$user_info->getRole(); $email=$user_info->getEmail(); $comment=$user_info->getComment(); $info = array(‘name‘=>$name, ‘role‘=>$role, ‘email‘=>$email, ‘comment‘=>$comment); // $info=array(‘name‘=>"hadoop", ‘role‘=>"role", ‘email‘=>"email", ‘comment‘=>"comment"); echo json_encode($info); } public function userMessage(){ //获取apply的个数-hss $model = new UserModelManager(); // $jsonStr[‘apply‘]=$model->getapplycount(); //echo json_encode($jsonStr); session_start(); if(isset($_SESSION[‘user_name‘])){ $user_name=$_SESSION[‘user_name‘]; }else{ $user_name="null"; } if(isset($_SESSION[‘password‘])){ $password=$_SESSION[‘password‘]; }else{ $password="null"; } $user_info = $model->getUsers($user_name, $password); $role=$user_info->getRole(); if($role=="admin") { $num=$model->getapplycount(); echo $num; } // else // echo 0; } public function applyUserInfo(){ //获取apply的个数-hss $model = new UserModelManager(); $user_info = $model->getApplyUserInfo(); echo json_encode($user_info); } public function agreeUserApply(){ $model = new UserModelManager(); $names=$_POST[‘names‘]; $operate_status = $model->addApplyUser($names); echo $operate_status; // $state=$model->getApplyUserInfo(); } public function refuseUserApply(){ $model = new UserModelManager(); $names=$_POST[‘names‘]; $operate_status = $model->deleteApplyUser($names); echo $operate_status; } public function userAdd(){ } public function userDel(){ } public function userMod(){ } }
view controller
1 <?php 2 class ViewController extends Controller{ 3 4 5 /** 6 * 显示登陆界面 7 */ 8 9 public function login(){ 10 $view = View::getInstance(); 11 $view->set_tpl(‘login.tpl‘, ‘login.tpl.php‘); 12 $view->assign(‘title‘,‘用户登陆‘); 13 $view->assign(‘logo_text‘,‘互联网离线学习系统‘); 14 $view->parse(‘login‘, ‘login.tpl‘); 15 $view->show(‘login‘); 16 } 17 /* 18 * 登出系统并销毁已经有的session会话,跳转到login界面 19 */ 20 public function logout(){ 21 session_start(); 22 unset($_SESSION[‘user_name‘]); 23 unset($_SESSION[‘session_id‘]); 24 unset($_SESSION[‘role‘]); 25 unset($_SESSION[‘password‘]); 26 unset($_SESSION[‘email‘]); 27 unset($_SESSION[‘comment‘]); 28 29 //unset(_SESSION); 30 session_destroy(); 31 header(‘location:‘.Server::getRootURL().‘login‘); 32 //header(‘location:http://localhost:8093/login‘); 33 } 34 35 36 /** 37 * 显示登陆成功的界面 38 */ 39 40 public function loginSuccess($role){ 41 // 显示登陆成功的视图 42 43 $view = View::getInstance(); 44 45 if($role=="admin"){ 46 $view->set_tpl(‘mangage-admin.tpl‘, ‘manage-admin.tpl.php‘); 47 $view->assign(‘title‘,‘登录成功‘); 48 $view->parse(‘mangage-admin‘, ‘mangage-admin.tpl‘); 49 $view->show(‘mangage-admin‘); 50 }else { 51 $view->set_tpl(‘mangage-normal.tpl‘, ‘manage-normal.tpl.php‘); 52 $view->assign(‘title‘,‘登录成功‘); 53 $view->parse(‘mangage-normal‘, ‘mangage-normal.tpl‘); 54 $view->show(‘mangage-normal‘); 55 } 56 57 } 58 59 /** 60 * 显示登陆失败的界面 61 */ 62 public function loginFail(){ 63 //return false; 64 // 显示验证失败的视图 65 // $view = new View(); 66 // $view->set_tpl(, $flag) 67 // header("location:../../statics/pages/errors/login_fail.php"); 68 // exit(); 69 //为了避免路径暴露,同样也为了更好的利用单点入口的设计,这里不能使用header去跳转,而是将php文件利用view载入然后show 70 $view = View::getInstance(); 71 $view->set_tpl(‘hintPage.tpl‘, ‘hintPage.tpl.php‘); 72 $view->assign(‘title‘,‘登陆失败‘); 73 $view->assign(‘hint‘,‘Opps~登陆失败...‘); 74 $view->assign(‘jumpHint‘,‘返回登陆界面‘); 75 $ref = Server::getRootURL().‘login‘; 76 $view->assign(‘ref‘,$ref); 77 $view->parse(‘hintPage‘, ‘hintPage.tpl‘); 78 $view->show(‘hintPage‘); 79 } 80 81 /** 82 * 注册界面 83 */ 84 public function register(){ 85 $view = View::getInstance(); 86 $view->set_tpl(‘registration.tpl‘, ‘registration.tpl.php‘); 87 $view->assign(‘title‘,‘用户注册‘); 88 $view->assign(‘logo_text‘,‘互联网离线学习系统‘); 89 $view->parse(‘registration‘, ‘registration.tpl‘); 90 $view->show(‘registration‘); 91 92 } 93 94 public function registerSuccess(){ 95 $view = View::getInstance(); 96 $view->set_tpl(‘hintPage.tpl‘, ‘hintPage.tpl.php‘); 97 $view->assign(‘title‘,‘注册成功‘); 98 $view->assign(‘hint‘,‘恭喜!注册成功‘); 99 $view->assign(‘jumpHint‘,‘马上去登陆‘); 100 $ref=Server::getRootURL().‘login‘; 101 $view->assign(‘ref‘,$ref); 102 $view->parse(‘hintPage‘, ‘hintPage.tpl‘); 103 $view->show(‘hintPage‘); 104 } 105 106 public function registerFail(){ 107 $view = View::getInstance(); 108 $view->set_tpl(‘hintPage.tpl‘, ‘hintPage.tpl.php‘); 109 $view->assign(‘title‘, ‘注册失败‘); 110 $view->assign(‘hint‘,‘Oops~注册失败...‘); 111 $ref=Server::getRootURL().‘register/inner‘; 112 $view->assign(‘jumpHint‘,$ref); 113 $view->parse(‘hintPage‘, ‘hintPage.tpl‘); 114 $view->show(‘hintPage‘); 115 } 116 117 public function userInfo(){ 118 $view = View::getInstance(); 119 $view->set_tpl(‘userInfo.tpl‘, ‘userInfo.tpl.php‘); 120 $view->assign(‘title‘,‘用户信息‘); 121 $view->parse(‘userInfo‘, ‘userInfo.tpl‘); 122 $view->show(‘userInfo‘); 123 } 124 125 public function password(){ 126 $view = View::getInstance(); 127 $view->set_tpl(‘password.tpl‘, ‘password.tpl.php‘); 128 $view->assign(‘title‘,‘修改密码‘); 129 $view->parse(‘password‘, ‘password.tpl‘); 130 $view->show(‘password‘); 131 } 132 133 public function apply(){ 134 $view = View::getInstance(); 135 $view->set_tpl(‘apply.tpl‘, ‘apply.tpl.php‘); 136 $view->assign(‘title‘,‘用户管理‘); 137 $view->parse(‘apply‘, ‘apply.tpl‘); 138 $view->show(‘apply‘); 139 } 140 141 142 public function fileManage(){ 143 $view = View::getInstance(); 144 $view->set_tpl(‘fileManage.tpl‘, ‘fileManage.tpl.php‘); 145 $view->assign(‘title‘, ‘文件管理‘); 146 $view->parse(‘manage‘, ‘fileManage.tpl‘); 147 $view->show(‘manage‘); 148 } 149 150 public function detectionManage(){ 151 $view = View::getInstance(); 152 $view->set_tpl(‘detection.tpl‘, ‘detection.tpl.php‘); 153 $view->assign(‘title‘, ‘行为检测‘); 154 $view->parse(‘detection‘, ‘detection.tpl‘); 155 $view->show(‘detection‘); 156 } 157 158 public function systemControl(){ 159 $view = View::getInstance(); 160 $view->set_tpl(‘systemControl.tpl‘, ‘systemControl.tpl.php‘); 161 $view->assign(‘title‘,‘系统控制‘); 162 $view->parse(‘control‘, ‘systemControl.tpl‘); 163 $view->show(‘control‘); 164 } 165 166 public function detectionProcess(){ 167 $view = View::getInstance(); 168 $view->set_tpl(‘run.tpl‘, ‘run.tpl.php‘); 169 $view->assign(‘title‘, ‘检测中‘); 170 $view->parse(‘run‘, ‘run.tpl‘); 171 $view->show(‘run‘); 172 } 173 174 public function nameNodeState(){ 175 $view = View::getInstance(); 176 $view->set_tpl(‘nameNode.tpl‘, ‘nameNode.tpl.php‘); 177 $view->assign(‘title‘, ‘nameNode状态‘); 178 $view->parse(‘nameNode‘, ‘nameNode.tpl‘); 179 $view->show(‘nameNode‘); 180 } 181 182 public function jobTrackerState(){ 183 $view = View::getInstance(); 184 $view->set_tpl(‘jobTracker.tpl‘, ‘jobTracker.tpl.php‘); 185 $view->assign(‘title‘, ‘jobTracker状态‘); 186 $view->parse(‘jobTracker‘, ‘jobTracker.tpl‘); 187 $view->show(‘jobTracker‘); 188 } 189 190 public function introduction(){ 191 $view = View::getInstance(); 192 $view->set_tpl(‘introduct.tpl‘, ‘introduct.tpl.php‘); 193 $view->assign(‘title‘, ‘系统介绍‘); 194 $view->parse(‘introduct‘, ‘introduct.tpl‘); 195 $view->show(‘introduct‘); 196 } 197 198 public function connect(){ 199 $view = View::getInstance(); 200 $view->set_tpl(‘connect.tpl‘, ‘connect.tpl.php‘); 201 $view->assign(‘title‘, ‘联系我们‘); 202 $view->parse(‘connect‘, ‘connect.tpl‘); 203 $view->show(‘connect‘); 204 } 205 206 }
标签:des style blog http color io os 使用 ar
原文地址:http://www.cnblogs.com/hemi/p/4019997.html