From e91daabb188d890803834ee509dfd899ce47db6f Mon Sep 17 00:00:00 2001 From: sprov <47310637+sprov065@users.noreply.github.com> Date: Tue, 15 Jun 2021 11:10:39 +0800 Subject: [PATCH] 0.1.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 改进 ui 界面 - 修复流量超出后账号不自动失效问题 - 修复vless生成的链接不正确问题 - 修复网页端重启面板功能问题 --- config/version | 2 +- main.go | 5 +- web/assets/js/model/models.js | 36 ++++++++++- web/assets/js/model/xray.js | 79 +++++++++++++++++++++++- web/controller/inbound.go | 9 ++- web/html/xui/component/inbound_info.html | 71 +++++++++++++++++++++ web/html/xui/form/protocol/vless.html | 2 +- web/html/xui/inbound_info_modal.html | 42 +++++++++++++ web/html/xui/inbounds.html | 51 ++++++++------- web/html/xui/setting.html | 14 ++--- web/service/inbound.go | 4 +- web/service/xray.go | 14 +++-- web/web.go | 33 ++++++---- 13 files changed, 303 insertions(+), 59 deletions(-) create mode 100644 web/html/xui/component/inbound_info.html create mode 100644 web/html/xui/inbound_info_modal.html diff --git a/config/version b/config/version index 7bcd0e36..6c6aa7cb 100644 --- a/config/version +++ b/config/version @@ -1 +1 @@ -0.0.2 \ No newline at end of file +0.1.0 \ No newline at end of file diff --git a/main.go b/main.go index f9c2390e..19ad8724 100644 --- a/main.go +++ b/main.go @@ -55,7 +55,10 @@ func runWebServer() { sig := <-sigCh if sig == syscall.SIGHUP { - server.Stop() + err := server.Stop() + if err != nil { + logger.Warning("stop server err:", err) + } server = web.NewServer() global.SetWebServer(server) err = server.Start() diff --git a/web/assets/js/model/models.js b/web/assets/js/model/models.js index 7fbed0ce..e0ad55d8 100644 --- a/web/assets/js/model/models.js +++ b/web/assets/js/model/models.js @@ -54,6 +54,38 @@ class DBInbound { this.total = toFixed(gb * ONE_GB, 0); } + get isVMess() { + return this.protocol === Protocols.VMESS; + } + + get isVLess() { + return this.protocol === Protocols.VLESS; + } + + get isTrojan() { + return this.protocol === Protocols.TROJAN; + } + + get isSS() { + return this.protocol === Protocols.SHADOWSOCKS; + } + + get isSocks() { + return this.protocol === Protocols.SOCKS; + } + + get isHTTP() { + return this.protocol === Protocols.HTTP; + } + + get address() { + let address = location.hostname; + if (!ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0") { + address = this.listen; + } + return address; + } + toInbound() { let settings = {}; if (!ObjectUtil.isEmpty(this.settings)) { @@ -93,9 +125,9 @@ class DBInbound { } } - genLink(address = "") { + genLink() { const inbound = this.toInbound(); - return inbound.genLink(address, this.remark); + return inbound.genLink(this.address, this.remark); } } diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js index 7acf1d4e..d50875f7 100644 --- a/web/assets/js/model/xray.js +++ b/web/assets/js/model/xray.js @@ -643,6 +643,81 @@ class Inbound extends XrayCommonClass { this.stream.network = network; } + // VMess & VLess + get uuid() { + switch (this.protocol) { + case Protocols.VMESS: + return this.settings.vmesses[0].id; + case Protocols.VLESS: + return this.settings.vlesses[0].id; + default: + return ""; + } + } + + // VLess + get flow() { + switch (this.protocol) { + case Protocols.VLESS: + return this.settings.vlesses[0].flow; + default: + return ""; + } + } + + // VMess + get alterId() { + switch (this.protocol) { + case Protocols.VMESS: + return this.settings.vmesses[0].alterId; + default: + return ""; + } + } + + // Socks & HTTP + get username() { + switch (this.protocol) { + case Protocols.SOCKS: + case Protocols.HTTP: + return this.settings.accounts[0].user; + default: + return ""; + } + } + + // Trojan & Shadowsocks & Socks & HTTP + get password() { + switch (this.protocol) { + case Protocols.TROJAN: + return this.settings.clients[0].password; + case Protocols.SHADOWSOCKS: + return this.settings.password; + case Protocols.SOCKS: + case Protocols.HTTP: + return this.settings.accounts[0].pass; + default: + return ""; + } + } + + // Shadowsocks + get method() { + switch (this.protocol) { + case Protocols.SHADOWSOCKS: + return this.settings.method; + default: + return ""; + } + } + + get serverName() { + if (this.stream.isTls || this.stream.isXTls) { + return this.stream.tls.server; + } + return ""; + } + canEnableTls() { switch (this.protocol) { case Protocols.VMESS: @@ -785,7 +860,7 @@ class Inbound extends XrayCommonClass { const type = this.stream.network; const params = new Map(); params.set("type", this.stream.network); - if (this.isXTls) { + if (this.xtls) { params.set("security", "xtls"); } else { params.set("security", this.stream.security); @@ -841,7 +916,7 @@ class Inbound extends XrayCommonClass { } } - if (this.isXTls) { + if (this.xtls) { params.set("flow", this.settings.vlesses[0].flow); } diff --git a/web/controller/inbound.go b/web/controller/inbound.go index dc97c16d..07dacfe7 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -36,8 +36,7 @@ func (a *InboundController) startTask() { webServer := global.GetWebServer() c := webServer.GetCron() c.AddFunc("@every 10s", func() { - if a.xrayService.IsNeedRestart() { - a.xrayService.SetIsNeedRestart(false) + if a.xrayService.IsNeedRestartAndSetFalse() { err := a.xrayService.RestartXray() if err != nil { logger.Error("restart xray failed:", err) @@ -70,7 +69,7 @@ func (a *InboundController) addInbound(c *gin.Context) { err = a.inboundService.AddInbound(inbound) jsonMsg(c, "添加", err) if err == nil { - a.xrayService.SetIsNeedRestart(true) + a.xrayService.SetToNeedRestart() } } @@ -83,7 +82,7 @@ func (a *InboundController) delInbound(c *gin.Context) { err = a.inboundService.DelInbound(id) jsonMsg(c, "删除", err) if err == nil { - a.xrayService.SetIsNeedRestart(true) + a.xrayService.SetToNeedRestart() } } @@ -104,6 +103,6 @@ func (a *InboundController) updateInbound(c *gin.Context) { err = a.inboundService.UpdateInbound(inbound) jsonMsg(c, "修改", err) if err == nil { - a.xrayService.SetIsNeedRestart(true) + a.xrayService.SetToNeedRestart() } } diff --git a/web/html/xui/component/inbound_info.html b/web/html/xui/component/inbound_info.html new file mode 100644 index 00000000..bf1c30ef --- /dev/null +++ b/web/html/xui/component/inbound_info.html @@ -0,0 +1,71 @@ +{{define "inboundInfoStream"}} +
传输:
tls:
xtls:
tls:
+ tls域名:
+ xtls域名:
协议:
地址:
端口:
uuid:
alterId:
uuid:
flow:
密码:
加密:
密码:
用户名:
密码:
用户名:
密码: