Merge remote-tracking branch 'origin/master'
This commit is contained in:
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM ubuntu:latest
|
||||
|
||||
LABEL authors="Endera"
|
||||
|
||||
EXPOSE 8081
|
||||
|
||||
COPY prepare.sh /root/prepare.sh
|
||||
|
||||
ENTRYPOINT ["bash", "/root/prepare.sh"]
|
||||
@@ -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'
|
||||
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -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
|
||||
|
||||
26
prepare.sh
Normal file
26
prepare.sh
Normal file
@@ -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
|
||||
@@ -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地址")
|
||||
|
||||
@@ -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表
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,6 @@ public class CommandService {
|
||||
commandInfo.setUUID(UUID.randomUUID().toString());
|
||||
commandMapper.createCommand(commandInfo);
|
||||
return commandInfo.getUUID();
|
||||
|
||||
}
|
||||
|
||||
public void createCommands(List<TaskCommandInfo> taskCommandInfos) {
|
||||
|
||||
@@ -48,7 +48,6 @@ public class StateHandler {
|
||||
}
|
||||
|
||||
protected Boolean handleResume(CommandService commandService, Long taskId) {
|
||||
|
||||
commandService.startCommandsByTaskId(taskId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
</insert>
|
||||
@@ -25,7 +26,8 @@
|
||||
<insert id="createCommands" parameterType="com.realtime.protection.configuration.entity.task.TaskCommandInfo">
|
||||
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
|
||||
<foreach collection="command_infos" item="info" separator=",">
|
||||
@@ -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 id="setCommandJudged">
|
||||
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 @@
|
||||
<select id="queryCommandInfo" resultType="java.lang.String">
|
||||
SELECT COMMAND_ID FROM t_command
|
||||
<where>
|
||||
<if test="command_info.taskId != null">AND TASK_ID = #{command_info.taskId}</if>
|
||||
<if test="command_info.taskId != null">
|
||||
AND TASK_ID = #{command_info.taskId}
|
||||
</if>
|
||||
<if test="#{command_info.fiveTupleWithMask.addrType} != null">
|
||||
AND ADDR_TYPE = #{command_info.fiveTupleWithMask.addrType}
|
||||
</if>
|
||||
<if test="command_info.fiveTupleWithMask.sourceIP != null">
|
||||
AND SRC_IP = #{command_info.fiveTupleWithMask.sourceIP}
|
||||
</if>
|
||||
|
||||
84
src/main/resources/nginx/nginx.conf
Normal file
84
src/main/resources/nginx/nginx.conf
Normal file
@@ -0,0 +1,84 @@
|
||||
user root root;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
include /etc/nginx/modules-enabled/*.conf;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
# multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
|
||||
##
|
||||
# Basic Settings
|
||||
##
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
types_hash_max_size 2048;
|
||||
# server_tokens off;
|
||||
|
||||
# server_names_hash_bucket_size 64;
|
||||
# server_name_in_redirect off;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
##
|
||||
# SSL Settings
|
||||
##
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
##
|
||||
# Logging Settings
|
||||
##
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
##
|
||||
# Gzip Settings
|
||||
##
|
||||
|
||||
gzip on;
|
||||
|
||||
# gzip_vary on;
|
||||
# gzip_proxied any;
|
||||
# gzip_comp_level 6;
|
||||
# gzip_buffers 16 8k;
|
||||
# gzip_http_version 1.1;
|
||||
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
##
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
include /home/wzw/nginx/configs/*.conf;
|
||||
}
|
||||
|
||||
|
||||
#mail {
|
||||
# # See sample authentication script at:
|
||||
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
|
||||
#
|
||||
# # auth_http localhost/auth.php;
|
||||
# # pop3_capabilities "TOP" "USER";
|
||||
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
|
||||
#
|
||||
# server {
|
||||
# listen localhost:110;
|
||||
# protocol pop3;
|
||||
# proxy on;
|
||||
# }
|
||||
#
|
||||
# server {
|
||||
# listen localhost:143;
|
||||
# protocol imap;
|
||||
# proxy on;
|
||||
# }
|
||||
#}
|
||||
BIN
src/main/resources/static/favicon.ico
Normal file
BIN
src/main/resources/static/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
47
src/main/resources/static/test.html
Normal file
47
src/main/resources/static/test.html
Normal file
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>cors test</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container" align="center">
|
||||
<h1>Cors Test</h1><br/>
|
||||
<p>input your target api address:</p>
|
||||
<input type="text" style="width:600px;height:30px;font-size:14px;" id="urlText"/><br/><br/><br/>
|
||||
<p>input your token:</p>
|
||||
<input type="text" style="width:600px;height:30px;font-size:14px;" id="tokenTxt" value=""/><br/><br/>
|
||||
<input type="button" class="btn btn-outline-primary" id="cors" value="CHECK CORS"/>
|
||||
</div>
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#cors").on('click', function (event) {
|
||||
event.preventDefault();
|
||||
var url2 = $("#urlText").val();
|
||||
$.get({
|
||||
contentType: 'application/json;charset=UTF-8',
|
||||
url: url2,
|
||||
beforeSend: function (xhr) {
|
||||
|
||||
if ($("#tokenTxt").val().trim()) {
|
||||
/* Authorization header */
|
||||
xhr.setRequestHeader("token", ""+ $("#tokenTxt").val());
|
||||
}
|
||||
},
|
||||
|
||||
success: function (data) {
|
||||
alert("success");
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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<TaskCommandInfo> 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user