diff --git a/README.md b/README.md index 1dc4b4ef2..5872ebc4d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@
logo
-

一款高颜值、现代化的智能运维&轻量堡垒机平台。

+

一款高颜值、现代化的自动化运维&轻量堡垒机平台。

https://github.com/dromara/orion-visor - 2.1.6 + 2.1.7 2.7.17 2.7.15 1.5.0 diff --git a/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/constant/AppConst.java b/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/constant/AppConst.java index 4d657f356..bf927fef8 100644 --- a/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/constant/AppConst.java +++ b/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/constant/AppConst.java @@ -14,7 +14,7 @@ public interface AppConst extends OrionConst { /** * 同 ${orion.version} 迭代时候需要手动更改 */ - String VERSION = "2.1.6"; + String VERSION = "2.1.7"; /** * 同 ${spring.application.name} diff --git a/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/constant/ExtraFieldConst.java b/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/constant/ExtraFieldConst.java index f0060c822..e8c4c48d4 100644 --- a/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/constant/ExtraFieldConst.java +++ b/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/constant/ExtraFieldConst.java @@ -21,6 +21,8 @@ public interface ExtraFieldConst extends FieldConst { String USERNAME = "username"; + String HOME = "home"; + String STATUS_NAME = "statusName"; String KEY_NAME = "keyName"; diff --git a/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/utils/Mixes.java b/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/utils/Mixes.java deleted file mode 100644 index 7feef3b5d..000000000 --- a/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/utils/Mixes.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.orion.visor.framework.common.utils; - -import com.orion.lang.utils.Arrays1; -import com.orion.lang.utils.crypto.Caesars; - -/** - * 混淆工具类 - * - * @author Jiahang Li - * @version 1.0.0 - * @since 2024/6/17 18:27 - */ -public class Mixes { - - private Mixes() { - } - - /** - * 混淆 - *

