Added xray access log viewer (#3309)

* added xray access log viewer

* made modal window width adaptive

* hide logs button if xray logs are disabled
This commit is contained in:
fgsfds
2025-08-04 21:47:48 +05:00
committed by GitHub
parent 05e60af283
commit 957f3dbb54
3 changed files with 151 additions and 2 deletions

View File

@@ -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 {