mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
fix: 优化 ssh 登录日志查询速度 (#1307)
This commit is contained in:
parent
7c600a357c
commit
39f952e460
@ -231,7 +231,8 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) {
|
|||||||
}
|
}
|
||||||
for i := 0; i < len(fileList); i++ {
|
for i := 0; i < len(fileList); i++ {
|
||||||
if strings.HasPrefix(path.Base(fileList[i]), "secure") {
|
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.FailedCount += len(dataItem)
|
||||||
data.TotalCount += len(dataItem)
|
data.TotalCount += len(dataItem)
|
||||||
if req.Status != constant.StatusSuccess {
|
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") {
|
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.FailedCount += len(dataItem)
|
||||||
data.TotalCount += len(dataItem)
|
data.TotalCount += len(dataItem)
|
||||||
if req.Status != constant.StatusSuccess {
|
if req.Status != constant.StatusSuccess {
|
||||||
data.Logs = append(data.Logs, dataItem...)
|
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)
|
data.TotalCount += len(dataItem)
|
||||||
if req.Status != constant.StatusFailed {
|
if req.Status != constant.StatusFailed {
|
||||||
data.Logs = append(data.Logs, dataItem...)
|
data.Logs = append(data.Logs, dataItem...)
|
||||||
@ -257,6 +260,18 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) {
|
|||||||
return nil, nil
|
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()
|
timeNow := time.Now()
|
||||||
nyc, _ := time.LoadLocation(common.LoadTimeZone())
|
nyc, _ := time.LoadLocation(common.LoadTimeZone())
|
||||||
qqWry, err := qqwry.NewQQwry()
|
qqWry, err := qqwry.NewQQwry()
|
||||||
@ -271,18 +286,6 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) {
|
|||||||
}
|
}
|
||||||
data.Logs = itemLogs
|
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
|
return &data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user