mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-07-01 12:32:09 +00:00
2 / logs-blocked
This commit is contained in:
parent
b484bfd4cb
commit
e386ef6232
3 changed files with 32 additions and 0 deletions
|
@ -143,3 +143,19 @@ func GetLogsSniffedDomains(c int) []string {
|
|||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func GetLogsBlockedDomains(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, "[blocked] for ") {
|
||||
index := strings.LastIndex(logBuffer[i].log, "for [")
|
||||
if index != -1 {
|
||||
domain := strings.Replace(logBuffer[i].log[index+5:], "]", "", -1)
|
||||
output = append(output, fmt.Sprintf("%s - %s", logBuffer[i].time, domain))
|
||||
}
|
||||
}
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) {
|
|||
g.POST("/installXray/:version", a.installXray)
|
||||
g.POST("/logs/:count", a.getLogs)
|
||||
g.GET("/logs-sniffed/:count", a.getLogsSniffedDomains)
|
||||
g.GET("/logs-blocked/:count", a.getLogsBlockedDomains)
|
||||
g.POST("/getConfigJson", a.getConfigJson)
|
||||
g.GET("/getDb", a.getDb)
|
||||
g.POST("/importDB", a.importDB)
|
||||
|
@ -132,6 +133,12 @@ func (a *ServerController) getLogsSniffedDomains(c *gin.Context) {
|
|||
jsonObj(c, logs, nil)
|
||||
}
|
||||
|
||||
func (a *ServerController) getLogsBlockedDomains(c *gin.Context) {
|
||||
count := c.Param("count")
|
||||
logs := a.serverService.GetLogsBlockedDomains(count)
|
||||
jsonObj(c, logs, nil)
|
||||
}
|
||||
|
||||
func (a *ServerController) getConfigJson(c *gin.Context) {
|
||||
configJson, err := a.serverService.GetConfigJson()
|
||||
if err != nil {
|
||||
|
|
|
@ -451,6 +451,15 @@ func (s *ServerService) GetLogsSniffedDomains(count string) []string {
|
|||
return lines
|
||||
}
|
||||
|
||||
func (s *ServerService) GetLogsBlockedDomains(count string) []string {
|
||||
c, _ := strconv.Atoi(count)
|
||||
var lines []string
|
||||
|
||||
lines = logger.GetLogsBlockedDomains(c)
|
||||
|
||||
return lines
|
||||
}
|
||||
|
||||
func (s *ServerService) GetConfigJson() (interface{}, error) {
|
||||
config, err := s.xrayService.GetXrayConfig()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue