From ad31a6c298330cb3b6a1868a01a0d899fcf7c73d Mon Sep 17 00:00:00 2001 From: lijiahangmax Date: Sun, 29 Jun 2025 02:03:00 +0800 Subject: [PATCH] =?UTF-8?q?:hammer:=20=E6=B7=BB=E5=8A=A0=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=E6=A8=A1=E5=BC=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../terminal/enums/DriveMountModeEnum.java | 161 ++++++++++++++++++ .../handler/terminal/session/RdpSession.java | 8 +- .../general/terminal-rdp-session-block.vue | 2 +- .../terminal/service/session/rdp-session.ts | 2 +- 4 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/enums/DriveMountModeEnum.java diff --git a/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/enums/DriveMountModeEnum.java b/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/enums/DriveMountModeEnum.java new file mode 100644 index 00000000..7f9c745f --- /dev/null +++ b/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/enums/DriveMountModeEnum.java @@ -0,0 +1,161 @@ +/* + * 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.terminal.enums; + +import cn.orionsec.kit.lang.utils.time.Dates; +import lombok.AllArgsConstructor; + +/** + * 驱动挂载模式 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2025/6/29 1:32 + */ +@AllArgsConstructor +public enum DriveMountModeEnum { + + /** + * 完全共享 + */ + SHARED("S") { + @Override + public String getDriveMountPath(Long userId, Long assetId, String sessionId) { + return this.buildDriveMountPath(DEFAULT_S, userId, DEFAULT_N, DEFAULT_S); + } + }, + + /** + * 会话维度 + */ + SESSION("SE") { + @Override + public String getDriveMountPath(Long userId, Long assetId, String sessionId) { + return this.buildDriveMountPath(Dates.current(Dates.YMD2), userId, assetId, sessionId); + } + }, + + /** + * 资产维度 + */ + ASSET("A") { + @Override + public String getDriveMountPath(Long userId, Long assetId, String sessionId) { + return this.buildDriveMountPath(DEFAULT_S, userId, assetId, DEFAULT_S); + } + }, + + /** + * 天维度 + */ + DAY("D") { + @Override + public String getDriveMountPath(Long userId, Long assetId, String sessionId) { + return this.buildDriveMountPath(Dates.current(Dates.YMD2), userId, DEFAULT_N, DEFAULT_S); + } + }, + + /** + * 天维度 + 资产维度 + */ + DAY_ASSET("DA") { + @Override + public String getDriveMountPath(Long userId, Long assetId, String sessionId) { + return this.buildDriveMountPath(Dates.current(Dates.YMD2), userId, DEFAULT_N, DEFAULT_S); + } + }, + + /** + * 月维度 + */ + MONTH("M") { + @Override + public String getDriveMountPath(Long userId, Long assetId, String sessionId) { + String date = Dates.stream() + .setDay(1) + .format(Dates.YMD2); + return this.buildDriveMountPath(date, userId, DEFAULT_N, DEFAULT_S); + } + }, + + /** + * 月维度 + 资产维度 + */ + MONTH_ASSET("MA") { + @Override + public String getDriveMountPath(Long userId, Long assetId, String sessionId) { + String date = Dates.stream() + .setDay(1) + .format(Dates.YMD2); + return this.buildDriveMountPath(date, userId, assetId, DEFAULT_S); + } + }, + + ; + + private static final Long DEFAULT_N = 0L; + + private static final String DEFAULT_S = "0"; + + private final String prefix; + + /** + * 获取驱动挂载路径 + * + * @param userId userId + * @param assetId assetId + * @param sessionId sessionId + * @return path + */ + public abstract String getDriveMountPath(Long userId, Long assetId, String sessionId); + + /** + * 构建驱动挂载路径 + * + * @param time time + * @param userId userId + * @param assetId assetId + * @param sessionId sessionId + * @return path + */ + protected String buildDriveMountPath(String time, Long userId, Long assetId, String sessionId) { + return prefix + "_" + + time + "_" + + userId + "_" + + assetId + "_" + + sessionId; + } + + public static DriveMountModeEnum of(String mode) { + if (mode == null) { + return ASSET; + } + for (DriveMountModeEnum value : values()) { + if (value.name().equalsIgnoreCase(mode)) { + return value; + } + } + return ASSET; + } + +} diff --git a/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/handler/terminal/session/RdpSession.java b/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/handler/terminal/session/RdpSession.java index 2f195757..f7ba72e4 100644 --- a/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/handler/terminal/session/RdpSession.java +++ b/orion-visor-modules/orion-visor-module-terminal/orion-visor-module-terminal-service/src/main/java/org/dromara/visor/module/terminal/handler/terminal/session/RdpSession.java @@ -25,11 +25,11 @@ package org.dromara.visor.module.terminal.handler.terminal.session; 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.lang.utils.time.Dates; import lombok.extern.slf4j.Slf4j; import org.dromara.visor.common.constant.AppConst; import org.dromara.visor.common.utils.AesEncryptUtils; import org.dromara.visor.module.common.config.GuacdConfig; +import org.dromara.visor.module.terminal.enums.DriveMountModeEnum; import org.dromara.visor.module.terminal.handler.guacd.GuacdTunnel; import org.dromara.visor.module.terminal.handler.guacd.IGuacdTunnel; import org.dromara.visor.module.terminal.handler.guacd.constant.GuacdConst; @@ -114,8 +114,10 @@ public class RdpSession extends AbstractGuacdSession i tunnel.setParameter(GuacdConst.ENABLE_DRIVE, true); tunnel.setParameter(GuacdConst.CREATE_DRIVE_PATH, true); tunnel.setParameter(GuacdConst.DRIVE_NAME, GuacdConst.DRIVE_DRIVE_NAME); - // 父文件夹必须存在 所以只能用 _ 分 - tunnel.setParameter(GuacdConst.DRIVE_PATH, Files1.getPath(guacdConfig.getDrivePath() + "/" + Dates.current(Dates.YMD2) + "_" + props.getUserId() + "_" + props.getHostId())); + // 父文件夹必须存在 否则会报错 所以不能分层 + String driveMountPath = DriveMountModeEnum.of(extra.getDriveMountMode()) + .getDriveMountPath(props.getUserId(), props.getHostId(), props.getId()); + tunnel.setParameter(GuacdConst.DRIVE_PATH, Files1.getPath(guacdConfig.getDrivePath() + "/" + driveMountPath)); // 预连接 String preConnectionId = config.getPreConnectionId(); if (!Strings.isBlank(preConnectionId)) { diff --git a/orion-visor-ui/src/views/terminal/components/setting/general/terminal-rdp-session-block.vue b/orion-visor-ui/src/views/terminal/components/setting/general/terminal-rdp-session-block.vue index 892324d3..763e604a 100644 --- a/orion-visor-ui/src/views/terminal/components/setting/general/terminal-rdp-session-block.vue +++ b/orion-visor-ui/src/views/terminal/components/setting/general/terminal-rdp-session-block.vue @@ -53,7 +53,7 @@ return; } // 同步 - updateTerminalPreference(TerminalPreferenceItem.RDP_SESSION_SETTING, formModel.value); + updateTerminalPreference(TerminalPreferenceItem.RDP_SESSION_SETTING, formModel.value, true); }, { deep: true }); diff --git a/orion-visor-ui/src/views/terminal/service/session/rdp-session.ts b/orion-visor-ui/src/views/terminal/service/session/rdp-session.ts index bed88a8d..eaafb149 100644 --- a/orion-visor-ui/src/views/terminal/service/session/rdp-session.ts +++ b/orion-visor-ui/src/views/terminal/service/session/rdp-session.ts @@ -20,7 +20,7 @@ import RdpSessionClipboardHandler from '../handler/rdp-session-clipboard-handler export const AUDIO_INPUT_MIMETYPE = 'audio/L16;rate=44100,channels=2'; -export const CONNECT_TIMEOUT = 10000; +export const CONNECT_TIMEOUT = 30000; // RDP 会话实现 export default class RdpSession extends BaseSession implements IRdpSession {