From 39f952e460deaa40471454c1c1699b8a11609501 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:44:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=20ssh=20=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=97=A5=E5=BF=97=E6=9F=A5=E8=AF=A2=E9=80=9F=E5=BA=A6?= =?UTF-8?q?=20(#1307)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/ssh.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/backend/app/service/ssh.go b/backend/app/service/ssh.go index e29c13be1272..af9a026d45df 100644 --- a/backend/app/service/ssh.go +++ b/backend/app/service/ssh.go @@ -231,7 +231,8 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) { } for i := 0; i < len(fileList); i++ { if strings.HasPrefix(path.Base(fileList[i]), "secure") { - dataItem := loadFailedSecureDatas(fmt.Sprintf("cat %s | grep -a 'Failed password for' | grep -v 'invalid' %s", fileList[i], command)) + commandItem := fmt.Sprintf("cat %s | grep -a 'Failed password for' | grep -v 'invalid' %s", fileList[i], command) + dataItem := loadFailedSecureDatas(commandItem) data.FailedCount += len(dataItem) data.TotalCount += len(dataItem) if req.Status != constant.StatusSuccess { @@ -239,14 +240,16 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) { } } if strings.HasPrefix(path.Base(fileList[i]), "auth.log") { - dataItem := loadFailedAuthDatas(fmt.Sprintf("cat %s | grep -a 'Connection closed by authenticating user' | grep -a 'preauth' %s", fileList[i], command)) + commandItem := fmt.Sprintf("cat %s | grep -a 'Connection closed by authenticating user' | grep -a 'preauth' %s", fileList[i], command) + dataItem := loadFailedAuthDatas(commandItem) data.FailedCount += len(dataItem) data.TotalCount += len(dataItem) if req.Status != constant.StatusSuccess { data.Logs = append(data.Logs, dataItem...) } } - dataItem := loadSuccessDatas(fmt.Sprintf("cat %s | grep Accepted %s", fileList[i], command)) + commandItem := fmt.Sprintf("cat %s | grep Accepted %s", fileList[i], command) + dataItem := loadSuccessDatas(commandItem) data.TotalCount += len(dataItem) if req.Status != constant.StatusFailed { data.Logs = append(data.Logs, dataItem...) @@ -257,6 +260,18 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) { return nil, nil } + var itemDatas []dto.SSHHistory + total, start, end := len(data.Logs), (req.Page-1)*req.PageSize, req.Page*req.PageSize + if start > total { + itemDatas = make([]dto.SSHHistory, 0) + } else { + if end >= total { + end = total + } + itemDatas = data.Logs[start:end] + } + data.Logs = itemDatas + timeNow := time.Now() nyc, _ := time.LoadLocation(common.LoadTimeZone()) qqWry, err := qqwry.NewQQwry() @@ -271,18 +286,6 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) { } data.Logs = itemLogs - var itemDatas []dto.SSHHistory - total, start, end := len(data.Logs), (req.Page-1)*req.PageSize, req.Page*req.PageSize - if start > total { - itemDatas = make([]dto.SSHHistory, 0) - } else { - if end >= total { - end = total - } - itemDatas = data.Logs[start:end] - } - data.Logs = itemDatas - return &data, nil }