From 4fdb81642afa42e00a0b5ebf839a19add9ad0940 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 6 Jun 2023 11:31:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=20ssh=20=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=97=A5=E5=BF=97=E6=8E=92=E5=BA=8F=E8=A7=84=E5=88=99?= =?UTF-8?q?=20(#1264)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/ssh.go | 22 ++++++++++++++++++++++ frontend/src/lang/modules/en.ts | 3 +++ frontend/src/lang/modules/zh.ts | 1 + frontend/src/views/host/ssh/log/log.vue | 9 +++++++++ 4 files changed, 35 insertions(+) diff --git a/backend/app/service/ssh.go b/backend/app/service/ssh.go index c07214070..e29c13be1 100644 --- a/backend/app/service/ssh.go +++ b/backend/app/service/ssh.go @@ -6,6 +6,7 @@ import ( "os/user" "path" "path/filepath" + "sort" "strings" "time" @@ -222,6 +223,7 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) { }); err != nil { return nil, err } + fileList = sortFileList(fileList) command := "" if len(req.Info) != 0 { @@ -284,6 +286,26 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) { return &data, nil } +func sortFileList(fileNames []string) []string { + if len(fileNames) < 2 { + return fileNames + } + var itemFile []string + if strings.Contains(fileNames[0], "secure") { + sort.Slice(fileNames, func(i, j int) bool { + return fileNames[i] < fileNames[j] + }) + itemFile = append(itemFile, fileNames[1:]...) + itemFile = append(itemFile, fileNames[0]) + return itemFile + } + + sort.Slice(fileNames, func(i, j int) bool { + return fileNames[i] > fileNames[j] + }) + return fileNames +} + func updateSSHConf(oldFiles []string, param string, value interface{}) []string { hasKey := false var newFiles []string diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 0e0798bf0..fb21e2945 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -228,6 +228,7 @@ const message = { container: 'Container', cronjob: 'Cronjob', host: 'Host', + ssh: 'SSH Setting', security: 'Security', files: 'File', monitor: 'Monitor', @@ -869,6 +870,8 @@ const message = { fileUploadStart: 'Uploading [{0}]....', }, ssh: { + sshAlert: + 'The list data is sorted based on login time, but please note that changing time zones or other operations may cause deviations in the time of login logs.', sshOperate: 'Operation [{0}] on the SSH service is performed. Do you want to continue?', sshChange: 'SSH Setting', sshChangeHelper: 'This action changed {0} to [{1}]. Do you want to continue?', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index a3102a72b..23b6b9e9c 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -863,6 +863,7 @@ const message = { fileUploadStart: '正在上传[{0}]....', }, ssh: { + sshAlert: '列表数据根据登录时间排序,但请注意,切换时区或其他操作可能导致登录日志的时间出现偏差。', sshOperate: '对 SSH 服务进行 [{0}] 操作,是否继续?', sshChange: 'SSH 配置修改', sshChangeHelper: '此操作将 {0} 修改为 [{1}] ,是否继续?', diff --git a/frontend/src/views/host/ssh/log/log.vue b/frontend/src/views/host/ssh/log/log.vue index 994aba5e0..2317cc12d 100644 --- a/frontend/src/views/host/ssh/log/log.vue +++ b/frontend/src/views/host/ssh/log/log.vue @@ -1,6 +1,15 @@