mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-09-14 18:45:49 +08:00
fix: Add non-standard log filtering for SSH (#9865)
This commit is contained in:
parent
a30066989b
commit
39bb7acdba
1 changed files with 12 additions and 4 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -541,7 +542,7 @@ func loadSSHData(ctx *gin.Context, command string, showCountFrom, showCountTo, c
|
||||||
switch {
|
switch {
|
||||||
case strings.Contains(lines[i], "Failed password for"):
|
case strings.Contains(lines[i], "Failed password for"):
|
||||||
itemData = loadFailedSecureDatas(lines[i])
|
itemData = loadFailedSecureDatas(lines[i])
|
||||||
if len(itemData.Address) != 0 {
|
if checkIsStandard(itemData) {
|
||||||
if successCount+failedCount >= showCountFrom && successCount+failedCount < showCountTo {
|
if successCount+failedCount >= showCountFrom && successCount+failedCount < showCountTo {
|
||||||
itemData.Area, _ = geo.GetIPLocation(getLoc, itemData.Address, common.GetLang(ctx))
|
itemData.Area, _ = geo.GetIPLocation(getLoc, itemData.Address, common.GetLang(ctx))
|
||||||
itemData.Date = loadDate(currentYear, itemData.DateStr, nyc)
|
itemData.Date = loadDate(currentYear, itemData.DateStr, nyc)
|
||||||
|
@ -551,7 +552,7 @@ func loadSSHData(ctx *gin.Context, command string, showCountFrom, showCountTo, c
|
||||||
}
|
}
|
||||||
case strings.Contains(lines[i], "Connection closed by authenticating user"):
|
case strings.Contains(lines[i], "Connection closed by authenticating user"):
|
||||||
itemData = loadFailedAuthDatas(lines[i])
|
itemData = loadFailedAuthDatas(lines[i])
|
||||||
if len(itemData.Address) != 0 {
|
if checkIsStandard(itemData) {
|
||||||
if successCount+failedCount >= showCountFrom && successCount+failedCount < showCountTo {
|
if successCount+failedCount >= showCountFrom && successCount+failedCount < showCountTo {
|
||||||
itemData.Area, _ = geo.GetIPLocation(getLoc, itemData.Address, common.GetLang(ctx))
|
itemData.Area, _ = geo.GetIPLocation(getLoc, itemData.Address, common.GetLang(ctx))
|
||||||
itemData.Date = loadDate(currentYear, itemData.DateStr, nyc)
|
itemData.Date = loadDate(currentYear, itemData.DateStr, nyc)
|
||||||
|
@ -561,7 +562,7 @@ func loadSSHData(ctx *gin.Context, command string, showCountFrom, showCountTo, c
|
||||||
}
|
}
|
||||||
case strings.Contains(lines[i], "Accepted "):
|
case strings.Contains(lines[i], "Accepted "):
|
||||||
itemData = loadSuccessDatas(lines[i])
|
itemData = loadSuccessDatas(lines[i])
|
||||||
if len(itemData.Address) != 0 {
|
if checkIsStandard(itemData) {
|
||||||
if successCount+failedCount >= showCountFrom && successCount+failedCount < showCountTo {
|
if successCount+failedCount >= showCountFrom && successCount+failedCount < showCountTo {
|
||||||
itemData.Area, _ = geo.GetIPLocation(getLoc, itemData.Address, common.GetLang(ctx))
|
itemData.Area, _ = geo.GetIPLocation(getLoc, itemData.Address, common.GetLang(ctx))
|
||||||
itemData.Date = loadDate(currentYear, itemData.DateStr, nyc)
|
itemData.Date = loadDate(currentYear, itemData.DateStr, nyc)
|
||||||
|
@ -589,7 +590,6 @@ func loadSuccessDatas(line string) dto.SSHHistory {
|
||||||
data.Status = constant.StatusSuccess
|
data.Status = constant.StatusSuccess
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFailedAuthDatas(line string) dto.SSHHistory {
|
func loadFailedAuthDatas(line string) dto.SSHHistory {
|
||||||
var data dto.SSHHistory
|
var data dto.SSHHistory
|
||||||
parts := strings.Fields(line)
|
parts := strings.Fields(line)
|
||||||
|
@ -639,6 +639,14 @@ func loadFailedSecureDatas(line string) dto.SSHHistory {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkIsStandard(item dto.SSHHistory) bool {
|
||||||
|
if len(item.Address) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
portItem, _ := strconv.Atoi(item.Port)
|
||||||
|
return portItem != 0
|
||||||
|
}
|
||||||
|
|
||||||
func handleGunzip(path string) error {
|
func handleGunzip(path string) error {
|
||||||
if _, err := cmd.RunDefaultWithStdoutBashCf("gunzip %s", path); err != nil {
|
if _, err := cmd.RunDefaultWithStdoutBashCf("gunzip %s", path); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Add table
Reference in a new issue