From 3152d5f1910de3019a7b06e9f45bb4466e1c3483 Mon Sep 17 00:00:00 2001 From: MHSanaei <33454419+MHSanaei@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:47:14 +0330 Subject: [PATCH 1/9] Remove ugly-bugy qrCode footer --- web/html/common/qrcode_modal.html | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/web/html/common/qrcode_modal.html b/web/html/common/qrcode_modal.html index e535b401..f492dabb 100644 --- a/web/html/common/qrcode_modal.html +++ b/web/html/common/qrcode_modal.html @@ -1,9 +1,10 @@ {{define "qrcodeModal"}} - {{ i18n "pages.inbounds.clickOnQRcode" }} + :footer="null" + width="300px"> + {{ i18n "pages.inbounds.clickOnQRcode" }} @@ -14,17 +15,15 @@ content: '', inbound: new Inbound(), dbInbound: new DBInbound(), - okText: '', copyText: '', qrcode: null, clipboard: null, visible: false, - show: function (title='', content='', dbInbound=new DBInbound(),okText='{{ i18n "copy" }}', copyText='') { + show: function (title='', content='', dbInbound=new DBInbound(), copyText='') { this.title = title; this.content = content; this.dbInbound = dbInbound; this.inbound = dbInbound.toInbound(); - this.okText = okText; if (ObjectUtil.isEmpty(copyText)) { this.copyText = content; } else { @@ -32,13 +31,6 @@ } this.visible = true; qrModalApp.$nextTick(() => { - this.clipboard = new ClipboardJS('#qr-modal-ok-btn', { - text: () => this.copyText, - }); - this.clipboard.on('success', () => { - app.$message.success('{{ i18n "copied" }}') - this.clipboard.destroy(); - }); if (this.qrcode === null) { this.qrcode = new QRious({ element: document.querySelector('#qrCode'), From f0d4dbf8382f42c9189f606ac8520d6405ee8f05 Mon Sep 17 00:00:00 2001 From: MHSanaei <33454419+MHSanaei@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:50:10 +0330 Subject: [PATCH 2/9] [tgbot] fix exhausted report --- web/service/tgbot.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web/service/tgbot.go b/web/service/tgbot.go index 63aa86ac..e88edbdf 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -473,7 +473,7 @@ func (t *Tgbot) getExhausted() string { } ExpireThreshold, err := t.settingService.GetTgExpireDiff() if err == nil && ExpireThreshold > 0 { - exDiff = int64(ExpireThreshold) * 84600 + exDiff = int64(ExpireThreshold) * 84600000 } inbounds, err := t.inboundService.GetAllInbounds() if err != nil { @@ -481,14 +481,14 @@ func (t *Tgbot) getExhausted() string { } for _, inbound := range inbounds { if inbound.Enable { - if (inbound.ExpiryTime > 0 && (now-inbound.ExpiryTime < exDiff)) || + if (inbound.ExpiryTime > 0 && (inbound.ExpiryTime-now < exDiff)) || (inbound.Total > 0 && (inbound.Total-inbound.Up+inbound.Down < trDiff)) { exhaustedInbounds = append(exhaustedInbounds, *inbound) } if len(inbound.ClientStats) > 0 { for _, client := range inbound.ClientStats { if client.Enable { - if (client.ExpiryTime > 0 && (now-client.ExpiryTime < exDiff)) || + if (client.ExpiryTime > 0 && (client.ExpiryTime-now < exDiff)) || (client.Total > 0 && (client.Total-client.Up+client.Down < trDiff)) { exhaustedClients = append(exhaustedClients, client) } @@ -502,7 +502,7 @@ func (t *Tgbot) getExhausted() string { } } output += fmt.Sprintf("Exhausted Inbounds count:\r\n🛑 Disabled: %d\r\n🔜 Exhaust soon: %d\r\n \r\n", len(disabledInbounds), len(exhaustedInbounds)) - if len(disabledInbounds)+len(exhaustedInbounds) > 0 { + if len(exhaustedInbounds) > 0 { output += "Exhausted Inbounds:\r\n" for _, inbound := range exhaustedInbounds { output += fmt.Sprintf("📍Inbound:%s\r\nPort:%d\r\nTraffic: %s (↑%s,↓%s)\r\n", inbound.Remark, inbound.Port, common.FormatTraffic((inbound.Up + inbound.Down)), common.FormatTraffic(inbound.Up), common.FormatTraffic(inbound.Down)) @@ -514,7 +514,7 @@ func (t *Tgbot) getExhausted() string { } } output += fmt.Sprintf("Exhausted Clients count:\r\n🛑 Disabled: %d\r\n🔜 Exhaust soon: %d\r\n \r\n", len(disabledClients), len(exhaustedClients)) - if len(disabledClients)+len(exhaustedClients) > 0 { + if len(exhaustedClients) > 0 { output += "Exhausted Clients:\r\n" for _, traffic := range exhaustedClients { expiryTime := "" @@ -529,7 +529,7 @@ func (t *Tgbot) getExhausted() string { } else { total = common.FormatTraffic((traffic.Total)) } - output += fmt.Sprintf("💡 Active: %t\r\n📧 Email: %s\r\n🔼 Upload↑: %s\r\n🔽 Download↓: %s\r\n🔄 Total: %s / %s\r\n📅 Expire in: %s\r\n", + output += fmt.Sprintf("💡 Active: %t\r\n📧 Email: %s\r\n🔼 Upload↑: %s\r\n🔽 Download↓: %s\r\n🔄 Total: %s / %s\r\n📅 Expire date: %s\r\n \r\n", traffic.Enable, traffic.Email, common.FormatTraffic(traffic.Up), common.FormatTraffic(traffic.Down), common.FormatTraffic((traffic.Up + traffic.Down)), total, expiryTime) } From 8dad9a4338142a566de038ee409bf3ce9b4ab949 Mon Sep 17 00:00:00 2001 From: MHSanaei <33454419+MHSanaei@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:51:43 +0330 Subject: [PATCH 3/9] [tgbot] fix admins input --- web/html/xui/setting.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/html/xui/setting.html b/web/html/xui/setting.html index 0c0f9682..f8f873e6 100644 --- a/web/html/xui/setting.html +++ b/web/html/xui/setting.html @@ -117,7 +117,7 @@ - + From 03a6c131f994e0d7984b07b153acc6a6ca943f10 Mon Sep 17 00:00:00 2001 From: MHSanaei <33454419+MHSanaei@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:54:21 +0330 Subject: [PATCH 4/9] [infoModal] better display --- web/html/xui/inbound_info_modal.html | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/web/html/xui/inbound_info_modal.html b/web/html/xui/inbound_info_modal.html index 0e1b1415..6de729f9 100644 --- a/web/html/xui/inbound_info_modal.html +++ b/web/html/xui/inbound_info_modal.html @@ -59,13 +59,11 @@ {{ i18n "pages.inbounds.client" }} - - - [[ col ]] - - - [[ col ]] - + + + [[ col ]] + [[ infoModal.clientSettings[col] ]] + {{ i18n "usage" }}{{ i18n "pages.inbounds.totalFlow" }}{{ i18n "pages.inbounds.expireDate" }}{{ i18n "enable" }} From a6dfdcdd316f53444a30ae7fa6038f252f1b20b7 Mon Sep 17 00:00:00 2001 From: MHSanaei <33454419+MHSanaei@users.noreply.github.com> Date: Fri, 24 Mar 2023 17:08:30 +0330 Subject: [PATCH 5/9] Add version and log --- web/controller/server.go | 21 ++++++++++---- web/html/xui/index.html | 47 ++++++++++++++++++++++++++---- web/html/xui/setting.html | 4 +-- web/service/inbound.go | 10 +++++++ web/service/server.go | 47 +++++++++++++++++++++++------- web/service/tgbot.go | 60 ++++++++++++++++++++++++++++++++++----- 6 files changed, 158 insertions(+), 31 deletions(-) diff --git a/web/controller/server.go b/web/controller/server.go index 673a96d8..7b7239d5 100644 --- a/web/controller/server.go +++ b/web/controller/server.go @@ -1,10 +1,11 @@ package controller import ( - "github.com/gin-gonic/gin" "time" "x-ui/web/global" "x-ui/web/service" + + "github.com/gin-gonic/gin" ) type ServerController struct { @@ -37,6 +38,7 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) { g.POST("/stopXrayService", a.stopXrayService) g.POST("/restartXrayService", a.restartXrayService) g.POST("/installXray/:version", a.installXray) + g.POST("/logs", a.getLogs) } func (a *ServerController) refreshStatus() { @@ -87,13 +89,13 @@ func (a *ServerController) installXray(c *gin.Context) { } func (a *ServerController) stopXrayService(c *gin.Context) { - a.lastGetStatusTime = time.Now() + a.lastGetStatusTime = time.Now() err := a.serverService.StopXrayService() if err != nil { jsonMsg(c, "", err) return } - jsonMsg(c, "Xray stoped",err) + jsonMsg(c, "Xray stoped", err) } func (a *ServerController) restartXrayService(c *gin.Context) { @@ -102,6 +104,15 @@ func (a *ServerController) restartXrayService(c *gin.Context) { jsonMsg(c, "", err) return } - jsonMsg(c, "Xray restarted",err) + jsonMsg(c, "Xray restarted", err) -} \ No newline at end of file +} + +func (a *ServerController) getLogs(c *gin.Context) { + logs, err := a.serverService.GetLogs() + if err != nil { + jsonMsg(c, I18n(c, "getLogs"), err) + return + } + jsonObj(c, logs, nil) +} diff --git a/web/html/xui/index.html b/web/html/xui/index.html index b8a1e4b5..713d5b7e 100644 --- a/web/html/xui/index.html +++ b/web/html/xui/index.html @@ -84,16 +84,18 @@ - [[ status.xray.version ]] - {{ i18n "pages.index.stopXray" }} - {{ i18n "pages.index.restartXray" }} - {{ i18n "pages.index.xraySwitch" }} + [[ status.xray.version ]] + {{ i18n "pages.index.stopXray" }} + {{ i18n "pages.index.restartXray" }} + {{ i18n "pages.index.xraySwitch" }} + x-ui: {{ .cur_ver }} + Logs {{ i18n "pages.index.operationHours" }}: - [[ formatSecond(status.uptime) ]] + [[ formatSecond(status.uptime) ]] {{ i18n "pages.index.operationHoursDesc" }} @@ -177,7 +179,7 @@ versionModal.visible = false" :class="siderDrawer.isDarkTheme ? darkClass : ''" - ok-text='{{ i18n "confirm" }}' cancel-text='{{ i18n "cancel"}}'> + footer=""> {{ i18n "pages.index.xraySwitchClick"}} {{ i18n "pages.index.xraySwitchClickDesk"}} @@ -187,6 +189,17 @@ + logModal.visible = false" @cancel="() => logModal.visible = false" + :class="siderDrawer.isDarkTheme ? darkClass : ''" + width="800px" + footer=""> + + + [[ index ]][[ log ]] + + + {{template "js" .}}