Skip to content

Commit

Permalink
Merge pull request #54 from dromara/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lijiahangmax committed Aug 22, 2024
2 parents 777f7b3 + 252c538 commit 120eb1e
Show file tree
Hide file tree
Showing 64 changed files with 1,270 additions and 558 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

```bash
# clone
git clone https://github.com/dromara/orion-visor
git clone --depth=1 https://github.com/dromara/orion-visor
cd orion-visor
# 启动
docker compose up -d
Expand Down
6 changes: 3 additions & 3 deletions docker-compose-testing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.3'
services:
service:
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-service:2.1.3
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-service:2.1.4
privileged: true
ports:
- 1081:80
Expand Down Expand Up @@ -32,7 +32,7 @@ services:
- mysql
- redis
mysql:
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-mysql:2.1.3
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-mysql:2.1.4
privileged: true
ports:
- 3307:3306
Expand All @@ -52,7 +52,7 @@ services:
retries: 10
start_period: 3s
redis:
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-redis:2.1.3
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-redis:2.1.4
privileged: true
ports:
- 6380:6379
Expand Down
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.3'
services:
service:
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-service:2.1.3
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-service:2.1.4
privileged: true
ports:
- ${SERVICE_PORT:-1081}:80
Expand All @@ -19,9 +19,9 @@ services:
- ${VOLUME_BASE:-/data/orion-visor-space/docker-volumes}/service/root-orion:/root/orion
healthcheck:
test: [ "CMD", "curl", "http://127.0.0.1:9200/orion-visor/api/server/bootstrap/health" ]
interval: 3s
interval: 15s
timeout: 300s
retries: 200
retries: 15
start_period: 3s
depends_on:
mysql:
Expand All @@ -32,7 +32,7 @@ services:
- mysql
- redis
mysql:
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-mysql:2.1.3
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-mysql:2.1.4
privileged: true
ports:
- 3307:3306
Expand All @@ -47,12 +47,12 @@ services:
- ${VOLUME_BASE:-/data/orion-visor-space/docker-volumes}/mysql/etc-mysql:/etc/mysql
healthcheck:
test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/3306" ]
interval: 3s
interval: 15s
timeout: 60s
retries: 10
retries: 15
start_period: 3s
redis:
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-redis:2.1.3
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-redis:2.1.4
privileged: true
ports:
- 6380:6379
Expand All @@ -63,12 +63,12 @@ services:
command: sh -c "redis-server /usr/local/redis.conf --requirepass $${REDIS_PASSWORD}"
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
interval: 3s
interval: 15s
timeout: 60s
retries: 10
retries: 15
start_period: 3s
adminer:
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-adminer:2.1.3
image: registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-adminer:2.1.4
ports:
- 8081:8080
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion docker/adminer/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/bin/bash
version=2.1.3
version=2.1.4
docker build -t orion-visor-adminer:${version} .
docker tag orion-visor-adminer:${version} registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-adminer:${version}
2 changes: 1 addition & 1 deletion docker/mysql/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/bin/bash
version=2.1.3
version=2.1.4
cp -r ../../sql ./sql
docker build -t orion-visor-mysql:${version} .
rm -rf ./sql
Expand Down
2 changes: 1 addition & 1 deletion docker/push.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/bin/bash
version=2.1.3
version=2.1.4
docker push registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-adminer:${version}
docker push registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-mysql:${version}
docker push registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-redis:${version}
Expand Down
2 changes: 1 addition & 1 deletion docker/redis/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/bin/bash
version=2.1.3
version=2.1.4
docker build -t orion-visor-redis:${version} .
docker tag orion-visor-redis:${version} registry.cn-hangzhou.aliyuncs.com/lijiahangmax/orion-visor-redis:${version}
2 changes: 1 addition & 1 deletion docker/service/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/bin/bash
version=2.1.3
version=2.1.4
mv ../../orion-visor-launch/target/orion-visor-launch.jar ./orion-visor-launch.jar
mv ../../orion-visor-ui/dist ./dist
docker build -t orion-visor-service:${version} .
Expand Down
2 changes: 1 addition & 1 deletion docker/service/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ server {
location /orion-visor/api {
proxy_pass http://localhost:9200/orion-visor/api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
Expand Down
2 changes: 1 addition & 1 deletion orion-visor-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<url>https://github.com/dromara/orion-visor</url>

<properties>
<revision>2.1.3</revision>
<revision>2.1.4</revision>
<spring.boot.version>2.7.17</spring.boot.version>
<spring.boot.admin.version>2.7.15</spring.boot.admin.version>
<flatten.maven.plugin.version>1.5.0</flatten.maven.plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface AppConst extends OrionConst {
/**
* 同 ${orion.version} 迭代时候需要手动更改
*/
String VERSION = "2.1.3";
String VERSION = "2.1.4";

/**
* 同 ${spring.application.name}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.orion.visor.framework.common.meta;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.orion.lang.id.UUIds;
import org.slf4j.MDC;

/**
* traceId 持有者
Expand All @@ -23,16 +25,74 @@ private TraceIdHolder() {
*/
private static final ThreadLocal<String> HOLDER = new TransmittableThreadLocal<>();

/**
* 获取 traceId
*
* @return traceId
*/
public static String get() {
return HOLDER.get();
}

/**
* 设置 traceId
*/
public static void set() {
set(createTraceId());
}

/**
* 设置 traceId
*
* @param traceId traceId
*/
public static void set(String traceId) {
// 设置应用上下文
HOLDER.set(traceId);
// 设置日志上下文
setMdc(traceId);
}

/**
* 删除 traceId
*/
public static void remove() {
// 移除应用上下文
HOLDER.remove();
// 移除日志上下文
removeMdc();
}

/**
* 从应用上下文 设置到日志上下文
*/
public static void setMdc() {
setMdc(HOLDER.get());
}

/**
* 设置到日志上下文
*
* @param traceId traceId
*/
public static void setMdc(String traceId) {
MDC.put(TRACE_ID_MDC, traceId);
}

/**
* 移除日志上下文
*/
public static void removeMdc() {
MDC.remove(TRACE_ID_MDC);
}

/**
* 创建 traceId
*
* @return traceId
*/
public static String createTraceId() {
return UUIds.random32();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.generator.config.po.TableField;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.orion.lang.utils.Exceptions;
import com.orion.lang.utils.Strings;
import com.orion.visor.framework.common.constant.Const;
import com.orion.visor.framework.common.constant.FieldConst;
Expand Down Expand Up @@ -47,7 +48,7 @@ public Map<String, DictMeta> parse() {
.stream()
.filter(s -> variable.equals(s.getName()) || variable.equals(s.getPropertyName()))
.findFirst()
.orElseThrow(() -> new RuntimeException("未查询到字典映射字段 " + variable));
.orElseThrow(() -> Exceptions.runtime("未查询到字典映射字段 " + variable));
// 设置字段名称
if (meta.getField() == null) {
meta.setField(Strings.firstUpper(tableField.getPropertyName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public static Long getLoginTimestamp() {
return loginUser != null ? loginUser.getTimestamp() : null;
}

/**
* 清空用户上下文
*/
public static void clearAuthentication() {
SecurityContextHolder.getContext().setAuthentication(null);
}

/**
* 设置当前用户
*
Expand All @@ -107,7 +114,9 @@ public static Long getLoginTimestamp() {
public static void setLoginUser(LoginUser loginUser, HttpServletRequest request) {
// 创建 authentication
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(loginUser, null, Collections.emptyList());
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
if (request != null) {
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
}
// 设置上下文
SecurityContextHolder.getContext().setAuthentication(authentication);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.orion.visor.framework.web.core.filter;

import com.orion.lang.id.UUIds;
import com.orion.visor.framework.common.meta.TraceIdHolder;
import org.slf4j.MDC;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
Expand All @@ -23,21 +21,17 @@ public class TraceIdFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
try {
// traceId
String traceId = UUIds.random32();
// 设置应用上下文
// 获取 traceId
String traceId = TraceIdHolder.createTraceId();
// 设置 traceId 上下文
TraceIdHolder.set(traceId);
// 设置日志上下文
MDC.put(TraceIdHolder.TRACE_ID_MDC, traceId);
// 设置响应头
response.setHeader(TraceIdHolder.TRACE_ID_HEADER, traceId);
// 执行请求
filterChain.doFilter(request, response);
} finally {
// 清理应用上下文
// 清空 traceId 上下文
TraceIdHolder.remove();
// 清理日志上下文
MDC.clear();
}
}

Expand Down
2 changes: 2 additions & 0 deletions orion-visor-launch/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ app:
allow-refresh: true
# 凭证续签最大次数
max-refresh-count: 3
# 登录失败发送站内信阈值
login-failed-send-threshold: 3
# 登录失败锁定次数
login-failed-lock-count: 5
# 登录失败锁定时间 (分)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.orion.visor.framework.common.validator.group.Page;
import com.orion.visor.framework.log.core.annotation.IgnoreLog;
import com.orion.visor.framework.log.core.enums.IgnoreLogMode;
import com.orion.visor.framework.web.core.annotation.DemoDisableApi;
import com.orion.visor.framework.web.core.annotation.RestWrapper;
import com.orion.visor.module.asset.define.operator.ExecJobOperatorType;
import com.orion.visor.module.asset.entity.request.exec.*;
Expand Down Expand Up @@ -39,6 +40,7 @@ public class ExecJobController {
@Resource
private ExecJobService execJobService;

@DemoDisableApi
@OperatorLog(ExecJobOperatorType.CREATE)
@PostMapping("/create")
@Operation(summary = "创建计划任务")
Expand All @@ -47,6 +49,7 @@ public Long createExecJob(@Validated @RequestBody ExecJobCreateRequest request)
return execJobService.createExecJob(request);
}

@DemoDisableApi
@OperatorLog(ExecJobOperatorType.UPDATE)
@PutMapping("/update")
@Operation(summary = "更新计划任务")
Expand All @@ -55,6 +58,7 @@ public Integer updateExecJob(@Validated @RequestBody ExecJobUpdateRequest reques
return execJobService.updateExecJobById(request);
}

@DemoDisableApi
@OperatorLog(ExecJobOperatorType.UPDATE_STATUS)
@PutMapping("/update-status")
@Operation(summary = "更新计划任务状态")
Expand Down Expand Up @@ -88,6 +92,7 @@ public DataGrid<ExecJobVO> getExecJobPage(@Validated(Page.class) @RequestBody Ex
return execJobService.getExecJobPage(request);
}

@DemoDisableApi
@OperatorLog(ExecJobOperatorType.DELETE)
@DeleteMapping("/delete")
@Operation(summary = "删除计划任务")
Expand All @@ -97,6 +102,7 @@ public Integer deleteExecJob(@RequestParam("id") Long id) {
return execJobService.deleteExecJobById(id);
}

@DemoDisableApi
@OperatorLog(ExecJobOperatorType.DELETE)
@DeleteMapping("/batch-delete")
@Operation(summary = "批量删除计划任务")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.orion.net.host.SessionHolder;
import com.orion.net.host.SessionLogger;
import com.orion.net.host.SessionStore;
import com.orion.visor.framework.common.constant.AppConst;
import com.orion.visor.framework.common.constant.Const;
import com.orion.visor.framework.common.utils.CryptoUtils;
import com.orion.visor.module.asset.entity.dto.HostTerminalConnectDTO;
Expand Down Expand Up @@ -43,6 +44,8 @@ public static SessionStore openSessionStore(HostTerminalConnectDTO conn) {
SessionHolder sessionHolder = SessionHolder.create();
sessionHolder.setLogger(SessionLogger.INFO);
SessionStore session = createSessionStore(conn, sessionHolder);
// 设置版本
session.getSession().setClientVersion("SSH-2.0-ORION_VISOR_V" + AppConst.VERSION);
// 连接
session.connect();
log.info("SessionStores-open-success hostId: {}, address: {}, username: {}", hostId, address, username);
Expand Down
Loading

0 comments on commit 120eb1e

Please sign in to comment.