From 2ecd9a167aa2878c4a3003bf8de556d872953218 Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Sat, 25 Dec 2021 19:34:30 +0800 Subject: [PATCH] =?UTF-8?q?vue=20ssh=20=E4=BF=AE=E6=94=B9=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E3=80=81ssh=20=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=8A=E4=BC=A0=E5=8E=8B=E7=BC=A9=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 + modules/agent/pom.xml | 6 +- modules/common/pom.xml | 6 ++ .../io/jpom/util/CompressionFileUtil.java | 0 .../node/ssh/SshFileController.java | 46 ++++++++++--- web-vue/src/pages/layout/index.vue | 2 +- web-vue/src/pages/node/list.vue | 2 +- .../node/node-layout/other/script-list.vue | 2 + .../node/node-layout/project/project-file.vue | 16 +---- .../src/pages/{node => }/ssh/command-log.vue | 0 .../pages/{node => }/ssh/command-view-log.vue | 0 web-vue/src/pages/{node => }/ssh/command.vue | 0 web-vue/src/pages/{node => ssh}/ssh-file.vue | 65 +++++++++---------- web-vue/src/pages/{node => ssh}/ssh.vue | 4 +- web-vue/src/pages/{node => ssh}/terminal.vue | 0 web-vue/src/router/index.js | 20 +++--- web-vue/src/router/route-menu.js | 6 +- web-vue/src/utils/const.js | 7 +- 18 files changed, 105 insertions(+), 79 deletions(-) rename modules/{agent => common}/src/main/java/io/jpom/util/CompressionFileUtil.java (100%) rename web-vue/src/pages/{node => }/ssh/command-log.vue (100%) rename web-vue/src/pages/{node => }/ssh/command-view-log.vue (100%) rename web-vue/src/pages/{node => }/ssh/command.vue (100%) rename web-vue/src/pages/{node => ssh}/ssh-file.vue (90%) rename web-vue/src/pages/{node => ssh}/ssh.vue (99%) rename web-vue/src/pages/{node => ssh}/terminal.vue (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22954cd0c..41f066c87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,12 @@ ### 新增功能 1. 脚本模版新增日志管理 +2. 【server】ssh 文件管理新增导入压缩包自动解压(感谢@刘志远) ### 解决BUG、优化功能 1. 【server】节点分发数据新增状态字段,启动程序时候触发修护异常数据 +2. 【server】定时执行相关 cron 表达式输入提示示例数据 ------ diff --git a/modules/agent/pom.xml b/modules/agent/pom.xml index 6a659794d..64847538e 100644 --- a/modules/agent/pom.xml +++ b/modules/agent/pom.xml @@ -33,11 +33,7 @@ bcprov-jdk15on 1.69 - - org.apache.commons - commons-compress - 1.21 - + io.jpom.plugins webhook diff --git a/modules/common/pom.xml b/modules/common/pom.xml index 188fd3de0..8c1ff376b 100644 --- a/modules/common/pom.xml +++ b/modules/common/pom.xml @@ -44,6 +44,12 @@ spring-boot-starter-aop + + org.apache.commons + commons-compress + 1.21 + + diff --git a/modules/agent/src/main/java/io/jpom/util/CompressionFileUtil.java b/modules/common/src/main/java/io/jpom/util/CompressionFileUtil.java similarity index 100% rename from modules/agent/src/main/java/io/jpom/util/CompressionFileUtil.java rename to modules/common/src/main/java/io/jpom/util/CompressionFileUtil.java diff --git a/modules/server/src/main/java/io/jpom/controller/node/ssh/SshFileController.java b/modules/server/src/main/java/io/jpom/controller/node/ssh/SshFileController.java index 8ca262f76..c25fcfe7b 100644 --- a/modules/server/src/main/java/io/jpom/controller/node/ssh/SshFileController.java +++ b/modules/server/src/main/java/io/jpom/controller/node/ssh/SshFileController.java @@ -1,6 +1,7 @@ package io.jpom.controller.node.ssh; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; @@ -26,6 +27,9 @@ import io.jpom.plugin.Feature; import io.jpom.plugin.MethodFeature; import io.jpom.service.node.ssh.SshService; import io.jpom.system.ServerConfigBean; +import io.jpom.util.CommandUtil; +import io.jpom.util.CompressionFileUtil; +import io.jpom.util.StringUtil; import org.springframework.http.MediaType; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestMapping; @@ -122,7 +126,6 @@ public class SshFileController extends BaseServerController { } @RequestMapping(value = "list_file_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(method = MethodFeature.LIST) public String listData(String id, String path, String children) throws SftpException { SshModel sshModel = this.check(id, path, children); @@ -132,7 +135,6 @@ public class SshFileController extends BaseServerController { } @RequestMapping(value = "read_file_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(method = MethodFeature.LIST) public String readFileData(String id, String path, String children) { SshModel sshModel = this.check(id, path, children); @@ -145,7 +147,6 @@ public class SshFileController extends BaseServerController { } @RequestMapping(value = "update_file_data.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody @Feature(method = MethodFeature.EDIT) public String updateFileData(String id, String path, String children, String content) { SshModel sshModel = this.check(id, path, children); @@ -413,23 +414,48 @@ public class SshFileController extends BaseServerController { @RequestMapping(value = "upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @Feature(method = MethodFeature.UPLOAD) - public String upload(String id, String path, String name) { + public String upload(String id, String path, String name, String unzip) { SshModel sshModel = sshService.getByKey(id, false); Assert.notNull(sshModel, "ssh error"); List fileDirs = sshModel.fileDirs(); Assert.state(CollUtil.contains(fileDirs, path), "没有配置此文件夹"); + String remotePath = FileUtil.normalize(path + StrUtil.SLASH + name); Session session = null; ChannelSftp channel = null; String localPath = null; try { session = SshService.getSessionByModel(sshModel); channel = (ChannelSftp) JschUtil.openChannel(session, ChannelType.SFTP); - MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file").setUseOriginalFilename(true); - localPath = multipartFileBuilder.save(); - File file = FileUtil.file(localPath); - String normalize = FileUtil.normalize(path + StrUtil.SLASH + name); - channel.cd(normalize); - channel.put(IoUtil.toStream(file), file.getName()); + MultipartFileBuilder multipart = createMultipart(); + // 保存路径 + File tempPath = ServerConfigBean.getInstance().getUserTempPath(); + File savePath = FileUtil.file(tempPath, "ssh", sshModel.getId()); + multipart.setSavePath(FileUtil.getAbsolutePath(savePath)); + multipart.addFieldName("file") + .setUseOriginalFilename(true); + // + if (Convert.toBool(unzip, false)) { + multipart.setFileExt(StringUtil.PACKAGE_EXT); + localPath = multipart.save(); + // 解压 + File file = new File(localPath); + File tempUnzipPath = FileUtil.file(savePath, IdUtil.fastSimpleUUID()); + try { + CompressionFileUtil.unCompress(file, tempUnzipPath); + // 同步上传文件 + sshService.uploadDir(sshModel, remotePath, tempUnzipPath); + } finally { + // 删除临时文件 + CommandUtil.systemFastDel(file); + CommandUtil.systemFastDel(tempUnzipPath); + } + } else { + localPath = multipart.save(); + File file = FileUtil.file(localPath); + channel.cd(remotePath); + channel.put(IoUtil.toStream(file), file.getName()); + } + } catch (Exception e) { DefaultSystemLog.getLog().error("ssh上传文件异常", e); return JsonMessage.getString(400, "上传失败"); diff --git a/web-vue/src/pages/layout/index.vue b/web-vue/src/pages/layout/index.vue index 7d14863af..3ab9d612a 100644 --- a/web-vue/src/pages/layout/index.vue +++ b/web-vue/src/pages/layout/index.vue @@ -181,7 +181,7 @@ export default { }, }; -