From 6131a99db0be3668e506de82e22bf7d33c6bc26d Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 21 May 2024 16:44:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86=20s?= =?UTF-8?q?sh=20=E7=99=BB=E5=BD=95=E6=97=A5=E5=BF=97=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98=20(#5081)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/ssh.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/backend/app/service/ssh.go b/backend/app/service/ssh.go index 15d353f14..c478a4b1e 100644 --- a/backend/app/service/ssh.go +++ b/backend/app/service/ssh.go @@ -479,9 +479,12 @@ func loadFailedAuthDatas(line string) dto.SSHHistory { return data } data.DateStr = dataStr - if index == 2 { + switch index { + case 1: + data.User = parts[9] + case 2: data.User = parts[10] - } else { + default: data.User = parts[7] } data.AuthMode = parts[6+index] @@ -543,14 +546,22 @@ func loadDate(currentYear int, DateStr string, nyc *time.Location) time.Time { func analyzeDateStr(parts []string) (int, string) { t, err := time.Parse("2006-01-02T15:04:05.999999-07:00", parts[0]) - if err != nil { + if err == nil { + if len(parts) < 12 { + return 0, "" + } + return 0, t.Format("2006 Jan 2 15:04:05") + } + t, err = time.Parse("2006-01-02 15:04:05", fmt.Sprintf("%s %s", parts[0], parts[1])) + if err == nil { if len(parts) < 14 { return 0, "" } - return 2, fmt.Sprintf("%s %s %s", parts[0], parts[1], parts[2]) + return 1, t.Format("2006 Jan 2 15:04:05") } - if len(parts) < 12 { + + if len(parts) < 14 { return 0, "" } - return 0, t.Format("2006 Jan 2 15:04:05") + return 2, fmt.Sprintf("%s %s %s", parts[0], parts[1], parts[2]) }