mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-02 11:15:03 +03:00
fix(server): keep only the requested tail while reading the access log
GetXrayLogs held one entry for every line of Xray's access log and cut the list to the requested count only at EOF, so the panel's memory grew with the file. Xray writes a line for every refused request, which puts the file's size in the hands of anyone who can reach an inbound port, and the periodic prune does not bound it between runs. A negative count also panicked on the final slice. Entries beyond the newest count are dropped while scanning, and count is clamped to 1..10000 with 100 as the fallback, as GetAmneziaWGLogs already does.
This commit is contained in:
@@ -1482,7 +1482,10 @@ func (s *ServerService) GetXrayLogs(
|
||||
Proxied
|
||||
)
|
||||
|
||||
countInt, _ := strconv.Atoi(count)
|
||||
countInt, err := strconv.Atoi(count)
|
||||
if err != nil || countInt < 1 || countInt > 10000 {
|
||||
countInt = 100
|
||||
}
|
||||
var entries []LogEntry
|
||||
|
||||
pathToAccessLog, err := xray.GetAccessLogPath()
|
||||
@@ -1530,17 +1533,18 @@ func (s *ServerService) GetXrayLogs(
|
||||
entry.Event = Proxied
|
||||
}
|
||||
|
||||
// Anyone reaching an inbound port adds lines here, so only the newest
|
||||
// countInt entries are kept while reading, not one per line of the file.
|
||||
entries = append(entries, entry)
|
||||
if len(entries) > countInt {
|
||||
entries = entries[1:]
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(entries) > countInt {
|
||||
entries = entries[len(entries)-countInt:]
|
||||
}
|
||||
|
||||
return entries
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user