mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-12-18 13:14:39 +03:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user