fix: 修改 ssh 登录日志排序规则 (#1264)

This commit is contained in:
ssongliu 2023-06-06 11:31:26 +08:00 committed by GitHub
parent 056c771d2e
commit 4fdb81642a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 0 deletions

View File

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

View File

@ -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?',

View File

@ -863,6 +863,7 @@ const message = {
fileUploadStart: '正在上传[{0}]....',
},
ssh: {
sshAlert: '列表数据根据登录时间排序但请注意切换时区或其他操作可能导致登录日志的时间出现偏差',
sshOperate: ' SSH 服务进行 [{0}] 操作是否继续',
sshChange: 'SSH 配置修改',
sshChangeHelper: '此操作将 {0} 修改为 [{1}] 是否继续',

View File

@ -1,6 +1,15 @@
<template>
<div>
<LayoutContent v-loading="loading" :title="$t('ssh.loginLogs')">
<template #prompt>
<el-alert type="info" :closable="false">
<template #default>
<span>
{{ $t('ssh.sshAlert') }}
</span>
</template>
</el-alert>
</template>
<template #toolbar>
<el-row>
<el-col :xs="24" :sm="16" :md="16" :lg="16" :xl="16">