Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfgsfds <4870330+fgsfds@users.noreply.github.com>2025-08-05 13:10:14 +0300
committerGitHub <noreply@github.com>2025-08-05 13:10:14 +0300
commit419ea63dd0f7f2a693dbf674e411782301e06dc6 (patch)
tree062e7194ba32d04729f0da3df0aa11557c5c34c4 /web/service
parent6a17285935cad302286d1aed0bb2357b56cf173f (diff)
Added filters to the xray logs viewer (#3314)
* added filters to xray logs viewer * better freedom/blackhole tags handling * better freedom/blackhole tags handling 2 * fix comments * fix comments 2
Diffstat (limited to 'web/service')
-rw-r--r--web/service/server.go56
1 files changed, 50 insertions, 6 deletions
diff --git a/web/service/server.go b/web/service/server.go
index 2b174e8b..ee13b268 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -482,8 +482,16 @@ func (s *ServerService) GetLogs(count string, level string, syslog string) []str
return lines
}
-func (s *ServerService) GetXrayLogs(count string) []string {
- c, _ := strconv.Atoi(count)
+func (s *ServerService) GetXrayLogs(
+ count string,
+ filter string,
+ showDirect string,
+ showBlocked string,
+ showProxy string,
+ freedoms []string,
+ blackholes []string) []string {
+
+ countInt, _ := strconv.Atoi(count)
var lines []string
pathToAccessLog, err := xray.GetAccessLogPath()
@@ -498,21 +506,57 @@ func (s *ServerService) GetXrayLogs(count string) []string {
defer file.Close()
scanner := bufio.NewScanner(file)
+
for scanner.Scan() {
- line := scanner.Text()
- if strings.TrimSpace(line) == "" || strings.Contains(line, "api -> api") {
+ line := strings.TrimSpace(scanner.Text())
+
+ if line == "" || strings.Contains(line, "api -> api") {
+ //skipping empty lines and api calls
continue
}
+
+ if filter != "" && !strings.Contains(line, filter) {
+ //applying filter if it's not empty
+ continue
+ }
+
+ //adding suffixes to further distinguish entries by outbound
+ if hasSuffix(line, freedoms) {
+ if showDirect == "false" {
+ continue
+ }
+ line = line + " f"
+ } else if hasSuffix(line, blackholes) {
+ if showBlocked == "false" {
+ continue
+ }
+ line = line + " b"
+ } else {
+ if showProxy == "false" {
+ continue
+ }
+ line = line + " p"
+ }
+
lines = append(lines, line)
}
- if len(lines) > c {
- lines = lines[len(lines)-c:]
+ if len(lines) > countInt {
+ lines = lines[len(lines)-countInt:]
}
return lines
}
+func hasSuffix(line string, suffixes []string) bool {
+ for _, sfx := range suffixes {
+ if strings.HasSuffix(line, sfx+"]") {
+ return true
+ }
+ }
+ return false
+}
+
func (s *ServerService) GetConfigJson() (any, error) {
config, err := s.xrayService.GetXrayConfig()
if err != nil {