mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-08-23 03:16:52 +00:00
better freedom/blackhole tags handling
This commit is contained in:
parent
3c4905db9a
commit
ddd47d69da
2 changed files with 61 additions and 9 deletions
|
@ -18,6 +18,7 @@ type ServerController struct {
|
|||
BaseController
|
||||
|
||||
serverService service.ServerService
|
||||
settingService service.SettingService
|
||||
|
||||
lastStatus *service.Status
|
||||
lastGetStatusTime time.Time
|
||||
|
@ -141,7 +142,41 @@ func (a *ServerController) getXrayLogs(c *gin.Context) {
|
|||
showDirect := c.PostForm("showDirect")
|
||||
showBlocked := c.PostForm("showBlocked")
|
||||
showProxy := c.PostForm("showProxy")
|
||||
logs := a.serverService.GetXrayLogs(count, filter, showDirect, showBlocked, showProxy)
|
||||
|
||||
var freedoms []string
|
||||
var blackholes []string
|
||||
|
||||
//getting tags for freedom and blackhole outbounds
|
||||
config, err := a.settingService.GetDefaultXrayConfig()
|
||||
if err == nil && config != nil {
|
||||
if cfgMap, ok := config.(map[string]interface{}); ok {
|
||||
if outbounds, ok := cfgMap["outbounds"].([]interface{}); ok {
|
||||
for _, outbound := range outbounds {
|
||||
if obMap, ok := outbound.(map[string]interface{}); ok {
|
||||
switch obMap["protocol"] {
|
||||
case "freedom":
|
||||
if tag, ok := obMap["tag"].(string); ok {
|
||||
freedoms = append(freedoms, tag)
|
||||
}
|
||||
case "blackhole":
|
||||
if tag, ok := obMap["tag"].(string); ok {
|
||||
blackholes = append(blackholes, tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(freedoms) == 0 {
|
||||
freedoms = []string{"direct"}
|
||||
}
|
||||
if len(blackholes) == 0 {
|
||||
blackholes = []string{"blocked"}
|
||||
}
|
||||
|
||||
logs := a.serverService.GetXrayLogs(count, filter, showDirect, showBlocked, showProxy, freedoms, blackholes)
|
||||
jsonObj(c, logs, nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -482,7 +482,14 @@ func (s *ServerService) GetLogs(count string, level string, syslog string) []str
|
|||
return lines
|
||||
}
|
||||
|
||||
func (s *ServerService) GetXrayLogs(count string, filter string, showDirect string, showBlocked string, showProxy string) []string {
|
||||
func (s *ServerService) GetXrayLogs(
|
||||
count string,
|
||||
filter string,
|
||||
showDirect string,
|
||||
showBlocked string,
|
||||
showProxy string,
|
||||
freedoms []string,
|
||||
blackholes []string) []string {
|
||||
c, _ := strconv.Atoi(count)
|
||||
var lines []string
|
||||
|
||||
|
@ -498,22 +505,23 @@ func (s *ServerService) GetXrayLogs(count string, filter string, showDirect stri
|
|||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
if strings.TrimSpace(line) == "" || strings.Contains(line, "api -> api") {
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
if line == "" || strings.Contains(line, "api -> api") {
|
||||
continue
|
||||
}
|
||||
if filter != "" && !strings.Contains(line, filter) {
|
||||
continue
|
||||
}
|
||||
if showDirect == "false" && strings.HasSuffix(line, "direct]") {
|
||||
|
||||
if showDirect == "false" && hasSuffix(line, freedoms) {
|
||||
continue
|
||||
}
|
||||
if showBlocked == "false" && strings.HasSuffix(line, "blocked]") {
|
||||
if showBlocked == "false" && hasSuffix(line, blackholes) {
|
||||
continue
|
||||
}
|
||||
if showProxy == "false" && !strings.HasSuffix(line, "blocked]") && !strings.HasSuffix(line, "direct]") {
|
||||
if showProxy == "false" && !hasSuffix(line, append(freedoms, blackholes...)) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -527,6 +535,15 @@ func (s *ServerService) GetXrayLogs(count string, filter string, showDirect stri
|
|||
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 {
|
||||
|
|
Loading…
Reference in a new issue