Commit 51383361 by 钱炳权

实验室环境成功返回websocket数据

parent 2b6461e2
......@@ -41,7 +41,7 @@ public class CmdTools {
* 运行需要后台运行cmd
* 通过websocket返回数据
*/
public void runProgramCmd(String cmd) throws AflnetException, JSchException, IOException {
public void runProgramCmd(String aflnetCmd,String pythonCmd,String recodeCmd) throws AflnetException, JSchException, IOException {
AflnetSshProperties aflnetSshProperties = GlobalParameters.aflnetSshProperties;
String host = aflnetSshProperties.getHost();
int port =aflnetSshProperties.getPort();
......@@ -50,7 +50,9 @@ public class CmdTools {
// 手动创建对象实现连接
LinuxCommandUtil linuxCommandUtil = new LinuxCommandUtil();
linuxCommandUtil.connect(host, port, user, password);
linuxCommandUtil.execCmd(cmd);
linuxCommandUtil.execCmd(aflnetCmd);
// linuxCommandUtil.execCmdWithoutResults(pythonCmd);
// linuxCommandUtil.execCmdWithoutResults(recodeCmd);
}
......
......@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import com.alibaba.fastjson.JSONObject;
import com.example.fuzzControll.pojo.vo.TestReturnEntity;
......@@ -11,6 +12,7 @@ import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import org.apache.tomcat.util.buf.Utf8Decoder;
public class LinuxCommandUtil {
......@@ -82,30 +84,66 @@ public class LinuxCommandUtil {
public void execCmd(String command) throws JSchException, IOException {
List<String> result = new ArrayList<>();
InputStream in = channelExec.getInputStream();
InputStream error = channelExec.getErrStream();
new Thread(new Runnable() {
@Override
public void run() {
outPutStream(in);
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
errorStream(error);
}
}).start();
channelExec.setCommand(command);
channelExec.setErrStream(System.err);
channelExec.connect();
}
/**
* 不需要结果执行指令
*/
public void execCmdWithoutResults(String command) throws JSchException, IOException {
channelExec.setCommand(command);
channelExec.connect();
}
public void outPutStream(InputStream in) {
Reader reader = new InputStreamReader(in);
BufferedReader bf = new BufferedReader(reader);
CmdTools cmdTools = new CmdTools();
String line = null;
TestReturnEntity returnEntity = new TestReturnEntity();
List<String> list = null;
try {
while ((line = bf.readLine()) != null && TestControlTools.getIsRunning()) {
System.out.println(line);
if (line.contains("american fuzzy")) {
list = new ArrayList<>();
}
if (list != null)
list.add(line + "\n");
if (line.contains("cpu"))
GlobalParameters.webSocket.appointSending("fuzzMaster", "web", list.toString());
}
//结束就关闭
if (!TestControlTools.getIsRunning()) {
close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void errorStream(InputStream error) {
Reader reader = new InputStreamReader(error);
BufferedReader bf = new BufferedReader(reader);
String line = null;
List<String> list = null;
try {
while ((line = bf.readLine()) != null && TestControlTools.getIsRunning()) {
System.out.println(line);
// cmdTools.makeReturnEntity(line, returnEntity);
// if (cmdTools.send) {
// String data = JSONObject.toJSONString(returnEntity);
// try {
// GlobalParameters.webSocket.appointSending("fuzzMaster", "web", data);
// } catch (Exception ignored) {
// }
// }
}
//结束就关闭
if(!TestControlTools.getIsRunning()){
if (!TestControlTools.getIsRunning()) {
close();
}
} catch (IOException e) {
......
......@@ -8,19 +8,17 @@
var ws1 = null;
var ws2 = null;
function myFunction() {
ws1 = new WebSocket("ws://192.168.9.177:8100/websocket/testResult/web");
ws1 = new WebSocket("ws://192.168.31.133:8100/websocket/testResult/web");
ws1.onmessage = function (evt) {
console.log(evt);
var received_msg =JSON.parse(evt.data) ;
const nameValue = Object.values(received_msg)
console.log(evt.data)
var context = '<div class="sendMsg">' +
'aflnet:<br/>'+
'aflnet<h3>'+nameValue+'</h3><br/>'+
'aflnet<h3>'+evt.data+'</h3><br/>'+
' </div>';
document.getElementById("sendDiv").innerHTML = context;
};
ws1.onclose = function () {
// 关闭 websocket
alert("连接已关闭...");
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment