diff --git a/web/controller/server.go b/web/controller/server.go
index 22f89f2f..9e167153 100644
--- a/web/controller/server.go
+++ b/web/controller/server.go
@@ -46,6 +46,7 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) {
g.POST("/installXray/:version", a.installXray)
g.POST("/updateGeofile/:fileName", a.updateGeofile)
g.POST("/logs/:count", a.getLogs)
+ g.POST("/xraylogs/:count", a.getXrayLogs)
g.POST("/getConfigJson", a.getConfigJson)
g.GET("/getDb", a.getDb)
g.POST("/importDB", a.importDB)
@@ -133,6 +134,12 @@ func (a *ServerController) getLogs(c *gin.Context) {
jsonObj(c, logs, nil)
}
+func (a *ServerController) getXrayLogs(c *gin.Context) {
+ count := c.Param("count")
+ logs := a.serverService.GetXrayLogs(count)
+ jsonObj(c, logs, nil)
+}
+
func (a *ServerController) getConfigJson(c *gin.Context) {
configJson, err := a.serverService.GetConfigJson()
if err != nil {
diff --git a/web/html/index.html b/web/html/index.html
index db678cd6..b60ebf7b 100644
--- a/web/html/index.html
+++ b/web/html/index.html
@@ -167,7 +167,10 @@
{{ i18n "pages.index.xrayErrorPopoverTitle" }}
-
+
+
+
+
@@ -179,6 +182,10 @@
+
+
+ {{ i18n "pages.index.logs" }}
+
{{ i18n "pages.index.stopXray" }}
@@ -422,6 +429,38 @@
+ xraylogModal.visible = false"
+ :class="themeSwitcher.currentTheme"
+ width="1200px" footer="">
+
+ {{ i18n "pages.index.logs" }}
+
+
+
+
+
+
+
+ 10
+ 20
+ 50
+ 100
+ 500
+
+
+
+
+
+
+
+
+
0 ? this.formatLogs(this.logs) : "No Record...";
+ },
+ formatLogs(logs) {
+ let formattedLogs = '';
+
+ logs.forEach((log, index) => {
+ if(index > 0) formattedLogs += '
';
+
+ const parts = log.split(' ');
+
+ if(parts.length === 9) {
+ const dateTime = `${parts[0]} ${parts[1]}`;
+ const from = `${parts[3]}`;
+ const to = `${parts[5].replace(/^\/+/, "")}`;
+
+ let outboundColor = '';
+ if (parts[8].startsWith('blocked')) {
+ outboundColor = ' style="color: #e04141;"';
+ }
+ else if (!parts[8].startsWith('direct')) {
+ outboundColor = ' style="color: #3c89e8;"';
+ }
+
+ formattedLogs += `
+${dateTime}
+ ${parts[2]}
+ ${from}
+ ${parts[4]}
+ ${to}
+ ${parts.slice(6).join(' ')}
+`;
+ } else {
+ formattedLogs += `${parts.join(' ')}`;
+ }
+ });
+
+ return formattedLogs;
+ },
+ hide() {
+ this.visible = false;
+ },
+ };
+
const backupModal = {
visible: false,
show() {
@@ -629,6 +719,7 @@
status: new Status(),
versionModal,
logModal,
+ xraylogModal,
backupModal,
loadingTip: '{{ i18n "loading"}}',
showAlert: false,
@@ -721,6 +812,16 @@
await PromiseUtil.sleep(500);
logModal.loading = false;
},
+ async openXrayLogs(){
+ xraylogModal.loading = true;
+ const msg = await HttpUtil.post('server/xraylogs/'+xraylogModal.rows);
+ if (!msg.success) {
+ return;
+ }
+ xraylogModal.show(msg.obj);
+ await PromiseUtil.sleep(500);
+ xraylogModal.loading = false;
+ },
async openConfig() {
this.loading(true);
const msg = await HttpUtil.post('server/getConfigJson');
diff --git a/web/service/server.go b/web/service/server.go
index e75a97b8..ea118f13 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -2,6 +2,7 @@ package service
import (
"archive/zip"
+ "bufio"
"bytes"
"encoding/json"
"fmt"
@@ -481,6 +482,37 @@ func (s *ServerService) GetLogs(count string, level string, syslog string) []str
return lines
}
+func (s *ServerService) GetXrayLogs(count string) []string {
+ c, _ := strconv.Atoi(count)
+ var lines []string
+
+ pathToAccessLog, err := xray.GetAccessLogPath()
+ if err != nil {
+ return lines
+ }
+
+ file, err := os.Open(pathToAccessLog)
+ if err != nil {
+ return lines
+ }
+ defer file.Close()
+
+ scanner := bufio.NewScanner(file)
+ for scanner.Scan() {
+ line := scanner.Text()
+ if strings.TrimSpace(line) == "" || strings.Contains(line, "api -> api") {
+ continue
+ }
+ lines = append(lines, line)
+ }
+
+ if len(lines) > c {
+ lines = lines[len(lines)-c:]
+ }
+
+ return lines
+}
+
func (s *ServerService) GetConfigJson() (any, error) {
config, err := s.xrayService.GetXrayConfig()
if err != nil {