diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-biz-operator-log/src/main/java/org/dromara/visor/framework/biz/operator/log/core/model/OperatorLogModel.java b/orion-visor-framework/orion-visor-spring-boot-starter-biz-operator-log/src/main/java/org/dromara/visor/framework/biz/operator/log/core/model/OperatorLogModel.java index a55430c5..c62c250a 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-biz-operator-log/src/main/java/org/dromara/visor/framework/biz/operator/log/core/model/OperatorLogModel.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-biz-operator-log/src/main/java/org/dromara/visor/framework/biz/operator/log/core/model/OperatorLogModel.java @@ -122,4 +122,9 @@ public class OperatorLogModel implements RequestIdentity { */ private Date endTime; + /** + * 创建时间 + */ + private Date createTime; + } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-redis/src/main/java/org/dromara/visor/framework/redis/core/utils/barrier/CacheBarriers.java b/orion-visor-framework/orion-visor-spring-boot-starter-redis/src/main/java/org/dromara/visor/framework/redis/core/utils/barrier/CacheBarriers.java index cda0e5d7..a9dad5bc 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-redis/src/main/java/org/dromara/visor/framework/redis/core/utils/barrier/CacheBarriers.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-redis/src/main/java/org/dromara/visor/framework/redis/core/utils/barrier/CacheBarriers.java @@ -49,6 +49,8 @@ public class CacheBarriers { public static final GenericsBarrier> MAP = GenericsAnonymousMapBarrier.create(Const.NONE_ID, Const.NONE_ID); + public static final GenericsBarrier> STRING_MAP = GenericsAnonymousMapBarrier.create(Const.NONE_ID.toString(), Const.NONE_ID); + /** * 创建屏障对象 防止穿透 * diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/constant/CloseCode.java b/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/constant/CloseCode.java new file mode 100644 index 00000000..80431ac8 --- /dev/null +++ b/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/constant/CloseCode.java @@ -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 + *

+ * > 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(); + +} diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/constant/WsCloseCode.java b/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/constant/WsCloseCode.java index 7d196c1c..9aa5d0b1 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/constant/WsCloseCode.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/constant/WsCloseCode.java @@ -22,27 +22,36 @@ */ package org.dromara.visor.framework.websocket.core.constant; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** - * ws 服务端关闭 code + * ws 关闭码 + *

+ * > 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; } diff --git a/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/utils/WebSockets.java b/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/utils/WebSockets.java index cba8eb6c..ef05e23a 100644 --- a/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/utils/WebSockets.java +++ b/orion-visor-framework/orion-visor-spring-boot-starter-websocket/src/main/java/org/dromara/visor/framework/websocket/core/utils/WebSockets.java @@ -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 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); } diff --git a/orion-visor-modules/orion-visor-module-common/pom.xml b/orion-visor-modules/orion-visor-module-common/pom.xml new file mode 100644 index 00000000..357bb191 --- /dev/null +++ b/orion-visor-modules/orion-visor-module-common/pom.xml @@ -0,0 +1,26 @@ + + + + org.dromara.visor + orion-visor-modules + ${revision} + + + 4.0.0 + orion-visor-module-common + jar + + 项目公共模块 + https://github.com/dromara/orion-visor + + + + + org.dromara.visor + orion-visor-common + + + + \ No newline at end of file diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/config/AppAutoClearConfig.java b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppAutoClearConfig.java similarity index 97% rename from orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/config/AppAutoClearConfig.java rename to orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppAutoClearConfig.java index 62242a1d..e0b10336 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/config/AppAutoClearConfig.java +++ b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppAutoClearConfig.java @@ -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; diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/config/AppLogConfig.java b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppLogConfig.java similarity index 97% rename from orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/config/AppLogConfig.java rename to orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppLogConfig.java index cb0437f0..922d77f1 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/config/AppLogConfig.java +++ b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppLogConfig.java @@ -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; diff --git a/orion-visor-modules/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/org/dromara/visor/module/infra/define/config/AppLoginConfig.java b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppLoginConfig.java similarity index 98% rename from orion-visor-modules/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/org/dromara/visor/module/infra/define/config/AppLoginConfig.java rename to orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppLoginConfig.java index 153eec0c..6c811b7b 100644 --- a/orion-visor-modules/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/org/dromara/visor/module/infra/define/config/AppLoginConfig.java +++ b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppLoginConfig.java @@ -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; diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/config/AppSftpConfig.java b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppSftpConfig.java similarity index 97% rename from orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/config/AppSftpConfig.java rename to orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppSftpConfig.java index d08bd8fc..44a8c4d7 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/define/config/AppSftpConfig.java +++ b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/AppSftpConfig.java @@ -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; diff --git a/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/GuacdConfig.java b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/GuacdConfig.java new file mode 100644 index 00000000..01a7eab2 --- /dev/null +++ b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/config/GuacdConfig.java @@ -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; + +} diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/transfer/model/SftpFileBackupParams.java b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/entity/dto/SftpFileBackupDTO.java similarity index 89% rename from orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/transfer/model/SftpFileBackupParams.java rename to orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/entity/dto/SftpFileBackupDTO.java index 63ca63f7..78de05f8 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/handler/host/transfer/model/SftpFileBackupParams.java +++ b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/entity/dto/SftpFileBackupDTO.java @@ -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); } diff --git a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/utils/SftpUtils.java b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/utils/SftpUtils.java similarity index 70% rename from orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/utils/SftpUtils.java rename to orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/utils/SftpUtils.java index c1404664..098d6385 100644 --- a/orion-visor-modules/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/org/dromara/visor/module/asset/utils/SftpUtils.java +++ b/orion-visor-modules/orion-visor-module-common/src/main/java/org/dromara/visor/module/common/utils/SftpUtils.java @@ -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))); + } + } + } diff --git a/orion-visor-modules/orion-visor-module-common/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/orion-visor-modules/orion-visor-module-common/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 00000000..a6dd66a7 --- /dev/null +++ b/orion-visor-modules/orion-visor-module-common/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -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 驱动路径." + } + ] +} \ No newline at end of file diff --git a/orion-visor-modules/pom.xml b/orion-visor-modules/pom.xml index f0a7dba8..a9e26967 100644 --- a/orion-visor-modules/pom.xml +++ b/orion-visor-modules/pom.xml @@ -16,8 +16,11 @@ https://github.com/dromara/orion-visor + orion-visor-module-common orion-visor-module-infra orion-visor-module-asset + orion-visor-module-exec + orion-visor-module-terminal \ No newline at end of file