diff options
| author | fgsfds <4870330+fgsfds@users.noreply.github.com> | 2025-08-04 19:47:48 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-04 19:47:48 +0300 |
| commit | 957f3dbb5449475f330d863171134b56e37da4ad (patch) | |
| tree | 9dce77a898311da6ee98be18e7d7c12d383703c5 /web/service | |
| parent | 05e60af283e4cb0e7c290b1fafd8f3d54028bda8 (diff) | |
Added xray access log viewer (#3309)
* added xray access log viewer
* made modal window width adaptive
* hide logs button if xray logs are disabled
Diffstat (limited to 'web/service')
| -rw-r--r-- | web/service/server.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/web/service/server.go b/web/service/server.go index f0be46c2..ade5b521 100644 --- a/web/service/server.go +++ b/web/service/server.go @@ -2,6 +2,7 @@ package service import ( "archive/zip" + "bufio" "bytes" "encoding/json" "fmt" @@ -481,6 +482,37 @@ func (s *ServerService) GetLogs(count string, level string, syslog string) []str return lines } +func (s *ServerService) GetXrayLogs(count string) []string { + c, _ := strconv.Atoi(count) + var lines []string + + pathToAccessLog, err := xray.GetAccessLogPath() + if err != nil { + return lines + } + + file, err := os.Open(pathToAccessLog) + if err != nil { + return lines + } + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + if strings.TrimSpace(line) == "" || strings.Contains(line, "api -> api") { + continue + } + lines = append(lines, line) + } + + if len(lines) > c { + lines = lines[len(lines)-c:] + } + + return lines +} + func (s *ServerService) GetConfigJson() (any, error) { config, err := s.xrayService.GetXrayConfig() if err != nil { |
