2 / GetLogsSniffedDomains

This commit is contained in:
serogaq 2024-11-13 12:47:52 +03:00
parent 2919ce2f29
commit 59330cb3a2
No known key found for this signature in database
GPG key ID: 6657A27160536D7E
3 changed files with 33 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"time" "time"
"strings"
"github.com/op/go-logging" "github.com/op/go-logging"
) )
@ -126,3 +127,19 @@ func GetLogs(c int, level string) []string {
} }
return output 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
}

View file

@ -45,6 +45,7 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) {
g.POST("/restartXrayService", a.restartXrayService) g.POST("/restartXrayService", a.restartXrayService)
g.POST("/installXray/:version", a.installXray) g.POST("/installXray/:version", a.installXray)
g.POST("/logs/:count", a.getLogs) g.POST("/logs/:count", a.getLogs)
g.GET("/logs-sniffed/:count", a.getLogsSniffedDomains)
g.POST("/getConfigJson", a.getConfigJson) g.POST("/getConfigJson", a.getConfigJson)
g.GET("/getDb", a.getDb) g.GET("/getDb", a.getDb)
g.POST("/importDB", a.importDB) g.POST("/importDB", a.importDB)
@ -125,6 +126,12 @@ func (a *ServerController) getLogs(c *gin.Context) {
jsonObj(c, logs, nil) 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) { func (a *ServerController) getConfigJson(c *gin.Context) {
configJson, err := a.serverService.GetConfigJson() configJson, err := a.serverService.GetConfigJson()
if err != nil { if err != nil {

View file

@ -442,6 +442,15 @@ func (s *ServerService) GetLogs(count string, level string, syslog string) []str
return lines 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) { func (s *ServerService) GetConfigJson() (interface{}, error) {
config, err := s.xrayService.GetXrayConfig() config, err := s.xrayService.GetXrayConfig()
if err != nil { if err != nil {