Skip to content

Commit d9c8923

Browse files
authored
Merge pull request #149 from dromara/dev
Dev
2 parents d8818c3 + aa913bc commit d9c8923

File tree

110 files changed

+2189
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2189
-336
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SPRING_PROFILES_ACTIVE=prod
66
DEMO_MODE=false
77

88
API_CORS=true
9+
API_IP_HEADERS=X-Forwarded-For,X-Real-IP
910
API_EXPOSE_TOKEN=pmqeHOyZaumHm0Wt
1011
SECRET_KEY=uQeacXV8b3isvKLK
1112

docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: '3.3'
22

3-
# latest = 2.5.4
3+
# latest = 2.5.5
44

55
# 支持以下源
66
# lijiahangmax/*
@@ -49,6 +49,7 @@ services:
4949
GUACD_DRIVE_PATH: ${GUACD_DRIVE_PATH:-/drive}
5050
SECRET_KEY: ${SECRET_KEY:-uQeacXV8b3isvKLK}
5151
API_EXPOSE_TOKEN: ${API_EXPOSE_TOKEN:-pmqeHOyZaumHm0Wt}
52+
API_IP_HEADERS: ${API_IP_HEADERS:-X-Forwarded-For,X-Real-IP}
5253
API_CORS: ${API_CORS:-true}
5354
DEMO_MODE: ${DEMO_MODE:-false}
5455
volumes:

docker/docker-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77
source ./project-build.sh "$@"
88

99
# 版本号
10-
version=2.5.4
10+
version=2.5.5
1111
# 是否推送镜像
1212
push_image=false
1313
# 是否构建 latest

docker/project-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
# DockerContext: orion-visor
55

66
# 版本号
7-
version=2.5.4
7+
version=2.5.5
88
# 是否构建 service
99
export build_service=false
1010
# 是否构建 ui
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2023 - present Dromara, All rights reserved.
3+
*
4+
* https://visor.dromara.org
5+
* https://visor.dromara.org.cn
6+
* https://visor.orionsec.cn
7+
*
8+
* Members:
9+
* Jiahang Li - ljh1553488six@139.com - author
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
23+
package org.dromara.visor.common.configuration;
24+
25+
import lombok.extern.slf4j.Slf4j;
26+
import org.dromara.visor.common.utils.IpUtils;
27+
import org.springframework.beans.factory.annotation.Value;
28+
import org.springframework.context.annotation.Configuration;
29+
30+
import javax.annotation.PostConstruct;
31+
32+
/**
33+
* 公共配置类
34+
*
35+
* @author Jiahang Li
36+
* @version 1.0.0
37+
* @since 2023/6/20 10:34
38+
*/
39+
@Slf4j
40+
@Configuration
41+
public class CommonConfiguration {
42+
43+
@Value("${orion.api.ip-headers}")
44+
private String[] ipHeaders;
45+
46+
/**
47+
* 设置 IP 请求头
48+
*/
49+
@PostConstruct
50+
public void setIpHeader() {
51+
IpUtils.setIpHeader(ipHeaders);
52+
log.info("IpUtils.setIpHeader {}", String.join(",", ipHeaders));
53+
}
54+
55+
}

