From cad007455796c4afcb1e1e3b4e5800cccafe890c Mon Sep 17 00:00:00 2001 From: egregors Date: Sun, 31 Aug 2025 18:48:56 +0200 Subject: [PATCH 1/7] Add periodic traffic reset feature model and ui with localization support --- database/model/model.go | 52 +++++++++++++------------ web/assets/js/model/dbinbound.js | 1 + web/assets/js/model/inbound.js | 14 +++++++ web/html/form/client.html | 18 +++++++++ web/html/form/inbound.html | 18 +++++++++ web/html/inbounds.html | 6 +++ web/html/modals/client_bulk_modal.html | 20 ++++++++++ web/html/modals/inbound_info_modal.html | 6 +++ web/translation/translate.ar_EG.toml | 8 ++++ web/translation/translate.en_US.toml | 8 ++++ web/translation/translate.es_ES.toml | 8 ++++ web/translation/translate.fa_IR.toml | 10 ++++- web/translation/translate.id_ID.toml | 8 ++++ web/translation/translate.ja_JP.toml | 8 ++++ web/translation/translate.pt_BR.toml | 8 ++++ web/translation/translate.ru_RU.toml | 8 ++++ web/translation/translate.tr_TR.toml | 8 ++++ web/translation/translate.uk_UA.toml | 8 ++++ web/translation/translate.vi_VN.toml | 8 ++++ web/translation/translate.zh_CN.toml | 8 ++++ web/translation/translate.zh_TW.toml | 8 ++++ 21 files changed, 215 insertions(+), 26 deletions(-) diff --git a/database/model/model.go b/database/model/model.go index 18211ef8..9d9fb0ef 100644 --- a/database/model/model.go +++ b/database/model/model.go @@ -27,16 +27,17 @@ type User struct { } type Inbound struct { - Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"` - UserId int `json:"-"` - Up int64 `json:"up" form:"up"` - Down int64 `json:"down" form:"down"` - Total int64 `json:"total" form:"total"` - AllTime int64 `json:"allTime" form:"allTime" gorm:"default:0"` - Remark string `json:"remark" form:"remark"` - Enable bool `json:"enable" form:"enable"` - ExpiryTime int64 `json:"expiryTime" form:"expiryTime"` - ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"` + Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"` + UserId int `json:"-"` + Up int64 `json:"up" form:"up"` + Down int64 `json:"down" form:"down"` + Total int64 `json:"total" form:"total"` + AllTime int64 `json:"allTime" form:"allTime" gorm:"default:0"` + Remark string `json:"remark" form:"remark"` + Enable bool `json:"enable" form:"enable"` + ExpiryTime int64 `json:"expiryTime" form:"expiryTime"` + PeriodicTrafficReset string `json:"periodicTrafficReset" form:"periodicTrafficReset" gorm:"default:never"` + ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"` // config part Listen string `json:"listen" form:"listen"` @@ -90,19 +91,20 @@ type Setting struct { } type Client struct { - ID string `json:"id"` - Security string `json:"security"` - Password string `json:"password"` - Flow string `json:"flow"` - Email string `json:"email"` - LimitIP int `json:"limitIp"` - TotalGB int64 `json:"totalGB" form:"totalGB"` - ExpiryTime int64 `json:"expiryTime" form:"expiryTime"` - Enable bool `json:"enable" form:"enable"` - TgID int64 `json:"tgId" form:"tgId"` - SubID string `json:"subId" form:"subId"` - Comment string `json:"comment" form:"comment"` - Reset int `json:"reset" form:"reset"` - CreatedAt int64 `json:"created_at,omitempty"` - UpdatedAt int64 `json:"updated_at,omitempty"` + ID string `json:"id"` + Security string `json:"security"` + Password string `json:"password"` + Flow string `json:"flow"` + Email string `json:"email"` + LimitIP int `json:"limitIp"` + TotalGB int64 `json:"totalGB" form:"totalGB"` + ExpiryTime int64 `json:"expiryTime" form:"expiryTime"` + Enable bool `json:"enable" form:"enable"` + TgID int64 `json:"tgId" form:"tgId"` + SubID string `json:"subId" form:"subId"` + Comment string `json:"comment" form:"comment"` + Reset int `json:"reset" form:"reset"` + PeriodicTrafficReset string `json:"periodicTrafficReset" form:"periodicTrafficReset"` + CreatedAt int64 `json:"created_at,omitempty"` + UpdatedAt int64 `json:"updated_at,omitempty"` } diff --git a/web/assets/js/model/dbinbound.js b/web/assets/js/model/dbinbound.js index acb62ce4..8687e781 100644 --- a/web/assets/js/model/dbinbound.js +++ b/web/assets/js/model/dbinbound.js @@ -10,6 +10,7 @@ class DBInbound { this.remark = ""; this.enable = true; this.expiryTime = 0; + this.periodicTrafficReset = "never"; this.listen = ""; this.port = 0; diff --git a/web/assets/js/model/inbound.js b/web/assets/js/model/inbound.js index c91dbd11..ec70a3c0 100644 --- a/web/assets/js/model/inbound.js +++ b/web/assets/js/model/inbound.js @@ -1792,6 +1792,7 @@ Inbound.VmessSettings.VMESS = class extends XrayCommonClass { subId = RandomUtil.randomLowerAndNum(16), comment = '', reset = 0, + periodicTrafficReset = 'never', created_at = undefined, updated_at = undefined ) { @@ -1807,6 +1808,7 @@ Inbound.VmessSettings.VMESS = class extends XrayCommonClass { this.subId = subId; this.comment = comment; this.reset = reset; + this.periodicTrafficReset = periodicTrafficReset; this.created_at = created_at; this.updated_at = updated_at; } @@ -1824,6 +1826,7 @@ Inbound.VmessSettings.VMESS = class extends XrayCommonClass { json.subId, json.comment, json.reset, + json.periodicTrafficReset, json.created_at, json.updated_at, ); @@ -1907,6 +1910,7 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass { subId = RandomUtil.randomLowerAndNum(16), comment = '', reset = 0, + periodicTrafficReset = 'never', created_at = undefined, updated_at = undefined ) { @@ -1922,6 +1926,7 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass { this.subId = subId; this.comment = comment; this.reset = reset; + this.periodicTrafficReset = periodicTrafficReset; this.created_at = created_at; this.updated_at = updated_at; } @@ -1939,6 +1944,7 @@ Inbound.VLESSSettings.VLESS = class extends XrayCommonClass { json.subId, json.comment, json.reset, + json.periodicTrafficReset, json.created_at, json.updated_at, ); @@ -2052,6 +2058,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass { subId = RandomUtil.randomLowerAndNum(16), comment = '', reset = 0, + periodicTrafficReset = 'never', created_at = undefined, updated_at = undefined ) { @@ -2066,6 +2073,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass { this.subId = subId; this.comment = comment; this.reset = reset; + this.periodicTrafficReset = periodicTrafficReset; this.created_at = created_at; this.updated_at = updated_at; } @@ -2082,6 +2090,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass { subId: this.subId, comment: this.comment, reset: this.reset, + periodicTrafficReset: this.periodicTrafficReset, created_at: this.created_at, updated_at: this.updated_at, }; @@ -2099,6 +2108,7 @@ Inbound.TrojanSettings.Trojan = class extends XrayCommonClass { json.subId, json.comment, json.reset, + json.periodicTrafficReset, json.created_at, json.updated_at, ); @@ -2221,6 +2231,7 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass { subId = RandomUtil.randomLowerAndNum(16), comment = '', reset = 0, + periodicTrafficReset = 'never', created_at = undefined, updated_at = undefined ) { @@ -2236,6 +2247,7 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass { this.subId = subId; this.comment = comment; this.reset = reset; + this.periodicTrafficReset = periodicTrafficReset; this.created_at = created_at; this.updated_at = updated_at; } @@ -2253,6 +2265,7 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass { subId: this.subId, comment: this.comment, reset: this.reset, + periodicTrafficReset: this.periodicTrafficReset, created_at: this.created_at, updated_at: this.updated_at, }; @@ -2271,6 +2284,7 @@ Inbound.ShadowsocksSettings.Shadowsocks = class extends XrayCommonClass { json.subId, json.comment, json.reset, + json.periodicTrafficReset, json.created_at, json.updated_at, ); diff --git a/web/html/form/client.html b/web/html/form/client.html index 908f28d2..fd205def 100644 --- a/web/html/form/client.html +++ b/web/html/form/client.html @@ -168,5 +168,23 @@ + + + + + {{ i18n "pages.inbounds.periodicTrafficReset.never" }} + {{ i18n "pages.inbounds.periodicTrafficReset.daily" }} + {{ i18n "pages.inbounds.periodicTrafficReset.weekly" }} + {{ i18n "pages.inbounds.periodicTrafficReset.monthly" }} + + {{end}} \ No newline at end of file diff --git a/web/html/form/inbound.html b/web/html/form/inbound.html index 9554d6aa..04f0f50c 100644 --- a/web/html/form/inbound.html +++ b/web/html/form/inbound.html @@ -61,6 +61,24 @@ value="dbInbound._expiryTime" v-model="dbInbound._expiryTime"> + + + + + {{ i18n "pages.inbounds.periodicTrafficReset.never" }} + {{ i18n "pages.inbounds.periodicTrafficReset.daily" }} + {{ i18n "pages.inbounds.periodicTrafficReset.weekly" }} + {{ i18n "pages.inbounds.periodicTrafficReset.monthly" }} + + diff --git a/web/html/inbounds.html b/web/html/inbounds.html index b0d9828f..fcae8289 100644 --- a/web/html/inbounds.html +++ b/web/html/inbounds.html @@ -645,6 +645,12 @@ + + {{ i18n "pages.inbounds.periodicTrafficResetTitle" }} + + [[ i18n("pages.inbounds.periodicTrafficReset." + dbInbound.periodicTrafficReset) ]] + + diff --git a/web/html/modals/client_bulk_modal.html b/web/html/modals/client_bulk_modal.html index ac0fa011..c08983bd 100644 --- a/web/html/modals/client_bulk_modal.html +++ b/web/html/modals/client_bulk_modal.html @@ -122,6 +122,23 @@ + + + + {{ i18n "pages.inbounds.periodicTrafficReset.never" }} + {{ i18n "pages.inbounds.periodicTrafficReset.daily" }} + {{ i18n "pages.inbounds.periodicTrafficReset.weekly" }} + {{ i18n "pages.inbounds.periodicTrafficReset.monthly" }} + +