mirror of
https://github.com/JetSprow/J-Board-Lite.git
synced 2026-05-01 01:14:10 +05:30
fix: support xray access log from format
This commit is contained in:
@@ -20,7 +20,7 @@ import (
|
||||
const maxXrayReadBytes int64 = 2 * 1024 * 1024
|
||||
const maxXrayEventsPerPush = 300
|
||||
|
||||
var xrayAccessLinePattern = regexp.MustCompile(`^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2})\s+(\S+)\s+(accepted|rejected)\s+(?:(tcp|udp):)?(\S+)\s+\[([^\]]+)\](?:.*?\bemail:\s*([^\s]+))?`)
|
||||
var xrayAccessLinePattern = regexp.MustCompile(`^(\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?)\s+(?:from\s+)?(\S+)\s+(accepted|rejected)\s+(?:(tcp|udp):)?(\S+)\s+\[([^\]]+)\](?:.*?\bemail:\s*([^\s]+))?`)
|
||||
|
||||
type xrayLogState struct {
|
||||
Path string `json:"path"`
|
||||
|
||||
@@ -44,6 +44,37 @@ func TestParseXrayAccessLineWithIPv6Source(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseXrayAccessLineWithFromAndFractionalTimestamp(t *testing.T) {
|
||||
line := "2026/04/29 09:20:06.006542 from tcp:220.240.111.193:59433 accepted udp:71.18.167.208:443 [inbound-17583 >> direct] email: user@test.com-cmojtnp3"
|
||||
got, ok := parseXrayAccessLine(line)
|
||||
if !ok {
|
||||
t.Fatal("parseXrayAccessLine() failed")
|
||||
}
|
||||
if got.SourceIP != "220.240.111.193" {
|
||||
t.Fatalf("SourceIP = %q", got.SourceIP)
|
||||
}
|
||||
if got.ClientEmail != "user@test.com-cmojtnp3" {
|
||||
t.Fatalf("ClientEmail = %q", got.ClientEmail)
|
||||
}
|
||||
if got.InboundTag != "inbound-17583" {
|
||||
t.Fatalf("InboundTag = %q", got.InboundTag)
|
||||
}
|
||||
if got.Network != "udp" || got.TargetHost != "71.18.167.208" || got.TargetPort != 443 {
|
||||
t.Fatalf("target = %s %s:%d", got.Network, got.TargetHost, got.TargetPort)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseXrayAccessLineWithFromPlainSource(t *testing.T) {
|
||||
line := "2026/04/29 09:20:05.982584 from 220.240.111.193:59425 accepted tcp:webcast3-core-c-lf.amemv.com:443 [inbound-17583 >> direct] email: user@test.com-cmojtnp3"
|
||||
got, ok := parseXrayAccessLine(line)
|
||||
if !ok {
|
||||
t.Fatal("parseXrayAccessLine() failed")
|
||||
}
|
||||
if got.SourceIP != "220.240.111.193" || got.Network != "tcp" || got.TargetHost != "webcast3-core-c-lf.amemv.com" {
|
||||
t.Fatalf("parsed = %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAggregateXrayAccessLines(t *testing.T) {
|
||||
lines := []string{
|
||||
"2026/04/29 10:11:12 203.0.113.9:51820 accepted tcp:example.com:443 [proxy] email: user@example.com-cabc1234",
|
||||
|
||||
Reference in New Issue
Block a user