From 214b217f12194b0778a70a5699518263b99d0e9a Mon Sep 17 00:00:00 2001 From: sprov <47310637+sprov065@users.noreply.github.com> Date: Sat, 12 Jun 2021 11:26:35 +0800 Subject: [PATCH] 0.0.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加设置总流量功能,流量超出后自动禁用 - 优化部分 ui 细节 - 修复监听 ip 不为空导致无法启动 xray 的问题 - 修复二维码链接没有包含 address 的问题 --- README.md | 38 ++++++++++++++++++++++- a.s | 0 config/config.go | 12 ++++++-- config/name | 1 + config/version | 1 + database/model/model.go | 12 ++++++-- main.go | 7 ++--- web/assets/js/model/models.js | 9 ++++++ web/assets/js/util/utils.js | 2 +- web/global/global.go | 3 +- web/html/xui/form/inbound.html | 12 ++++++++ web/html/xui/inbounds.html | 55 ++++++++++++++++++++++++---------- web/service/inbound.go | 13 ++++++++ web/web.go | 20 +++++++++---- 14 files changed, 149 insertions(+), 36 deletions(-) delete mode 100644 a.s create mode 100644 config/name create mode 100644 config/version diff --git a/README.md b/README.md index 2110bb2637..75b290d4cf 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,38 @@ # x-ui -a web panel based on xray-core +支持多协议多用户 xray 面板 + +# 功能介绍 +- 系统状态监控 +- 支持多用户多协议,网页可视化操作 +- 支持的协议:vmess、vless、trojan、shadowsocks、dokodemo-door、socks、http +- 支持配置更多传输配置 +- 账号流量统计 +- 可自定义 xray 配置模板 +- 支持 https 访问面板(自备域名 + ssl 证书) +- 更多高级配置项,详见面板 + +# 安装&升级 +## 测试版 +``` +bash <(curl -Ls https://raw.githubusercontent.com/sprov065/x-ui/master/install.sh) 0.0.1 +``` + +## 建议系统 +- CentOS 7+ +- Ubuntu 16+ +- Debian 8+ + +# 常见问题 +## 与 v2-ui 关系 +x-ui 相当于 v2-ui 的加强版,未来会加入更多功能,待 x-ui 功能稳定后,v2-ui 将不再提供更新 + +x-ui 可与 v2-ui 并存,数据不互通,不影响对方的运行 + +# Telegram +群组:https://t.me/sprov_blog + +频道:https://t.me/sprov_channel + +## Stargazers over time + +[![Stargazers over time](https://starchart.cc/sprov065/x-ui.svg)](https://starchart.cc/sprov065/x-ui) diff --git a/a.s b/a.s deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/config/config.go b/config/config.go index 50f67ac84a..e1c7f911fb 100644 --- a/config/config.go +++ b/config/config.go @@ -1,10 +1,18 @@ package config import ( + _ "embed" "fmt" "os" + "strings" ) +//go:embed version +var version string + +//go:embed name +var name string + type LogLevel string const ( @@ -15,11 +23,11 @@ const ( ) func GetVersion() string { - return "0.0.1" + return strings.TrimSpace(version) } func GetName() string { - return "x-ui" + return strings.TrimSpace(name) } func GetLogLevel() LogLevel { diff --git a/config/name b/config/name new file mode 100644 index 0000000000..491114af6b --- /dev/null +++ b/config/name @@ -0,0 +1 @@ +x-ui \ No newline at end of file diff --git a/config/version b/config/version new file mode 100644 index 0000000000..7bcd0e3612 --- /dev/null +++ b/config/version @@ -0,0 +1 @@ +0.0.2 \ No newline at end of file diff --git a/database/model/model.go b/database/model/model.go index 1c325cfecf..bc19444598 100644 --- a/database/model/model.go +++ b/database/model/model.go @@ -1,6 +1,7 @@ package model import ( + "fmt" "x-ui/util/json_util" "x-ui/xray" ) @@ -25,8 +26,9 @@ type User struct { type Inbound struct { Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"` UserId int `json:"-"` - Up int64 `json:"up"` - Down int64 `json:"down"` + Up int64 `json:"up" form:"up"` + Down int64 `json:"down" form:"down"` + Total int64 `json:"total" form:"total"` Remark string `json:"remark" form:"remark"` Enable bool `json:"enable" form:"enable"` ExpiryTime int64 `json:"expiryTime" form:"expiryTime"` @@ -42,8 +44,12 @@ type Inbound struct { } func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig { + listen := i.Listen + if listen != "" { + listen = fmt.Sprintf("\"%v\"", listen) + } return &xray.InboundConfig{ - Listen: json_util.RawMessage(i.Listen), + Listen: json_util.RawMessage(listen), Port: i.Port, Protocol: string(i.Protocol), Settings: json_util.RawMessage(i.Settings), diff --git a/main.go b/main.go index 4d1f771b8d..f9c2390ebd 100644 --- a/main.go +++ b/main.go @@ -18,9 +18,6 @@ import ( "x-ui/web/service" ) -// this function call global.setWebServer -func setWebServer(server global.WebServer) - func runWebServer() { log.Printf("%v %v", config.GetName(), config.GetVersion()) @@ -45,7 +42,7 @@ func runWebServer() { var server *web.Server server = web.NewServer() - setWebServer(server) + global.SetWebServer(server) err = server.Start() if err != nil { log.Println(err) @@ -60,7 +57,7 @@ func runWebServer() { if sig == syscall.SIGHUP { server.Stop() server = web.NewServer() - setWebServer(server) + global.SetWebServer(server) err = server.Start() if err != nil { log.Println(err) diff --git a/web/assets/js/model/models.js b/web/assets/js/model/models.js index 650d247790..7fbed0cee0 100644 --- a/web/assets/js/model/models.js +++ b/web/assets/js/model/models.js @@ -26,6 +26,7 @@ class DBInbound { userId = 0; up = 0; down = 0; + total = 0; remark = ""; enable = true; expiryTime = 0; @@ -45,6 +46,14 @@ class DBInbound { ObjectUtil.cloneProps(this, data); } + get totalGB() { + return toFixed(this.total / ONE_GB, 2); + } + + set totalGB(gb) { + this.total = toFixed(gb * ONE_GB, 0); + } + toInbound() { let settings = {}; if (!ObjectUtil.isEmpty(this.settings)) { diff --git a/web/assets/js/util/utils.js b/web/assets/js/util/utils.js index 78beb20439..9c6d38e941 100644 --- a/web/assets/js/util/utils.js +++ b/web/assets/js/util/utils.js @@ -284,7 +284,7 @@ class ObjectUtil { return false; } } - return true + return true; } } diff --git a/web/global/global.go b/web/global/global.go index f8bfd02d53..09d0683a33 100644 --- a/web/global/global.go +++ b/web/global/global.go @@ -13,8 +13,7 @@ type WebServer interface { GetCtx() context.Context } -//go:linkname setWebServer main.setWebServer -func setWebServer(s WebServer) { +func SetWebServer(s WebServer) { webServer = s } diff --git a/web/html/xui/form/inbound.html b/web/html/xui/form/inbound.html index dafe467d13..64da61e90b 100644 --- a/web/html/xui/form/inbound.html +++ b/web/html/xui/form/inbound.html @@ -27,6 +27,18 @@ + + + 总流量(GB) + + + + + + + diff --git a/web/html/xui/inbounds.html b/web/html/xui/inbounds.html index a0e7aa9f81..3649d4a1d8 100644 --- a/web/html/xui/inbounds.html +++ b/web/html/xui/inbounds.html @@ -27,15 +27,15 @@ - upload / download: + 总上传 / 下载: [[ sizeFormat(total.up) ]] / [[ sizeFormat(total.down) ]] - total traffic: + 总用量: [[ sizeFormat(total.up + total.down) ]] - number of accounts: + 入站数量: [[ dbInbounds.length ]] @@ -59,6 +59,8 @@