Commit 41283d5e by 钱炳权

kitty测试结果持久化完成

parent 00d5206b
......@@ -113,6 +113,12 @@
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--PageHelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.6</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
......
......@@ -4,9 +4,18 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component("seedProperties")
@ConfigurationProperties(prefix = "filepath")
public class SeedProperties {
@ConfigurationProperties(prefix = "aflnet")
public class AflnetProperties {
String seedPath;
String outputPath;
public String getOutputPath() {
return outputPath;
}
public void setOutputPath(String outputPath) {
this.outputPath = outputPath;
}
public String getSeedPath() {
return seedPath;
......
......@@ -4,8 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component("PathProperties")
@ConfigurationProperties(prefix = "path")
public class PathProperties {
@ConfigurationProperties(prefix = "integrationpath")
public class IntegrationPathProperties {
String webSocketUri;
public String getWebSocketUri() {
......
package com.example.fuzzControll.controller.dataController;
import com.example.fuzzControll.service.AflnetPersistenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/aflnet")
@Slf4j
public class AflnetDataController {
@Autowired
AflnetPersistenceService aflnetPersistenceService;
}
package com.example.fuzzControll.controller.dataController;
import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.service.FuzzPersistenceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/kittyServer")
@Slf4j
public class KittyDataController {
@Autowired
FuzzPersistenceService fuzzPersistenceService;
/**
* 查询kitty结果
*/
@RequestMapping(value = "/KittyResultSelect", method = RequestMethod.GET)
public AjaxResult KittyResultSelect( ){
List<KittyResult> results;
try {
results = fuzzPersistenceService.getKittyResults();
} catch (Exception e) {
e.printStackTrace();
return AjaxResult.error();
}
return AjaxResult.success(results);
}
}
package com.example.fuzzControll.mapper;
import com.example.fuzzControll.pojo.vo.AflnetResult;
import com.example.fuzzControll.pojo.vo.KittyResult;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
import java.util.List;
@Mapper
@Component("AflnetMapper")
public interface AflnetMapper {
/**
* 查询kitty模糊测试结果
*/
// List<KittyResult> getKittyResults();
/**
* 存储alfnet测试结果
*/
void aflnetOutputBackup(AflnetResult aflnetResult);
}
......@@ -4,15 +4,19 @@ package com.example.fuzzControll.mapper;
import com.example.fuzzControll.pojo.vo.KittyLog;
import com.example.fuzzControll.pojo.vo.KittyResult;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
import java.util.List;
@Mapper
@Component("KittyMapper")
public interface KittyMapper {
/**
* 查询kitty模糊测试结果
*/
List<KittyResult> selectAll();
List<KittyResult> getKittyResults();
void kittyResultsBackup(KittyResult kittyResult);
/**
* 查询kitty日志
......
package com.example.fuzzControll.pojo.vo;
import lombok.Data;
@Data
public class AflnetResult {
private int id;
private int missionId;
private byte[] file;
private String fileName;
public AflnetResult(int missionId, byte[] file, String fileName) {
this.missionId = missionId;
this.file = file;
this.fileName = fileName;
}
public AflnetResult() {
}
}
......@@ -5,6 +5,16 @@ import lombok.Data;
@Data
public class KittyResult {
private int id;
private int missionId;
private String resultOut;
private String resultError;
public KittyResult() {
}
public KittyResult(int missionId, String resultOut, String resultError) {
this.missionId = missionId;
this.resultOut = resultOut;
this.resultError = resultError;
}
}
package com.example.fuzzControll.service;
import com.example.fuzzControll.pojo.vo.AflnetResult;
public interface AflnetPersistenceService {
public void aflnetResultBackup(String filename);
}
package com.example.fuzzControll.service;
import com.example.fuzzControll.pojo.vo.KittyResult;
import java.util.List;
public interface FuzzPersistenceService {
List<KittyResult> getKittyResults();
}
package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.mapper.AflnetMapper;
import com.example.fuzzControll.pojo.vo.AflnetResult;
import com.example.fuzzControll.service.AflnetPersistenceService;
import com.example.fuzzControll.tools.FileTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class AflnetPersistenceServiceImpl implements AflnetPersistenceService {
@Autowired
AflnetMapper AflnetMapper;
FileTools fileTools = new FileTools();
@Override
public void aflnetResultBackup(String filename) {
//todo 需要传入任务id
AflnetResult result = new AflnetResult(1,fileTools.fileReadAndBackup(filename),filename);
AflnetMapper.aflnetOutputBackup(result);
}
}
package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.mapper.KittyMapper;
import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.service.FuzzPersistenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@Slf4j
public class FuzzPersistenceServiceImpl implements FuzzPersistenceService {
@Autowired
KittyMapper kittyMapper;
@Override
public List<KittyResult> getKittyResults() {
return kittyMapper.getKittyResults();
}
}
......@@ -34,7 +34,7 @@ public class TestServiceImpl implements TestService {
String outputPathName = df.format(date)+cmdStartParams.getProtopcol()+"-output";
String finalCmd = CmdConstent.RUN_AFLNET_BEFORE + outputPathName + CmdConstent.RUN_AFLNET_AFTER + cmd + kittyProperties.getAflnetPath() + "live555/testProgs/testOnDemandRTSPServer 8554";
log.info("The cmd is [{}]",finalCmd);
cmdTools.runProgramCmd(finalCmd);
cmdTools.runProgramCmd(finalCmd,outputPathName);
}
......
package com.example.fuzzControll.tools;
import com.alibaba.fastjson.JSONObject;
import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.exception.AflnetException;
import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.mapper.KittyMapper;
import com.example.fuzzControll.pojo.vo.CmdStartParams;
import com.example.fuzzControll.pojo.vo.KittyResult;
import com.example.fuzzControll.pojo.vo.TestReturnEntity;
import com.example.fuzzControll.service.AflnetPersistenceService;
import com.example.fuzzControll.service.impl.websocketClientServiceImpl;
import lombok.extern.slf4j.Slf4j;
import javax.swing.*;
import java.io.*;
import java.util.*;
......@@ -20,7 +25,8 @@ public class CmdTools {
Boolean show = true;
SqlTools sqlTools = new SqlTools();
AflnetPersistenceService AflnetPersistenceService = (AflnetPersistenceService) SpringContextUtil.getBean("AflnetPersistenceService");
/**
* 运行不需要后台运行cmd
*/
......@@ -44,12 +50,13 @@ public class CmdTools {
* 运行需要后台运行cmd
* 通过websocket返回数据
*/
public void runProgramCmd(String cmd) throws AflnetException {
public void runProgramCmd(String cmd,String outputPathName) throws AflnetException {
try {
Process process = Runtime.getRuntime().exec(cmd);
printMessageToWeb(process.getInputStream());
printMessage(process.getErrorStream(), new ArrayList<String>());
process.waitFor();
AflnetPersistenceService.aflnetResultBackup(outputPathName);
log.info("Aflnet cmd have been run.");
} catch (Exception e) {
e.printStackTrace();
......@@ -70,12 +77,22 @@ public class CmdTools {
printMessageByProgramCmd(process.getInputStream(), out);
printMessageByProgramCmd(process.getErrorStream(), error);
process.waitFor();
//todo 对于无法运行和数据较长的还需要观察
try {
KittyResult kittyResult = new KittyResult(1, out.toString(), error.toString());
sqlTools.kittyBackup(kittyResult);
} catch (Exception e) {
e.printStackTrace();
log.error("kitty backup error!");
}
} catch (Exception e) {
e.printStackTrace();
throw new CmdException("run fuzz error !");
}
result.put("out", out);
result.put("error", error);
//todo 需要传入任务参数,后期再开发
return result;
}
......@@ -237,11 +254,13 @@ public class CmdTools {
public String parse(CmdStartParams cmdStartParams) throws AflnetException {
if (cmdStartParams == null) {
throw new AflnetException("CmdStartParams is null!");
throw new AflnetException("CmdStartParams is null !");
}
StringBuilder cmd = new StringBuilder();
if (cmdStartParams.getNetinfo() != "") {
if (cmdStartParams.getNetinfo() != "" && cmdStartParams.getNetinfo() != null) {
cmd.append(" -N " + cmdStartParams.getNetinfo());
} else {
throw new AflnetException("There is no netinfo !");
}
if (cmdStartParams.getProtopcol() != "") {
cmd.append(" -P " + cmdStartParams.getProtopcol());
......
package com.example.fuzzControll.tools;
import com.example.fuzzControll.conf.AflnetProperties;
import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.conf.SeedProperties;
import com.example.fuzzControll.exception.FileException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.*;
@Slf4j
public class FileTools {
SeedProperties properties = (SeedProperties) SpringContextUtil.getBean("seedProperties");
AflnetProperties properties = (AflnetProperties) SpringContextUtil.getBean("AflnetProperties");
public void load(MultipartFile file) throws FileException {
if (file == null) {
......@@ -34,4 +31,25 @@ public class FileTools {
}
}
public byte[] fileReadAndBackup(String filename) {
File file = new File(properties.getOutputPath() + "/" + filename);
try (
FileInputStream inputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);) {
if (file.length() > Integer.MAX_VALUE) {
throw new IOException();
}
byte[] buffer = new byte[(int) file.length()];
int bytesRead;
while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
bufferedInputStream.read(buffer, 0, bytesRead);
}
return buffer;
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException("File is to large " + file.getName());
}
}
}
\ No newline at end of file
package com.example.fuzzControll.tools;
import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.mapper.KittyMapper;
import com.example.fuzzControll.pojo.vo.KittyResult;
public class SqlTools {
KittyMapper kittyMapper = (KittyMapper) SpringContextUtil.getBean("KittyMapper");
public void kittyBackup(KittyResult kittyResult) {
kittyMapper.kittyResultsBackup(kittyResult);
}
}
......@@ -19,9 +19,9 @@ logging:
rollingPolicy:
max-file-size: 10MB
filepath:
aflnet:
seedPath: "/usr/fuzzenv/fuzzenv/aflnet/tutorials/live555/in-rtsp"
outputPath: "D:/code/companyProjects/files" #D:/code/companyProjects/files
kitty:
aflnetPath: "/usr/fuzzenv/fuzzenv/"#alfnet路径
outputPath: "/home/" #alfnet输出路径
......@@ -44,7 +44,7 @@ spring:
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
path:
integrationpath:
webSocketUri: ws://${fuzzmaster-docker.ip}:8101/websocket/testResult/
nacos-docker:
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.fuzzControll.mapper.AflnetMapper">
<resultMap type="com.example.fuzzControll.pojo.vo.AflnetResult" id="AflnetResult">
<result property="id" column="id" />
<result property="missionId" column="missionId" />
<result property="file" column="file" />
<result property="fileName" column="fileName" />
</resultMap>
<sql id="selectKittyResult">
select id, missionId,file, fileName from kittyResult;
</sql>
<insert id="aflnetOutputBackup">
insert into alfnetResult(id,missionId, file, fileName) values(#{id}, #{missionId},#{file}, #{fileName})
</insert>
</mapper>
\ No newline at end of file
......@@ -6,15 +6,19 @@
<resultMap type="com.example.fuzzControll.pojo.vo.KittyResult" id="KittyResult">
<result property="id" column="id" />
<result property="missionId" column="missionId" />
<result property="resultOut" column="resultOut" />
<result property="resultError" column="resultError" />
</resultMap>
<sql id="selectKittyResult">
select id, resultOut, resultError from kittyResult;
select id, missionId,resultOut, resultError from kittyResult;
</sql>
<insert id="kittyResultsBackup">
insert into kittyResult(id,missionId, resultOut, resultError) values(#{id}, #{missionId},#{resultOut}, #{resultError})
</insert>
<select id="selectAll" resultMap="KittyResult">
<select id="getKittyResults" resultMap="KittyResult">
<include refid="selectKittyResult"/>
</select>
......
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