mirror of
				https://github.com/MHSanaei/3x-ui.git
				synced 2025-10-29 19:32:51 +00:00 
			
		
		
		
	2 / GetLogsSniffedDomains
This commit is contained in:
		
							parent
							
								
									2919ce2f29
								
							
						
					
					
						commit
						59330cb3a2
					
				
					 3 changed files with 33 additions and 0 deletions
				
			
		|  | @ -4,6 +4,7 @@ import ( | |||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"time" | ||||
| 	"strings" | ||||
| 
 | ||||
| 	"github.com/op/go-logging" | ||||
| ) | ||||
|  | @ -126,3 +127,19 @@ func GetLogs(c int, level string) []string { | |||
| 	} | ||||
| 	return output | ||||
| } | ||||
| 
 | ||||
| func GetLogsSniffedDomains(c int) []string { | ||||
| 	var output []string | ||||
| 	logLevel, _ := logging.LogLevel("info") | ||||
| 
 | ||||
| 	for i := len(logBuffer) - 1; i >= 0 && len(output) <= c; i-- { | ||||
| 		if logBuffer[i].level <= logLevel && strings.Contains(logBuffer[i].log, "sniffed domain: ") { | ||||
| 			index := strings.LastIndex(log, ": ") | ||||
| 			if index != -1 { | ||||
| 				domain := log[index+2:] | ||||
| 				output = append(output, fmt.Sprintf("%s - %s", logBuffer[i].time, domain)) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return output | ||||
| } | ||||
|  |  | |||
|  | @ -45,6 +45,7 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) { | |||
| 	g.POST("/restartXrayService", a.restartXrayService) | ||||
| 	g.POST("/installXray/:version", a.installXray) | ||||
| 	g.POST("/logs/:count", a.getLogs) | ||||
| 	g.GET("/logs-sniffed/:count", a.getLogsSniffedDomains) | ||||
| 	g.POST("/getConfigJson", a.getConfigJson) | ||||
| 	g.GET("/getDb", a.getDb) | ||||
| 	g.POST("/importDB", a.importDB) | ||||
|  | @ -125,6 +126,12 @@ func (a *ServerController) getLogs(c *gin.Context) { | |||
| 	jsonObj(c, logs, nil) | ||||
| } | ||||
| 
 | ||||
| func (a *ServerController) getLogsSniffedDomains(c *gin.Context) { | ||||
| 	count := c.Param("count") | ||||
| 	logs := a.serverService.GetLogsSniffedDomains(count) | ||||
| 	jsonObj(c, logs, nil) | ||||
| } | ||||
| 
 | ||||
| func (a *ServerController) getConfigJson(c *gin.Context) { | ||||
| 	configJson, err := a.serverService.GetConfigJson() | ||||
| 	if err != nil { | ||||
|  |  | |||
|  | @ -442,6 +442,15 @@ func (s *ServerService) GetLogs(count string, level string, syslog string) []str | |||
| 	return lines | ||||
| } | ||||
| 
 | ||||
| func (s *ServerService) GetLogsSniffedDomains(count string) []string { | ||||
| 	c, _ := strconv.Atoi(count) | ||||
| 	var lines []string | ||||
| 
 | ||||
| 	lines = logger.GetLogsSniffedDomains(c) | ||||
| 
 | ||||
| 	return lines | ||||
| } | ||||
| 
 | ||||
| func (s *ServerService) GetConfigJson() (interface{}, error) { | ||||
| 	config, err := s.xrayService.GetXrayConfig() | ||||
| 	if err != nil { | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 serogaq
						serogaq