orion-visor-common/src/main/java/org/dromara/visor/common/constant/AppConst.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface AppConst extends OrionConst {
3636
/**
3737
* 同 ${orion.version} 迭代时候需要手动更改
3838
*/
39-
String VERSION = "2.5.4";
39+
String VERSION = "2.5.5";
4040

4141
/**
4242
* 同 ${spring.application.name}

orion-visor-common/src/main/java/org/dromara/visor/common/entity/RequestIdentity.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
*/
3434
public interface RequestIdentity extends Serializable {
3535

36+
/**
37+
* 获取请求时间戳
38+
*
39+
* @return timestamp
40+
*/
41+
Long getTimestamp();
42+
43+
/**
44+
* 设置请求时间戳
45+
*
46+
* @param timestamp timestamp
47+
*/
48+
void setTimestamp(Long timestamp);
49+
3650
/**
3751
* 获取请求地址
3852
*

orion-visor-common/src/main/java/org/dromara/visor/common/entity/RequestIdentityModel.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
package org.dromara.visor.common.entity;
2424

2525
import io.swagger.v3.oas.annotations.media.Schema;
26+
import lombok.AllArgsConstructor;
27+
import lombok.Builder;
2628
import lombok.Data;
29+
import lombok.NoArgsConstructor;
2730

2831
/**
2932
* 请求留痕模型
@@ -33,9 +36,15 @@
3336
* @since 2023/12/29 11:57
3437
*/
3538
@Data
39+
@Builder
40+
@NoArgsConstructor
41+
@AllArgsConstructor
3642
@Schema(name = "RequestIdentityModel", description = "请求留痕模型")
3743
public class RequestIdentityModel implements RequestIdentity {
3844

45+
@Schema(description = "时间戳")
46+
private Long timestamp;
47+
3948
@Schema(description = "请求地址")
4049
private String address;
4150

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2023 - present Dromara, All rights reserved.
3+
*
4+
* https://visor.dromara.org
5+
* https://visor.dromara.org.cn
6+
* https://visor.orionsec.cn
7+
*
8+
* Members:
9+
* Jiahang Li - ljh1553488six@139.com - author
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
*/
23+
package org.dromara.visor.common.mapstruct;
24+
25+
import java.util.Date;
26+
27+
/**
28+
* date 转换器
29+
*
30+
* @author Jiahang Li
31+
* @version 1.0.0
32+
* @since 2025/3/7 17:43
33+
*/
34+
public class DateConversion {
35+
36+
private DateConversion() {
37+
}
38+
39+
/**
40+
* Long > Date
41+
*
42+
* @param timestamp timestamp
43+
* @return Date
44+
*/
45+
public static Date longToDate(Long timestamp) {
46+
return timestamp != null ? new Date(timestamp) : null;
47+
}
48+
49+
/**
50+
* Date > Long
51+
*
52+
* @param date date
53+
* @return Long
54+
*/
55+
public static Long dateToLong(Date date) {
56+
return date != null ? date.getTime() : null;
57+
}
58+
59+
}

orion-visor-common/src/main/java/org/dromara/visor/common/utils/IpUtils.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import cn.orionsec.kit.ext.location.Region;
2626
import cn.orionsec.kit.ext.location.region.LocationRegions;
27-
import cn.orionsec.kit.web.servlet.web.Servlets;
27+
import cn.orionsec.kit.lang.utils.net.IPs;
2828
import org.dromara.visor.common.constant.Const;
2929

3030
import javax.servlet.http.HttpServletRequest;
@@ -40,6 +40,8 @@
4040
*/
4141
public class IpUtils {
4242

43+
private static String[] IP_HEADER = new String[]{"X-Forwarded-For", "X-Real-IP"};
44+
4345
private static final Map<String, String> CACHE = new HashMap<>();
4446

4547
private IpUtils() {
@@ -52,13 +54,17 @@ private IpUtils() {
5254
* @return addr
5355
*/
5456
public static String getRemoteAddr(HttpServletRequest request) {
55-
// 获取实际地址 X_REAL_IP 在多代理情况下会有问题
56-
// String realIp = request.getHeader(StandardHttpHeader.X_REAL_IP);
57-
// if (!Strings.isBlank(realIp)) {
58-
// return realIp;
59-
// }
60-
// 获取请求地址
61-
return Servlets.getRemoteAddr(request);
57+
if (request == null) {
58+
return null;
59+
} else {
60+
for (String remoteAddrHeader : IP_HEADER) {
61+
String addr = checkIpHeader(request.getHeader(remoteAddrHeader));
62+
if (addr != null) {
63+
return addr;
64+
}
65+
}
66+
return checkIpHeader(request.getRemoteAddr());
67+
}
6268
}
6369

6470
/**
@@ -112,4 +118,23 @@ private static String queryLocation(String ip) {
112118
return Const.CN_UNKNOWN;
113119
}
114120

121+
/**
122+
* 检查 ip 请求头
123+
*
124+
* @param headerValue headerValue
125+
* @return header
126+
*/
127+
private static String checkIpHeader(String headerValue) {
128+
if (headerValue == null) {
129+
return null;
130+
} else {
131+
headerValue = headerValue.split(",")[0];
132+
return IPs.checkIp(headerValue);
133+
}
134+
}
135+
136+
public static void setIpHeader(String[] ipHeader) {
137+
IP_HEADER = ipHeader;
138+
}
139+
115140
}

0 commit comments

Comments
 (0)