Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fuzzBackEnd
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钱炳权
fuzzBackEnd
Commits
f60354b1
Commit
f60354b1
authored
8 months ago
by
钱炳权
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
测试启动有bug
parent
d0d52dc1
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
233 additions
and
116 deletions
+233
-116
aroundAop.java
...src/main/java/com/example/fuzzControll/aop/aroundAop.java
+13
-6
beforeAop.java
...src/main/java/com/example/fuzzControll/aop/beforeAop.java
+5
-4
MissionStateEnum.java
.../com/example/fuzzControll/constents/MissionStateEnum.java
+2
-1
AlfnetController.java
...zControll/controller/testController/AlfnetController.java
+0
-27
MissionInfo.java
.../java/com/example/fuzzControll/domain/po/MissionInfo.java
+2
-5
MissionInfoMapper.java
...va/com/example/fuzzControll/mapper/MissionInfoMapper.java
+2
-6
TestMapper.java
...main/java/com/example/fuzzControll/mapper/TestMapper.java
+2
-0
TestService.java
...in/java/com/example/fuzzControll/service/TestService.java
+2
-1
AflnetPersistenceServiceImpl.java
...zzControll/service/impl/AflnetPersistenceServiceImpl.java
+4
-1
FuzzLogServiceImpl.java
...example/fuzzControll/service/impl/FuzzLogServiceImpl.java
+13
-13
ProtocolTemplateImpl.java
...ample/fuzzControll/service/impl/ProtocolTemplateImpl.java
+1
-1
TestMissionServiceImpl.java
...ple/fuzzControll/service/impl/TestMissionServiceImpl.java
+93
-10
TestServiceImpl.java
...om/example/fuzzControll/service/impl/TestServiceImpl.java
+4
-16
StringUtils.java
...com/example/fuzzControll/tools/component/StringUtils.java
+20
-0
SystemRunningParams.java
...xample/fuzzControll/tools/system/SystemRunningParams.java
+12
-0
TestCmdTools.java
...ava/com/example/fuzzControll/tools/test/TestCmdTools.java
+11
-10
FuzzParamsMapper.xml
...ntegration/src/main/resources/mapper/FuzzParamsMapper.xml
+1
-1
MissionInfoMapper.xml
...tegration/src/main/resources/mapper/MissionInfoMapper.xml
+22
-13
TestMapper.xml
fuzzIntegration/src/main/resources/mapper/TestMapper.xml
+12
-0
TestMissionController.java
...e/fuzzbackendmaster/controller/TestMissionController.java
+7
-1
FuzzIntegrationFileApi.java
...ple/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
+5
-0
No files found.
fuzzIntegration/src/main/java/com/example/fuzzControll/aop/aroundAop.java
View file @
f60354b1
...
...
@@ -8,6 +8,7 @@ import com.example.fuzzControll.domain.po.MissionInfo;
import
com.example.fuzzControll.exception.mysqlException.MysqlException
;
import
com.example.fuzzControll.exception.testException.AflnetException
;
import
com.example.fuzzControll.exception.testException.KittyException
;
import
com.example.fuzzControll.mapper.MissionInfoMapper
;
import
com.example.fuzzControll.tools.system.GlobalClass
;
import
com.example.fuzzControll.tools.system.SystemRunningParams
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -18,6 +19,7 @@ import org.aspectj.lang.annotation.Around;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.Ordered
;
import
org.springframework.stereotype.Component
;
...
...
@@ -30,6 +32,8 @@ import java.util.Map;
@Component
@Slf4j
public
class
aroundAop
implements
Ordered
{
@Autowired
MissionInfoMapper
missionInfoMapper
;
@Pointcut
(
value
=
"@annotation(com.example.fuzzControll.annotion.NeedCutAround)"
)
private
void
aroundCut
()
{
}
...
...
@@ -69,11 +73,11 @@ public class aroundAop implements Ordered {
/*运行前处理*/
/*存入kitty启动时的任务信息*/
try
{
int
missionId
=
GlobalClass
.
missionInfoMapper
.
selectTopMissionId
()
+
1
;
SystemRunningParams
.
kittyMissionId
=
missionId
;
MissionInfo
missionInfo
=
new
MissionInfo
(
missionId
,
TableClassEnum
.
KITTY_RESULT
.
getTableId
(),
new
Date
(),
SystemRunningParams
.
kittyData
.
get
(
"missionName"
),
MissionStateEnum
.
RUNNING
.
getStateCode
(),
0L
);
GlobalClass
.
missionInfoMapper
.
insertMission
(
missionInfo
);
//
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId() + 1;
//
SystemRunningParams.kittyMissionId = missionId;
//
MissionInfo missionInfo = new MissionInfo(missionId, TableClassEnum.KITTY_RESULT.getTableId(), new Date(), SystemRunningParams.kittyData.get("missionName"),
//
MissionStateEnum.RUNNING.getStateCode(), 0L);
//
GlobalClass.missionInfoMapper.insertMission(missionInfo);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
MysqlException
(
"Kitty start backup failed!"
);
...
...
@@ -99,7 +103,10 @@ public class aroundAop implements Ordered {
int
missionId
=
SystemRunningParams
.
kittyMissionId
;
Long
runTime
=
SystemRunningParams
.
testTimeMessage
.
get
(
"kitty"
).
get
(
"end"
)
-
SystemRunningParams
.
testTimeMessage
.
get
(
"kitty"
).
get
(
"start"
);
System
.
out
.
println
(
"MissionId :"
+
missionId
);
GlobalClass
.
missionInfoMapper
.
updateMission
(
MissionStateEnum
.
DONE
.
getStateCode
(),
runTime
,
missionId
);
//更新该次任务的执行时间;
MissionInfo
missionInfo
=
missionInfoMapper
.
selectByMissionId
(
missionId
);
missionInfo
.
setState
(
MissionStateEnum
.
DONE
.
getStateCode
());
missionInfo
.
setRunTime
(
runTime
);
GlobalClass
.
missionInfoMapper
.
updateMission
(
missionInfo
);
//更新该次任务的执行时间;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
MysqlException
(
"Kitty start backup failed!"
);
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/aop/beforeAop.java
View file @
f60354b1
...
...
@@ -25,6 +25,7 @@ import org.springframework.stereotype.Component;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Parameter
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -86,10 +87,10 @@ public class beforeAop implements Ordered{
if
(
"startBackup"
.
equals
(
function
))
{
/*存入alfnet启动时的任务信息*/
try
{
int
missionId
=
GlobalClass
.
missionInfoMapper
.
selectTopMissionId
()
+
1
;
SystemRunningParams
.
aflnetMissionId
=
missionId
;
GlobalClass
.
missionInfoMapper
.
insertMission
(
new
MissionInfo
(
missionId
,
TableClassEnum
.
AFLNET
.
getTableId
(),
new
Date
(),
SystemRunningParams
.
aflnetData
.
get
(
"missionName"
),
MissionStateEnum
.
RUNNING
.
getStateCode
(),
0L
));
//
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId() + 1;
//
SystemRunningParams.aflnetMissionId = missionId;
//
GlobalClass.missionInfoMapper.insertMission(new MissionInfo(missionId, TableClassEnum.AFLNET.getTableId(), new Date(), SystemRunningParams.aflnetData.get("missionName"),
//
MissionStateEnum.RUNNING.getStateCode(), 0L));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
MysqlException
(
"Aflnet start backup failed!"
);
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/constents/MissionStateEnum.java
View file @
f60354b1
...
...
@@ -6,7 +6,8 @@ package com.example.fuzzControll.constents;
public
enum
MissionStateEnum
{
DONE
(
"done"
,
1
),
RUNNING
(
"running"
,
2
),
FAILED
(
"failed"
,
3
);
FAILED
(
"failed"
,
3
),
STARTING
(
"starting"
,
4
);
private
String
stateName
;
private
int
stateCode
;
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/controller/testController/AlfnetController.java
View file @
f60354b1
...
...
@@ -29,33 +29,6 @@ public class AlfnetController {
TestService
service
;
/**
* 测试启动
*/
@RequestMapping
(
value
=
"/testStart"
,
method
=
RequestMethod
.
POST
)
public
AjaxResult
start
(
@RequestBody
final
CmdStartParams
cmdStartParams
)
{
try
{
SystemRunningParams
.
aflnetData
.
put
(
"missionName"
,
cmdStartParams
.
getProtopcol
());
Thread
subThread
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
service
.
testStart
(
cmdStartParams
);
}
});
SystemRunningParams
.
ThreadState
.
put
(
subThread
,
"start"
);
subThread
.
setUncaughtExceptionHandler
(
new
MyExceptionHandler
());
subThread
.
start
();
// subThread.join();
Thread
.
sleep
(
1000
*
10
);
//暂停3s,让系统运行至指令完全运行 todo跟据系统运行设定时间
if
(
"error"
.
equals
(
SystemRunningParams
.
ThreadState
.
get
(
subThread
)))
{
//使用join串行就无法停止
throw
new
Exception
();
}
}
catch
(
Exception
e
)
{
return
AjaxResult
.
error
(
"测试启动失败!"
);
}
return
AjaxResult
.
success
(
"测试已启动!"
);
}
/**
* 测试停止
*/
@RequestMapping
(
value
=
"/testStop"
,
method
=
RequestMethod
.
GET
)
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/domain/po/MissionInfo.java
View file @
f60354b1
...
...
@@ -9,7 +9,6 @@ import java.util.Date;
public
class
MissionInfo
{
@JsonIgnore
private
int
id
;
private
int
missionId
;
@JsonIgnore
private
int
tableId
;
//返回数据忽略字段;aflnet 为1 kitty为2
private
Date
createTime
;
...
...
@@ -21,8 +20,7 @@ public class MissionInfo {
public
MissionInfo
()
{
}
public
MissionInfo
(
int
missionId
,
int
tableId
,
Date
createTime
,
String
missionName
,
int
state
,
Long
runTime
)
{
this
.
missionId
=
missionId
;
public
MissionInfo
(
int
tableId
,
Date
createTime
,
String
missionName
,
int
state
,
Long
runTime
)
{
this
.
tableId
=
tableId
;
this
.
createTime
=
createTime
;
this
.
missionName
=
missionName
;
...
...
@@ -30,8 +28,7 @@ public class MissionInfo {
this
.
runTime
=
runTime
;
}
public
MissionInfo
(
int
missionId
,
Date
createTime
,
String
missionName
,
Long
runTime
,
String
stateName
)
{
this
.
missionId
=
missionId
;
public
MissionInfo
(
Date
createTime
,
String
missionName
,
Long
runTime
,
String
stateName
)
{
this
.
createTime
=
createTime
;
this
.
missionName
=
missionName
;
this
.
runTime
=
runTime
;
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/mapper/MissionInfoMapper.java
View file @
f60354b1
...
...
@@ -15,12 +15,8 @@ public interface MissionInfoMapper {
* 查询任务信息列表
*/
List
<
MissionInfo
>
selectMissionInfoList
();
/**
* 查询当前任务Id
*/
int
selectTopMissionId
();
void
insertMission
(
MissionInfo
missionInfo
);
boolean
insertMission
(
MissionInfo
missionInfo
);
void
updateMission
(
int
state
,
Long
runTime
,
int
missionId
);
void
updateMission
(
MissionInfo
missionInfo
);
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/mapper/TestMapper.java
View file @
f60354b1
...
...
@@ -25,4 +25,6 @@ public interface TestMapper {
boolean
deleteEmptyById
(
int
id
);
boolean
editTestName
(
String
testName
,
int
id
);
void
update
(
Test
test
);
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/TestService.java
View file @
f60354b1
package
com
.
example
.
fuzzControll
.
service
;
import
com.example.fuzzControll.domain.bo.CmdStartParams
;
import
com.example.fuzzControll.domain.po.MissionInfo
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
...
...
@@ -8,7 +9,7 @@ import java.util.concurrent.ConcurrentHashMap;
public
interface
TestService
{
void
testStart
(
CmdStartParams
cmdStartParams
);
void
testStart
(
CmdStartParams
cmdStartParams
,
MissionInfo
missionInfo
);
void
testStop
();
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/AflnetPersistenceServiceImpl.java
View file @
f60354b1
...
...
@@ -48,9 +48,12 @@ public class AflnetPersistenceServiceImpl implements AflnetPersistenceService {
@Transactional
(
rollbackFor
=
MysqlException
.
class
)
public
int
mysqlTransaction
(
String
filename
,
int
state
,
Long
runTime
)
{
int
aflnetMissionId
=
SystemRunningParams
.
aflnetMissionId
;
//获取系统正在操作的aflnet的missionId
MissionInfo
missionInfo
=
missionInfoMapper
.
selectByMissionId
(
aflnetMissionId
);
AflnetResult
result
=
new
AflnetResult
(
aflnetMissionId
,
fileTools
.
fileReadAndTranstoBytes
(
aflnetProperties
.
getOutputPath
(),
filename
),
filename
);
aflnetMapper
.
aflnetOutputBackup
(
result
);
//存入日志文件
missionInfoMapper
.
updateMission
(
state
,
runTime
,
aflnetMissionId
);
//更新该次任务的执行时间
missionInfo
.
setRunTime
(
runTime
);
missionInfo
.
setState
(
state
);
missionInfoMapper
.
updateMission
(
missionInfo
);
//更新该次任务的执行时间
return
1
;
}
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/FuzzLogServiceImpl.java
View file @
f60354b1
...
...
@@ -51,11 +51,11 @@ public class FuzzLogServiceImpl implements FuzzLogService {
public
List
<
FuzzLogTransEntity
>
downloadKittyProtocalFile
(
MissionInfo
missionInfo
)
{
/*获取结果日志*/
List
<
FuzzLogTransEntity
>
fuzzLogList
=
new
ArrayList
<
FuzzLogTransEntity
>();
KittyResult
kittyResult
=
kittyMapper
.
getKittyResultByMissionId
(
missionInfo
.
getMissionId
());
StringBuffer
buffer
=
new
StringBuffer
();
buffer
.
append
(
kittyResult
.
getResultError
()).
append
(
System
.
lineSeparator
()).
append
(
kittyResult
.
getResultOut
());
FuzzLogTransEntity
fuzzLogTransEntity
=
new
FuzzLogTransEntity
(
buffer
.
toString
().
getBytes
(),
missionInfo
.
getMissionName
()
+
".txt"
);
fuzzLogList
.
add
(
fuzzLogTransEntity
);
//
KittyResult kittyResult = kittyMapper.getKittyResultByMissionId(missionInfo.getMissionId());
//
StringBuffer buffer = new StringBuffer();
//
buffer.append(kittyResult.getResultError()).append(System.lineSeparator()).append(kittyResult.getResultOut());
//
FuzzLogTransEntity fuzzLogTransEntity = new FuzzLogTransEntity(buffer.toString().getBytes(), missionInfo.getMissionName() + ".txt");
//
fuzzLogList.add(fuzzLogTransEntity);
/*获取数据包文件*/
// KittyPackageFile kittyPackageFile = kittyMapper.getKittyPackageFileById(missionInfo.getMissionId());
// FuzzLogTransEntity fuzzLogTransEntitySend = new FuzzLogTransEntity(kittyPackageFile.getKittySendFile(), kittyPackageFile.getKittyRecvFileName());
...
...
@@ -68,20 +68,20 @@ public class FuzzLogServiceImpl implements FuzzLogService {
@Transactional
(
rollbackFor
=
MysqlException
.
class
)
public
List
<
FuzzLogTransEntity
>
downloadKittyOtherMethodFile
(
MissionInfo
missionInfo
)
{
List
<
FuzzLogTransEntity
>
fuzzLogList
=
new
ArrayList
<
FuzzLogTransEntity
>();
KittyResult
kittyResult
=
kittyMapper
.
getKittyResultByMissionId
(
missionInfo
.
getMissionId
());
StringBuffer
buffer
=
new
StringBuffer
();
buffer
.
append
(
kittyResult
.
getResultError
()).
append
(
System
.
lineSeparator
()).
append
(
kittyResult
.
getResultOut
());
FuzzLogTransEntity
fuzzLogTransEntity
=
new
FuzzLogTransEntity
(
buffer
.
toString
().
getBytes
(),
missionInfo
.
getMissionName
()
+
".txt"
);
fuzzLogList
.
add
(
fuzzLogTransEntity
);
//
KittyResult kittyResult = kittyMapper.getKittyResultByMissionId(missionInfo.getMissionId());
//
StringBuffer buffer = new StringBuffer();
//
buffer.append(kittyResult.getResultError()).append(System.lineSeparator()).append(kittyResult.getResultOut());
//
FuzzLogTransEntity fuzzLogTransEntity = new FuzzLogTransEntity(buffer.toString().getBytes(), missionInfo.getMissionName() + ".txt");
//
fuzzLogList.add(fuzzLogTransEntity);
return
fuzzLogList
;
}
@Transactional
(
rollbackFor
=
MysqlException
.
class
)
public
List
<
FuzzLogTransEntity
>
downloadAflnetFile
(
MissionInfo
missionInfo
)
{
List
<
FuzzLogTransEntity
>
fuzzLogList
=
new
ArrayList
<
FuzzLogTransEntity
>();
AflnetResult
aflnetResult
=
aflnetMapper
.
selectResultById
(
missionInfo
.
getMissionId
());
FuzzLogTransEntity
fuzzLogTransEntity
=
new
FuzzLogTransEntity
(
aflnetResult
.
getFile
(),
aflnetResult
.
getFileName
());
fuzzLogList
.
add
(
fuzzLogTransEntity
);
//
AflnetResult aflnetResult = aflnetMapper.selectResultById(missionInfo.getMissionId());
//
FuzzLogTransEntity fuzzLogTransEntity = new FuzzLogTransEntity(aflnetResult.getFile(), aflnetResult.getFileName());
//
fuzzLogList.add(fuzzLogTransEntity);
return
fuzzLogList
;
}
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/ProtocolTemplateImpl.java
View file @
f60354b1
...
...
@@ -44,7 +44,7 @@ public class ProtocolTemplateImpl implements ProtocolTemplateService {
@NeedCutAround
(
name
=
"kitty"
,
function
=
"generation"
)
public
Map
<
String
,
List
<
String
>>
generation
(
TestEntity
testEntity
)
throws
FuzzException
,
CmdException
{
/*存入参数*/
int
missionId
=
GlobalClass
.
missionInfoMapper
.
selectTopMissionId
();
//
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId();
// boolean flag = fuzzParamsService.saveFuzzParams(new FuzzParams(JSON.toJSONString(testEntity.getParamJson()), new Date(), missionId));
// if (!flag) {
// throw new AflnetException("Save params error!");
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/TestMissionServiceImpl.java
View file @
f60354b1
package
com
.
example
.
fuzzControll
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.example.fuzzControll.constents.MissionStateEnum
;
import
com.example.fuzzControll.constents.TableClassEnum
;
import
com.example.fuzzControll.domain.bo.CmdStartParams
;
...
...
@@ -9,11 +10,15 @@ import com.example.fuzzControll.domain.bo.TestEntity;
import
com.example.fuzzControll.domain.po.MissionInfo
;
import
com.example.fuzzControll.domain.po.Test
;
import
com.example.fuzzControll.domain.po.TestAndParams
;
import
com.example.fuzzControll.domain.vo.AjaxResult
;
import
com.example.fuzzControll.exception.mysqlException.MysqlException
;
import
com.example.fuzzControll.exception.threadException.MyExceptionHandler
;
import
com.example.fuzzControll.mapper.FuzzParamsMapper
;
import
com.example.fuzzControll.mapper.MissionInfoMapper
;
import
com.example.fuzzControll.mapper.TestMapper
;
import
com.example.fuzzControll.service.TestMissionService
;
import
com.example.fuzzControll.service.TestService
;
import
com.example.fuzzControll.tools.component.StringUtils
;
import
com.example.fuzzControll.tools.system.GlobalClass
;
import
com.example.fuzzControll.tools.system.SystemRunningParams
;
import
lombok.Data
;
...
...
@@ -23,10 +28,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.*
;
import
java.util.stream.Collectors
;
@Slf4j
...
...
@@ -38,6 +40,8 @@ public class TestMissionServiceImpl implements TestMissionService {
FuzzParamsMapper
fuzzParamsMapper
;
@Autowired
MissionInfoMapper
missionInfoMapper
;
@Autowired
TestService
service
;
@Override
public
List
<
TestAndParams
>
getTestAndParamsList
()
{
...
...
@@ -152,18 +156,97 @@ public class TestMissionServiceImpl implements TestMissionService {
return
flag
;
}
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
@Override
public
void
startMission
(
int
id
)
{
Boolean
isAflnet
=
false
;
Test
test
=
testMapper
.
getTestById
(
id
);
if
(
!(
test
.
getFuzzParamsId
()
==
0
)
)
{
if
(
test
.
getFuzzParamsId
()
==
0
)
{
log
.
error
(
"This is a empty test!"
);
throw
new
RuntimeException
();
}
/*生成任务*/
int
missionId
=
GlobalClass
.
missionInfoMapper
.
selectTopMissionId
()
+
1
;
SystemRunningParams
.
kittyMissionId
=
missionId
;
MissionInfo
missionInfo
=
new
MissionInfo
(
missionId
,
TableClassEnum
.
KITTY_RESULT
.
getTableId
(),
new
Date
(),
SystemRunningParams
.
kittyData
.
get
(
"missionName"
),
MissionStateEnum
.
RUNNING
.
getStateCode
(),
0L
);
FuzzParams
fuzzParams
=
null
;
try
{
fuzzParams
=
fuzzParamsMapper
.
getFuzzParamsById
(
test
.
getFuzzParamsId
());
}
catch
(
Exception
e
)
{
log
.
error
(
"Get fuzzParams error!:[{}]"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
/*生成任务,并插入任务数据,回填测试生成的任务字段*/
String
protocol
=
fuzzParams
.
getProtocol
();
MissionInfo
missionInfo
;
if
(
Arrays
.
asList
(
SystemRunningParams
.
AflnetProtocol
).
contains
(
protocol
))
{
missionInfo
=
new
MissionInfo
(
TableClassEnum
.
AFLNET
.
getTableId
(),
new
Date
(),
protocol
,
MissionStateEnum
.
STARTING
.
getStateCode
(),
0L
);
isAflnet
=
true
;
}
else
if
(
Arrays
.
asList
(
SystemRunningParams
.
KittyProtocol
).
contains
(
protocol
))
{
missionInfo
=
new
MissionInfo
(
TableClassEnum
.
KITTY_RESULT
.
getTableId
(),
new
Date
(),
protocol
,
MissionStateEnum
.
STARTING
.
getStateCode
(),
0L
);
isAflnet
=
false
;
}
else
{
log
.
error
(
"Unknown protocol!"
);
throw
new
RuntimeException
();
}
Boolean
flag
=
false
;
try
{
flag
=
missionInfoMapper
.
insertMission
(
missionInfo
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Error inserting mission:[{}]"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
if
(!
flag
)
{
log
.
error
(
"Insert mission error!"
);
throw
new
RuntimeException
();
}
try
{
String
missionIds
=
StringUtils
.
getArrayFormatString
(
test
.
getMissionIds
(),
String
.
valueOf
(
missionInfo
.
getId
()));
test
.
setMissionIds
(
missionIds
);
testMapper
.
update
(
test
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Update test error:[{}]"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
/*运行程序*/
try
{
if
(
isAflnet
)
{
// 启动alfnet
aflnetMissionStart
(
fuzzParams
,
missionInfo
);
}
else
{
}
}
catch
(
Exception
e
)
{
log
.
error
(
"Mission start error:[{}]"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
}
/**
* 启动aflnet任务
*/
private
void
aflnetMissionStart
(
FuzzParams
fuzzParams
,
MissionInfo
missionInfo
)
{
CmdStartParams
cmdStartParams
=
(
CmdStartParams
)
JSONObject
.
parseObject
(
fuzzParams
.
getParams
(),
CmdStartParams
.
class
);
try
{
SystemRunningParams
.
aflnetData
.
put
(
"missionName"
,
cmdStartParams
.
getProtopcol
());
Thread
subThread
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
missionInfo
.
setState
(
MissionStateEnum
.
RUNNING
.
getStateCode
());
missionInfoMapper
.
updateMission
(
missionInfo
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Error updating mission:[{}]"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
service
.
testStart
(
cmdStartParams
,
missionInfo
);
}
});
SystemRunningParams
.
ThreadState
.
put
(
subThread
,
"start"
);
subThread
.
setUncaughtExceptionHandler
(
new
MyExceptionHandler
());
subThread
.
start
();
// subThread.join();
Thread
.
sleep
(
1000
*
10
);
//暂停3s,让系统运行至指令完全运行 todo跟据系统运行设定时间
if
(
"error"
.
equals
(
SystemRunningParams
.
ThreadState
.
get
(
subThread
)))
{
//使用join串行就无法停止
throw
new
Exception
();
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
();
}
}
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/service/impl/TestServiceImpl.java
View file @
f60354b1
...
...
@@ -5,6 +5,7 @@ import com.example.fuzzControll.annotion.NeedCutBefore;
import
com.example.fuzzControll.conf.AflnetProperties
;
import
com.example.fuzzControll.constents.CmdConstent
;
import
com.example.fuzzControll.domain.bo.FuzzParams
;
import
com.example.fuzzControll.domain.po.MissionInfo
;
import
com.example.fuzzControll.exception.testException.AflnetException
;
import
com.example.fuzzControll.exception.testException.CmdException
;
import
com.example.fuzzControll.domain.bo.CmdStartParams
;
...
...
@@ -47,21 +48,8 @@ public class TestServiceImpl implements TestService {
//todo 不同服务不同端口
@Override
public
void
testStart
(
CmdStartParams
cmdStartParams
)
throws
AflnetException
,
CmdException
{
/*存入参数*/
int
missionId
=
GlobalClass
.
missionInfoMapper
.
selectTopMissionId
()
+
1
;
boolean
flag
=
false
;
try
{
// flag = fuzzParamsService.saveFuzzParams(new FuzzParams(JSON.toJSONString(cmdStartParams), new Date(), missionId));
System
.
out
.
println
(
"flag = "
+
flag
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Save fuzz error:{}"
,
e
.
getMessage
());
throw
new
RuntimeException
(
e
);
}
if
(!
flag
)
{
log
.
error
(
"Save fuzzParams failed!"
);
throw
new
AflnetException
(
"Save params error!"
);
}
public
void
testStart
(
CmdStartParams
cmdStartParams
,
MissionInfo
missionInfo
)
throws
AflnetException
,
CmdException
{
SystemRunningParams
.
aflnetMissionId
=
missionInfo
.
getId
();
/*拼接指令*/
TestControlTools
.
setIsRunning
(
true
);
String
cmd
=
cmdTools
.
parse
(
cmdStartParams
);
...
...
@@ -73,7 +61,7 @@ public class TestServiceImpl implements TestService {
log
.
info
(
"The cmd is [{}]"
,
finalCmd
);
/*执行指令*/
System
.
out
.
println
(
"testStart"
);
cmdTools
.
runProgramCmd
(
finalCmd
,
outputFileName
+
".zip"
);
cmdTools
.
runProgramCmd
(
finalCmd
,
outputFileName
+
".zip"
,
missionInfo
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/component/StringUtils.java
0 → 100644
View file @
f60354b1
package
com
.
example
.
fuzzControll
.
tools
.
component
;
public
class
StringUtils
{
/**
* 向[]格式字符转插入数据变成[a,b]
*/
public
static
String
getArrayFormatString
(
String
source
,
String
insert
)
{
String
finalString
;
if
(
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
source
))
{
source
=
"[]"
;
String
temp
=
source
.
replace
(
"]"
,
""
);
finalString
=
temp
+
insert
+
"]"
;
}
else
{
String
temp
=
source
.
replace
(
"]"
,
""
);
finalString
=
temp
+
","
+
insert
+
"]"
;
}
return
finalString
;
}
}
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/system/SystemRunningParams.java
View file @
f60354b1
...
...
@@ -48,6 +48,18 @@ public class SystemRunningParams {
* 异常重放启动服务器信息数据
*/
public
static
List
<
String
>
ReplayRunServerMessage
=
new
ArrayList
<>();
/**
* kitty协议对应字符串数组
*/
public
static
String
[]
KittyProtocol
=
new
String
[]{
"arp"
,
"rarp"
,
"lldp"
,
"hdlc"
,
"mstp"
,
"ppp"
,
"pppoe"
,
"igmpv1"
,
"igmpv2"
,
"stp"
,
"vlan"
,
"ospf"
,
"isis"
,
"ip"
,
"icmp"
,
"sip"
,
"udp"
,
"tcp"
,
"rip"
,
"netbios"
,
"radius"
,
"rpc"
,
"snmp"
,
"sharp"
,
"dhcp"
,
"dns"
,
"ntp"
,
"tftp"
,
"http"
,
"nntp"
,
"telnet"
,
"bgp"
,
"ftp"
,
"nfs"
,
"smb"
,
"upnp"
,
"imap"
,
"pop3"
,
"ipsec"
,
"ssl"
,
"ssh"
,
"https"
,
"frp"
,
"ntf"
,
"ripng"
,
"rstp"
,
"smtp"
,
"tirp"
};
/**
* aflnet协议对应字符串数组 //todo 需要补充
*/
public
static
String
[]
AflnetProtocol
=
new
String
[]{
"RTSP"
};
public
static
void
init
()
{
/*初始化aflnet和kitty时间参数*/
testTimeMessage
.
put
(
"aflnet"
,
new
ConcurrentHashMap
<>());
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/java/com/example/fuzzControll/tools/test/TestCmdTools.java
View file @
f60354b1
...
...
@@ -3,6 +3,7 @@ package com.example.fuzzControll.tools.test;
import
com.alibaba.fastjson.JSONObject
;
import
com.example.fuzzControll.annotion.NeedCutBefore
;
import
com.example.fuzzControll.domain.bo.CmdStartParams
;
import
com.example.fuzzControll.domain.po.MissionInfo
;
import
com.example.fuzzControll.domain.vo.KittyResult
;
import
com.example.fuzzControll.domain.vo.TestReturnEntity
;
import
com.example.fuzzControll.exception.testException.AflnetException
;
...
...
@@ -29,6 +30,7 @@ public class TestCmdTools {
Boolean
send
=
false
;
Boolean
show
=
true
;
/**
* 运行指令返回错误信息
*/
...
...
@@ -49,6 +51,7 @@ public class TestCmdTools {
}
return
error
;
}
/**
* 运行会阻塞的命令行
*/
...
...
@@ -114,8 +117,7 @@ public class TestCmdTools {
* 运行需要后台运行cmd
* 通过websocket返回数据
*/
@NeedCutBefore
(
name
=
"aflnet"
,
function
=
"startBackup"
)
public
void
runProgramCmd
(
String
cmd
,
String
outputFileName
)
throws
AflnetException
{
public
void
runProgramCmd
(
String
cmd
,
String
outputFileName
,
MissionInfo
missionInfo
)
throws
AflnetException
{
try
{
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmd
);
//执行模糊测试指令
/*打印模糊测试输出*/
...
...
@@ -125,7 +127,7 @@ public class TestCmdTools {
log
.
info
(
"Aflnet cmd have been run."
);
}
catch
(
Exception
e
)
{
log
.
error
(
"alfnet run error!:"
+
e
.
getMessage
());
throw
new
AflnetException
(
"
Aflnet run error
"
);
throw
new
AflnetException
(
""
);
}
}
...
...
@@ -273,12 +275,12 @@ public class TestCmdTools {
* @return
*/
private
TestReturnEntity
makeReturnEntity
(
String
line
,
TestReturnEntity
returnEntity
)
{
if
(
line
.
contains
(
"All set and ready to roll!"
)
||
line
.
contains
(
"american fuzzy"
)
||
line
.
contains
(
"process timing overall results"
))
{
show
=
false
;
}
else
if
(
line
.
contains
(
"PROGRAM ABORT"
))
{
log
.
error
(
"Aflnet run failed !"
);
throw
new
AflnetException
(
"Aflnet run failed !
"
);
}
//
if (line.contains("All set and ready to roll!") || line.contains("american fuzzy") || line.contains("process timing overall results")) {
//
show = false;
//
} else if (line.contains("PROGRAM ABORT")) {
//
log.error("Aflnet run failed !");
// throw new AflnetException("
");
//
}
if
(
show
)
{
log
.
info
(
line
);
}
...
...
@@ -378,7 +380,6 @@ public class TestCmdTools {
}
public
String
parse
(
CmdStartParams
cmdStartParams
)
throws
AflnetException
{
log
.
info
(
"Cmd is [{}]"
,
cmdStartParams
);
System
.
out
.
println
(
"cmd is :"
+
cmdStartParams
);
if
(
cmdStartParams
==
null
)
{
throw
new
AflnetException
(
"CmdStartParams is null !"
);
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/resources/mapper/FuzzParamsMapper.xml
View file @
f60354b1
...
...
@@ -37,7 +37,7 @@
</update>
<select
id=
"getFuzzParamsById"
resultMap=
"fuzzParams"
>
<include
refid=
"selectFuzzParams"
/>
whereid = #{id}
where
id = #{id}
</select>
<select
id=
"getFuzzParamsList"
resultMap=
"fuzzParams"
>
<include
refid=
"selectFuzzParams"
/>
...
...
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/resources/mapper/MissionInfoMapper.xml
View file @
f60354b1
...
...
@@ -6,7 +6,6 @@
<resultMap
type=
"com.example.fuzzControll.domain.po.MissionInfo"
id=
"MissionInfoInDataBase"
>
<result
property=
"id"
column=
"id"
/>
<result
property=
"missionId"
column=
"missionId"
/>
<result
property=
"tableId"
column=
"tableId"
/>
<result
property=
"createTime"
column=
"createTime"
/>
<result
property=
"missionName"
column=
"missionName"
/>
...
...
@@ -15,36 +14,45 @@
</resultMap>
<resultMap
type=
"com.example.fuzzControll.domain.po.MissionInfo"
id=
"MissionInfoInVo"
>
<result
property=
"id"
column=
"id"
/>
<result
property=
"missionId"
column=
"missionId"
/>
<result
property=
"createTime"
column=
"createTime"
/>
<result
property=
"missionName"
column=
"missionName"
/>
<result
property=
"stateName"
column=
"state"
/>
<result
property=
"runTime"
column=
"runTime"
/>
</resultMap>
<sql
id=
"selectMissionInfo"
>
select id,
missionId ,createTime,missionName ,state,runTime from missionId
Info
select id,
createTime,missionName ,state,runTime from mission
Info
</sql>
<sql
id=
"selectMissionInfoInDataBase"
>
select id,
missionId,tableId, createTime,missionName ,state,runTime from missionId
Info
select id,
tableId, createTime,missionName ,state,runTime from mission
Info
</sql>
<insert
id=
"insertMission"
>
insert into missionIdInfo(missionId, tableId, createTime, missionName, state, runTime)
values (#{missionId}, #{tableId}, #{createTime}, #{missionName}, #{state}, #{runTime})
insert into missionInfo( tableId, createTime, missionName, state, runTime)
values ( #{tableId}, #{createTime}, #{missionName}, #{state}, #{runTime})
<selectKey
keyProperty=
"id"
order=
"AFTER"
resultType=
"java.lang.Integer"
>
SELECT LAST_INSERT_ID()
</selectKey>
</insert>
<update
id=
"updateMission"
>
update missionIdInfo
set state = #{state}, runTime = #{runTime}
where missionId = #{missionId}
update missionInfo
<set>
<if
test=
"id != null"
>
id = #{id},
</if>
<if
test=
"tableId != null"
>
tableId = #{tableId},
</if>
<if
test=
"createTime != null "
>
createTime = #{createTime},
</if>
<if
test=
"missionName != null and missionName != ''"
>
missionName = #{missionName},
</if>
<if
test=
"state != null"
>
state = #{state},
</if>
<if
test=
"runTime != null "
>
runTime = #{runTime},
</if>
</set>
where id = #{id}
</update>
<select
id=
"selectByMissionId"
resultMap=
"MissionInfoInVo"
>
<include
refid=
"selectMissionInfoInDataBase"
/>
where
missionId = #{missionI
d}
where
id = #{i
d}
</select>
<select
id=
"selectMissionInfoList"
resultMap=
"MissionInfoInVo"
>
<include
refid=
"selectMissionInfo"
/>
</select>
<
select
id=
"selectTopMissionId"
resultType=
"java.lang.Integer"
>
select IFNULL((select missionId from missionIdInfo order by missionId desc limit 1),0) as missionId;
</select
>
<
!-- <select id="selectTop " resultType="java.lang.Integer">--
>
<!-- select IFNULL((select id from Info order by desc limit 1),0) as ;-->
<!-- </select>--
>
</mapper>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
fuzzIntegration/src/main/resources/mapper/TestMapper.xml
View file @
f60354b1
...
...
@@ -30,6 +30,18 @@
set testName = #{testName}
where id = #{id}
</update>
<update
id=
"update"
>
update test
<set>
<if
test=
"id != null"
>
id = #{id},
</if>
<if
test=
"fuzzParamsId != null "
>
fuzzParamsId = #{fuzzParamsId},
</if>
<if
test=
"createTime != null"
>
createTime = #{createTime},
</if>
<if
test=
"updateTime != null"
>
updateTime = #{updateTime},
</if>
<if
test=
"missionIds != null and missionIds != ''"
>
missionIds = #{missionIds},
</if>
<if
test=
"testName != null and testName != ''"
>
testName = #{testName},
</if>
</set>
where id = #{id}
</update>
<delete
id=
"deleteById"
>
DELETE
t1, t2
...
...
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/controller/TestMissionController.java
View file @
f60354b1
...
...
@@ -15,7 +15,13 @@ import org.springframework.web.bind.annotation.*;
public
class
TestMissionController
{
@Autowired
FuzzIntegrationFileApi
fuzzIntegrationFileApi
;
/**
* 新建测试
*/
@RequestMapping
(
value
=
"/startmission"
,
method
=
RequestMethod
.
GET
)
public
AjaxResult
getAll
(
@RequestParam
int
id
)
{
return
fuzzIntegrationFileApi
.
startmission
(
id
);
}
/**
* 获取全部测试信息
*/
...
...
This diff is collapsed.
Click to expand it.
fuzzbackendmaster/src/main/java/com/example/fuzzbackendmaster/service/FuzzIntegrationFileApi.java
View file @
f60354b1
...
...
@@ -183,4 +183,9 @@ public interface FuzzIntegrationFileApi {
*/
@RequestMapping
(
value
=
"/testmission/editTestName"
,
method
=
RequestMethod
.
GET
)
AjaxResult
editTestName
(
@RequestParam
String
testName
,
@RequestParam
int
id
);
/**
* 启动测试
*/
@RequestMapping
(
value
=
"/testmission/startmission"
,
method
=
RequestMethod
.
GET
)
AjaxResult
startmission
(
@RequestParam
int
id
);
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment