🎉 优化系统架构.

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

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

@@ -0,0 +1,83 @@
/*
* 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 org.dromara.visor.common.config.ConfigRef;
import org.dromara.visor.common.config.ConfigStore;
import org.dromara.visor.common.constant.ConfigKeys;
import org.springframework.stereotype.Component;
/**
* 自动清理设置
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/6/24 15:01
*/
@Component
public class AppAutoClearConfig {
/**
* 是否开启自动清理命令记录
*/
private final ConfigRef<Boolean> execLogEnabled;
/**
* 自动清理命令记录保留天数
*/
private final ConfigRef<Integer> execLogKeepDays;
/**
* 是否开启自动清理终端连接记录
*/
private final ConfigRef<Boolean> terminalLogEnabled;
/**
* 自动清理终端连接记录保留天数
*/
private final ConfigRef<Integer> terminalLogKeepDays;
public AppAutoClearConfig(ConfigStore configStore) {
this.execLogEnabled = configStore.bool(ConfigKeys.AUTO_CLEAR_EXEC_LOG_ENABLED);
this.execLogKeepDays = configStore.int32(ConfigKeys.AUTO_CLEAR_EXEC_LOG_KEEP_DAYS);
this.terminalLogEnabled = configStore.bool(ConfigKeys.AUTO_CLEAR_TERMINAL_LOG_ENABLED);
this.terminalLogKeepDays = configStore.int32(ConfigKeys.AUTO_CLEAR_TERMINAL_LOG_KEEP_DAYS);
}
public Boolean getExecLogEnabled() {
return execLogEnabled.value;
}
public Integer getExecLogKeepDays() {
return execLogKeepDays.value;
}
public Boolean getTerminalLogEnabled() {
return terminalLogEnabled.value;
}
public Integer getTerminalLogKeepDays() {
return terminalLogKeepDays.value;
}
}

View File

@@ -0,0 +1,73 @@
/*
* 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 org.dromara.visor.common.config.ConfigRef;
import org.dromara.visor.common.config.ConfigStore;
import org.dromara.visor.common.constant.ConfigKeys;
import org.springframework.stereotype.Component;
/**
* 应用日志设置
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/4/15 22:00
*/
@Component
public class AppLogConfig {
/**
* 日志加载偏移行
*/
private final ConfigRef<Integer> trackerLoadLines;
/**
* 日志加载间隔毫秒
*/
private final ConfigRef<Integer> trackerLoadInterval;
/**
* 是否生成详细的执行日志
*/
private final ConfigRef<Boolean> execDetailLog;
public AppLogConfig(ConfigStore configStore) {
this.trackerLoadLines = configStore.int32(ConfigKeys.LOG_TRACKER_LOAD_LINES);
this.trackerLoadInterval = configStore.int32(ConfigKeys.LOG_TRACKER_LOAD_INTERVAL);
this.execDetailLog = configStore.bool(ConfigKeys.LOG_EXEC_DETAIL_LOG);
}
public Integer getTrackerLoadLines() {
return trackerLoadLines.value;
}
public Integer getTrackerLoadInterval() {
return trackerLoadInterval.value;
}
public Boolean getExecDetailLog() {
return execDetailLog.value;
}
}

View File

