Commit 3976f673 by 钱炳权

exception is changed

parent f9e51c78
......@@ -2,16 +2,20 @@ package com.example.fuzzControll.controller;
import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.service.GetServerMessageService;
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.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
/**
* kitty服务器信息
*/
@RestController
@RequestMapping("/kittyServer")
@Slf4j
public class KittyServerMessageController {
@Autowired
GetServerMessageService getServerMessageService;
......@@ -23,6 +27,7 @@ public class KittyServerMessageController {
try {
return AjaxResult.success(getServerMessageService.getStats());
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
return AjaxResult.error("stats信息获取失败!");
}
}
......@@ -34,6 +39,7 @@ public class KittyServerMessageController {
try {
return AjaxResult.success(getServerMessageService.getTemplateInfo());
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
return AjaxResult.error("templateInfo信息获取失败!");
}
}
......@@ -45,6 +51,7 @@ public class KittyServerMessageController {
try {
return AjaxResult.success(getServerMessageService.getStages());
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
return AjaxResult.error("stages信息获取失败!");
}
}
......@@ -56,6 +63,7 @@ public class KittyServerMessageController {
try {
return AjaxResult.success(getServerMessageService.getReport());
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
return AjaxResult.error("report信息获取失败!");
}
}
......
......@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.Arrays;
import java.util.List;
/**
......@@ -32,7 +33,7 @@ public class SeedFileController {
try {
files = service.getSeedFiles();
} catch (Exception e) {
log.error(e.toString());
log.error(Arrays.toString(e.getStackTrace()));
return AjaxResult.error("种子文件获取失败!");
}
return AjaxResult.success(files);
......@@ -46,7 +47,7 @@ public class SeedFileController {
try {
service.delFile(fileName);
} catch (Exception e) {
log.error(e.toString());
log.error(Arrays.toString(e.getStackTrace()));
return AjaxResult.error("种子文件删除失败!");
}
return AjaxResult.success("种子文件删除成功!");
......@@ -59,7 +60,7 @@ public class SeedFileController {
try {
service.upload(file);
} catch (Exception e) {
log.error(e.toString());
log.error(Arrays.toString(e.getStackTrace()));
return AjaxResult.error("种子文件upload失败!");
}
return AjaxResult.success("种子文件upload成功!");
......
......@@ -3,15 +3,19 @@ package com.example.fuzzControll.controller;
import com.example.fuzzControll.pojo.vo.AjaxResult;
import com.example.fuzzControll.pojo.vo.CmdStartParams;
import com.example.fuzzControll.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
/**
* aflnet测试控制
*/
@Slf4j
@RestController
@RequestMapping("/test")
public class TestControler {
......@@ -31,6 +35,7 @@ public class TestControler {
}
}).start();
} catch (Exception e) {
log.error(Arrays.toString(e.getStackTrace()));
return AjaxResult.error("测试启动失败!");
}
return AjaxResult.success("测试启动成功!");
......
......@@ -32,6 +32,9 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
}
public String parseParameters(TestEntity testEntity) {
if(testEntity==null){
throw new FuzzException("testEntity is null!");
}
switch (testEntity.getTestClassName().toLowerCase()) {
case "arp":
return arpCmd(testEntity);
......@@ -645,7 +648,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
return "";
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.HDLC;
}
//todo need change
private String ftpCmd(TestEntity testEntity) {
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "ftp"))
return "";
......@@ -656,6 +659,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
target_port = testEntity.getParamJson()[1];
} catch (Exception e) {
log.error("ftp参数解析失败!");
throw new FuzzException("count of params is not match!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.FTP + target_host + " " + target_port;
}
......@@ -670,6 +674,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
target_port = testEntity.getParamJson()[1];
} catch (Exception e) {
log.error("frp参数解析失败!");
throw new FuzzException("count of params is not match!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.FRP + target_host + " " + target_port;
}
......@@ -684,6 +689,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
dst_port = testEntity.getParamJson()[1];
} catch (Exception e) {
log.error("dns参数解析失败!");
throw new FuzzException("count of params is not match!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.DNS + dst_ip + " " + dst_port;
}
......@@ -698,6 +704,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
dst_port = testEntity.getParamJson()[1];
} catch (Exception e) {
log.error("dhcp参数解析失败!");
throw new FuzzException("count of params is not match!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.DHCP + dst_ip + " " + dst_port;
}
......@@ -716,11 +723,12 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
dst_port = testEntity.getParamJson()[3];
} catch (Exception e) {
log.error("bgp参数解析失败!");
throw new FuzzException("count of params is not match!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.BGP + src_ip + " " + src_port + " " + dst_ip + " " + dst_port;
}
public String arpCmd(TestEntity testEntity) {
public String arpCmd(TestEntity testEntity) throws FuzzException{
if (!TestTools.paramsLenghtTest(testEntity.getParamJson().length, 2, "arp"))
return "";
String dst_mac = null;
......@@ -730,6 +738,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
src_mac = testEntity.getParamJson()[1];
} catch (Exception e) {
log.error("arp参数解析失败!");
throw new FuzzException("count of params is not match!");
}
return kitty.getVenvPath() + " " + kitty.getPath() + ProtocolConstent.ARP + dst_mac + " " + src_mac;
}
......
......@@ -3,6 +3,8 @@ package com.example.fuzzControll.service.impl;
import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.conf.KittyProperties;
import com.example.fuzzControll.constents.CmdConstent;
import com.example.fuzzControll.exception.AflnetException;
import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.pojo.vo.CmdStartParams;
import com.example.fuzzControll.service.TestService;
import com.example.fuzzControll.tools.CmdTools;
......@@ -17,7 +19,7 @@ public class TestServiceImpl implements TestService {
//todo 不同服务不同端口
@Override
public void testStart(CmdStartParams cmdStartParams) {
public void testStart(CmdStartParams cmdStartParams) throws AflnetException {
TestControlTools.setIsRunning(true);
String cmd = cmdTools.parse(cmdStartParams);
String finalCmd = CmdConstent.RUN_AFLNET + cmd + kittyProperties.getAflnetPath()+"live555/testProgs/testOnDemandRTSPServer 8554";
......
......@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools;
import com.alibaba.fastjson.JSONObject;
import com.example.fuzzControll.conf.SpringContextUtil;
import com.example.fuzzControll.controller.WebSocket;
import com.example.fuzzControll.exception.AflnetException;
import com.example.fuzzControll.exception.CmdException;
import com.example.fuzzControll.exception.FuzzException;
import com.example.fuzzControll.pojo.vo.CmdStartParams;
......@@ -217,7 +218,10 @@ public class CmdTools {
return returnEntity;
}
public String parse(CmdStartParams cmdStartParams) {
public String parse(CmdStartParams cmdStartParams) throws AflnetException{
if(cmdStartParams==null){
throw new AflnetException("CmdStartParams is null!");
}
StringBuilder cmd = new StringBuilder();
if (cmdStartParams.getNetinfo() != "") {
cmd.append(" -N " + cmdStartParams.getNetinfo());
......
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