|
@ -1,8 +1,6 @@
|
|
package com.yihu.hos.remoteManage.controller;
|
|
package com.yihu.hos.remoteManage.controller;
|
|
|
|
|
|
import com.jcraft.jsch.Session;
|
|
|
|
import com.yihu.hos.remoteManage.service.RemoteShellService;
|
|
import com.yihu.hos.remoteManage.service.RemoteShellService;
|
|
import com.yihu.hos.remoteManage.service.SSHLinuxTool;
|
|
|
|
import com.yihu.hos.web.framework.util.controller.BaseController;
|
|
import com.yihu.hos.web.framework.util.controller.BaseController;
|
|
import io.swagger.annotations.ApiParam;
|
|
import io.swagger.annotations.ApiParam;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
@ -28,10 +26,6 @@ public class RemoteShellController extends BaseController {
|
|
@Resource(name = RemoteShellService.BEAN_ID)
|
|
@Resource(name = RemoteShellService.BEAN_ID)
|
|
private RemoteShellService remoteShellService;
|
|
private RemoteShellService remoteShellService;
|
|
|
|
|
|
@Resource(name = SSHLinuxTool.BEAN_ID)
|
|
|
|
private SSHLinuxTool sshLinuxTool;
|
|
|
|
|
|
|
|
public static Session session ;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 远程shell操作页面
|
|
* 远程shell操作页面
|
|
@ -68,33 +62,33 @@ public class RemoteShellController extends BaseController {
|
|
return result;
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
//
|
|
|
|
// //连接操作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;
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|