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

pull/1268/head
ssongliu 1 year ago committed by GitHub
parent 056c771d2e
commit 4fdb81642a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

@ -863,6 +863,7 @@ const message = {
fileUploadStart: '[{0}]....',
},
ssh: {
sshAlert: '',
sshOperate: ' SSH [{0}] ',
sshChange: 'SSH ',
sshChangeHelper: ' {0} [{1}] ',

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

Loading…
Cancel
Save