🎉 优化系统架构.

This commit is contained in:
lijiahangmax
2025-06-25 18:59:16 +08:00
parent cec7e21d5a
commit f69093de66
15 changed files with 263 additions and 26 deletions

View File

@@ -122,4 +122,9 @@ public class OperatorLogModel implements RequestIdentity {
*/
private Date endTime;
/**
* 创建时间
*/
private Date createTime;
}

View File

@@ -49,6 +49,8 @@ public class CacheBarriers {
public static final GenericsBarrier<Map<?, ?>> MAP = GenericsAnonymousMapBarrier.create(Const.NONE_ID, Const.NONE_ID);
public static final GenericsBarrier<Map<?, ?>> STRING_MAP = GenericsAnonymousMapBarrier.create(Const.NONE_ID.toString(), Const.NONE_ID);
/**
* 创建屏障对象 防止穿透
*

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2023 - present Dromara, All rights reserved.
*
* https://visor.dromara.org
* https://visor.dromara.org.cn
* https://visor.orionsec.cn
*
* Members:
* Jiahang Li - ljh1553488six@139.com - author
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.framework.websocket.core.constant;
/**
* ws 服务端关闭 code
* <p>
* > 2999 && < 5000
*
* @author Jiahang Li
* @version 1.0.0
* @since 2021/6/16 15:18
*/
public interface CloseCode {
/**
* code
*
* @return code
*/
int getCode();
/**
* reason
*
* @return reason
*/
String getReason();
}

View File

@@ -22,27 +22,36 @@
*/
package org.dromara.visor.framework.websocket.core.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* ws 服务端关闭 code
* ws 关闭码
* <p>
* > 2999 && < 5000
*
* @author Jiahang Li
* @version 1.0.0
* @since 2021/6/16 15:18
* @since 2024/7/31 17:41
*/
public interface WsCloseCode {
@Getter
@AllArgsConstructor
public enum WsCloseCode implements CloseCode {
/**
* code
*
* @return code
* 初始化失败
*/
int getCode();
INIT_ERROR(3000, "init error"),
/**
* reason
*
* @return reason
* 会话已关闭
*/
String getReason();
SESSION_CLOSED(3100, "session closed"),
;
private final int code;
private final String reason;
}

View File

@@ -22,18 +22,23 @@
*/
package org.dromara.visor.framework.websocket.core.utils;
import cn.orionsec.kit.lang.constant.StandardHttpHeader;
import cn.orionsec.kit.lang.utils.Exceptions;
import cn.orionsec.kit.lang.utils.Threads;
import cn.orionsec.kit.lang.utils.io.Streams;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.dromara.visor.common.constant.Const;
import org.dromara.visor.framework.websocket.core.constant.WsCloseCode;
import org.dromara.visor.framework.websocket.core.constant.CloseCode;
import org.dromara.visor.framework.websocket.core.session.WebSocketSyncSession;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
import java.util.List;
/**
* websocket 工具类
@@ -132,18 +137,54 @@ public class WebSockets {
}
}
/**
* 设置子协议
*
* @param request request
* @param response response
*/
public static void setSubProtocols(ServerHttpRequest request, ServerHttpResponse response) {
List<String> subProtocols = request.getHeaders().get(StandardHttpHeader.SEC_WEBSOCKET_PROTOCOL);
if (subProtocols != null) {
response.getHeaders().put(StandardHttpHeader.SEC_WEBSOCKET_PROTOCOL, subProtocols);
}
}
/**
* 关闭会话
*
* @param session session
*/
public static void close(WebSocketSession session) {
if (!session.isOpen()) {
return;
}
Streams.close(session);
}
/**
* 关闭会话
*
* @param session session
* @param code code
*/
public static void close(WebSocketSession session, WsCloseCode code) {
public static void close(WebSocketSession session, CloseCode code) {
close(session, code.getCode(), code.getReason());
}
/**
* 关闭会话
*
* @param session session
* @param code code
* @param reason reason
*/
public static void close(WebSocketSession session, int code, String reason) {
if (!session.isOpen()) {
return;
}
try {
session.close(new CloseStatus(code.getCode(), code.getReason()));
session.close(new CloseStatus(code, reason));
} catch (Exception e) {
log.error("websocket close failure", e);
}

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.dromara.visor</groupId>
<artifactId>orion-visor-modules</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>orion-visor-module-common</artifactId>
<packaging>jar</packaging>
<description>项目公共模块</description>
<url>https://github.com/dromara/orion-visor</url>
<dependencies>
<!-- common -->
<dependency>
<groupId>org.dromara.visor</groupId>
<artifactId>orion-visor-common</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -20,7 +20,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.module.asset.define.config;
package org.dromara.visor.module.common.config;
import org.dromara.visor.common.config.ConfigRef;
import org.dromara.visor.common.config.ConfigStore;

View File

@@ -20,7 +20,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.module.asset.define.config;
package org.dromara.visor.module.common.config;
import org.dromara.visor.common.config.ConfigRef;
import org.dromara.visor.common.config.ConfigStore;

View File

@@ -20,7 +20,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.module.infra.define.config;
package org.dromara.visor.module.common.config;
import org.dromara.visor.common.config.ConfigRef;
import org.dromara.visor.common.config.ConfigStore;

View File

@@ -20,7 +20,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.module.asset.define.config;
package org.dromara.visor.module.common.config;
import org.dromara.visor.common.config.ConfigRef;
import org.dromara.visor.common.config.ConfigStore;

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023 - present Dromara, All rights reserved.
*
* https://visor.dromara.org
* https://visor.dromara.org.cn
* https://visor.orionsec.cn
*
* Members:
* Jiahang Li - ljh1553488six@139.com - author
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.module.common.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* guacd 配置
*
* @author Jiahang Li
* @version 1.0.0
* @since 2025/6/9 19:41
*/
@Data
@Component
@ConfigurationProperties(prefix = "guacd")
public class GuacdConfig {
/**
* guacd 主机
*/
private String host;
/**
* guacd 端口
*/
private Integer port;
/**
* guacd 驱动路径
*/
private String drivePath;
}

View File

@@ -20,7 +20,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.module.asset.handler.host.transfer.model;
package org.dromara.visor.module.common.entity.dto;
import cn.orionsec.kit.lang.utils.time.Dates;
import lombok.Data;
@@ -35,7 +35,7 @@ import java.util.Date;
* @since 2024/4/15 23:13
*/
@Data
public class SftpFileBackupParams {
public class SftpFileBackupDTO {
/**
* 文件名称
@@ -52,9 +52,9 @@ public class SftpFileBackupParams {
*/
private String time;
public SftpFileBackupParams(String fileName) {
this.fileName = fileName;
public SftpFileBackupDTO(String fileName) {
Date date = new Date();
this.fileName = fileName;
this.timestamp = date.getTime();
this.time = Dates.format(date, Dates.YMD_HMS2);
}

View File

@@ -20,16 +20,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.visor.module.asset.utils;
package org.dromara.visor.module.common.utils;
import org.dromara.visor.module.common.config.AppSftpConfig;
import org.dromara.visor.module.common.entity.dto.SftpFileBackupDTO;
import cn.orionsec.kit.lang.constant.Letters;
import cn.orionsec.kit.lang.utils.Booleans;
import cn.orionsec.kit.lang.utils.Strings;
import cn.orionsec.kit.lang.utils.io.Files1;
import cn.orionsec.kit.net.host.sftp.SftpExecutor;
import cn.orionsec.kit.net.host.sftp.SftpFile;
import cn.orionsec.kit.spring.SpringHolder;
import com.alibaba.fastjson.JSON;
import org.dromara.visor.module.asset.define.config.AppSftpConfig;
import org.dromara.visor.module.asset.handler.host.transfer.model.SftpFileBackupParams;
/**
* sftp 工具类
@@ -60,11 +62,28 @@ public class SftpUtils {
SftpFile file = executor.getFile(path);
if (file != null) {
// 文件存在则备份
SftpFileBackupParams backupParams = new SftpFileBackupParams(file.getName());
SftpFileBackupDTO backupParams = new SftpFileBackupDTO(file.getName());
String target = Strings.format(appSftpConfig.getUploadBackupFileName(), JSON.parseObject(JSON.toJSONString(backupParams)));
// 移动
executor.move(path, target);
}
}
/**
* 获取移动目标路径
*
* @param source source
* @param target target
* @return absolute target
*/
public static String getAbsoluteTargetPath(String source, String target) {
if (target.charAt(0) == Letters.SLASH) {
// 绝对路径
return Files1.getPath(Files1.normalize(target));
} else {
// 相对路径
return Files1.getPath(Files1.normalize(Files1.getPath(source + "/../" + target)));
}
}
}

View File

@@ -0,0 +1,26 @@
{
"groups": [
{
"name": "guacd",
"type": "org.dromara.visor.module.common.config.GuacdConfig",
"sourceType": "org.dromara.visor.module.common.config.GuacdConfig"
}
],
"properties": [
{
"name": "guacd.host",
"type": "java.lang.String",
"description": "guacd 主机."
},
{
"name": "guacd.port",
"type": "java.lang.Integer",
"description": "guacd 端口."
},
{
"name": "guacd.drive-path",
"type": "java.lang.String",
"description": "guacd 驱动路径."
}
]
}

View File

@@ -16,8 +16,11 @@
<url>https://github.com/dromara/orion-visor</url>
<modules>
<module>orion-visor-module-common</module>
<module>orion-visor-module-infra</module>
<module>orion-visor-module-asset</module>
<module>orion-visor-module-exec</module>
<module>orion-visor-module-terminal</module>
</modules>
</project>