Skip to content

Commit 39bb7ac

Browse files
authored
fix: Add non-standard log filtering for SSH (1Panel-dev#9865)
1 parent a300669 commit 39bb7ac

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

agent/app/service/ssh.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os/user"
99
"path"
1010
"sort"
11+
"strconv"
1112
"strings"
1213
"time"
1314

@@ -541,7 +542,7 @@ func loadSSHData(ctx *gin.Context, command string, showCountFrom, showCountTo, c
541542
switch {
542543
case strings.Contains(lines[i], "Failed password for"):
543544
itemData = loadFailedSecureDatas(lines[i])
544-
if len(itemData.Address) != 0 {
545+
if checkIsStandard(itemData) {
545546
if successCount+failedCount >= showCountFrom && successCount+failedCount < showCountTo {
546547
itemData.Area, _ = geo.GetIPLocation(getLoc, itemData.Address, common.GetLang(ctx))
547548
itemData.Date = loadDate(currentYear, itemData.DateStr, nyc)
@@ -551,7 +552,7 @@ func loadSSHData(ctx *gin.Context, command string, showCountFrom, showCountTo, c
551552
}
552553
case strings.Contains(lines[i], "Connection closed by authenticating user"):
553554
itemData = loadFailedAuthDatas(lines[i])
554-
if len(itemData.Address) != 0 {
555+
if checkIsStandard(itemData) {
555556
if successCount+failedCount >= showCountFrom && successCount+failedCount < showCountTo {
556557
itemData.Area, _ = geo.GetIPLocation(getLoc, itemData.Address, common.GetLang(ctx))
557558
itemData.Date = loadDate(currentYear, itemData.DateStr, nyc)
@@ -561,7 +562,7 @@ func loadSSHData(ctx *gin.Context, command string, showCountFrom, showCountTo, c
561562
}
562563
case strings.Contains(lines[i], "Accepted "):
563564
itemData = loadSuccessDatas(lines[i])
564-
if len(itemData.Address) != 0 {
565+
if checkIsStandard(itemData) {
565566
if successCount+failedCount >= showCountFrom && successCount+failedCount < showCountTo {
566567
itemData.Area, _ = geo.GetIPLocation(getLoc, itemData.Address, common.GetLang(ctx))
567568
itemData.Date = loadDate(currentYear, itemData.DateStr, nyc)
@@ -589,7 +590,6 @@ func loadSuccessDatas(line string) dto.SSHHistory {
589590
data.Status = constant.StatusSuccess
590591
return data
591592
}
592-
593593
func loadFailedAuthDatas(line string) dto.SSHHistory {
594594
var data dto.SSHHistory
595595
parts := strings.Fields(line)
@@ -639,6 +639,14 @@ func loadFailedSecureDatas(line string) dto.SSHHistory {
639639
return data
640640
}
641641

642+
func checkIsStandard(item dto.SSHHistory) bool {
643+
if len(item.Address) == 0 {
644+
return false
645+
}
646+
portItem, _ := strconv.Atoi(item.Port)
647+
return portItem != 0
648+
}
649+
642650
func handleGunzip(path string) error {
643651
if _, err := cmd.RunDefaultWithStdoutBashCf("gunzip %s", path); err != nil {
644652
return err

0 commit comments

Comments
 (0)