@@ -0,0 +1,143 @@
/*
* 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 org.dromara.visor.common.config.ConfigRef;
import org.dromara.visor.common.config.ConfigStore;
import org.dromara.visor.common.constant.ConfigKeys;
import org.springframework.stereotype.Component;
/**
* 应用登录配置
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/3/5 18:26
*/
@Component
public class AppLoginConfig {
/**
* 凭证有效期(分)
*/
private final ConfigRef<Integer> loginSessionTime;
/**
* 是否允许多端登录
*/
private final ConfigRef<Boolean> allowMultiDevice;
/**
* 是否允许凭证续签
*/
private final ConfigRef<Boolean> allowRefresh;
/**
* 凭证续签最大次数
*/
private final ConfigRef<Integer> maxRefreshCount;
/**
* 凭证续签间隔分
*/
private final ConfigRef<Integer> refreshInterval;
/**
* 登录失败是否锁定
*/
private final ConfigRef<Boolean> loginFailedLock;
/**
* 登录失败锁定阈值
*/
private final ConfigRef<Integer> loginFailedLockThreshold;
/**
* 登录失败锁定时间 (分)
*/
private final ConfigRef<Integer> loginFailedLockTime;
/**
* 登录失败发信
*/
private final ConfigRef<Boolean> loginFailedSend;
/**
* 登录失败发送站内信阈值
*/
private final ConfigRef<Integer> loginFailedSendThreshold;
public AppLoginConfig(ConfigStore configStore) {
this.loginSessionTime = configStore.int32(ConfigKeys.LOGIN_LOGIN_SESSION_TIME);
this.allowMultiDevice = configStore.bool(ConfigKeys.LOGIN_ALLOW_MULTI_DEVICE);
this.allowRefresh = configStore.bool(ConfigKeys.LOGIN_ALLOW_REFRESH);
this.maxRefreshCount = configStore.int32(ConfigKeys.LOGIN_MAX_REFRESH_COUNT);
this.refreshInterval = configStore.int32(ConfigKeys.LOGIN_REFRESH_INTERVAL);
this.loginFailedLock = configStore.bool(ConfigKeys.LOGIN_LOGIN_FAILED_LOCK);
this.loginFailedLockThreshold = configStore.int32(ConfigKeys.LOGIN_LOGIN_FAILED_LOCK_THRESHOLD);
this.loginFailedLockTime = configStore.int32(ConfigKeys.LOGIN_LOGIN_FAILED_LOCK_TIME);
this.loginFailedSend = configStore.bool(ConfigKeys.LOGIN_LOGIN_FAILED_SEND);
this.loginFailedSendThreshold = configStore.int32(ConfigKeys.LOGIN_LOGIN_FAILED_SEND_THRESHOLD);
}
public Integer getLoginSessionTime() {
return loginSessionTime.value;
}
public Boolean getAllowMultiDevice() {
return allowMultiDevice.value;
}
public Boolean getAllowRefresh() {
return allowRefresh.value;
}
public Integer getMaxRefreshCount() {
return maxRefreshCount.value;
}
public Integer getRefreshInterval() {
return refreshInterval.value;
}
public Boolean getLoginFailedLock() {
return loginFailedLock.value;
}
public Integer getLoginFailedLockThreshold() {
return loginFailedLockThreshold.value;
}
public Integer getLoginFailedLockTime() {
return loginFailedLockTime.value;
}
public Boolean getLoginFailedSend() {
return loginFailedSend.value;
}
public Integer getLoginFailedSendThreshold() {
return loginFailedSendThreshold.value;
}
}

View File

@@ -0,0 +1,73 @@
/*
* 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 org.dromara.visor.common.config.ConfigRef;
import org.dromara.visor.common.config.ConfigStore;
import org.dromara.visor.common.constant.ConfigKeys;
import org.springframework.stereotype.Component;
/**
* 应用 sftp 配置
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/4/15 22:00
*/
@Component
public class AppSftpConfig {
/**
* 文件预览大小
*/
private final ConfigRef<Integer> previewSize;
/**
* 重复文件备份
*/
private final ConfigRef<Boolean> uploadPresentBackup;
/**
* 备份文件名称
*/
private final ConfigRef<String> uploadBackupFileName;
public AppSftpConfig(ConfigStore configStore) {
this.previewSize = configStore.int32(ConfigKeys.SFTP_PREVIEW_SIZE);
this.uploadPresentBackup = configStore.bool(ConfigKeys.SFTP_UPLOAD_PRESENT_BACKUP);
this.uploadBackupFileName = configStore.string(ConfigKeys.SFTP_UPLOAD_BACKUP_FILE_NAME);
}
public Integer getPreviewSize() {
return previewSize.value;
}
public Boolean getUploadPresentBackup() {
return uploadPresentBackup.value;
}
public String getUploadBackupFileName() {
return uploadBackupFileName.value;
}
}

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

@@ -0,0 +1,62 @@
/*
* 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.entity.dto;
import cn.orionsec.kit.lang.utils.time.Dates;
import lombok.Data;
import java.util.Date;
/**
* sftp 文件备份参数
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/4/15 23:13
*/
@Data
public class SftpFileBackupDTO {
/**
* 文件名称
*/
private String fileName;
/**
* 时间戳
*/
private Long timestamp;
/**
* 当前时间
*/
private String time;
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

@@ -0,0 +1,89 @@
/*
* 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.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;
/**
* sftp 工具类
*
* @author Jiahang Li
* @version 1.0.0
* @since 2024/5/8 16:17
*/
public class SftpUtils {
private static final AppSftpConfig appSftpConfig = SpringHolder.getBean(AppSftpConfig.class);
private SftpUtils() {
}
/**
* 检查上传文件是否存在 并且执行响应策略
*
* @param executor executor
* @param path path
*/
public static void checkUploadFilePresent(SftpExecutor executor, String path) {
// 重复不备份
if (!Booleans.isTrue(appSftpConfig.getUploadPresentBackup())) {
return;
}
// 检查文件是否存在
SftpFile file = executor.getFile(path);
if (file != null) {
// 文件存在则备份
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 驱动路径."
}
]
}