diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6979d37 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:latest + +LABEL authors="Endera" + +EXPOSE 8081 + +COPY prepare.sh /root/prepare.sh + +ENTRYPOINT ["bash", "/root/prepare.sh"] \ No newline at end of file diff --git a/build.gradle b/build.gradle index 754bb09..5680c07 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '3.2.1' id 'io.spring.dependency-management' version '1.1.4' + id 'io.freefair.lombok' version '6.2.0' } group = 'com.realtime' @@ -30,10 +31,12 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'com.mysql:mysql-connector-j' runtimeOnly 'com.oracle.database.jdbc:ojdbc8:19.7.0.0' - annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.3' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e09..1589a40 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.5-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/prepare.sh b/prepare.sh new file mode 100644 index 0000000..eb7eb1b --- /dev/null +++ b/prepare.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +cd ~ + +bash -c "cat << EOF > /etc/apt/sources.list && apt update +deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse +deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse +deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse +deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse +deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse +deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse +EOF" + +apt install sudo git wget openjdk-17-jdk -y + +git config --global user.name "EnderByEndera" +git config --global user.password "8Bs8hxHtE-iq44g" + +git clone https://git.mesalab.cn/EnderByEndera/realtime_protection.git + +cd realtime_protection +./gradlew clean && ./gradlew bootJar \ No newline at end of file diff --git a/src/main/java/com/realtime/protection/configuration/entity/task/FiveTupleWithMask.java b/src/main/java/com/realtime/protection/configuration/entity/task/FiveTupleWithMask.java index 2803fac..e868f5d 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/task/FiveTupleWithMask.java +++ b/src/main/java/com/realtime/protection/configuration/entity/task/FiveTupleWithMask.java @@ -11,7 +11,7 @@ import lombok.Data; public class FiveTupleWithMask { @Schema(description = "地址类型(IPv4 or IPv6)", example = "4") @JsonProperty("addr_type") - private Integer addrType; + private Integer addrType = 4; @Schema(description = "源IP", example = "192.168.104.14") @Pattern(regexp = "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$", message = "源IP:无效IPv4地址") diff --git a/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java b/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java index ef7f7da..9a15837 100644 --- a/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java +++ b/src/main/java/com/realtime/protection/configuration/entity/task/TaskCommandInfo.java @@ -67,6 +67,10 @@ public class TaskCommandInfo { @JsonProperty("is_valid") private Boolean isValid = true; + @Schema(description = "指令是否已研判", example = "true") + @JsonProperty("is_judged") + private Boolean isJudged = true; + @Schema(description = "五元组信息") @NotNull(message = "五元组信息不能为空。") @JsonProperty("five_tuple_with_mask") @@ -87,10 +91,6 @@ public class TaskCommandInfo { @Schema(description = "最新下发时间", accessMode = Schema.AccessMode.READ_ONLY) @JsonProperty("latest_send_times") private LocalDateTime latestSendTime; - - @Schema(description = "指令是否研判", example = "true") - @JsonProperty("is_judeged") - private Boolean isJudged = true; /* 以下属性用于动态规则生成,不写入doris:t_command表 */ diff --git a/src/main/java/com/realtime/protection/server/command/CommandService.java b/src/main/java/com/realtime/protection/server/command/CommandService.java index 92c9094..9174954 100644 --- a/src/main/java/com/realtime/protection/server/command/CommandService.java +++ b/src/main/java/com/realtime/protection/server/command/CommandService.java @@ -36,7 +36,6 @@ public class CommandService { commandInfo.setUUID(UUID.randomUUID().toString()); commandMapper.createCommand(commandInfo); return commandInfo.getUUID(); - } public void createCommands(List taskCommandInfos) { diff --git a/src/main/java/com/realtime/protection/server/task/status/StateHandler.java b/src/main/java/com/realtime/protection/server/task/status/StateHandler.java index aea8730..18c4853 100644 --- a/src/main/java/com/realtime/protection/server/task/status/StateHandler.java +++ b/src/main/java/com/realtime/protection/server/task/status/StateHandler.java @@ -48,7 +48,6 @@ public class StateHandler { } protected Boolean handleResume(CommandService commandService, Long taskId) { - commandService.startCommandsByTaskId(taskId); return true; } diff --git a/src/main/resources/mappers/CommandMapper.xml b/src/main/resources/mappers/CommandMapper.xml index e51b91c..897cee0 100644 --- a/src/main/resources/mappers/CommandMapper.xml +++ b/src/main/resources/mappers/CommandMapper.xml @@ -17,7 +17,8 @@ #{info.fiveTupleWithMask.maskSourceIP}, #{info.fiveTupleWithMask.maskSourcePort}, #{info.fiveTupleWithMask.maskDestinationIP}, #{info.fiveTupleWithMask.maskDestinationPort}, #{info.fiveTupleWithMask.maskProtocol}, - #{info.startTime}, #{info.endTime}, #{info.isValid}, #{info.isJudged}, + #{info.startTime}, #{info.endTime}, #{info.isValid}, + #{info.isJudged}, 0, 0, NOW(), NOW(), FALSE) @@ -25,7 +26,8 @@ insert into t_command(COMMAND_ID, TASK_ID, TASK_ACT, FREQUENCY, ADDR_TYPE, SRC_IP, SRC_PORT, DST_IP, DST_PORT, PROTOCOL, - MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME, INVALID_TIME, IS_VALID, IS_JUDGED, + MASK_SRC_IP, MASK_SRC_PORT, MASK_DST_IP, MASK_DST_PORT, MASK_PROTOCOL, VALID_TIME, INVALID_TIME, IS_VALID, + IS_JUDGED, SEND_TIMES, SUCCESS_TIMES, CREATE_TIME, LAST_UPDATE, IS_DELETED) values @@ -37,7 +39,8 @@ #{info.fiveTupleWithMask.maskSourceIP}, #{info.fiveTupleWithMask.maskSourcePort}, #{info.fiveTupleWithMask.maskDestinationIP}, #{info.fiveTupleWithMask.maskDestinationPort}, #{info.fiveTupleWithMask.maskProtocol}, - #{info.startTime}, #{info.endTime}, #{info.isValid}, DEFAULT, + #{info.startTime}, #{info.endTime}, #{info.isValid}, + #{info.isJudged}, 0, 0, NOW(), NOW(), FALSE ) @@ -128,7 +131,7 @@ UPDATE t_command - SET IS_JUDGED = #{is_judged}, + SET IS_JUDGED = #{is_judged}, LAST_UPDATE = NOW() WHERE COMMAND_ID = #{command_id} AND IS_DELETED = FALSE @@ -137,7 +140,12 @@


