mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6357] [Feature]: Read-only HWID device-slot status on the subscription API (registered / limit / remaining) #4312
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4312
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Namso9 on GitHub (Aug 29, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6357
Is your feature request related to a problem?
When a client has an HWID device limit, the subscriber has no way to see how many
device slots they have used. The subscription API only exposes whether the gate is
active:
X-Hwid-Active: true and X-Hwid-Not-Supported: true — a boolean state only.
limitHwid and no registered-device count.
The counts already exist internally (clients.limit_hwid and the client_hwids
table) and the admin panel displays them, but that path requires an admin session.
So a subscriber whose single slot is already taken just sees a failed connection
with no explanation, and every "why can't I connect on my new phone" case has to
be answered manually by the operator.
Describe the solution you'd like
Add one additive, public, read-only aggregate endpoint on the subscription router:
GET /{subPath}/{subId}/hwid-status
Response:
{
"active": true,
"limit": 1,
"registered": 1,
"remaining": 0,
"full": true
}
Behaviour:
not call the existing enforcement path.
no User-Agent.
admin token and no new auth mechanism is needed.
A separate route keeps the existing response contracts untouched: /{subPath}/{subId},
?format=info, and the JSON/Clash routes all stay exactly as they are, so no
existing client is affected.
Roughly, this is a new SELECT-only helper next to the existing HWID service, a new
handler file, and one route registration in the subscription router's initRouter.
Alternatives you've considered
contract that third-party panels already parse.
data would only be visible after a connection attempt has already failed.
to a public-facing service, which is not acceptable.
seems generally useful rather than specific to one deployment.
Concrete use case
I run a subscription service where each plan has a one-device HWID limit, with a
customer-facing web panel that renders the subscription link. Today that panel can
show quota and expiry but nothing about devices. With this endpoint it could show
"Devices 1/1 — no slots remaining" or "1 slot remaining", so the customer
understands why a second device fails instead of opening a support ticket.
The same applies to any reseller bot or panel built on the subscription API.
Mockups, screenshots, or examples
Request:
curl -fsS 'https://panel.example.com:2096/api/SUB_ID/hwid-status'
Full:
{"active":true,"limit":1,"registered":1,"remaining":0,"full":true}
Slot free:
{"active":true,"limit":2,"registered":1,"remaining":1,"full":false}
No HWID limit:
{"active":false,"limit":0,"registered":0,"remaining":0,"full":false}
Customer-facing rendering: "Devices 1/1 · Device limit full".
Which parts of the panel would this affect?
Subscription (share links / Clash / JSON)
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Aug 29, 2026):
The gap you describe is real: I confirmed in the source that nothing on the subscription server exposes HWID slot counts today, so this is a valid feature request. Below is what I verified, plus three things that make the change smaller than your write-up assumes and two caveats worth deciding before anyone builds it.
What the code actually does today
The subscription router registers only the three body routes — there is no fourth path under
subPath(internal/sub/controller.go:290-304):?format=inforeturnssubPageContext(page)withlinksdeleted (internal/sub/controller.go:326-340), and that map (internal/sub/controller.go:596-619) carries traffic, expiry, online state and URLs — nolimitHwid, no device count. Your reading is correct.The only HWID signal on the wire is the four booleans in
applyHwidHeaders(internal/sub/controller.go:642-655):X-Hwid-Active,X-Hwid-Not-Supported,X-Hwid-Limit,X-Hwid-Max-Devices-Reached.The counts are otherwise admin-only, as you said:
POST /panel/api/inbounds/hwids/:email(internal/web/controller/client.go:79) →ClientService.ListClientHwids(internal/web/service/client_hwid.go:159).Three things that make this cheaper than the proposal assumes
1. The aggregate already exists and already reaches the sub controller.
HwidGateResultcarries both numbers (internal/web/service/client_hwid.go:30-31):EnforceHwidForSubIDpopulates them, andenforceHwidreceives the whole struct atinternal/sub/controller.go:634—applyHwidHeadersjust never serializes those two fields.2. The SELECT-only helper you describe is one
Countaway.effectiveHwidLimitForSubID(internal/web/service/client_hwid.go:70-77) is already a pure SELECT, and the registered count is the same query used atclient_hwid.go:127and:139. So a read-only helper needs no new query shape and, as you say, no migration.3. Your
active/limit/registeredshape matches storage exactly. The limit is per subscription, not per client —COALESCE(MAX(limit_hwid), 0)over enabled clients sharing thesub_id(client_hwid.go:73-74) — and devices are keyed bysub_id, so the aggregate is well defined for asubIdwith several clients attached.One premise to correct, which does not change your conclusion
applyHwidHeaders(c, result)runs atinternal/sub/controller.go:634, before theif !result.Allowedcheck on line 635 — so those headers are on 200 responses too, not only on the 404. Your conclusion still holds for your use case, though, for a different reason: a caller that sends noX-HWID(a customer-facing panel) hits the early return atclient_hwid.go:100-103, which setsNotSupportedand returns before any count runs. On that pathRegisteredis 0 andLimitis set, so simply emitting the existing fields as headers would not answer "how many slots are used" for your panel.Your other requirements are already existing behaviour rather than new work: an unknown
subIdon the info surface already 404s viawriteSubError, pinned byTestSubInfoEndpoint_UnknownSubIs404(internal/sub/info_endpoint_test.go:81-96), and the precedent for a non-gated info surface undersubPathisTestSubscriptionHwidGateSkipsHtmlInfoPage(internal/sub/hwid_controller_test.go:124-134) plus the ordering insubs(), wheremaybeServeSubInforuns at line 389 andenforceHwidonly at line 397.Two caveats for whoever decides this
grepforAccess-Control-Allow-Originacross every.gofile in the tree returns nothing — the subscription server sets no CORS headers at all. Yourcurlexample works, and a server-side proxy in your panel works, but a browserfetch()from your panel's own origin to the sub server will be blocked. That is orthogonal to this endpoint but decides whether it is usable the way your mockup implies.?format=infoserializes amap[string]any; adding keys leaves every existing key and value byte-identical, so a third-party parser that readstotal/expireis not affected. It would also feed the HTML sub page'swindow.__SUB_PAGE_DATA__from the same place with no new route. A separate endpoint is still the cleaner contract — just noting the trade-off is smaller than "changes an existing response contract" suggests.For scope: sub-server routes sit outside
TestRouteRegistryContract(internal/web/routes_contract_test.go:25-29), so a new route here does not pull in theendpoints.ts/ openapigen chain that/panel/api/*routes require.Related, not a duplicate: #6331 asks for placeholder configs instead of a 404 when the HWID limit is hit — same underlying frustration ("the subscriber cannot tell why it failed"), different mechanism, so I have left both open. HWID limits themselves landed in
694ad6de(#5802) and shipped in v3.7.0; nothing since adds a subscription-side status surface.Whether this is accepted and in what shape is the maintainer's call.
Verdict: Feature request
This reply was generated automatically; a maintainer may follow up.