Compare commits
3 Commits
dev-applic
...
dev-worksp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62ea5f5542 | ||
|
|
357ee0be62 | ||
|
|
2945c51b0f |
@@ -61,9 +61,8 @@ 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
|
||||
- tar -zcvf $FILE_NAME asw-controller.jar
|
||||
- "git log -100 --pretty=format:'%ad : %s' > git-log.html"
|
||||
- tar -zcvf $FILE_NAME asw-controller.jar git-log.html
|
||||
- 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,13 +33,6 @@ 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
|
||||
@@ -66,9 +59,6 @@ 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,13 +387,6 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 多参数校验,不能同时为空
|
||||
*
|
||||
|
||||
@@ -2,180 +2,145 @@ 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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/application")
|
||||
@RequestMapping("/api/v1/{workspaceId}/application")
|
||||
public class ApplicationController {
|
||||
|
||||
@Autowired
|
||||
private IApplicationService applicationService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationSignatureService signatureService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationNoteService noteService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationAttachmentService attachmentService;
|
||||
private ISysUserService userService;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public R detail(@PathVariable("id") String id, String workspaceId) {
|
||||
T.VerifyUtil.is(workspaceId).notNull();
|
||||
ApplicationEntity entity = applicationService.detail(id, workspaceId);
|
||||
public R detail(@PathVariable String workspaceId,
|
||||
@PathVariable String id) {
|
||||
ApplicationEntity entity = applicationService.getOne(new LambdaQueryWrapper<ApplicationEntity>()
|
||||
.eq(ApplicationEntity::getId, id)
|
||||
.eq(ApplicationEntity::getWorkspaceId, 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 workspaceId,
|
||||
@PathVariable String id,
|
||||
@PathVariable(required = false) String version) {
|
||||
ApplicationEntity entity = applicationService.queryByApplicationAndLog(id, version, 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
|
||||
public R list(@RequestParam Map<String, Object> params) {
|
||||
public R list(@PathVariable String workspaceId,
|
||||
@RequestParam Map<String, Object> params) {
|
||||
T.VerifyUtil.is(params).notNull()
|
||||
.and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
params.put("workspaceId", workspaceId);
|
||||
Page page = applicationService.queryList(params);
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public R add(@RequestBody ApplicationEntity entity) {
|
||||
public R add(@PathVariable String workspaceId,
|
||||
@RequestBody ApplicationEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getName()).notEmpty(RCode.APP_NAME_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);
|
||||
//.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(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
entity.setWorkspaceId(workspaceId);
|
||||
ApplicationEntity applicationEntity = applicationService.saveApplication(entity);
|
||||
return R.ok().putData("id", applicationEntity.getId());
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public R update(@RequestBody ApplicationEntity entity) {
|
||||
public R update(@PathVariable String workspaceId,
|
||||
@RequestBody ApplicationEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
|
||||
.and(entity.getName()).notEmpty(RCode.NAME_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);
|
||||
|
||||
//.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(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
entity.setWorkspaceId(workspaceId);
|
||||
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) {
|
||||
public R delete(@PathVariable String workspaceId,
|
||||
String[] ids) {
|
||||
T.VerifyUtil.is(ids).notEmpty();
|
||||
applicationService.removeApplication(T.ListUtil.of(ids));
|
||||
applicationService.removeApplication(T.ListUtil.of(ids), workspaceId);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
@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}/log")
|
||||
public R queryLogList(@PathVariable String workspaceId,
|
||||
@PathVariable("id") String id) {
|
||||
List<ApplicationEntity> applicationEntityList = applicationService.queryLogList(id, workspaceId);
|
||||
return R.ok().putData("record", applicationEntityList);
|
||||
}
|
||||
|
||||
|
||||
@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) {
|
||||
|
||||
attachmentService.removedAttachment(applicationId, ids);
|
||||
return R.ok();
|
||||
@GetMapping("/{id}/{oldVersion}/{newVersion}")
|
||||
public R applicationCompare(@PathVariable String workspaceId,
|
||||
@PathVariable("id") String id,
|
||||
@PathVariable("oldVersion") String oldVersion,
|
||||
@PathVariable("newVersion") String newVersion) {
|
||||
List<ApplicationEntity> list = applicationService.compare(id, oldVersion, newVersion,workspaceId);
|
||||
return R.ok().putData("record", list);
|
||||
}
|
||||
|
||||
|
||||
@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,
|
||||
@PostMapping("/{id}/{version}/restore")
|
||||
public R restore(@PathVariable String workspaceId,
|
||||
@PathVariable("id") String id,
|
||||
@PathVariable("version") String version) {
|
||||
signatureService.restore(applicationId, version);
|
||||
applicationService.restore(id, version, workspaceId);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/analyze")
|
||||
public void analyze(@PathVariable String workspaceId,
|
||||
@RequestParam String pcapIds,
|
||||
HttpServletResponse response) throws IOException {
|
||||
applicationService.redirectDiscoverPage(workspaceId, pcapIds, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.geedge.asw.module.app.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import net.geedge.asw.common.util.R;
|
||||
import net.geedge.asw.common.util.RCode;
|
||||
@@ -12,53 +13,63 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/package")
|
||||
@RequestMapping("/api/v1/{workspaceId}/package")
|
||||
public class PackageController {
|
||||
|
||||
@Autowired
|
||||
private IPackageService packageService;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public R detail(@PathVariable("id") String id) {
|
||||
PackageEntity entity = packageService.getById(id);
|
||||
public R detail(@PathVariable String workspaceId,
|
||||
@PathVariable("id") String id) {
|
||||
PackageEntity entity = packageService.getOne(new LambdaQueryWrapper<PackageEntity>()
|
||||
.eq(PackageEntity::getId, id)
|
||||
.eq(PackageEntity::getWorkspaceId, workspaceId));
|
||||
return R.ok().putData("record", entity);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public R list(@RequestParam Map<String, Object> params) {
|
||||
public R list(@PathVariable String workspaceId,
|
||||
@RequestParam Map<String, Object> params) {
|
||||
T.VerifyUtil.is(params).notNull()
|
||||
.and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
params.put("workspaceId", workspaceId);
|
||||
Page page = packageService.queryList(params);
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public R add(@RequestBody PackageEntity entity) {
|
||||
public R add(@PathVariable String workspaceId,
|
||||
@RequestBody PackageEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
|
||||
.and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY)
|
||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
entity.setWorkspaceId(workspaceId);
|
||||
PackageEntity pkgEntity = packageService.savePackage(entity);
|
||||
return R.ok().putData("id", pkgEntity.getId());
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public R update(@RequestBody PackageEntity entity) {
|
||||
public R update(@PathVariable String workspaceId,
|
||||
@RequestBody PackageEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
|
||||
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
|
||||
.and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY)
|
||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
entity.setWorkspaceId(workspaceId);
|
||||
PackageEntity pkgEntity = packageService.updatePackage(entity);
|
||||
return R.ok().putData("id", pkgEntity.getId());
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public R delete(String[] ids) {
|
||||
public R delete(@PathVariable String workspaceId,
|
||||
String[] ids) {
|
||||
T.VerifyUtil.is(ids).notEmpty();
|
||||
packageService.removePackage(T.ListUtil.of(ids));
|
||||
packageService.removePackage(T.ListUtil.of(ids), workspaceId);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
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>{
|
||||
|
||||
}
|
||||
@@ -15,10 +15,10 @@ public interface ApplicationDao extends BaseMapper<ApplicationEntity>{
|
||||
|
||||
List<ApplicationEntity> queryList(Page page, Map<String, Object> params);
|
||||
|
||||
@Select("select * from ( select * from application union select * from application_log ) app where app.id = #{id} and app.op_version = #{version}")
|
||||
ApplicationEntity queryByApplicationAndLog(String id, String version);
|
||||
@Select("select * from ( select * from application union select * from application_log ) app where app.id = #{id} and app.op_version = #{version} and app.workspace_id = #{workspaceId}")
|
||||
ApplicationEntity queryByApplicationAndLog(String id, String version, String workspaceId);
|
||||
|
||||
List<ApplicationEntity> queryLogList(String id);
|
||||
List<ApplicationEntity> queryLogList(String id, String workspaceId);
|
||||
|
||||
List<ApplicationEntity> compare(@Param("params") Map<String, Object> params);
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -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.ApplicationNoteEntity;
|
||||
import net.geedge.asw.module.app.entity.SignatureEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ApplicationNoteDao extends BaseMapper<ApplicationNoteEntity>{
|
||||
public interface SignatureDao extends BaseMapper<SignatureEntity>{
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
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,39 +7,24 @@ 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 tags;
|
||||
|
||||
private String packageName;
|
||||
|
||||
private String website;
|
||||
|
||||
private String provider;
|
||||
|
||||
private String status;
|
||||
|
||||
private String longName;
|
||||
private String properties;
|
||||
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)
|
||||
@@ -48,12 +33,4 @@ 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,60 +1,24 @@
|
||||
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 tags;
|
||||
|
||||
private String packageName;
|
||||
|
||||
private String website;
|
||||
|
||||
private String provider;
|
||||
|
||||
private String status;
|
||||
|
||||
private String longName;
|
||||
private String properties;
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -6,20 +6,24 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("application_note")
|
||||
public class ApplicationNoteEntity {
|
||||
@TableName("signature")
|
||||
public class SignatureEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
private String applicationId;
|
||||
|
||||
private String content;
|
||||
|
||||
private Long createTimestamp;
|
||||
|
||||
private String createUserId;
|
||||
|
||||
private String appId;
|
||||
private String name;
|
||||
private String tags;
|
||||
private String description;
|
||||
private Integer displayFlag;
|
||||
private String conditions;
|
||||
private Long opVersion;
|
||||
|
||||
private Long createTimestamp;
|
||||
private Long updateTimestamp;
|
||||
private String createUserId;
|
||||
private String updateUserId;
|
||||
|
||||
private String workspaceId;
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
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,24 +2,31 @@ 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, String workspaceId);
|
||||
|
||||
void removeApplication(List<String> ids);
|
||||
ApplicationEntity queryByApplicationAndLog(String id, String version, String workspaceId);
|
||||
|
||||
List<ApplicationEntity> compare(String id, String oldVersion, String newVersion, String workspaceId);
|
||||
|
||||
List<ApplicationEntity> queryLogList(String id, String workspaceId);
|
||||
|
||||
void restore(String id, String version, String workspaceId);
|
||||
|
||||
void redirectDiscoverPage(String workspaceId, String pcapIds, HttpServletResponse response) throws IOException;
|
||||
|
||||
String generateKibanaDiscoverUrl(String workspaceId, String pcapIds);
|
||||
}
|
||||
|
||||
@@ -15,5 +15,5 @@ public interface IPackageService extends IService<PackageEntity>{
|
||||
|
||||
PackageEntity updatePackage(PackageEntity entity);
|
||||
|
||||
void removePackage(List<String> ids);
|
||||
void removePackage(List<String> ids, String workspaceId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
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>{
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
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,17 +10,18 @@ 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.*;
|
||||
import net.geedge.asw.module.app.service.*;
|
||||
import net.geedge.asw.module.feign.client.KibanaClient;
|
||||
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.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;
|
||||
@@ -28,6 +29,8 @@ 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;
|
||||
@@ -49,49 +52,13 @@ 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 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;
|
||||
public ApplicationEntity queryByApplicationAndLog(String id, String version, String workspaceId) {
|
||||
ApplicationEntity entity = this.baseMapper.queryByApplicationAndLog(id, version, workspaceId);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,79 +69,36 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
return page;
|
||||
}
|
||||
|
||||
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) && !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) {
|
||||
ApplicationEntity one = this.getOne(new LambdaQueryWrapper<ApplicationEntity>()
|
||||
.eq(ApplicationEntity::getWorkspaceId, entity.getWorkspaceId())
|
||||
.eq(ApplicationEntity::getName, entity.getName()));
|
||||
if (T.ObjectUtil.isNotNull(one)) {
|
||||
throw ASWException.builder().rcode(RCode.APP_DUPLICATE_RECORD).build();
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -183,22 +107,11 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
this.updateById(entity);
|
||||
|
||||
// save log
|
||||
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());
|
||||
}
|
||||
|
||||
this.saveApplcationToLog(one);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void saveApplicationToLog(ApplicationEntity one) {
|
||||
private void saveApplcationToLog(ApplicationEntity one) {
|
||||
ApplicationLogEntity applicationLogEntity = T.BeanUtil.toBean(one, ApplicationLogEntity.class);
|
||||
applicationLogEntity.setUpdateTimestamp(System.currentTimeMillis());
|
||||
applicationLogEntity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||
@@ -209,13 +122,50 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeApplication(List<String> ids) {
|
||||
public void removeApplication(List<String> ids, String workspaceId) {
|
||||
// remove
|
||||
this.removeBatchByIds(ids);
|
||||
applicationLogService.removeBatchByIds(ids);
|
||||
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));
|
||||
this.remove(new LambdaQueryWrapper<ApplicationEntity>()
|
||||
.in(ApplicationEntity::getId, ids)
|
||||
.eq(ApplicationEntity::getWorkspaceId, workspaceId));
|
||||
applicationLogService.remove(new LambdaQueryWrapper<ApplicationLogEntity>()
|
||||
.in(ApplicationLogEntity::getId, ids)
|
||||
.eq(ApplicationLogEntity::getWorkspaceId, workspaceId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationEntity> queryLogList(String id, String workspaceId) {
|
||||
List<ApplicationEntity> packageList = this.getBaseMapper().queryLogList(id, workspaceId);
|
||||
return packageList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApplicationEntity> compare(String id, String oldVersion, String newVersion, String workspaceId) {
|
||||
Map<String, Object> params = Map.of("id", id, "versions", Arrays.asList(oldVersion, newVersion),"workspaceId",workspaceId);
|
||||
List<ApplicationEntity> packageList = this.getBaseMapper().compare(params);
|
||||
return packageList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void restore(String id, String version, String workspaceId) {
|
||||
// save current to log
|
||||
ApplicationEntity curApplication = this.getOne(new LambdaQueryWrapper<ApplicationEntity>()
|
||||
.eq(ApplicationEntity::getId, id)
|
||||
.eq(ApplicationEntity::getWorkspaceId, workspaceId));
|
||||
this.saveApplcationToLog(curApplication);
|
||||
// restore
|
||||
ApplicationLogEntity oldApplication = applicationLogService.getOne(new LambdaQueryWrapper<ApplicationLogEntity>()
|
||||
.eq(ApplicationLogEntity::getId, id)
|
||||
.eq(ApplicationLogEntity::getWorkspaceId, workspaceId)
|
||||
.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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,10 +182,11 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
* }
|
||||
* @param workspaceId
|
||||
* @param pcapIds
|
||||
* @return kibana discover url
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public String generateKibanaDiscoverUrl(String workspaceId, String pcapIds) {
|
||||
public void redirectDiscoverPage(String workspaceId, String pcapIds, HttpServletResponse response) throws IOException {
|
||||
// verify
|
||||
WorkspaceEntity workspace = workspaceService.getById(workspaceId);
|
||||
T.VerifyUtil.is(workspace).notNull(RCode.SYS_RECORD_NOT_FOUND);
|
||||
@@ -264,7 +215,7 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
|
||||
.findFirst()
|
||||
.isPresent();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("[generateKibanaDiscoverUrl] [idnex-pattern: {}] [exists: {}]", indexName, indexExists);
|
||||
log.debug("[redirectDiscoverPage] [idnex-pattern: {}] [exists: {}]", indexName, indexExists);
|
||||
}
|
||||
|
||||
// create index
|
||||
@@ -287,42 +238,20 @@ 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 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 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 query = String.format("?%s&%s&%s", param1, param2, param3);
|
||||
String kibanaDiscoverUrl = baseUrl + "#" + query;
|
||||
String redirectUrl = baseUrl + "#" + query;
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("[generateKibanaDiscoverUrl] [url: {}]", kibanaDiscoverUrl);
|
||||
}
|
||||
return kibanaDiscoverUrl;
|
||||
}
|
||||
|
||||
@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();
|
||||
if(log.isDebugEnabled()){
|
||||
log.debug("[redirectDiscoverPage] [url: {}]", redirectUrl);
|
||||
}
|
||||
|
||||
// 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;
|
||||
// redirect
|
||||
response.sendRedirect(redirectUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -80,9 +80,11 @@ public class PackageServiceImpl extends ServiceImpl<PackageDao, PackageEntity> i
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removePackage(List<String> ids) {
|
||||
public void removePackage(List<String> ids, String workspaceId) {
|
||||
// remove
|
||||
this.removeBatchByIds(ids);
|
||||
this.remove(new LambdaQueryWrapper<PackageEntity>()
|
||||
.eq(PackageEntity::getWorkspaceId, workspaceId)
|
||||
.in(PackageEntity::getId, ids));
|
||||
// workbook resource
|
||||
workbookResourceService.removeResource(ids, WorkbookConstant.ResourceType.PACKAGE.getValue());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
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,7 +6,6 @@ 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;
|
||||
@@ -29,9 +28,6 @@ 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();
|
||||
@@ -65,15 +61,4 @@ 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -13,33 +13,38 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/job")
|
||||
@RequestMapping("/api/v1/{workspaceId}/job")
|
||||
public class JobController {
|
||||
|
||||
@Autowired
|
||||
private IJobService jobService;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public R detail(@PathVariable("id") String id) {
|
||||
JobEntity jobEntity = jobService.queryInfo(id);
|
||||
public R detail(@PathVariable String workspaceId,
|
||||
@PathVariable("id") String id) {
|
||||
JobEntity jobEntity = jobService.queryInfo(id, workspaceId);
|
||||
return R.ok().putData("record", jobEntity);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public R list(@RequestParam Map<String, Object> params) {
|
||||
public R list(@PathVariable String workspaceId,
|
||||
@RequestParam Map<String, Object> params) {
|
||||
T.VerifyUtil.is(params).notNull()
|
||||
.and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
params.put("workspaceId", workspaceId);
|
||||
Page page = jobService.queryList(params);
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public R add(@RequestBody JobEntity entity) {
|
||||
public R add(@PathVariable String workspaceId,
|
||||
@RequestBody JobEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getRunnerId()).notEmpty(RCode.RUNNER_ID_CANNOT_EMPTY)
|
||||
.and(entity.getPackageId()).notEmpty(RCode.PACKAGE_ID_CANNOT_EMPTY)
|
||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
entity.setWorkspaceId(workspaceId);
|
||||
JobEntity jobEntity = jobService.saveJob(entity);
|
||||
return R.ok().putData("id", jobEntity.getId());
|
||||
}
|
||||
|
||||
@@ -2,20 +2,14 @@ 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.*;
|
||||
@@ -23,10 +17,12 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/pcap")
|
||||
@RequestMapping("/api/v1/{workspaceId}/pcap")
|
||||
public class PcapController {
|
||||
|
||||
private static final Log log = Log.get();
|
||||
@@ -34,20 +30,20 @@ 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);
|
||||
public R detail(@PathVariable String workspaceId,
|
||||
@PathVariable("id") String id) {
|
||||
PcapEntity pcapEntity = pcapService.queryInfo(id,workspaceId);
|
||||
return R.ok().putData("record", pcapEntity);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public R list(@RequestParam Map<String, Object> params) {
|
||||
public R list(@PathVariable String workspaceId,
|
||||
@RequestParam Map<String, Object> params) {
|
||||
T.VerifyUtil.is(params).notNull()
|
||||
.and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
params.put("workspaceId",workspaceId);
|
||||
Page page = pcapService.queryList(params);
|
||||
return R.ok(page);
|
||||
}
|
||||
@@ -132,40 +128,4 @@ 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();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package net.geedge.asw.module.runner.controller;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.core.lang.Opt;
|
||||
import cn.hutool.log.Log;
|
||||
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 jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -23,7 +24,7 @@ import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/runner")
|
||||
@RequestMapping("/api/v1/{workspaceId}/runner")
|
||||
public class RunnerController {
|
||||
|
||||
private static final Log log = Log.get();
|
||||
@@ -35,35 +36,44 @@ public class RunnerController {
|
||||
private IRunnerService runnerService;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public R detail(@PathVariable("id") String id) {
|
||||
RunnerEntity runnerEntity = runnerService.getById(id);
|
||||
public R detail(@PathVariable String workspaceId,
|
||||
@PathVariable("id") String id) {
|
||||
RunnerEntity runnerEntity = runnerService.getOne(new LambdaQueryWrapper<RunnerEntity>()
|
||||
.eq(RunnerEntity::getId, id)
|
||||
.eq(RunnerEntity::getWorkspaceId, workspaceId));
|
||||
return R.ok().putData("record", runnerEntity);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public R list(@RequestParam Map<String, Object> params) {
|
||||
public R list(@PathVariable String workspaceId,
|
||||
@RequestParam Map<String, Object> params) {
|
||||
T.VerifyUtil.is(params).notNull()
|
||||
.and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
params.put("workspaceId", workspaceId);
|
||||
Page page = runnerService.queryList(params);
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public R add(@RequestBody RunnerEntity entity) {
|
||||
public R add(@PathVariable String workspaceId,
|
||||
@RequestBody RunnerEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
entity.setWorkspaceId(workspaceId);
|
||||
RunnerEntity runner = runnerService.saveRunner(entity);
|
||||
return R.ok().putData("record", runner);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public R update(@RequestBody RunnerEntity entity) {
|
||||
public R update(@PathVariable String workspaceId,
|
||||
@RequestBody RunnerEntity entity) {
|
||||
T.VerifyUtil.is(entity).notNull()
|
||||
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
|
||||
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
.and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
|
||||
|
||||
entity.setWorkspaceId(workspaceId);
|
||||
RunnerEntity runner = runnerService.updateRunner(entity);
|
||||
return R.ok().putData("record", runner);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ public class PcapEntity {
|
||||
private Long size;
|
||||
private String md5;
|
||||
private String status;
|
||||
private String summary;
|
||||
private Long createTimestamp;
|
||||
private String createUserId;
|
||||
private String workspaceId;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Map;
|
||||
|
||||
public interface IJobService extends IService<JobEntity>{
|
||||
|
||||
JobEntity queryInfo(String id);
|
||||
JobEntity queryInfo(String id, String workspaceId);
|
||||
|
||||
Page queryList(Map<String, Object> params);
|
||||
|
||||
|
||||
@@ -5,11 +5,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.geedge.asw.module.runner.entity.PcapEntity;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IPcapService extends IService<PcapEntity>{
|
||||
|
||||
PcapEntity queryInfo(String id);
|
||||
PcapEntity queryInfo(String id, String workspaceId);
|
||||
|
||||
Page queryList(Map<String, Object> params);
|
||||
|
||||
@@ -21,5 +22,4 @@ public interface IPcapService extends IService<PcapEntity>{
|
||||
|
||||
void parse2session(String... ids);
|
||||
|
||||
void unparse2session(String[] ids);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.geedge.asw.module.runner.service.impl;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.log.Log;
|
||||
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;
|
||||
@@ -67,21 +68,31 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobEntity queryInfo(String id) {
|
||||
JobEntity job = this.getById(id);
|
||||
public JobEntity queryInfo(String id, String workspaceId) {
|
||||
JobEntity job = this.getOne(new LambdaQueryWrapper<JobEntity>()
|
||||
.eq(JobEntity::getId, id)
|
||||
.eq(JobEntity::getWorkspaceId, workspaceId));
|
||||
T.VerifyUtil.is(job).notNull(RCode.SYS_RECORD_NOT_FOUND);
|
||||
|
||||
RunnerEntity runner = runnerService.getById(job.getRunnerId());
|
||||
RunnerEntity runner = runnerService.getOne(new LambdaQueryWrapper<RunnerEntity>()
|
||||
.eq(RunnerEntity::getId, job.getRunnerId())
|
||||
.eq(RunnerEntity::getWorkspaceId, workspaceId));
|
||||
job.setRunner(runner);
|
||||
|
||||
PlaybookEntity playbook = playbookService.getById(job.getPlaybookId());
|
||||
PlaybookEntity playbook = playbookService.getOne(new LambdaQueryWrapper<PlaybookEntity>()
|
||||
.eq(PlaybookEntity::getId, job.getPlaybookId())
|
||||
.eq(PlaybookEntity::getWorkspaceId, workspaceId));
|
||||
job.setPlaybook(playbook);
|
||||
|
||||
PackageEntity pkg = packageService.getById(job.getPackageId());
|
||||
PackageEntity pkg = packageService.getOne(new LambdaQueryWrapper<PackageEntity>()
|
||||
.eq(PackageEntity::getId, job.getPackageId())
|
||||
.eq(PackageEntity::getWorkspaceId, workspaceId));
|
||||
job.setPkg(pkg);
|
||||
|
||||
if (T.ObjectUtil.isNotNull(playbook)) {
|
||||
ApplicationEntity application = applicationService.getById(playbook.getAppId());
|
||||
ApplicationEntity application = applicationService.getOne(new LambdaQueryWrapper<ApplicationEntity>()
|
||||
.eq(ApplicationEntity::getId, playbook.getAppId())
|
||||
.eq(ApplicationEntity::getWorkspaceId, workspaceId));
|
||||
job.setApplication(application);
|
||||
}
|
||||
return job;
|
||||
@@ -106,9 +117,10 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
|
||||
// save
|
||||
this.save(entity);
|
||||
|
||||
// workbook resource
|
||||
workbookResourceService.saveResource(entity.getWorkbookId(), entity.getId(), WorkbookConstant.ResourceType.JOB.getValue());
|
||||
|
||||
if (T.StrUtil.isEmpty(entity.getWorkbookId())){
|
||||
// workbook resource
|
||||
workbookResourceService.saveResource(entity.getWorkbookId(), entity.getId(), WorkbookConstant.ResourceType.JOB.getValue());
|
||||
}
|
||||
// trace log file path
|
||||
File traceLogFile = T.FileUtil.file(this.getJobResultPath(entity.getId()), "trace.log");
|
||||
this.update(new LambdaUpdateWrapper<JobEntity>()
|
||||
|
||||
@@ -6,7 +6,6 @@ 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;
|
||||
@@ -30,11 +29,7 @@ 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;
|
||||
@@ -43,7 +38,6 @@ 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;
|
||||
@@ -54,9 +48,6 @@ 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;
|
||||
|
||||
@@ -79,8 +70,8 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
|
||||
private IWorkspaceService workspaceService;
|
||||
|
||||
@Override
|
||||
public PcapEntity queryInfo(String id) {
|
||||
PcapEntity pcap = this.getById(id);
|
||||
public PcapEntity queryInfo(String id, String workspaceId) {
|
||||
PcapEntity pcap = this.getOne(new LambdaQueryWrapper<PcapEntity>().eq(PcapEntity::getId, id).eq(PcapEntity::getWorkspaceId, workspaceId));
|
||||
T.VerifyUtil.is(pcap).notNull(RCode.SYS_RECORD_NOT_FOUND);
|
||||
|
||||
JobEntity job = jobService.getOne(new LambdaQueryWrapper<JobEntity>().eq(JobEntity::getPcapId, pcap.getId()));
|
||||
@@ -189,11 +180,6 @@ 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)) {
|
||||
@@ -202,7 +188,6 @@ 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();
|
||||
@@ -229,42 +214,6 @@ 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,8 +22,10 @@ import org.opensearch.client.opensearch.indices.ExistsRequest;
|
||||
import org.opensearch.client.opensearch.indices.IndexSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.geedge.asw.module.runner.util.RunnerConstant.PcapStatus;
|
||||
|
||||
@@ -32,8 +34,6 @@ public class PcapParserThread implements Runnable {
|
||||
|
||||
private Log log = Log.get();
|
||||
|
||||
private Properties properties;
|
||||
|
||||
private PcapEntity pcapEntity;
|
||||
private IPcapService pcapService;
|
||||
|
||||
@@ -88,33 +88,27 @@ public class PcapParserThread implements Runnable {
|
||||
|
||||
// geoip
|
||||
List<String> ipList = jsonArray.stream()
|
||||
.map(obj -> T.MapUtil.getStr((JSONObject) obj, "id.resp_h", ""))
|
||||
.flatMap(obj -> Stream.of(
|
||||
T.MapUtil.getStr((JSONObject) obj, "id.orig_h", ""),
|
||||
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 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");
|
||||
// add source&geoip_info field
|
||||
String fileName = T.FileUtil.getName(pcapEntity.getPath());
|
||||
for (Object obj : jsonArray) {
|
||||
JSONObject pojo = (JSONObject) obj;
|
||||
pojo.put("pcap.id", pcapId);
|
||||
pojo.put("pcap.name", pcapName);
|
||||
pojo.put("source", fileName);
|
||||
|
||||
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 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 resp = T.MapUtil.getStr(pojo, "id.resp_h", "");
|
||||
@@ -126,9 +120,6 @@ public class PcapParserThread implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
// summary
|
||||
this.statisticSummary(jsonArray);
|
||||
|
||||
// opensearch
|
||||
this.uploadToOpenSearch(jsonArray);
|
||||
}
|
||||
@@ -156,44 +147,6 @@ 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,12 +5,10 @@
|
||||
<resultMap id="appResult" type="net.geedge.asw.module.app.entity.ApplicationEntity">
|
||||
<result property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<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="longName" column="long_name"/>
|
||||
<result property="properties" column="properties"/>
|
||||
<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"/>
|
||||
@@ -47,9 +45,13 @@
|
||||
#{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>
|
||||
@@ -74,6 +76,9 @@
|
||||
<if test="id != null and id != ''">
|
||||
AND app.id = #{id}
|
||||
</if>
|
||||
<if test="workspaceId != null and workspaceId != ''">
|
||||
AND app.workspace_id = #{workspaceId}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY app.op_version DESC
|
||||
</select>
|
||||
@@ -99,6 +104,9 @@
|
||||
<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>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
<?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,7 +11,6 @@
|
||||
<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,20 +89,6 @@ 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,7 +227,6 @@ 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',
|
||||
@@ -245,12 +244,10 @@ DROP TABLE IF EXISTS `application`;
|
||||
CREATE TABLE `application` (
|
||||
`id` varchar(64) NOT NULL COMMENT '主键',
|
||||
`name` varchar(256) 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',
|
||||
`long_name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用全称',
|
||||
`properties` text NOT NULL DEFAULT '' COMMENT '应用数据',
|
||||
`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 '创建人',
|
||||
@@ -259,6 +256,7 @@ 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;
|
||||
|
||||
@@ -270,12 +268,10 @@ DROP TABLE IF EXISTS `application_log`;
|
||||
CREATE TABLE `application_log` (
|
||||
`id` varchar(64) NOT NULL COMMENT '主键',
|
||||
`name` varchar(256) 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',
|
||||
`long_name` varchar(256) NOT NULL DEFAULT '' COMMENT '应用全称',
|
||||
`properties` text NOT NULL DEFAULT '' COMMENT '应用数据',
|
||||
`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 '创建人',
|
||||
@@ -285,48 +281,6 @@ 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