Compare commits
13 Commits
dev-worksp
...
dev-applic
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e675144a6c | ||
|
|
c57ade402f | ||
|
|
f14763512e | ||
|
|
b480734c94 | ||
|
|
1c35979b24 | ||
|
|
68ccb87c76 | ||
|
|
a98566f5d5 | ||
|
|
634166c4b3 | ||
|
|
ecb57f6c6c | ||
|
|
58b38fbe91 | ||
|
|
582856c066 | ||
|
|
76e52d91e9 | ||
|
|
f3d048c240 |
@@ -61,8 +61,9 @@ dev_build:
|
||||
- export FILE_NAME=$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA.tar.gz
|
||||
- mvn clean install -Dmaven.test.skip=true
|
||||
- cd ./target
|
||||
- "git log -100 --pretty=format:'%ad : %s' > git-log.html"
|
||||
- tar -zcvf $FILE_NAME asw-controller.jar git-log.html
|
||||
# - "git log -100 --pretty=format:'%ad : %s' > git-log.html"
|
||||
# - tar -zcvf $FILE_NAME asw-controller.jar git-log.html
|
||||
- tar -zcvf $FILE_NAME asw-controller.jar
|
||||
- md5sum $FILE_NAME > $CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-latest.tar.gz.md5sum.txt
|
||||
# 将 文件 上传到 minio
|
||||
- mc alias set asw $MINIO_HOST $MINIO_USER $MINIO_PWD
|
||||
|
||||
@@ -33,6 +33,13 @@ public enum RCode {
|
||||
APP_DESCRIPTION_CANNOT_EMPTY(201006, "application description cannot be empty"),
|
||||
APP_DUPLICATE_RECORD(201007, "application duplicate record"),
|
||||
APP_NOT_EXIST(201008, "application does not exist"),
|
||||
APP_PACKAGE_NAME_FORMAT_ERROR(201009, "application package name format error"),
|
||||
APP_TAGS_FORMAT_ERROR(201010, "application tags format error"),
|
||||
APP_SIGNATURE_FORMAT_ERROR(201011, "application signature format error"),
|
||||
APP_SIGNATURE_CONTENT_CANNOT_EMPTY(201012, "application signature content cannot be empty"),
|
||||
APP_SIGNATURE_NOT_EXIST(201013, "application signature does not exist"),
|
||||
APP_NOTE_CONTENT_CANNOT_EMPTY(201014, "application note content cannot be empty"),
|
||||
|
||||
|
||||
|
||||
// Package
|
||||
@@ -59,6 +66,9 @@ public enum RCode {
|
||||
WORKSPACE_VISIBILITY_ERROR(401008, "workspace visibility error"),
|
||||
WORKSPACE_BUILT_IN(401009, "Built-in workspace cannot be update"),
|
||||
|
||||
//PCAP
|
||||
PCAP_UPLOAD_WEB_SHARK_ERROR(501001, "web shark upload pcap error"),
|
||||
|
||||
|
||||
SUCCESS(200, "success"); // 成功
|
||||
|
||||
|
||||
@@ -387,6 +387,13 @@ public class VerifyUtil {
|
||||
return this;
|
||||
}
|
||||
|
||||
public VerifyUtil json(RCode code) {
|
||||
if (!T.JSONUtil.isTypeJSON(T.StrUtil.toStringOrNull(value))) {
|
||||
throw ASWException.builder().rcode(code).build();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多参数校验,不能同时为空
|
||||
*
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package net.geedge.asw.module.app.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.geedge.asw.common.util.ASWException;
|
||||
import net.geedge.asw.common.util.R;
|
||||
import net.geedge.asw.common.util.RCode;
|
||||
import net.geedge.asw.common.util.T;
|
||||
import net.geedge.asw.module.app.entity.ApplicationAttachmentEntity;
|
||||
import net.geedge.asw.module.app.entity.ApplicationEntity;
|
||||
import net.geedge.asw.module.app.entity.ApplicationNoteEntity;
|
||||
import net.geedge.asw.module.app.entity.ApplicationSignatureEntity;
|
||||
import net.geedge.asw.module.app.service.ApplicationAttachmentService;
|
||||
import net.geedge.asw.module.app.service.ApplicationNoteService;
|
||||
import net.geedge.asw.module.app.service.ApplicationSignatureService;
|
||||
import net.geedge.asw.module.app.service.IApplicationService;
|
||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||
import net.geedge.asw.module.sys.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -25,35 +29,21 @@ public class ApplicationController {
|
||||
private IApplicationService applicationService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
private ApplicationSignatureService signatureService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationNoteService noteService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationAttachmentService attachmentService;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public R detail(@PathVariable String id) {
|
||||
ApplicationEntity entity = applicationService.getById(id);
|
||||
public R detail(@PathVariable("id") String id, String workspaceId) {
|
||||
T.VerifyUtil.is(workspaceId).notNull();
|
||||
ApplicationEntity entity = applicationService.detail(id, workspaceId);
|
||||
if (T.ObjectUtil.isNull(entity)) {
|
||||
throw new ASWException(RCode.APP_NOT_EXIST);
|
||||
}
|
||||
SysUserEntity createUser = userService.getById(entity.getCreateUserId());
|
||||
SysUserEntity updateUser = userService.getById(entity.getUpdateUserId());
|
||||
entity.setCreateUser(createUser);
|
||||
entity.setUpdateUser(updateUser);
|
||||
return R.ok().putData("record", entity);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/{version}")
|
||||
public R detail(@PathVariable String id,
|
||||
@PathVariable(required = false) String version) {
|
||||
ApplicationEntity entity = applicationService.getById(id);
|
||||
if (T.StrUtil.isNotEmpty(version)){
|
||||
entity = applicationService.queryByApplicationAndLog(id, version);
|
||||
}
|
||||
if (T.ObjectUtil.isNull(entity)){
|
||||
throw new ASWException(RCode.APP_NOT_EXIST);
|
||||
}
|
||||
SysUserEntity createUser = userService.getById(entity.getCreateUserId());
|
||||
SysUserEntity updateUser = userService.getById(entity.getUpdateUserId());
|
||||
entity.setCreateUser(createUser);
|
||||
entity.setUpdateUser(updateUser);
|
||||
return R.ok().putData("record", entity);
|
||||
}
|
||||
|
||||
@@ -70,10 +60,8 @@ public class ApplicationController {
|
||||
public R add(@RequestBody ApplicationEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getName()).notEmpty(RCode.APP_NAME_CANNOT_EMPTY)
|
||||
//.and(entity.getLongName()).notEmpty(RCode.APP_LONGNAME_CANNOT_EMPTY)
|
||||
//.and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY)
|
||||
//.and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY)
|
||||
//.and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY)
|
||||
//.and(entity.getSignature()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY)
|
||||
//.and(entity.getNote()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY)
|
||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
ApplicationEntity applicationEntity = applicationService.saveApplication(entity);
|
||||
@@ -85,16 +73,44 @@ public class ApplicationController {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
|
||||
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
|
||||
//.and(entity.getLongName()).notEmpty(RCode.APP_LONGNAME_CANNOT_EMPTY)
|
||||
//.and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY)
|
||||
//.and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY)
|
||||
//.and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY)
|
||||
//.and(entity.getSignature()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY)
|
||||
//.and(entity.getNote()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY)
|
||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
ApplicationEntity applicationEntity = applicationService.updateApplication(entity);
|
||||
return R.ok().putData("id", applicationEntity.getId());
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/{id}/basic")
|
||||
public R basic(@PathVariable String id, @RequestBody ApplicationEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
|
||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
entity.setId(id);
|
||||
ApplicationEntity app = applicationService.updateBasic(entity);
|
||||
return R.ok().putData("id", app.getId());
|
||||
}
|
||||
|
||||
@PutMapping("/{applicationId}/signature")
|
||||
public R updateSignature(@PathVariable("applicationId") String applicationId, @RequestBody ApplicationSignatureEntity signature) {
|
||||
T.VerifyUtil.is(signature).notNull()
|
||||
.and(signature.getContent()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY)
|
||||
.and(signature.getContent()).json(RCode.APP_SURROGATES_CANNOT_EMPTY);
|
||||
|
||||
signatureService.saveSignature(signature, applicationId);
|
||||
return R.ok().putData("id", signature.getId());
|
||||
}
|
||||
|
||||
@PutMapping("/{applicationId}/note")
|
||||
public R updateNote(@PathVariable("applicationId") String applicationId, @RequestBody ApplicationNoteEntity note) {
|
||||
T.VerifyUtil.is(note).notNull()
|
||||
.and(note.getContent()).notEmpty(RCode.APP_NOTE_CONTENT_CANNOT_EMPTY);
|
||||
|
||||
noteService.saveNote(note, applicationId);
|
||||
return R.ok().putData("id", note.getId());
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public R delete(String[] ids) {
|
||||
T.VerifyUtil.is(ids).notEmpty();
|
||||
@@ -102,34 +118,64 @@ public class ApplicationController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/log")
|
||||
public R queryLogList(@PathVariable("id") String id) {
|
||||
List<ApplicationEntity> applicationEntityList = applicationService.queryLogList(id);
|
||||
return R.ok().putData("record", applicationEntityList);
|
||||
|
||||
@GetMapping("/{applicationId}/attachment")
|
||||
public R queryAttachment(@PathVariable String applicationId) {
|
||||
T.VerifyUtil.is(applicationId).notNull();
|
||||
|
||||
List<ApplicationAttachmentEntity> list = attachmentService.list(new LambdaQueryWrapper<ApplicationAttachmentEntity>().eq(ApplicationAttachmentEntity::getApplicationId, applicationId));
|
||||
return R.ok().putData("records", list);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/{id}/{oldVersion}/{newVersion}")
|
||||
public R applicationCompare(@PathVariable("id") String id,
|
||||
@PathVariable("oldVersion") String oldVersion,
|
||||
@PathVariable("newVersion") String newVersion) {
|
||||
List<ApplicationEntity> list = applicationService.compare(id, oldVersion, newVersion);
|
||||
return R.ok().putData("record", list);
|
||||
@PostMapping("/{applicationId}/attachment")
|
||||
public R uploadAttachment(@PathVariable String applicationId, @RequestParam("files") List<MultipartFile> fileList) {
|
||||
|
||||
List<ApplicationAttachmentEntity> recordList = T.ListUtil.list(true);
|
||||
for (int i = 0; i < fileList.size(); i++) {
|
||||
MultipartFile file = fileList.get(i);
|
||||
ApplicationAttachmentEntity attachmentEntity = attachmentService.saveAttachment(file.getResource(), applicationId);
|
||||
recordList.add(attachmentEntity);
|
||||
}
|
||||
return R.ok().putData("records", recordList);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{applicationId}/attachment")
|
||||
public R removedAttachment(@PathVariable String applicationId, @RequestParam String ids) {
|
||||
|
||||
@PostMapping("/{id}/{version}/restore")
|
||||
public R restore(@PathVariable("id") String id,
|
||||
@PathVariable("version") String version) {
|
||||
applicationService.restore(id, version);
|
||||
attachmentService.removedAttachment(applicationId, ids);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/analyze")
|
||||
public void analyze(@RequestParam String workspaceId,
|
||||
@RequestParam String pcapIds,
|
||||
HttpServletResponse response) throws IOException {
|
||||
applicationService.redirectDiscoverPage(workspaceId, pcapIds, response);
|
||||
|
||||
@GetMapping("/{applicationId}/signature")
|
||||
public R querySignature(@PathVariable String applicationId) {
|
||||
T.VerifyUtil.is(applicationId).notNull();
|
||||
List<ApplicationSignatureEntity> signatureList = signatureService.queryList(applicationId);
|
||||
return R.ok().putData("records", signatureList);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/explore")
|
||||
public R explore(@RequestParam String workspaceId, @RequestParam String pcapIds) {
|
||||
String discoverUrl = applicationService.generateKibanaDiscoverUrl(workspaceId, pcapIds);
|
||||
return R.ok().putData("url", discoverUrl);
|
||||
}
|
||||
|
||||
@GetMapping("/{applicationId}/signature/{oldVersion}/{newVersion}")
|
||||
public R signatureCompare(@PathVariable("applicationId") String applicationId,
|
||||
@PathVariable("oldVersion") String oldVersion,
|
||||
@PathVariable("newVersion") String newVersion) {
|
||||
List<ApplicationSignatureEntity> list = signatureService.compare(applicationId, oldVersion, newVersion);
|
||||
return R.ok().putData("records", list);
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/{applicationId}/signature/{version}/restore")
|
||||
public R restore(@PathVariable("applicationId") String applicationId,
|
||||
@PathVariable("version") String version) {
|
||||
signatureService.restore(applicationId, version);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package net.geedge.asw.module.app.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import net.geedge.asw.module.app.entity.ApplicationAttachmentEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ApplicationAttachmentDao extends BaseMapper<ApplicationAttachmentEntity>{
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.geedge.asw.module.app.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import net.geedge.asw.module.app.entity.SignatureEntity;
|
||||
import net.geedge.asw.module.app.entity.ApplicationNoteEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SignatureDao extends BaseMapper<SignatureEntity>{
|
||||
public interface ApplicationNoteDao extends BaseMapper<ApplicationNoteEntity>{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.geedge.asw.module.app.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import net.geedge.asw.module.app.entity.ApplicationSignatureEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface ApplicationSignatureDao extends BaseMapper<ApplicationSignatureEntity>{
|
||||
|
||||
List<ApplicationSignatureEntity> queryList(@Param("params") Map<Object, Object> params);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.geedge.asw.module.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("application_attachment")
|
||||
public class ApplicationAttachmentEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
private String applicationId;
|
||||
|
||||
private String name;
|
||||
|
||||
private String path;
|
||||
|
||||
private Long createTimestamp;
|
||||
|
||||
private String createUserId;
|
||||
|
||||
}
|
||||
@@ -7,24 +7,39 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@TableName("application")
|
||||
public class ApplicationEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
private String longName;
|
||||
private String properties;
|
||||
|
||||
private String tags;
|
||||
|
||||
private String packageName;
|
||||
|
||||
private String website;
|
||||
|
||||
private String provider;
|
||||
|
||||
private String status;
|
||||
|
||||
private String description;
|
||||
private String surrogates;
|
||||
|
||||
private Long createTimestamp;
|
||||
|
||||
private Long updateTimestamp;
|
||||
|
||||
private String createUserId;
|
||||
|
||||
private String updateUserId;
|
||||
|
||||
private String workspaceId;
|
||||
|
||||
private Integer opVersion;
|
||||
|
||||
@TableField(exist = false)
|
||||
@@ -33,4 +48,12 @@ public class ApplicationEntity {
|
||||
@TableField(exist = false)
|
||||
private SysUserEntity updateUser;
|
||||
|
||||
@TableField(exist = false)
|
||||
private ApplicationSignatureEntity signature;
|
||||
|
||||
@TableField(exist = false)
|
||||
private ApplicationNoteEntity note;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ApplicationAttachmentEntity> attatchments;
|
||||
}
|
||||
@@ -1,24 +1,60 @@
|
||||
package net.geedge.asw.module.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@TableName("application_log")
|
||||
public class ApplicationLogEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
private String longName;
|
||||
private String properties;
|
||||
|
||||
private String tags;
|
||||
|
||||
private String packageName;
|
||||
|
||||
private String website;
|
||||
|
||||
private String provider;
|
||||
|
||||
private String status;
|
||||
|
||||
private String description;
|
||||
private String surrogates;
|
||||
|
||||
private Long createTimestamp;
|
||||
|
||||
private Long updateTimestamp;
|
||||
|
||||
private String createUserId;
|
||||
|
||||
private String updateUserId;
|
||||
|
||||
private String workspaceId;
|
||||
|
||||
private Integer opVersion;
|
||||
|
||||
@TableField(exist = false)
|
||||
private SysUserEntity createUser;
|
||||
|
||||
@TableField(exist = false)
|
||||
private SysUserEntity updateUser;
|
||||
|
||||
@TableField(exist = false)
|
||||
private ApplicationSignatureEntity signature;
|
||||
|
||||
@TableField(exist = false)
|
||||
private ApplicationNoteEntity note;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ApplicationAttachmentEntity> attatchments;
|
||||
|
||||
}
|
||||
|
||||
@@ -6,24 +6,20 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("signature")
|
||||
public class SignatureEntity {
|
||||
@TableName("application_note")
|
||||
public class ApplicationNoteEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
private String appId;
|
||||
private String name;
|
||||
private String tags;
|
||||
private String description;
|
||||
private Integer displayFlag;
|
||||
private String conditions;
|
||||
private Long opVersion;
|
||||
|
||||
private String applicationId;
|
||||
|
||||
private String content;
|
||||
|
||||
private Long createTimestamp;
|
||||
private Long updateTimestamp;
|
||||
private String createUserId;
|
||||
private String updateUserId;
|
||||
|
||||
private String workspaceId;
|
||||
private String createUserId;
|
||||
|
||||
private Long opVersion;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.geedge.asw.module.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||
|
||||
@Data
|
||||
@TableName("application_signature")
|
||||
public class ApplicationSignatureEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
private String applicationId;
|
||||
|
||||
private String content;
|
||||
|
||||
private Long createTimestamp;
|
||||
|
||||
private String createUserId;
|
||||
|
||||
private Long opVersion;
|
||||
|
||||
@TableField(exist = false)
|
||||
private SysUserEntity createUser;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.geedge.asw.module.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.geedge.asw.module.app.entity.ApplicationAttachmentEntity;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
public interface ApplicationAttachmentService extends IService<ApplicationAttachmentEntity>{
|
||||
|
||||
ApplicationAttachmentEntity saveAttachment(Resource fileResource, String applicationId);
|
||||
|
||||
void removedAttachment(String applicationId, String ids);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.geedge.asw.module.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.geedge.asw.module.app.entity.ApplicationNoteEntity;
|
||||
|
||||
public interface ApplicationNoteService extends IService<ApplicationNoteEntity>{
|
||||
|
||||
void saveNote(ApplicationNoteEntity note, String applicationId);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.geedge.asw.module.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.geedge.asw.module.app.entity.ApplicationSignatureEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ApplicationSignatureService extends IService<ApplicationSignatureEntity>{
|
||||
|
||||
void saveSignature(ApplicationSignatureEntity signature, String applicationId);
|
||||
|
||||
List<ApplicationSignatureEntity> queryList(String applicationId);
|
||||
|
||||
List<ApplicationSignatureEntity> compare(String applicationId, String oldVersion, String newVersion);
|
||||
|
||||
void restore(String id, String version);
|
||||
}
|
||||
@@ -2,31 +2,24 @@ package net.geedge.asw.module.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.geedge.asw.module.app.entity.ApplicationEntity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IApplicationService extends IService<ApplicationEntity>{
|
||||
|
||||
ApplicationEntity detail(String id, String workspaceId);
|
||||
|
||||
Page queryList(Map<String, Object> params);
|
||||
|
||||
ApplicationEntity saveApplication(ApplicationEntity entity);
|
||||
|
||||
ApplicationEntity updateApplication(ApplicationEntity entity);
|
||||
|
||||
ApplicationEntity updateBasic(ApplicationEntity entity);
|
||||
|
||||
void removeApplication(List<String> ids);
|
||||
|
||||
ApplicationEntity queryByApplicationAndLog(String id, String version);
|
||||
|
||||
List<ApplicationEntity> compare(String id, String oldVersion, String newVersion);
|
||||
|
||||
List<ApplicationEntity> queryLogList(String id);
|
||||
|
||||
void restore(String id, String version);
|
||||
|
||||
void redirectDiscoverPage(String workspaceId, String pcapIds, HttpServletResponse response) throws IOException;
|
||||
|
||||
String generateKibanaDiscoverUrl(String workspaceId, String pcapIds);
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.geedge.asw.module.app.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.geedge.asw.module.app.entity.SignatureEntity;
|
||||
|
||||
public interface ISignatureService extends IService<SignatureEntity>{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package net.geedge.asw.module.app.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.log.Log;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.geedge.asw.common.util.ASWException;
|
||||
import net.geedge.asw.common.util.RCode;
|
||||
import net.geedge.asw.common.util.T;
|
||||
import net.geedge.asw.module.app.dao.ApplicationAttachmentDao;
|
||||
import net.geedge.asw.module.app.entity.ApplicationAttachmentEntity;
|
||||
import net.geedge.asw.module.app.entity.ApplicationEntity;
|
||||
import net.geedge.asw.module.app.service.ApplicationAttachmentService;
|
||||
import net.geedge.asw.module.app.service.IApplicationService;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ApplicationAttachmentServiceImpl extends ServiceImpl<ApplicationAttachmentDao, ApplicationAttachmentEntity> implements ApplicationAttachmentService {
|
||||
|
||||
private static final Log log = Log.get();
|
||||
|
||||
@Autowired
|
||||
private IApplicationService applicationService;
|
||||
|
||||
@Override
|
||||
public ApplicationAttachmentEntity saveAttachment(Resource fileResource, String applicationId) {
|
||||
|
||||
ApplicationEntity app = applicationService.getById(applicationId);
|
||||
ApplicationAttachmentEntity entity = new ApplicationAttachmentEntity();
|
||||
try {
|
||||
entity.setName(fileResource.getFilename());
|
||||
entity.setCreateTimestamp(System.currentTimeMillis());
|
||||
entity.setCreateUserId(StpUtil.getLoginIdAsString());
|
||||
entity.setApplicationId(applicationId);
|
||||
|
||||
// path
|
||||
File destination = T.FileUtil.file(T.WebPathUtil.getRootPath(), app.getId(), fileResource.getFilename());
|
||||
FileUtils.copyInputStreamToFile(fileResource.getInputStream(), destination);
|
||||
entity.setPath(destination.getPath());
|
||||
|
||||
// 根据文件 applicationId path 判断是否已上存在,存在则响应当前实体
|
||||
ApplicationAttachmentEntity attachment = this.getOne(new LambdaQueryWrapper<ApplicationAttachmentEntity>()
|
||||
.eq(ApplicationAttachmentEntity::getApplicationId, applicationId)
|
||||
.eq(ApplicationAttachmentEntity::getPath, destination.getPath()));
|
||||
if (T.ObjectUtil.isNotNull(attachment)) {
|
||||
return attachment;
|
||||
}
|
||||
|
||||
// save
|
||||
this.save(entity);
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error(e, "[saveAttachment] [error] [applicationId: {}]", applicationId);
|
||||
throw new ASWException(RCode.ERROR);
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removedAttachment(String applicationId, String ids) {
|
||||
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
|
||||
for (String id : idList) {
|
||||
ApplicationAttachmentEntity attachment = this.getOne(new LambdaQueryWrapper<ApplicationAttachmentEntity>()
|
||||
.eq(ApplicationAttachmentEntity::getApplicationId, applicationId)
|
||||
.eq(ApplicationAttachmentEntity::getId, id));
|
||||
|
||||
T.FileUtil.del(FileUtil.file(attachment.getPath()));
|
||||
this.removeById(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package net.geedge.asw.module.app.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.geedge.asw.common.util.T;
|
||||
import net.geedge.asw.module.app.dao.ApplicationNoteDao;
|
||||
import net.geedge.asw.module.app.entity.ApplicationNoteEntity;
|
||||
import net.geedge.asw.module.app.service.ApplicationNoteService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
public class ApplicationNoteServiceImpl extends ServiceImpl<ApplicationNoteDao, ApplicationNoteEntity> implements ApplicationNoteService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveNote(ApplicationNoteEntity note, String applicationId) {
|
||||
// query last note
|
||||
ApplicationNoteEntity noteLast = this.getOne(new LambdaQueryWrapper<ApplicationNoteEntity>()
|
||||
.eq(ApplicationNoteEntity::getApplicationId, applicationId)
|
||||
.orderByDesc(ApplicationNoteEntity::getOpVersion)
|
||||
.last("limit 1"));
|
||||
|
||||
if (T.ObjectUtil.isNotEmpty(noteLast)){
|
||||
note.setOpVersion(noteLast.getOpVersion() + 1);
|
||||
}
|
||||
|
||||
//save note
|
||||
note.setApplicationId(applicationId);
|
||||
note.setCreateTimestamp(System.currentTimeMillis());
|
||||
note.setCreateUserId(StpUtil.getLoginIdAsString());
|
||||
|
||||
this.save(note);
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.geedge.asw.module.feign.client.KibanaClient;
|
||||
import net.geedge.asw.common.util.ASWException;
|
||||
import net.geedge.asw.common.util.RCode;
|
||||
import net.geedge.asw.common.util.T;
|
||||
import net.geedge.asw.module.app.dao.ApplicationDao;
|
||||
import net.geedge.asw.module.app.entity.ApplicationEntity;
|
||||
import net.geedge.asw.module.app.entity.ApplicationLogEntity;
|
||||
import net.geedge.asw.module.app.service.IApplicationLogService;
|
||||
import net.geedge.asw.module.app.service.IApplicationService;
|
||||
import net.geedge.asw.module.app.entity.*;
|
||||
import net.geedge.asw.module.app.service.*;
|
||||
import net.geedge.asw.module.feign.client.KibanaClient;
|
||||
import net.geedge.asw.module.runner.entity.PcapEntity;
|
||||
import net.geedge.asw.module.runner.service.IPcapService;
|
||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||
import net.geedge.asw.module.sys.service.ISysUserService;
|
||||
import net.geedge.asw.module.workspace.entity.WorkspaceEntity;
|
||||
import net.geedge.asw.module.workspace.service.IWorkspaceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,8 +28,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -52,13 +49,49 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
@Autowired
|
||||
private IPcapService pcapService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationSignatureService signatureService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationNoteService noteService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationAttachmentService attachmentService;
|
||||
|
||||
@Resource
|
||||
private KibanaClient kibanaClient;
|
||||
|
||||
@Override
|
||||
public ApplicationEntity queryByApplicationAndLog(String id, String version) {
|
||||
ApplicationEntity entity = this.baseMapper.queryByApplicationAndLog(id, version);
|
||||
return entity;
|
||||
public ApplicationEntity detail(String id, String workspaceId) {
|
||||
ApplicationEntity app = this.getOne(new LambdaQueryWrapper<ApplicationEntity>()
|
||||
.eq(ApplicationEntity::getId, id)
|
||||
.eq(ApplicationEntity::getWorkspaceId, workspaceId));
|
||||
|
||||
ApplicationSignatureEntity signature = signatureService.getOne(new LambdaQueryWrapper<ApplicationSignatureEntity>()
|
||||
.eq(ApplicationSignatureEntity::getApplicationId, app.getId())
|
||||
.orderByDesc(ApplicationSignatureEntity::getOpVersion)
|
||||
.last("limit 1"));
|
||||
app.setSignature(signature);
|
||||
|
||||
ApplicationNoteEntity note = noteService.getOne(new LambdaQueryWrapper<ApplicationNoteEntity>()
|
||||
.eq(ApplicationNoteEntity::getApplicationId, app.getId())
|
||||
.orderByDesc(ApplicationNoteEntity::getOpVersion)
|
||||
.last("limit 1"));
|
||||
app.setNote(note);
|
||||
|
||||
List<ApplicationAttachmentEntity> attachmentEntityList = attachmentService.list(new LambdaQueryWrapper<ApplicationAttachmentEntity>()
|
||||
.eq(ApplicationAttachmentEntity::getApplicationId, app.getId()));
|
||||
app.setAttatchments(attachmentEntityList);
|
||||
|
||||
SysUserEntity createUser = userService.getById(app.getCreateUserId());
|
||||
SysUserEntity updateUser = userService.getById(app.getUpdateUserId());
|
||||
app.setCreateUser(createUser);
|
||||
app.setUpdateUser(updateUser);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,36 +102,79 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApplicationEntity saveApplication(ApplicationEntity entity) {
|
||||
private void validateParam(ApplicationEntity entity, boolean isUpdate) {
|
||||
ApplicationEntity one = this.getOne(new LambdaQueryWrapper<ApplicationEntity>()
|
||||
.eq(ApplicationEntity::getWorkspaceId, entity.getWorkspaceId())
|
||||
.eq(ApplicationEntity::getName, entity.getName()));
|
||||
if (T.ObjectUtil.isNotNull(one)) {
|
||||
|
||||
if (T.ObjectUtil.isNotNull(one) && !isUpdate || T.ObjectUtil.isNotNull(one) && isUpdate && !T.StrUtil.equals(entity.getId(), one.getId())) {
|
||||
throw ASWException.builder().rcode(RCode.APP_DUPLICATE_RECORD).build();
|
||||
}
|
||||
|
||||
// package name format
|
||||
if (T.ObjectUtil.isNotEmpty(entity.getPackageName()) && !T.JSONUtil.isTypeJSON(entity.getPackageName())) {
|
||||
throw ASWException.builder().rcode(RCode.APP_PACKAGE_NAME_FORMAT_ERROR).build();
|
||||
} else if (T.ObjectUtil.isEmpty(entity.getPackageName())) {
|
||||
entity.setPackageName("{}");
|
||||
}
|
||||
|
||||
// tags name format
|
||||
if (T.StrUtil.isNotEmpty(entity.getTags()) && !T.JSONUtil.isTypeJSON(entity.getTags())) {
|
||||
throw ASWException.builder().rcode(RCode.APP_TAGS_FORMAT_ERROR).build();
|
||||
}
|
||||
|
||||
// signature
|
||||
if (T.ObjectUtil.isNotEmpty(entity.getSignature())) {
|
||||
if (!T.StrUtil.isNotEmpty(entity.getSignature().getContent())){
|
||||
throw ASWException.builder().rcode(RCode.APP_SIGNATURE_CONTENT_CANNOT_EMPTY).build();
|
||||
}
|
||||
|
||||
if (!T.JSONUtil.isTypeJSON(entity.getSignature().getContent())){
|
||||
throw ASWException.builder().rcode(RCode.APP_SIGNATURE_CONTENT_CANNOT_EMPTY).build();
|
||||
}
|
||||
}
|
||||
|
||||
// note
|
||||
if (T.ObjectUtil.isNotEmpty(entity.getNote()) && !T.StrUtil.isNotEmpty(entity.getNote().getContent())) {
|
||||
throw ASWException.builder().rcode(RCode.APP_NOTE_CONTENT_CANNOT_EMPTY).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApplicationEntity saveApplication(ApplicationEntity entity) {
|
||||
|
||||
this.validateParam(entity, false);
|
||||
|
||||
// save
|
||||
entity.setCreateTimestamp(System.currentTimeMillis());
|
||||
entity.setUpdateTimestamp(System.currentTimeMillis());
|
||||
entity.setCreateUserId(StpUtil.getLoginIdAsString());
|
||||
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||
|
||||
// save
|
||||
this.save(entity);
|
||||
|
||||
if (T.ObjectUtil.isNotEmpty(entity.getSignature())){
|
||||
// save signature
|
||||
signatureService.saveSignature(entity.getSignature(), entity.getId());
|
||||
}
|
||||
|
||||
if (T.ObjectUtil.isNotEmpty(entity.getNote())){
|
||||
//save note
|
||||
noteService.saveNote(entity.getNote(), entity.getId());
|
||||
}
|
||||
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApplicationEntity updateApplication(ApplicationEntity entity) {
|
||||
ApplicationEntity one = this.getOne(new LambdaQueryWrapper<ApplicationEntity>()
|
||||
.eq(ApplicationEntity::getWorkspaceId, entity.getWorkspaceId())
|
||||
.eq(ApplicationEntity::getId, entity.getId()));
|
||||
if (T.ObjectUtil.isNull(one)) {
|
||||
throw ASWException.builder().rcode(RCode.APP_NOT_EXIST).build();
|
||||
}
|
||||
|
||||
this.validateParam(entity, true);
|
||||
|
||||
ApplicationEntity one = this.getById(entity.getId());
|
||||
entity.setUpdateTimestamp(System.currentTimeMillis());
|
||||
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||
entity.setOpVersion(one.getOpVersion() + 1);
|
||||
@@ -107,11 +183,22 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
this.updateById(entity);
|
||||
|
||||
// save log
|
||||
this.saveApplcationToLog(one);
|
||||
this.saveApplicationToLog(one);
|
||||
|
||||
if (T.ObjectUtil.isNotEmpty(entity.getSignature())){
|
||||
// save signature
|
||||
signatureService.saveSignature(entity.getSignature(), entity.getId());
|
||||
}
|
||||
|
||||
if (T.ObjectUtil.isNotEmpty(entity.getNote())){
|
||||
//save note
|
||||
noteService.saveNote(entity.getNote(), entity.getId());
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void saveApplcationToLog(ApplicationEntity one) {
|
||||
private void saveApplicationToLog(ApplicationEntity one) {
|
||||
ApplicationLogEntity applicationLogEntity = T.BeanUtil.toBean(one, ApplicationLogEntity.class);
|
||||
applicationLogEntity.setUpdateTimestamp(System.currentTimeMillis());
|
||||
applicationLogEntity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||
@@ -126,39 +213,9 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
// remove
|
||||
this.removeBatchByIds(ids);
|
||||
applicationLogService.removeBatchByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationEntity> queryLogList(String id) {
|
||||
List<ApplicationEntity> packageList = this.getBaseMapper().queryLogList(id);
|
||||
return packageList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationEntity> compare(String id, String oldVersion, String newVersion) {
|
||||
Map<String, Object> params = Map.of("id", id, "versions", Arrays.asList(oldVersion, newVersion));
|
||||
List<ApplicationEntity> packageList = this.getBaseMapper().compare(params);
|
||||
return packageList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void restore(String id, String version) {
|
||||
// save current to log
|
||||
ApplicationEntity curApplication = this.getById(id);
|
||||
this.saveApplcationToLog(curApplication);
|
||||
// restore
|
||||
ApplicationLogEntity oldApplication = applicationLogService.getOne(new LambdaQueryWrapper<ApplicationLogEntity>()
|
||||
.eq(ApplicationLogEntity::getId, id)
|
||||
.eq(ApplicationLogEntity::getOpVersion, version));
|
||||
|
||||
oldApplication.setUpdateTimestamp(System.currentTimeMillis());
|
||||
oldApplication.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||
oldApplication.setOpVersion(curApplication.getOpVersion() + 1);
|
||||
|
||||
ApplicationEntity application = T.BeanUtil.toBean(oldApplication, ApplicationEntity.class);
|
||||
this.updateById(application);
|
||||
signatureService.remove(new LambdaQueryWrapper<ApplicationSignatureEntity>().in(ApplicationSignatureEntity::getApplicationId, ids));
|
||||
noteService.remove(new LambdaQueryWrapper<ApplicationNoteEntity>().in(ApplicationNoteEntity::getApplicationId, ids));
|
||||
attachmentService.remove(new LambdaQueryWrapper<ApplicationAttachmentEntity>().in(ApplicationAttachmentEntity::getApplicationId, ids));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,11 +232,10 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
* }
|
||||
* @param workspaceId
|
||||
* @param pcapIds
|
||||
* @param response
|
||||
* @throws IOException
|
||||
* @return kibana discover url
|
||||
*/
|
||||
@Override
|
||||
public void redirectDiscoverPage(String workspaceId, String pcapIds, HttpServletResponse response) throws IOException {
|
||||
public String generateKibanaDiscoverUrl(String workspaceId, String pcapIds) {
|
||||
// verify
|
||||
WorkspaceEntity workspace = workspaceService.getById(workspaceId);
|
||||
T.VerifyUtil.is(workspace).notNull(RCode.SYS_RECORD_NOT_FOUND);
|
||||
@@ -208,7 +264,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
.findFirst()
|
||||
.isPresent();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("[redirectDiscoverPage] [idnex-pattern: {}] [exists: {}]", indexName, indexExists);
|
||||
log.debug("[generateKibanaDiscoverUrl] [idnex-pattern: {}] [exists: {}]", indexName, indexExists);
|
||||
}
|
||||
|
||||
// create index
|
||||
@@ -231,20 +287,42 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
String param1 = String.format("_a=(discover:(columns:!(_source),isDirty:!f,sort:!()),metadata:(indexPattern:'%s',view:discover))", workspaceId);
|
||||
String param2 = "_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-15m,to:now))";
|
||||
|
||||
String source = pcapList.stream()
|
||||
.map(PcapEntity::getName)
|
||||
.map(fileName -> "\"" + fileName + "\"")
|
||||
.collect(Collectors.joining("|", "source: (", ")"));
|
||||
String param3 = String.format("_q=(filters:!(),query:(language:lucene,query:'%s'))", source);
|
||||
String filter = pcapList.stream()
|
||||
.map(PcapEntity::getId)
|
||||
.map(pcapId -> "\"" + pcapId + "\"")
|
||||
.collect(Collectors.joining("|", "pcap.id: (", ")"));
|
||||
String param3 = String.format("_q=(filters:!(),query:(language:lucene,query:'%s'))", filter);
|
||||
|
||||
String query = String.format("?%s&%s&%s", param1, param2, param3);
|
||||
String redirectUrl = baseUrl + "#" + query;
|
||||
String kibanaDiscoverUrl = baseUrl + "#" + query;
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("[redirectDiscoverPage] [url: {}]", redirectUrl);
|
||||
log.debug("[generateKibanaDiscoverUrl] [url: {}]", kibanaDiscoverUrl);
|
||||
}
|
||||
return kibanaDiscoverUrl;
|
||||
}
|
||||
|
||||
// redirect
|
||||
response.sendRedirect(redirectUrl);
|
||||
@Override
|
||||
public ApplicationEntity updateBasic(ApplicationEntity entity) {
|
||||
|
||||
ApplicationEntity one = this.getById(entity.getId());
|
||||
if (T.ObjectUtil.isNotNull(one) && !T.StrUtil.equals(entity.getId(), one.getId())) {
|
||||
throw ASWException.builder().rcode(RCode.APP_DUPLICATE_RECORD).build();
|
||||
}
|
||||
|
||||
// package name format
|
||||
if (T.ObjectUtil.isNotEmpty(entity.getPackageName()) && !T.JSONUtil.isTypeJSON(entity.getPackageName())) {
|
||||
throw ASWException.builder().rcode(RCode.APP_PACKAGE_NAME_FORMAT_ERROR).build();
|
||||
} else if (T.ObjectUtil.isEmpty(entity.getPackageName())) {
|
||||
entity.setPackageName("{}");
|
||||
}
|
||||
|
||||
entity.setUpdateTimestamp(System.currentTimeMillis());
|
||||
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||
entity.setOpVersion(one.getOpVersion() + 1);
|
||||
|
||||
this.saveApplicationToLog(one);
|
||||
this.updateById(entity);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package net.geedge.asw.module.app.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.geedge.asw.common.util.ASWException;
|
||||
import net.geedge.asw.common.util.RCode;
|
||||
import net.geedge.asw.common.util.T;
|
||||
import net.geedge.asw.module.app.dao.ApplicationSignatureDao;
|
||||
import net.geedge.asw.module.app.entity.ApplicationSignatureEntity;
|
||||
import net.geedge.asw.module.app.service.ApplicationSignatureService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ApplicationSignatureServiceImpl extends ServiceImpl<ApplicationSignatureDao, ApplicationSignatureEntity> implements ApplicationSignatureService {
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveSignature(ApplicationSignatureEntity signature, String applicationId) {
|
||||
// query last note
|
||||
ApplicationSignatureEntity signatureLast = this.getOne(new LambdaQueryWrapper<ApplicationSignatureEntity>()
|
||||
.eq(ApplicationSignatureEntity::getApplicationId, applicationId)
|
||||
.orderByDesc(ApplicationSignatureEntity::getOpVersion)
|
||||
.last("limit 1"));
|
||||
|
||||
if (T.ObjectUtil.isNotEmpty(signatureLast)){
|
||||
signature.setOpVersion(signatureLast.getOpVersion() + 1);
|
||||
}
|
||||
|
||||
// save signature
|
||||
signature.setApplicationId(applicationId);
|
||||
signature.setCreateTimestamp(System.currentTimeMillis());
|
||||
signature.setCreateUserId(StpUtil.getLoginIdAsString());
|
||||
|
||||
this.save(signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationSignatureEntity> queryList(String applicationId) {
|
||||
Map<Object, Object> params = T.MapUtil.builder().put("applicationId", applicationId).build();
|
||||
List<ApplicationSignatureEntity> list = this.getBaseMapper().queryList(params);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationSignatureEntity> compare(String applicationId, String oldVersion, String newVersion) {
|
||||
|
||||
List<String> versionList = Arrays.asList(oldVersion, newVersion);
|
||||
Map<Object, Object> params = T.MapUtil.builder()
|
||||
.put("applicationId", applicationId)
|
||||
.put("versions", versionList)
|
||||
.build();
|
||||
List<ApplicationSignatureEntity> list = this.getBaseMapper().queryList(params);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore(String applicationId, String version) {
|
||||
ApplicationSignatureEntity signature = this.getOne(new LambdaQueryWrapper<ApplicationSignatureEntity>()
|
||||
.eq(ApplicationSignatureEntity::getApplicationId, applicationId)
|
||||
.eq(ApplicationSignatureEntity::getOpVersion, version));
|
||||
ApplicationSignatureEntity lastSignature = this.getOne(new LambdaQueryWrapper<ApplicationSignatureEntity>()
|
||||
.eq(ApplicationSignatureEntity::getApplicationId, applicationId)
|
||||
.orderByDesc(ApplicationSignatureEntity::getOpVersion)
|
||||
.last("limit 1"));
|
||||
if (T.ObjectUtil.isEmpty(signature)) {
|
||||
throw ASWException.builder().rcode(RCode.APP_SIGNATURE_NOT_EXIST).build();
|
||||
}
|
||||
|
||||
// restore
|
||||
signature.setId(null);
|
||||
signature.setOpVersion(lastSignature.getOpVersion() + 1);
|
||||
this.save(signature);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package net.geedge.asw.module.app.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.geedge.asw.module.app.dao.SignatureDao;
|
||||
import net.geedge.asw.module.app.entity.SignatureEntity;
|
||||
import net.geedge.asw.module.app.service.ISignatureService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SignatureServiceImpl extends ServiceImpl<SignatureDao, SignatureEntity> implements ISignatureService {
|
||||
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import feign.Feign;
|
||||
import feign.form.FormEncoder;
|
||||
import net.geedge.asw.module.feign.client.GeoipClient;
|
||||
import net.geedge.asw.module.feign.client.KibanaClient;
|
||||
import net.geedge.asw.module.feign.client.WebSharkClient;
|
||||
import net.geedge.asw.module.feign.client.ZeekClient;
|
||||
import net.geedge.asw.module.feign.support.Fastjson2Decoder;
|
||||
import net.geedge.asw.module.feign.support.Fastjson2Encoder;
|
||||
@@ -28,6 +29,9 @@ public class FeignClientConfiguration {
|
||||
@Value("${kibana.url:127.0.0.1:5601}")
|
||||
private String kibanaUrl;
|
||||
|
||||
@Value("${webShark.url:127.0.0.1:8085}")
|
||||
private String websharkurl;
|
||||
|
||||
@Bean("zeekClient")
|
||||
public ZeekClient zeekClient() {
|
||||
String url = UrlBuilder.ofHttp(zeekUrl).toString();
|
||||
@@ -61,4 +65,15 @@ public class FeignClientConfiguration {
|
||||
.target(KibanaClient.class, url);
|
||||
}
|
||||
|
||||
@Bean("webSharkClient")
|
||||
public WebSharkClient webSharkClient() {
|
||||
String url = UrlBuilder.ofHttp(websharkurl).toString();
|
||||
log.info("[webSharkClient] [url: {}]", url);
|
||||
return Feign.builder()
|
||||
.encoder(new FormEncoder())
|
||||
.decoder(new Fastjson2Decoder())
|
||||
.client(new Http2Client())
|
||||
.target(WebSharkClient.class, url);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.geedge.asw.module.feign.client;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import feign.Headers;
|
||||
import feign.Param;
|
||||
import feign.RequestLine;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
@FeignClient(name = "webSharkClient")
|
||||
public interface WebSharkClient {
|
||||
|
||||
@RequestLine("POST /webshark/upload")
|
||||
@Headers("Content-Type: multipart/form-data")
|
||||
JSONObject upload(@Param("fileKey") File file);
|
||||
}
|
||||
@@ -2,14 +2,20 @@ package net.geedge.asw.module.runner.controller;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.log.Log;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import net.geedge.asw.common.config.SpringContextUtils;
|
||||
import net.geedge.asw.common.util.*;
|
||||
import net.geedge.asw.module.feign.client.WebSharkClient;
|
||||
import net.geedge.asw.module.runner.entity.PcapEntity;
|
||||
import net.geedge.asw.module.runner.service.IPcapService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -17,9 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/pcap")
|
||||
@@ -30,6 +34,9 @@ public class PcapController {
|
||||
@Autowired
|
||||
private IPcapService pcapService;
|
||||
|
||||
@Value("${webShark.url:127.0.0.1:8085}")
|
||||
private String websharkurl;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public R detail(@PathVariable("id") String id) {
|
||||
PcapEntity pcapEntity = pcapService.queryInfo(id);
|
||||
@@ -125,4 +132,40 @@ public class PcapController {
|
||||
T.FileUtil.del(zipFile);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/webshark")
|
||||
public R webshark(@PathVariable String id) {
|
||||
T.VerifyUtil.is(id).notEmpty();
|
||||
|
||||
HashMap<Object, Object> result = T.MapUtil.newHashMap();
|
||||
PcapEntity pcap = pcapService.getById(id);
|
||||
File pcapFile = T.FileUtil.file(pcap.getPath());
|
||||
String uploadFileName = T.StrUtil.concat(true, id, ".", T.FileUtil.getSuffix(pcapFile));
|
||||
File newFile = FileUtil.copy(pcapFile, FileUtil.file(Constants.TEMP_PATH, uploadFileName), false);
|
||||
try {
|
||||
WebSharkClient webSharkClient = (WebSharkClient) SpringContextUtils.getBean("webSharkClient");
|
||||
JSONObject obj = webSharkClient.upload(newFile);
|
||||
|
||||
String baseUrl = UrlBuilder.ofHttp(websharkurl)
|
||||
.addPath("/webshark")
|
||||
.toString();
|
||||
result.put("fileName", uploadFileName);
|
||||
result.put("url", baseUrl);
|
||||
}catch (Exception e){
|
||||
log.error(e, "webshark upload pcap error, id: {}", pcap.getId());
|
||||
throw new ASWException(RCode.PCAP_UPLOAD_WEB_SHARK_ERROR);
|
||||
}finally {
|
||||
FileUtil.del(newFile);
|
||||
}
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/unparse2session")
|
||||
public R unparse2session(String[] ids) {
|
||||
T.VerifyUtil.is(ids).notEmpty();
|
||||
|
||||
pcapService.unparse2session(ids);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ public class PcapEntity {
|
||||
private Long size;
|
||||
private String md5;
|
||||
private String status;
|
||||
private String summary;
|
||||
private Long createTimestamp;
|
||||
private String createUserId;
|
||||
private String workspaceId;
|
||||
|
||||
@@ -21,4 +21,5 @@ public interface IPcapService extends IService<PcapEntity>{
|
||||
|
||||
void parse2session(String... ids);
|
||||
|
||||
void unparse2session(String[] ids);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.geedge.asw.common.config.SpringContextUtils;
|
||||
import net.geedge.asw.common.util.ASWException;
|
||||
import net.geedge.asw.common.util.RCode;
|
||||
import net.geedge.asw.common.util.T;
|
||||
@@ -29,7 +30,11 @@ import net.geedge.asw.module.workbook.util.WorkbookConstant;
|
||||
import net.geedge.asw.module.workspace.entity.WorkspaceEntity;
|
||||
import net.geedge.asw.module.workspace.service.IWorkspaceService;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.opensearch.client.opensearch.OpenSearchClient;
|
||||
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
|
||||
import org.opensearch.client.opensearch.indices.ExistsRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -38,6 +43,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -48,6 +54,9 @@ import java.util.stream.Collectors;
|
||||
public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements IPcapService {
|
||||
private static final Log log = Log.get();
|
||||
|
||||
@Value("${sharkdApi.host:127.0.0.1}")
|
||||
private String sharkdApiHostAddr;
|
||||
|
||||
@Autowired
|
||||
private IJobService jobService;
|
||||
|
||||
@@ -180,6 +189,11 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
|
||||
public void parse2session(String... ids) {
|
||||
List<Runnable> taskList = T.ListUtil.list(true);
|
||||
Long maxFileSize = 0L;
|
||||
|
||||
// parse thread config properties
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("sharkdApiHostAddr", this.sharkdApiHostAddr);
|
||||
|
||||
for (String id : ids) {
|
||||
PcapEntity pcapEntity = this.getById(id);
|
||||
if (T.ObjectUtil.isNotNull(pcapEntity)) {
|
||||
@@ -188,6 +202,7 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
|
||||
|
||||
PcapParserThread pcapParserThread = new PcapParserThread();
|
||||
pcapParserThread.setPcapEntity(pcapEntity);
|
||||
pcapParserThread.setProperties(properties);
|
||||
taskList.add(pcapParserThread);
|
||||
|
||||
Long size = pcapEntity.getSize();
|
||||
@@ -214,6 +229,42 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unparse2session(String[] ids) {
|
||||
OpenSearchClient openSearchClient = (OpenSearchClient) SpringContextUtils.getBean("openSearchClient");
|
||||
|
||||
for (String id : ids) {
|
||||
PcapEntity pcapEntity = this.getById(id);
|
||||
if (T.ObjectUtil.isNotNull(pcapEntity)) {
|
||||
WorkspaceEntity workspace = workspaceService.getById(pcapEntity.getWorkspaceId());
|
||||
pcapEntity.setWorkspace(workspace);
|
||||
String pcapPath = pcapEntity.getPath();
|
||||
String md5Hex = T.DigestUtil.md5Hex(T.FileUtil.file(pcapPath));
|
||||
|
||||
String workspaceName = pcapEntity.getWorkspace().getName();
|
||||
String indexName = String.format("workspace-%s-%s", workspaceName, md5Hex);
|
||||
|
||||
try {
|
||||
// check if index exists
|
||||
boolean indexExists = openSearchClient.indices()
|
||||
.exists(new ExistsRequest.Builder().index(indexName).build())
|
||||
.value();
|
||||
|
||||
// if index exists, delete
|
||||
if (indexExists) {
|
||||
openSearchClient.indices().delete(new DeleteIndexRequest.Builder().index(indexName).build());
|
||||
log.debug("delete openSearch index: {}", indexName);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("delete openSearch index error index: {}", indexName);
|
||||
throw new RuntimeException("delete openSearch index error ", e);
|
||||
}
|
||||
pcapEntity.setStatus(RunnerConstant.PcapStatus.UPLOADED.getValue());
|
||||
this.updateById(pcapEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* calculate Parse Thread Timeout
|
||||
*
|
||||
|
||||
@@ -22,10 +22,8 @@ import org.opensearch.client.opensearch.indices.ExistsRequest;
|
||||
import org.opensearch.client.opensearch.indices.IndexSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.geedge.asw.module.runner.util.RunnerConstant.PcapStatus;
|
||||
|
||||
@@ -34,6 +32,8 @@ public class PcapParserThread implements Runnable {
|
||||
|
||||
private Log log = Log.get();
|
||||
|
||||
private Properties properties;
|
||||
|
||||
private PcapEntity pcapEntity;
|
||||
private IPcapService pcapService;
|
||||
|
||||
@@ -88,27 +88,33 @@ public class PcapParserThread implements Runnable {
|
||||
|
||||
// geoip
|
||||
List<String> ipList = jsonArray.stream()
|
||||
.flatMap(obj -> Stream.of(
|
||||
T.MapUtil.getStr((JSONObject) obj, "id.orig_h", ""),
|
||||
T.MapUtil.getStr((JSONObject) obj, "id.resp_h", "")
|
||||
))
|
||||
.map(obj -> T.MapUtil.getStr((JSONObject) obj, "id.resp_h", ""))
|
||||
.filter(s -> T.StrUtil.isNotEmpty(s))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<String, JSONObject> geoipInfo = this.queryGeoip(ipList);
|
||||
|
||||
// add source&geoip_info field
|
||||
String fileName = T.FileUtil.getName(pcapEntity.getPath());
|
||||
// add custom field
|
||||
String pcapId = pcapEntity.getId();
|
||||
String pcapName = T.FileUtil.getName(pcapEntity.getPath());
|
||||
Long tcpStream = 0L, udpStream = 0L;
|
||||
|
||||
String sharkdApiHostAddr = properties.getProperty("sharkdApiHostAddr", "127.0.0.1");
|
||||
for (Object obj : jsonArray) {
|
||||
JSONObject pojo = (JSONObject) obj;
|
||||
pojo.put("source", fileName);
|
||||
pojo.put("pcap.id", pcapId);
|
||||
pojo.put("pcap.name", pcapName);
|
||||
|
||||
String orig = T.MapUtil.getStr(pojo, "id.orig_h", "");
|
||||
if (T.StrUtil.isNotEmpty(orig)) {
|
||||
JSONObject jsonObject = T.MapUtil.get(geoipInfo, orig, JSONObject.class, new JSONObject());
|
||||
pojo.put("id.orig_country", T.MapUtil.getStr(jsonObject, "country", ""));
|
||||
pojo.put("id.orig_asn", T.MapUtil.getStr(jsonObject, "asn", ""));
|
||||
pojo.put("id.orig_asname", T.MapUtil.getStr(jsonObject, "asname", ""));
|
||||
String proto = T.MapUtil.getStr(pojo, "proto", "");
|
||||
if (T.StrUtil.equalsIgnoreCase("tcp", proto)) {
|
||||
Long streamId = tcpStream++;
|
||||
pojo.put("pcap.tcp_stream", streamId);
|
||||
pojo.put("pcap.stream_url", String.format("http://%s/pcap/%s/tcp/%s", sharkdApiHostAddr, pcapId, streamId));
|
||||
}
|
||||
if (T.StrUtil.equalsIgnoreCase("udp", proto)) {
|
||||
Long streamId = udpStream++;
|
||||
pojo.put("pcap.udp_stream", streamId);
|
||||
pojo.put("pcap.stream_url", String.format("http://%s/pcap/%s/udp/%s", sharkdApiHostAddr, pcapId, streamId));
|
||||
}
|
||||
|
||||
String resp = T.MapUtil.getStr(pojo, "id.resp_h", "");
|
||||
@@ -120,6 +126,9 @@ public class PcapParserThread implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
// summary
|
||||
this.statisticSummary(jsonArray);
|
||||
|
||||
// opensearch
|
||||
this.uploadToOpenSearch(jsonArray);
|
||||
}
|
||||
@@ -147,6 +156,44 @@ public class PcapParserThread implements Runnable {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* statistic summary
|
||||
*
|
||||
* @param jsonArray
|
||||
*/
|
||||
private void statisticSummary(JSONArray jsonArray) {
|
||||
if (T.ObjectUtil.isEmpty(jsonArray)) {
|
||||
log.warn("[statisticSummary] [data array is empty] [id: {}]", pcapEntity.getId());
|
||||
} else {
|
||||
Set<String> services = new HashSet<>();
|
||||
Long packets = 0L;
|
||||
for (Object obj : jsonArray) {
|
||||
JSONObject pojo = (JSONObject) obj;
|
||||
long origPkts = pojo.getLongValue("orig_pkts", 0);
|
||||
long respPkts = pojo.getLongValue("resp_pkts", 0);
|
||||
packets = packets + (origPkts + respPkts);
|
||||
|
||||
services.add(pojo.getString("proto"));
|
||||
services.add(pojo.getString("service"));
|
||||
}
|
||||
|
||||
JSONObject first = (JSONObject) jsonArray.getFirst();
|
||||
JSONObject last = (JSONObject) jsonArray.getLast();
|
||||
|
||||
Map<Object, Object> m = T.MapUtil.builder()
|
||||
.put("startTimestamp", first.getBigDecimal("ts"))
|
||||
.put("endTimestamp", last.getBigDecimal("ts"))
|
||||
.put("sessions", jsonArray.size())
|
||||
.put("packets", packets)
|
||||
.put("services", services)
|
||||
.build();
|
||||
pcapService.update(new LambdaUpdateWrapper<PcapEntity>()
|
||||
.set(PcapEntity::getSummary, T.JSONUtil.toJsonStr(m))
|
||||
.eq(PcapEntity::getId, pcapEntity.getId())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* upload to opensearch
|
||||
*
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
<resultMap id="appResult" type="net.geedge.asw.module.app.entity.ApplicationEntity">
|
||||
<result property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="longName" column="long_name"/>
|
||||
<result property="properties" column="properties"/>
|
||||
<result property="tags" column="tags"/>
|
||||
<result property="packageName" column="package_name"/>
|
||||
<result property="website" column="website"/>
|
||||
<result property="provider" column="provider"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="description" column="description"/>
|
||||
<result property="surrogates" column="surrogates"/>
|
||||
<result property="createTimestamp" column="create_timestamp"/>
|
||||
<result property="updateTimestamp" column="update_timestamp"/>
|
||||
<result property="createUserId" column="create_user_id"/>
|
||||
@@ -45,13 +47,9 @@
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
<if test="params.q != null and params.q != ''">
|
||||
AND ( locate(#{params.q}, app.name) OR locate(#{params.q}, app.description) )
|
||||
</if>
|
||||
<if test="params.id != null and params.id != ''">
|
||||
AND app.id = #{params.id}
|
||||
</if>
|
||||
<if test="params.workspaceId != null and params.workspaceId != ''">
|
||||
AND app.workspace_id = #{params.workspaceId}
|
||||
</if>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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="net.geedge.asw.module.app.dao.ApplicationSignatureDao">
|
||||
<resultMap id="signatureResult" type="net.geedge.asw.module.app.entity.ApplicationSignatureEntity">
|
||||
<result property="id" column="id"/>
|
||||
<result property="applicationId" column="application_id"/>
|
||||
<result property="content" column="content"/>
|
||||
<result property="createTimestamp" column="create_timestamp"/>
|
||||
<result property="createUserId" column="create_user_id"/>
|
||||
<result property="opVersion" column="op_version"/>
|
||||
|
||||
<association property="createUser" columnPrefix="c_" javaType="net.geedge.asw.module.sys.entity.SysUserEntity">
|
||||
<id property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
|
||||
<select id="queryList" resultMap="signatureResult">
|
||||
SELECT
|
||||
asg.*,
|
||||
cu.id as c_id,
|
||||
cu.name as c_name
|
||||
FROM
|
||||
application_signature asg
|
||||
left join sys_user cu on asg.create_user_id = cu.id
|
||||
<where>
|
||||
<if test="params.applicationId != null and params.applicationId != ''">
|
||||
AND asg.application_id = #{params.applicationId}
|
||||
</if>
|
||||
<if test="params.versions != null and params.versions != ''">
|
||||
AND asg.op_version in
|
||||
<foreach item="version" collection="params.versions" separator="," open="(" close=")">
|
||||
#{version}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY asg.op_version DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -11,6 +11,7 @@
|
||||
<result property="size" column="size"/>
|
||||
<result property="md5" column="md5"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="summary" column="summary"/>
|
||||
<result property="createTimestamp" column="create_timestamp"/>
|
||||
<result property="createUserId" column="create_user_id"/>
|
||||
<result property="workspaceId" column="workspace_id"/>
|
||||
|
||||
@@ -89,6 +89,20 @@ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (135, '100011', 'USER_NOT_EXIST', '用户不存在', 'zh', '', 'admin', 1719280800000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (137, '100012', 'ROLE_NOT_EXIST', 'role does not exist', 'en', '', 'admin', 1719280800000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (139, '100012', 'ROLE_NOT_EXIST', '权限不存在', 'zh', '', 'admin', 1719280800000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (141, '501001', 'PCAP_UPLOAD_WEB_SHARK_ERROR', 'web shark upload pcap error', 'en', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (143, '501001', 'PCAP_UPLOAD_WEB_SHARK_ERROR', 'pcap 上传失败', 'zh', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (145, '201009', 'APP_PACKAGE_NAME_FORMAT_ERROR', 'application package name format error', 'en', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (147, '201009', 'APP_PACKAGE_NAME_FORMAT_ERROR', '应用安装包名称格式错误', 'zh', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (149, '201010', 'APP_TAGS_FORMAT_ERROR', 'application tags format error', 'en', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (151, '201010', 'APP_TAGS_FORMAT_ERROR', '应用标签格式错误', 'zh', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (153, '201011', 'APP_SIGNATURE_FORMAT_ERROR', 'application signature format error', 'en', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (155, '201011', 'APP_SIGNATURE_FORMAT_ERROR', '应用特征格式错误', 'zh', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (157, '201012', 'APP_SIGNATURE_CONTENT_CANNOT_EMPTY', 'application signature content cannot be empty', 'en', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (159, '201012', 'APP_SIGNATURE_CONTENT_CANNOT_EMPTY', '应用特征内容不能为空', 'zh', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (161, '201013', 'APP_SIGNATURE_NOT_EXIST', 'application signature does not exist', 'en', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (163, '201013', 'APP_SIGNATURE_NOT_EXIST', '应用特征不存在', 'zh', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (165, '201014', 'APP_NOTE_CONTENT_CANNOT_EMPTY', 'application note content cannot be empty', 'en', '', 'admin', 1724030366000);
|
||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (167, '201014', 'APP_NOTE_CONTENT_CANNOT_EMPTY', '应用说明内容不能为空', 'zh', '', 'admin', 1724030366000);
|
||||
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
@@ -227,6 +227,7 @@ CREATE TABLE `pcap` (
|
||||
`size` bigint(20) NOT NULL DEFAULT 0 COMMENT '文件大小',
|
||||
`md5` varchar(64) NOT NULL DEFAULT '' COMMENT '摘要值,根据文件md5值判断是否已上存在,存在则响应当前id',
|
||||
`status` varchar(64) NOT NULL DEFAULT '' COMMENT '状态,可选值 Uploaded,Analyzing,Completed',
|
||||
`summary` varchar(512) NOT NULL DEFAULT '{}' COMMENT '摘要信息, JSON 格式',
|
||||
`create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳',
|
||||
`create_user_id` varchar(64) NOT NULL COMMENT '创建人',
|
||||
`workspace_id` varchar(64) NOT NULL DEFAULT '' COMMENT '工作空间ID',
|
||||
@@ -244,10 +245,12 @@ DROP TABLE IF EXISTS `application`;
|
||||
CREATE TABLE `application` (
|
||||
`id` varchar(64) NOT NULL COMMENT '主键',
|
||||
`name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用名称',
|
||||
`long_name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用全称',
|
||||
`properties` text NOT NULL DEFAULT '' COMMENT '应用数据',
|
||||
`tags` TEXT NOT NULL DEFAULT '' COMMENT '标签',
|
||||
`package_name` VARCHAR(512) NOT NULL DEFAULT '' COMMENT '包名',
|
||||
`website` VARCHAR(1024) NOT NULL DEFAULT '' COMMENT '网站',
|
||||
`provider` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '开发者',
|
||||
`status` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '状态:open,inprogress,done',
|
||||
`description` text NOT NULL DEFAULT '' COMMENT '描述信息',
|
||||
`surrogates` text NOT NULL DEFAULT '' COMMENT '',
|
||||
`create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳',
|
||||
`update_timestamp` bigint(20) NOT NULL COMMENT '更新时间戳',
|
||||
`create_user_id` varchar(64) NOT NULL COMMENT '创建人',
|
||||
@@ -256,7 +259,6 @@ CREATE TABLE `application` (
|
||||
`op_version` int(10) NOT NULL DEFAULT 1 COMMENT '版本号',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `idx_name` (`name`) USING BTREE,
|
||||
KEY `idx_long_name` (`long_name`) USING BTREE,
|
||||
KEY `idx_workspace_id` (`workspace_id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
@@ -268,10 +270,12 @@ DROP TABLE IF EXISTS `application_log`;
|
||||
CREATE TABLE `application_log` (
|
||||
`id` varchar(64) NOT NULL COMMENT '主键',
|
||||
`name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用名称',
|
||||
`long_name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用全称',
|
||||
`properties` text NOT NULL DEFAULT '' COMMENT '应用数据',
|
||||
`tags` TEXT NOT NULL DEFAULT '' COMMENT '标签',
|
||||
`package_name` VARCHAR(512) NOT NULL DEFAULT '' COMMENT '包名',
|
||||
`website` VARCHAR(1024) NOT NULL DEFAULT '' COMMENT '网站',
|
||||
`provider` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '开发者',
|
||||
`status` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '状态:open,inprogress,done',
|
||||
`description` text NOT NULL DEFAULT '' COMMENT '描述信息',
|
||||
`surrogates` text NOT NULL DEFAULT '' COMMENT '',
|
||||
`create_timestamp` bigint(20) NOT NULL COMMENT '创建时间戳',
|
||||
`update_timestamp` bigint(20) NOT NULL COMMENT '更新时间戳',
|
||||
`create_user_id` varchar(64) NOT NULL COMMENT '创建人',
|
||||
@@ -281,6 +285,48 @@ CREATE TABLE `application_log` (
|
||||
UNIQUE INDEX `index_id_version` (`id`, `op_version`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
/**
|
||||
* 新增 application_signature 表
|
||||
*/
|
||||
DROP TABLE IF EXISTS `application_signature`;
|
||||
CREATE TABLE `application_signature` (
|
||||
`id` VARCHAR(64) NOT NULL COMMENT '主键',
|
||||
`application_id` VARCHAR(64) NOT NULL COMMENT '应用id',
|
||||
`content` TEXT NOT NULL COMMENT '特征 json',
|
||||
`create_timestamp` BIGINT(20) NOT NULL COMMENT '创建时间戳',
|
||||
`create_user_id` VARCHAR(64) NOT NULL COMMENT '创建人',
|
||||
`op_version` INT(10) NOT NULL DEFAULT 1 COMMENT '版本号',
|
||||
UNIQUE INDEX `index_id_version` (`id`, `op_version`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
/**
|
||||
* 新增 application_note 表
|
||||
*/
|
||||
DROP TABLE IF EXISTS `application_note`;
|
||||
CREATE TABLE `application_note` (
|
||||
`id` VARCHAR(64) NOT NULL COMMENT '主键',
|
||||
`application_id` VARCHAR(64) NOT NULL COMMENT '应用id',
|
||||
`content` TEXT NOT NULL ,
|
||||
`create_timestamp` BIGINT(20) NOT NULL COMMENT '创建时间戳',
|
||||
`create_user_id` VARCHAR(64) NOT NULL COMMENT '创建人id',
|
||||
`op_version` INT(10) NOT NULL DEFAULT 1 COMMENT '版本号',
|
||||
UNIQUE INDEX `index_id_version` (`id`, `op_version`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
/**
|
||||
* 新增 application_attachment 表
|
||||
*/
|
||||
DROP TABLE IF EXISTS `application_attachment`;
|
||||
CREATE TABLE `application_attachment` (
|
||||
`id` VARCHAR(64) NOT NULL COMMENT '主键',
|
||||
`application_id` VARCHAR(64) NOT NULL COMMENT '应用id',
|
||||
`name` VARCHAR(256) NOT NULL COMMENT '文件名',
|
||||
`path` VARCHAR(512) NOT NULL COMMENT '文件路径',
|
||||
`create_timestamp` BIGINT(20) NOT NULL COMMENT '创建时间戳',
|
||||
`create_user_id` VARCHAR(64) NOT NULL COMMENT '创建人id',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
/**
|
||||
* 新增 package 表
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user