🔨 添加驱动挂载模式.

This commit is contained in:
lijiahangmax
2025-06-29 02:03:00 +08:00
parent b55efe035d
commit ad31a6c298
4 changed files with 168 additions and 5 deletions

View File

@@ -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;
}
}

View File

@@ -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<TerminalSessionRdpConfig> 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)) {

View File

@@ -53,7 +53,7 @@
return;
}
// 同步
updateTerminalPreference(TerminalPreferenceItem.RDP_SESSION_SETTING, formModel.value);
updateTerminalPreference(TerminalPreferenceItem.RDP_SESSION_SETTING, formModel.value, true);
}, { deep: true });
</script>

View File

@@ -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<GuacdReactiveSessionStatus, IGuacdChannel> implements IRdpSession {