feat(sub): add per-client subscription HWID limits (#5802)

* feat(sub): add per-client subscription HWID limits

* fix(sub): address HWID review on shared subId and bulk create

* fix(sub): store HWID devices by sub_id and drop anchor client workaround

* fix(sub): restore UA auto-detect and HTML page routing in subs()

The cherry-pick of the HWID gate onto main's refactored SUBController
had dropped main's UA-based format auto-detection and sub-page handling
from subs(). Restore those branches, slotting enforceHwid after the
HTML page and before format detection so the gate only applies to
machine-readable subscription bodies.

Also adapt tests to main's options-struct constructor and to the
ClientService.Update signature extended with limitHwid.

* fix(frontend): drop axios from HttpUtil.delete

The bulk-delete rework's committed version still referenced axios,
which this file no longer imports, breaking typecheck in CI. Use the
httpRequest wrapper like the other verbs.

---------

Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
Rouzbeh†
2026-08-15 18:20:20 +03:30
committed by GitHub
parent 1793a9b8b4
commit 694ad6deae
45 changed files with 1212 additions and 50 deletions
+25
View File
@@ -914,6 +914,7 @@ type ClientRecord struct {
Secret string `json:"secret" gorm:"column:secret"`
AdTag string `json:"adTag" gorm:"column:ad_tag;default:''"`
LimitIP int `json:"limitIp" gorm:"column:limit_ip"`
LimitHwid int `json:"limitHwid" gorm:"column:limit_hwid;default:0"`
TotalGB int64 `json:"totalGB" gorm:"column:total_gb"`
ExpiryTime int64 `json:"expiryTime" gorm:"column:expiry_time"`
Enable bool `json:"enable" gorm:"default:true"`
@@ -981,6 +982,20 @@ type ClientInbound struct {
func (ClientInbound) TableName() string { return "client_inbounds" }
type ClientHwid struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
SubID string `json:"subId" gorm:"column:sub_id;not null;index;uniqueIndex:idx_client_hwids_sub_hash,priority:1"`
HwidHash string `json:"-" gorm:"column:hwid_hash;size:64;not null;uniqueIndex:idx_client_hwids_sub_hash,priority:2"`
FirstSeen int64 `json:"firstSeen" gorm:"column:first_seen;not null"`
LastSeen int64 `json:"lastSeen" gorm:"column:last_seen;not null;index"`
UserAgent string `json:"userAgent" gorm:"column:user_agent"`
DeviceOS string `json:"deviceOs" gorm:"column:device_os"`
OsVersion string `json:"osVersion" gorm:"column:os_version"`
DeviceModel string `json:"deviceModel" gorm:"column:device_model"`
}
func (ClientHwid) TableName() string { return "client_hwids" }
// ClientExternalLink is a per-client entry surfaced in the client's
// subscription. Two kinds:
// - "link": a single third-party share link (vless://, vmess://, trojan://,
@@ -1267,6 +1282,16 @@ func MergeClientRecord(existing *ClientRecord, incoming *ClientRecord) []ClientM
existing.LimitIP = picked
}
}
if existing.LimitHwid != incoming.LimitHwid && incoming.LimitHwid != 0 {
picked := existing.LimitHwid
if existing.LimitHwid == 0 || incoming.LimitHwid > existing.LimitHwid {
picked = incoming.LimitHwid
}
if picked != existing.LimitHwid {
keep("limitHwid", existing.LimitHwid, incoming.LimitHwid, picked)
existing.LimitHwid = picked
}
}
if existing.TgID != incoming.TgID && incoming.TgID != 0 {
if incomingNewer || existing.TgID == 0 {
keep("tgId", existing.TgID, incoming.TgID, incoming.TgID)