- * 此方法不可修改 - * - * @param str str - * @return str - */ - public static String obfuscate(String str) { - char[] chars = str.toCharArray(); - Arrays1.reverse(chars); - for (int i = 0; i < chars.length; i += 2) { - char temp = chars[i]; - chars[i] = chars[i + 1]; - chars[i + 1] = temp; - } - String res = new String(chars); - return new Caesars().encrypt(res); - } - -} diff --git a/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/utils/PathUtils.java b/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/utils/PathUtils.java index 61631269b..b361d8573 100644 --- a/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/utils/PathUtils.java +++ b/orion-visor-framework/orion-visor-framework-common/src/main/java/com/orion/visor/framework/common/utils/PathUtils.java @@ -1,6 +1,8 @@ package com.orion.visor.framework.common.utils; import com.orion.lang.utils.Objects1; +import com.orion.lang.utils.Systems; +import com.orion.lang.utils.io.Files1; import com.orion.visor.framework.common.constant.AppConst; import com.orion.visor.framework.common.constant.Const; @@ -24,9 +26,25 @@ private PathUtils() { * @return 用户目录 */ public static String getHomePath(boolean isWindows, String username) { + return getHomePath(isWindows, username, false); + } + + /** + * 获取用户根目录 + * + * @param isWindows isWindows + * @param username 用户名 + * @param prependSeparator 是否在头部添加分隔符 + * @return 用户目录 + */ + public static String getHomePath(boolean isWindows, String username, boolean prependSeparator) { if (isWindows) { // windows - return "C:/Users/" + username; + if (prependSeparator) { + return "/C:/Users/" + username; + } else { + return "C:/Users/" + username; + } } else { // linux if (Const.ROOT.equals(username)) { @@ -66,4 +84,34 @@ public static String buildAppPath(boolean isWindows, String username, Object... return path.toString(); } + /** + * 头部添加分隔符 + * + * @param path path + * @return path + */ + public static String prependSeparator(String path) { + if (path.startsWith("/")) { + return path; + } + return "/" + path; + } + + /** + * 获取 orion path + * + * @param path path + * @return path + */ + public static String getOrionPath(String path) { + path = Systems.HOME_DIR + + Files1.SEPARATOR + + AppConst.ORION + + Files1.SEPARATOR + + AppConst.APP_NAME + + Files1.SEPARATOR + + path; + return Files1.getPath(path); + } + } diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/convert/HostConvert.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/convert/HostConvert.java index e2b06b92f..ff6eefc22 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/convert/HostConvert.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/convert/HostConvert.java @@ -40,4 +40,6 @@ public interface HostConvert { List toList(List domain); + List toBaseList(List domain); + } diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/define/operator/UploadTaskOperatorType.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/define/operator/UploadTaskOperatorType.java index 34e69cf35..c42aaedb3 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/define/operator/UploadTaskOperatorType.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/define/operator/UploadTaskOperatorType.java @@ -28,7 +28,7 @@ public class UploadTaskOperatorType extends InitializingOperatorTypes { @Override public OperatorType[] types() { return new OperatorType[]{ - new OperatorType(M, UPLOAD, "批量上传文件 ${count}个 (${name})"), + new OperatorType(M, UPLOAD, "批量上传文件 ${count} 个 (${name})"), new OperatorType(M, CANCEL, "取消上传文件 ${name}"), new OperatorType(H, DELETE, "删除上传记录 ${count}条"), new OperatorType(H, CLEAR, "清理上传记录 ${count}条"), diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/entity/domain/UploadTaskFileDO.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/entity/domain/UploadTaskFileDO.java index 655e790aa..0f76c622a 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/entity/domain/UploadTaskFileDO.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/entity/domain/UploadTaskFileDO.java @@ -48,6 +48,10 @@ public class UploadTaskFileDO extends BaseDO { @TableField("file_path") private String filePath; + @Schema(description = "实际文件路径") + @TableField("real_file_path") + private String realFilePath; + @Schema(description = "文件大小") @TableField("file_size") private Long fileSize; diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/entity/vo/UploadTaskFileVO.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/entity/vo/UploadTaskFileVO.java index dbd6e8004..5ade57021 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/entity/vo/UploadTaskFileVO.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/entity/vo/UploadTaskFileVO.java @@ -40,6 +40,9 @@ public class UploadTaskFileVO implements Serializable { @Schema(description = "文件路径") private String filePath; + @Schema(description = "实际文件路径") + private String realFilePath; + @Schema(description = "文件大小") private Long fileSize; diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/enums/HostSshOsTypeEnum.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/enums/HostSshOsTypeEnum.java index 63d07784a..393ac2fe4 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/enums/HostSshOsTypeEnum.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/enums/HostSshOsTypeEnum.java @@ -40,4 +40,24 @@ public static HostSshOsTypeEnum of(String type) { return LINUX; } + /** + * 是否为 linux 系统 + * + * @param type type + * @return isLinux + */ + public static boolean isLinux(String type) { + return LINUX.name().equals(type); + } + + /** + * 是否为 windows 系统 + * + * @param type type + * @return isWindows + */ + public static boolean isWindows(String type) { + return WINDOWS.name().equals(type); + } + } diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/exec/command/handler/BaseExecCommandHandler.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/exec/command/handler/BaseExecCommandHandler.java index d500c493b..0d63c03e4 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/exec/command/handler/BaseExecCommandHandler.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/exec/command/handler/BaseExecCommandHandler.java @@ -17,6 +17,7 @@ import com.orion.spring.SpringHolder; import com.orion.visor.framework.common.constant.ErrorMessage; import com.orion.visor.framework.common.file.FileClient; +import com.orion.visor.framework.common.utils.PathUtils; import com.orion.visor.module.asset.dao.ExecHostLogDAO; import com.orion.visor.module.asset.entity.domain.ExecHostLogDO; import com.orion.visor.module.asset.entity.dto.HostTerminalConnectDTO; @@ -159,11 +160,8 @@ protected void uploadScriptFile() { // 打开 sftp sftpExecutor = sessionStore.getSftpExecutor(execHostCommand.getFileNameCharset()); sftpExecutor.connect(); - // 必须要以 / 开头 - String scriptPath = execHostCommand.getScriptPath(); - if (!scriptPath.startsWith("/")) { - scriptPath = "/" + scriptPath; - } + // 文件上传必须要以 / 开头 + String scriptPath = PathUtils.prependSeparator(execHostCommand.getScriptPath()); // 创建文件 sftpExecutor.touch(scriptPath); // 写入命令 @@ -225,29 +223,33 @@ private void updateStatus(ExecHostStatusEnum status, Exception ex) { Long id = execHostCommand.getHostLogId(); String statusName = status.name(); log.info("BaseExecCommandHandler.updateStatus start id: {}, status: {}", id, statusName); - updateRecord.setId(id); - updateRecord.setStatus(statusName); - if (ExecHostStatusEnum.RUNNING.equals(status)) { - // 运行中 - updateRecord.setStartTime(new Date()); - } else if (ExecHostStatusEnum.COMPLETED.equals(status)) { - // 完成 - updateRecord.setFinishTime(new Date()); - updateRecord.setExitCode(executor.getExitCode()); - this.exitCode = executor.getExitCode(); - } else if (ExecHostStatusEnum.FAILED.equals(status)) { - // 失败 - updateRecord.setFinishTime(new Date()); - updateRecord.setErrorMessage(this.getErrorMessage(ex)); - } else if (ExecHostStatusEnum.TIMEOUT.equals(status)) { - // 超时 - updateRecord.setFinishTime(new Date()); - } else if (ExecHostStatusEnum.INTERRUPTED.equals(status)) { - // 中断 - updateRecord.setFinishTime(new Date()); + try { + updateRecord.setId(id); + updateRecord.setStatus(statusName); + if (ExecHostStatusEnum.RUNNING.equals(status)) { + // 运行中 + updateRecord.setStartTime(new Date()); + } else if (ExecHostStatusEnum.COMPLETED.equals(status)) { + // 完成 + updateRecord.setFinishTime(new Date()); + updateRecord.setExitCode(executor.getExitCode()); + this.exitCode = executor.getExitCode(); + } else if (ExecHostStatusEnum.FAILED.equals(status)) { + // 失败 + updateRecord.setFinishTime(new Date()); + updateRecord.setErrorMessage(this.getErrorMessage(ex)); + } else if (ExecHostStatusEnum.TIMEOUT.equals(status)) { + // 超时 + updateRecord.setFinishTime(new Date()); + } else if (ExecHostStatusEnum.INTERRUPTED.equals(status)) { + // 中断 + updateRecord.setFinishTime(new Date()); + } + int effect = execHostLogDAO.updateById(updateRecord); + log.info("BaseExecCommandHandler.updateStatus finish id: {}, effect: {}", id, effect); + } catch (Exception e) { + log.error("BaseExecCommandHandler.updateStatus error id: {}", id, e); } - int effect = execHostLogDAO.updateById(updateRecord); - log.info("BaseExecCommandHandler.updateStatus finish id: {}, effect: {}", id, effect); } @Override diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/exec/command/handler/ExecTaskHandler.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/exec/command/handler/ExecTaskHandler.java index c467571df..bcbeb0aa1 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/exec/command/handler/ExecTaskHandler.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/exec/command/handler/ExecTaskHandler.java @@ -154,24 +154,28 @@ private IExecCommandHandler createCommandHandler(ExecCommandHostDTO host) { */ private void updateStatus(ExecStatusEnum status) { Long id = execCommand.getLogId(); - String statusName = status.name(); - log.info("ExecTaskHandler-updateStatus start id: {}, status: {}", id, statusName); - ExecLogDO update = new ExecLogDO(); - update.setId(id); - update.setStatus(statusName); - if (ExecStatusEnum.RUNNING.equals(status)) { - // 执行中 - this.startTime = new Date(); - update.setStartTime(new Date()); - } else if (ExecStatusEnum.COMPLETED.equals(status)) { - // 执行完成 - update.setFinishTime(new Date()); - } else if (ExecStatusEnum.FAILED.equals(status)) { - // 执行失败 - update.setFinishTime(new Date()); + try { + String statusName = status.name(); + log.info("ExecTaskHandler-updateStatus start id: {}, status: {}", id, statusName); + ExecLogDO update = new ExecLogDO(); + update.setId(id); + update.setStatus(statusName); + if (ExecStatusEnum.RUNNING.equals(status)) { + // 执行中 + this.startTime = new Date(); + update.setStartTime(new Date()); + } else if (ExecStatusEnum.COMPLETED.equals(status)) { + // 执行完成 + update.setFinishTime(new Date()); + } else if (ExecStatusEnum.FAILED.equals(status)) { + // 执行失败 + update.setFinishTime(new Date()); + } + int effect = execLogDAO.updateById(update); + log.info("ExecTaskHandler-updateStatus finish id: {}, effect: {}", id, effect); + } catch (Exception e) { + log.error("ExecTaskHandler-updateStatus error id: {}", id, e); } - int effect = execLogDAO.updateById(update); - log.info("ExecTaskHandler-updateStatus finish id: {}, effect: {}", id, effect); } /** diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/upload/task/FileUploadTask.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/upload/task/FileUploadTask.java index f1ffd4439..a73848d16 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/upload/task/FileUploadTask.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/upload/task/FileUploadTask.java @@ -1,11 +1,9 @@ package com.orion.visor.module.asset.handler.host.upload.task; import com.orion.lang.utils.Threads; -import com.orion.lang.utils.io.Files1; import com.orion.lang.utils.io.Streams; import com.orion.lang.utils.time.Dates; import com.orion.spring.SpringHolder; -import com.orion.visor.framework.common.constant.Const; import com.orion.visor.framework.common.constant.ExtraFieldConst; import com.orion.visor.module.asset.dao.UploadTaskDAO; import com.orion.visor.module.asset.dao.UploadTaskFileDAO; @@ -143,7 +141,7 @@ private void createFileUploader() { .map(s -> FileUploadFileItemDTO.builder() .id(s.getId()) .fileId(s.getFileId()) - .remotePath(Files1.getPath(Const.SLASH + record.getRemotePath() + Const.SLASH + s.getFilePath())) + .remotePath(s.getRealFilePath()) .status(UploadTaskFileStatusEnum.WAITING.name()) .current(0L) .build()) diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/upload/uploader/FileUploader.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/upload/uploader/FileUploader.java index c6a1f26e0..35c8d7955 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/upload/uploader/FileUploader.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/handler/host/upload/uploader/FileUploader.java @@ -1,8 +1,5 @@ package com.orion.visor.module.asset.handler.host.upload.uploader; -import com.orion.lang.utils.Strings; -import com.orion.lang.utils.collect.Maps; -import com.orion.lang.utils.io.Files1; import com.orion.lang.utils.io.Streams; import com.orion.net.host.SessionStore; import com.orion.net.host.sftp.SftpExecutor; @@ -10,12 +7,10 @@ import com.orion.visor.framework.common.constant.Const; import com.orion.visor.framework.common.enums.EndpointDefine; import com.orion.visor.framework.common.file.FileClient; -import com.orion.visor.framework.common.utils.PathUtils; import com.orion.visor.module.asset.dao.UploadTaskFileDAO; import com.orion.visor.module.asset.define.config.AppSftpConfig; import com.orion.visor.module.asset.entity.domain.UploadTaskFileDO; import com.orion.visor.module.asset.entity.dto.HostTerminalConnectDTO; -import com.orion.visor.module.asset.enums.HostSshOsTypeEnum; import com.orion.visor.module.asset.enums.UploadTaskFileStatusEnum; import com.orion.visor.module.asset.handler.host.jsch.SessionStores; import com.orion.visor.module.asset.handler.host.upload.model.FileUploadFileItemDTO; @@ -28,7 +23,6 @@ import java.io.OutputStream; import java.util.Date; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; /** @@ -106,10 +100,8 @@ public void run() { private boolean initSession() { log.info("HostFileUploader.initSession start taskId: {}, hostId: {}", taskId, hostId); try { - // 替换用户路径 - HostTerminalConnectDTO connectInfo = hostTerminalService.getTerminalConnectInfo(hostId); - this.replaceRemotePathVariable(connectInfo.getOsType(), connectInfo.getUsername()); // 打开会话 + HostTerminalConnectDTO connectInfo = hostTerminalService.getTerminalConnectInfo(hostId); this.sessionStore = SessionStores.openSessionStore(connectInfo); this.executor = sessionStore.getSftpExecutor(connectInfo.getFileNameCharset()); executor.connect(); @@ -222,27 +214,6 @@ private void updateStatus(FileUploadFileItemDTO file, UploadTaskFileStatusEnum s uploadTaskFileDAO.updateById(update); } - /** - * 替换文件路径变量 - * - * @param osType osType - * @param username username - */ - private void replaceRemotePathVariable(String osType, String username) { - // 包含变量 - if (!files.get(0).getRemotePath().contains(Const.DOLLAR)) { - return; - } - String home = PathUtils.getHomePath(HostSshOsTypeEnum.WINDOWS.name().equals(osType), username); - // 替换变量 - Map env = Maps.newMap(4); - env.put("username", username); - env.put("home", home); - for (FileUploadFileItemDTO file : files) { - file.setRemotePath(Files1.getPath(Strings.format(file.getRemotePath(), env))); - } - } - @Override public void cancel() { log.info("HostFileUploader.cancel taskId: {}, hostId: {}, canceled: {}, closed: {}", taskId, hostId, canceled, closed); diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/UploadTaskServiceImpl.java b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/UploadTaskServiceImpl.java index 1515b279e..c382e4549 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/UploadTaskServiceImpl.java +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/java/com/orion/visor/module/asset/service/impl/UploadTaskServiceImpl.java @@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.orion.lang.annotation.Keep; +import com.orion.lang.define.collect.MultiHashMap; import com.orion.lang.define.wrapper.DataGrid; import com.orion.lang.utils.Arrays1; import com.orion.lang.utils.Booleans; @@ -15,9 +16,11 @@ import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs; import com.orion.visor.framework.common.constant.Const; import com.orion.visor.framework.common.constant.ErrorMessage; +import com.orion.visor.framework.common.constant.ExtraFieldConst; import com.orion.visor.framework.common.enums.EndpointDefine; import com.orion.visor.framework.common.file.FileClient; import com.orion.visor.framework.common.security.LoginUser; +import com.orion.visor.framework.common.utils.PathUtils; import com.orion.visor.framework.common.utils.SqlUtils; import com.orion.visor.framework.common.utils.Valid; import com.orion.visor.framework.mybatis.core.query.Conditions; @@ -28,20 +31,21 @@ import com.orion.visor.module.asset.dao.HostDAO; import com.orion.visor.module.asset.dao.UploadTaskDAO; import com.orion.visor.module.asset.dao.UploadTaskFileDAO; +import com.orion.visor.module.asset.entity.domain.HostDO; import com.orion.visor.module.asset.entity.domain.UploadTaskDO; import com.orion.visor.module.asset.entity.domain.UploadTaskFileDO; import com.orion.visor.module.asset.entity.dto.UploadTaskExtraDTO; import com.orion.visor.module.asset.entity.request.upload.*; import com.orion.visor.module.asset.entity.vo.*; -import com.orion.visor.module.asset.enums.HostTypeEnum; -import com.orion.visor.module.asset.enums.UploadTaskFileStatusEnum; -import com.orion.visor.module.asset.enums.UploadTaskStatusEnum; +import com.orion.visor.module.asset.enums.*; +import com.orion.visor.module.asset.handler.host.config.model.HostSshConfigModel; import com.orion.visor.module.asset.handler.host.upload.FileUploadTasks; import com.orion.visor.module.asset.handler.host.upload.manager.FileUploadTaskManager; import com.orion.visor.module.asset.handler.host.upload.model.FileUploadFileItemDTO; import com.orion.visor.module.asset.handler.host.upload.task.IFileUploadTask; import com.orion.visor.module.asset.handler.host.upload.uploader.IFileUploader; import com.orion.visor.module.asset.service.AssetAuthorizedDataService; +import com.orion.visor.module.asset.service.HostConfigService; import com.orion.visor.module.asset.service.UploadTaskFileService; import com.orion.visor.module.asset.service.UploadTaskService; import com.orion.visor.module.infra.api.FileUploadApi; @@ -83,6 +87,9 @@ public class UploadTaskServiceImpl implements UploadTaskService { @Resource private AssetAuthorizedDataService assetAuthorizedDataService; + @Resource + private HostConfigService hostConfigService; + @Resource private FileUploadTaskManager fileUploadTaskManager; @@ -103,10 +110,9 @@ public UploadTaskCreateVO createUploadTask(UploadTaskCreateRequest request) { // 检查主机是否有权限 this.checkHostPermission(hostIdList); // 查询主机信息 - List hosts = hostDAO.selectBaseByIdList(hostIdList) - .stream() - .map(HostConvert.MAPPER::toBase) - .collect(Collectors.toList()); + List hosts = this.getUploadTaskHosts(hostIdList); + // 计算文件路径 + MultiHashMap realRemoteFilePathMap = this.setFileRealRemotePath(request, hosts); // 转换 UploadTaskDO record = UploadTaskConvert.MAPPER.to(request); record.setUserId(user.getId()); @@ -117,7 +123,7 @@ public UploadTaskCreateVO createUploadTask(UploadTaskCreateRequest request) { record.setHostCount(hostIdList.size()); UploadTaskExtraDTO extra = UploadTaskExtraDTO.builder() .hostIdList(hostIdList) - .hosts(hosts) + .hosts(HostConvert.MAPPER.toBaseList(hosts)) .build(); record.setExtraInfo(JSON.toJSONString(extra)); // 插入任务表 @@ -132,6 +138,7 @@ public UploadTaskCreateVO createUploadTask(UploadTaskCreateRequest request) { .hostId(hostId) .fileId(s.getFileId()) .filePath(s.getFilePath()) + .realFilePath(realRemoteFilePathMap.get(hostId, s.getFileId())) .fileSize(s.getFileSize()) .status(UploadTaskFileStatusEnum.WAITING.name()) .build()) @@ -336,6 +343,68 @@ private void checkHostPermission(List hostIdList) { } } + /** + * 查询上传任务主机信息 + * + * @param hostIdList hostIdList + * @return hosts + */ + public List getUploadTaskHosts(List hostIdList) { + // 查询主机信息 + List hosts = hostDAO.selectBatchIds(hostIdList); + // 检查主机数量 + Valid.eq(hosts.size(), hostIdList.size(), ErrorMessage.HOST_ABSENT); + // 检查主机状态 + boolean allEnabled = hosts.stream() + .map(HostDO::getStatus) + .allMatch(s -> HostStatusEnum.ENABLED.name().equals(s)); + Valid.isTrue(allEnabled, ErrorMessage.HOST_NOT_ENABLED); + return hosts; + } + + /** + * 设置文件实际路径 + * + * @param request request + * @param hosts hosts + * @return realRemoteFilePathMap + */ + public MultiHashMap setFileRealRemotePath(UploadTaskCreateRequest request, + List hosts) { + MultiHashMap realRemoteFilePathMap = MultiHashMap.create(); + // 计算上传目录 + String remotePath = request.getRemotePath(); + List files = request.getFiles(); + boolean containsEnv = remotePath.contains(Const.DOLLAR); + if (containsEnv) { + // 获取主机配置信息 + Map hostConfigMap = hostConfigService.buildHostConfigMap(hosts, HostTypeEnum.SSH); + hostConfigMap.forEach((k, v) -> { + // 替换占位符 + String username = v.getUsername(); + String home = PathUtils.getHomePath(HostSshOsTypeEnum.isWindows(v.getOsType()), username); + // 替换环境变量路径 + Map env = Maps.newMap(4); + env.put(ExtraFieldConst.USERNAME, username); + env.put(ExtraFieldConst.HOME, home); + // 设置主机上传路径 + String realRemotePath = Files1.getPath(Strings.format(remotePath, env)); + for (UploadTaskFileRequest file : files) { + realRemoteFilePathMap.put(k, file.getFileId(), Files1.getPath(realRemotePath, file.getFilePath())); + } + }); + } else { + // 无占位符 + for (UploadTaskFileRequest file : files) { + String path = Files1.getPath(remotePath, file.getFilePath()); + for (HostDO host : hosts) { + realRemoteFilePathMap.put(host.getId(), file.getFileId(), path); + } + } + } + return realRemoteFilePathMap; + } + /** * 检查文件完整性 * diff --git a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/resources/mapper/UploadTaskFileMapper.xml b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/resources/mapper/UploadTaskFileMapper.xml index af04e2933..60d8fa41a 100644 --- a/orion-visor-module-asset/orion-visor-module-asset-service/src/main/resources/mapper/UploadTaskFileMapper.xml +++ b/orion-visor-module-asset/orion-visor-module-asset-service/src/main/resources/mapper/UploadTaskFileMapper.xml @@ -9,6 +9,7 @@ + @@ -22,7 +23,7 @@ - id, task_id, host_id, file_id, file_path, file_size, status, start_time, end_time, create_time, update_time, creator, updater, deleted + id, task_id, host_id, file_id, file_path, real_file_path, file_size, status, start_time, end_time, create_time, update_time, creator, updater, deleted diff --git a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/SystemSettingServiceImpl.java b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/SystemSettingServiceImpl.java index 0ac50bcd6..430779229 100644 --- a/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/SystemSettingServiceImpl.java +++ b/orion-visor-module-infra/orion-visor-module-infra-service/src/main/java/com/orion/visor/module/infra/service/impl/SystemSettingServiceImpl.java @@ -4,10 +4,10 @@ import com.orion.lang.support.Attempt; import com.orion.lang.utils.Arrays1; import com.orion.lang.utils.Strings; +import com.orion.lang.utils.crypto.Signatures; import com.orion.lang.utils.io.Streams; import com.orion.visor.framework.common.constant.AppConst; import com.orion.visor.framework.common.constant.Const; -import com.orion.visor.framework.common.utils.Mixes; import com.orion.visor.module.infra.entity.vo.AppInfoVO; import com.orion.visor.module.infra.service.SystemSettingService; import org.springframework.stereotype.Service; @@ -70,7 +70,7 @@ private String getSystemUuid() { if (!Strings.isBlank(extraUuid)) { uuid = extraUuid.trim(); } - return this.uuid = Mixes.obfuscate(uuid); + return this.uuid = Signatures.md5(uuid); } catch (Exception e) { // IGNORED } diff --git a/orion-visor-ui/.env.development b/orion-visor-ui/.env.development index b4d7ca0f1..bbd686e3e 100644 --- a/orion-visor-ui/.env.development +++ b/orion-visor-ui/.env.development @@ -1,6 +1,6 @@ VITE_API_BASE_URL= 'http://127.0.0.1:9200/orion-visor/api' VITE_WS_BASE_URL= 'ws://127.0.0.1:9200/orion-visor/keep-alive' -VITE_APP_VERSION= '2.1.6' +VITE_APP_VERSION= '2.1.7' VITE_APP_RELEASE= 'community' VITE_SFTP_PREVIEW_MB= 2 VITE_DEMO_MODE= false diff --git a/orion-visor-ui/.env.production b/orion-visor-ui/.env.production index 1e5d1f6ec..ccfcbff78 100644 --- a/orion-visor-ui/.env.production +++ b/orion-visor-ui/.env.production @@ -1,6 +1,6 @@ VITE_API_BASE_URL= '/orion-visor/api' VITE_WS_BASE_URL= '/orion-visor/keep-alive' -VITE_APP_VERSION= '2.1.6' +VITE_APP_VERSION= '2.1.7' VITE_APP_RELEASE= 'community' VITE_SFTP_PREVIEW_MB= 2 VITE_DEMO_MODE= false diff --git a/orion-visor-ui/config/plugin/pwa.ts b/orion-visor-ui/config/plugin/pwa.ts index 52cb57e0b..7a51896fa 100644 --- a/orion-visor-ui/config/plugin/pwa.ts +++ b/orion-visor-ui/config/plugin/pwa.ts @@ -34,7 +34,7 @@ const enabled = (): Partial => { manifest: { name: 'Orion Visor Community', short_name: 'Orion Visor', - description: '一款高颜值、现代化的智能运维&轻量堡垒机平台。', + description: '一款高颜值、现代化的自动化运维&轻量堡垒机平台。', theme_color: '#212529', icons: [{ src: 'manifest_logo_267.png', diff --git a/orion-visor-ui/package.json b/orion-visor-ui/package.json index 70a61efba..14f3c2509 100644 --- a/orion-visor-ui/package.json +++ b/orion-visor-ui/package.json @@ -1,7 +1,7 @@ { "name": "orion-visor-ui", "description": "Orion Visor UI", - "version": "2.1.6", + "version": "2.1.7", "private": true, "author": "Jiahang Li", "license": "Apache 2.0", diff --git a/orion-visor-ui/src/views/authentication/login/locale/zh-CN.ts b/orion-visor-ui/src/views/authentication/login/locale/zh-CN.ts index 30a958e70..a60504f2d 100644 --- a/orion-visor-ui/src/views/authentication/login/locale/zh-CN.ts +++ b/orion-visor-ui/src/views/authentication/login/locale/zh-CN.ts @@ -9,7 +9,7 @@ export default { 'login.form.userName.placeholder': '用户名', 'login.form.password.placeholder': '密码', 'login.form.login': '登录', - 'login.banner.slogan1': '现代化的智能运维平台', + 'login.banner.slogan1': '现代化的自动化运维平台', 'login.banner.subSlogan1': '一站式操作 让运维变得更简单', 'login.banner.slogan2': '高颜值的轻量堡垒机平台', 'login.banner.subSlogan2': '内置批量处理模块 让工作更高效', diff --git a/pom.xml b/pom.xml index a26438fc1..b5e5612ca 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ - 2.1.6 + 2.1.7 8 8 3.0.0-M5 diff --git a/sql/init-2-schema-tables.sql b/sql/init-2-schema-tables.sql index 043b47b00..59fc20054 100644 --- a/sql/init-2-schema-tables.sql +++ b/sql/init-2-schema-tables.sql @@ -824,20 +824,21 @@ CREATE TABLE `upload_task` DROP TABLE IF EXISTS `upload_task_file`; CREATE TABLE `upload_task_file` ( - `id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT 'id', - `task_id` bigint(0) NULL DEFAULT NULL COMMENT '用户id', - `host_id` bigint(0) NULL DEFAULT NULL COMMENT '主机id', - `file_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '文件id', - `file_path` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '文件路径', - `file_size` bigint(0) NULL DEFAULT NULL COMMENT '文件大小', - `status` char(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '状态', - `start_time` datetime(3) NULL DEFAULT NULL COMMENT '开始时间', - `end_time` datetime(3) NULL DEFAULT NULL COMMENT '结束时间', - `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '修改时间', - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建人', - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新人', - `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '是否删除 0未删除 1已删除', + `id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT 'id', + `task_id` bigint(0) NULL DEFAULT NULL COMMENT '用户id', + `host_id` bigint(0) NULL DEFAULT NULL COMMENT '主机id', + `file_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '文件id', + `file_path` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '文件路径', + `real_file_path` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '实际文件路径', + `file_size` bigint(0) NULL DEFAULT NULL COMMENT '文件大小', + `status` char(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '状态', + `start_time` datetime(3) NULL DEFAULT NULL COMMENT '开始时间', + `end_time` datetime(3) NULL DEFAULT NULL COMMENT '结束时间', + `create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '修改时间', + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建人', + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新人', + `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '是否删除 0未删除 1已删除', PRIMARY KEY (`id`) USING BTREE, INDEX `idx_task_id` (`task_id`) USING BTREE ) ENGINE = InnoDB