+

input your token:

+

+ + + + + + + + + + + diff --git a/src/test/java/com/realtime/protection/server/task/status/CommandServiceTest.java b/src/test/java/com/realtime/protection/server/task/status/CommandServiceTest.java index 28e9b07..f8f393f 100644 --- a/src/test/java/com/realtime/protection/server/task/status/CommandServiceTest.java +++ b/src/test/java/com/realtime/protection/server/task/status/CommandServiceTest.java @@ -13,6 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest; import java.time.LocalDateTime; import java.util.List; +import java.util.Random; import static org.junit.jupiter.api.Assertions.*; @@ -54,8 +55,7 @@ class CommandServiceTest extends ProtectionApplicationTests { @Test void createCommand() { - assertDoesNotThrow(() -> commandService.createCommand(taskCommandInfo)); - assertNotNull(taskCommandInfo.getUUID()); + assertDoesNotThrow(() -> assertNotNull(commandService.createCommand(taskCommandInfo))); } @Test @@ -85,7 +85,7 @@ class CommandServiceTest extends ProtectionApplicationTests { } @Test - void queryCommandByUUID() { + void queryCommandInfos() { List taskCommandInfos = commandService.queryCommandInfos(30L, null, null, null, null,1, 5); assertTrue(taskCommandInfos != null && !taskCommandInfos.isEmpty()); @@ -94,4 +94,14 @@ class CommandServiceTest extends ProtectionApplicationTests { assertNotNull(commandService.queryCommandInfoByUUID(taskCommandInfo.getUUID())); } } + + @Test + void queryCommandByUUID() { + taskCommandInfo.setTaskId(new Random().nextLong()); + String uuid = commandService.createCommand(taskCommandInfo); + TaskCommandInfo taskCommandInfo = commandService.queryCommandInfoByUUID(uuid); + assertNotNull(taskCommandInfo); + assertNotNull(taskCommandInfo.getUUID()); + assertEquals(uuid, taskCommandInfo.getUUID()); + } } \ No newline at end of file