|
@ -0,0 +1,94 @@
|
|
|
package com.yihu.hos.remoteManage.controller;
|
|
|
|
|
|
import com.yihu.hos.remoteManage.service.RemoteShellService;
|
|
|
import com.yihu.hos.web.framework.util.controller.BaseController;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
/**
|
|
|
* 远程终端管理--shell操作
|
|
|
*
|
|
|
* @author HZY
|
|
|
* @vsrsion 1.0
|
|
|
* Created at 2017/1/5.
|
|
|
*/
|
|
|
@RequestMapping("/shell")
|
|
|
@Controller
|
|
|
public class RemoteShellController extends BaseController {
|
|
|
|
|
|
@Resource(name = RemoteShellService.BEAN_ID)
|
|
|
private RemoteShellService remoteShellService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 远程shell操作页面
|
|
|
*
|
|
|
* @param model
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping("/initial")
|
|
|
public String appInitial(Model model) {
|
|
|
model.addAttribute("contentPage", "shell/shell");
|
|
|
return "partView";
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/shell", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
|
|
|
@ResponseBody
|
|
|
public String shellTest(
|
|
|
@ApiParam(name = "command", value = "shell命令")
|
|
|
@RequestParam(value = "command", required = false) String command,
|
|
|
// @ApiParam(name = "tenant", value = "租户名称")
|
|
|
// @RequestParam(value = "tenant", required = false) String tenant,
|
|
|
@ApiParam(name = "disCon", value = "是否断开会话连接")
|
|
|
@RequestParam(value = "disCon", required = true) boolean disCon) {
|
|
|
String result = "";
|
|
|
try {
|
|
|
//TODO 发送shell命令 消息
|
|
|
System.out.println("发送shell请求==================");
|
|
|
remoteShellService.sendShell(command, disCon);
|
|
|
System.out.println("结果1:" + result);
|
|
|
//TODO 接收shell命令执行结果 消息
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//
|
|
|
// //连接操作shell测试
|
|
|
// @RequestMapping(value = "/shell", produces = "application/json;charset=UTF-8", method = RequestMethod.GET)
|
|
|
// @ResponseBody
|
|
|
// public String shellTest(String cmd, String disCon) {
|
|
|
// String result = "";
|
|
|
// try {
|
|
|
// if (session==null){
|
|
|
// session = sshLinuxTool.getsessionConn();
|
|
|
// }
|
|
|
// if ("false".equals(disCon)) {
|
|
|
// //保持通道连接
|
|
|
// System.out.println("循环开始1111111==================");
|
|
|
// result = sshLinuxTool.sshShell(session, cmd, false);
|
|
|
// System.out.println("结果:"+result);
|
|
|
// } else {
|
|
|
// //断开通道连接,会话
|
|
|
// System.out.println("循环开始2222222222==================");
|
|
|
// result = sshLinuxTool.sshShell(session, cmd, true);
|
|
|
// session = null;
|
|
|
// System.out.println("结果:"+result);
|
|
|
// }
|
|
|
// } catch (Exception e) {
|
|
|
// e.printStackTrace();
|
|
|
// }
|
|
|
// return result;
|
|
|
// }
|
|
|
|
|
|
|
|
|
}
|