[PR #4158] [CLOSED] feat: Shared Subscription Traffic Quota across multiple clients #5616

Closed
opened 2026-10-31 20:48:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4158
Author: @Sadegh-Kalami
Created: 5/4/2026
Status: ❌ Closed

Base: main ← Head: main


📝 Commits (3)

  • 32c7cee feat: implement shared subscription traffic quota across multiple inbounds
  • a52c3fd fix: reliable SubTotal synchronization across identical inbounds
  • cb66c1a feat: override traffic statistics with shared subscription quota if available

📊 Changes

24 files changed (+375 additions, -46 deletions)

View changed files

📝 database/db.go (+44 -0)
📝 database/model/model.go (+1 -0)
📝 sub/subService.go (+14 -0)
📝 web/assets/js/model/inbound.js (+22 -10)
📝 web/controller/inbound.go (+11 -0)
📝 web/html/component/aClientTable.html (+9 -1)
📝 web/html/form/client.html (+12 -0)
📝 web/html/modals/client_bulk_modal.html (+15 -0)
📝 web/html/modals/inbound_info_modal.html (+29 -0)
📝 web/service/inbound.go (+190 -34)
📝 web/translation/translate.ar_EG.toml (+2 -0)
📝 web/translation/translate.en_US.toml (+2 -0)
📝 web/translation/translate.es_ES.toml (+2 -0)
📝 web/translation/translate.fa_IR.toml (+2 -0)
📝 web/translation/translate.id_ID.toml (+2 -0)
📝 web/translation/translate.ja_JP.toml (+2 -0)
📝 web/translation/translate.pt_BR.toml (+2 -0)
📝 web/translation/translate.ru_RU.toml (+2 -0)
📝 web/translation/translate.tr_TR.toml (+2 -0)
📝 web/translation/translate.uk_UA.toml (+2 -0)

...and 4 more files

📄 Description

feat: Shared Subscription Traffic Quota across multiple inbounds

  • Added SubTotal synchronization across all clients sharing a SubID
  • Implemented real-time traffic aggregation for subscription groups
  • Updated UI to display shared remaining quota in info modals
  • Added full i18n support for 13 languages

What is the pull request?

This PR adds a Shared Subscription Quota feature. It allows administrators to set a single, aggregated traffic limit for multiple client configurations that share the same Subscription ID (SubID).

What users see

  • Sub. Total Flow Field: A new numeric input in the client configuration and edit modals.
  • Quota Synchronization: When multiple clients share the same SubID, updating the quota for one client automatically synchronizes that limit to all other clients in the same subscription group.
  • Shared Remaining Quota: The Inbound Info Modal now displays Remained (Sub.), showing the remaining traffic from the shared pool (calculated as: Shared Total - Combined Usage of all associated clients).
  • Full Localization: Support for all 13 languages in the panel, including consistent terminology ("Sub. Total Flow").

Why this is needed (Feature Goal)

Previously, traffic limits were strictly per-client/per-inbound. If a user was given multiple connection protocols (e.g., VLESS, VMess, Trojan) via the same subscription, there was no way to enforce a combined traffic limit for that user.

This feature enables a "pay-once, use-anywhere" model:

  1. Admins can provide multiple protocols to one user using a single SubID.
  2. All data usage across all protocols counts toward the same shared traffic ceiling.
  3. Once the shared limit is reached, all associated inbounds are restricted simultaneously.

Which part of the application is affected by the change?

  • Frontend
  • Backend

Type of Changes

  • Bug fix
  • New feature
  • Refactoring
  • Other

Technical Implementation Details

Backend

  • Service Layer (web/service/inbound.go):
    • Added SyncSubTotal to propagate SubTotal changes across all database records sharing a SubID.
    • Implemented GetSubTraffic to perform high-performance database-level aggregation of stats for subscription groups.
  • Controller Layer (web/controller/inbound.go):
    • Registered the /panel/inbound/getSubTraffic API endpoint.

Frontend

  • UI Logic (inbound_info_modal.html): Integrated dynamic fetch and calculation logic to display shared remaining quota.
  • Forms: Updated client forms to support the new subTotal field.
  • Localization: Updated all 13 translation .toml files with subTotalFlow and subTotalFlowDesc keys.

Screenshots

image image image

Verification

  • Sync Test: Verified that updating Client A's shared quota immediately updates Client B (same SubID) in the database and UI.
  • Aggregation Test: Confirmed that usage from different protocols sharing a SubID correctly calculates the collective remaining quota.
  • Compatibility: Verified that existing clients without a SubID or shared quota continue to work exactly as before without any data loss or logic changes.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/4158 **Author:** [@Sadegh-Kalami](https://github.com/Sadegh-Kalami) **Created:** 5/4/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (3) - [`32c7cee`](https://github.com/MHSanaei/3x-ui/commit/32c7ceec554f851b78baeb639546842fc387d6a5) feat: implement shared subscription traffic quota across multiple inbounds - [`a52c3fd`](https://github.com/MHSanaei/3x-ui/commit/a52c3fd768cabc1ef6264cb26083755b0f4e4ba5) fix: reliable SubTotal synchronization across identical inbounds - [`cb66c1a`](https://github.com/MHSanaei/3x-ui/commit/cb66c1a586789b694e7f77ae06ef77c0645d67d6) feat: override traffic statistics with shared subscription quota if available ### 📊 Changes **24 files changed** (+375 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `database/db.go` (+44 -0) 📝 `database/model/model.go` (+1 -0) 📝 `sub/subService.go` (+14 -0) 📝 `web/assets/js/model/inbound.js` (+22 -10) 📝 `web/controller/inbound.go` (+11 -0) 📝 `web/html/component/aClientTable.html` (+9 -1) 📝 `web/html/form/client.html` (+12 -0) 📝 `web/html/modals/client_bulk_modal.html` (+15 -0) 📝 `web/html/modals/inbound_info_modal.html` (+29 -0) 📝 `web/service/inbound.go` (+190 -34) 📝 `web/translation/translate.ar_EG.toml` (+2 -0) 📝 `web/translation/translate.en_US.toml` (+2 -0) 📝 `web/translation/translate.es_ES.toml` (+2 -0) 📝 `web/translation/translate.fa_IR.toml` (+2 -0) 📝 `web/translation/translate.id_ID.toml` (+2 -0) 📝 `web/translation/translate.ja_JP.toml` (+2 -0) 📝 `web/translation/translate.pt_BR.toml` (+2 -0) 📝 `web/translation/translate.ru_RU.toml` (+2 -0) 📝 `web/translation/translate.tr_TR.toml` (+2 -0) 📝 `web/translation/translate.uk_UA.toml` (+2 -0) _...and 4 more files_ </details> ### 📄 Description # feat: Shared Subscription Traffic Quota across multiple inbounds - Added SubTotal synchronization across all clients sharing a SubID - Implemented real-time traffic aggregation for subscription groups - Updated UI to display shared remaining quota in info modals - Added full i18n support for 13 languages ## What is the pull request? This PR adds a **Shared Subscription Quota** feature. It allows administrators to set a single, aggregated traffic limit for multiple client configurations that share the same Subscription ID (`SubID`). ### What users see - **Sub. Total Flow Field**: A new numeric input in the client configuration and edit modals. - **Quota Synchronization**: When multiple clients share the same `SubID`, updating the quota for one client automatically synchronizes that limit to all other clients in the same subscription group. - **Shared Remaining Quota**: The **Inbound Info Modal** now displays **Remained (Sub.)**, showing the remaining traffic from the shared pool (calculated as: `Shared Total - Combined Usage of all associated clients`). - **Full Localization**: Support for all 13 languages in the panel, including consistent terminology ("Sub. Total Flow"). ### Why this is needed (Feature Goal) Previously, traffic limits were strictly per-client/per-inbound. If a user was given multiple connection protocols (e.g., VLESS, VMess, Trojan) via the same subscription, there was no way to enforce a combined traffic limit for that user. This feature enables a **"pay-once, use-anywhere"** model: 1. Admins can provide multiple protocols to one user using a single `SubID`. 2. All data usage across all protocols counts toward the same shared traffic ceiling. 3. Once the shared limit is reached, all associated inbounds are restricted simultaneously. ## Which part of the application is affected by the change? - [x] Frontend - [x] Backend ## Type of Changes - [ ] Bug fix - [x] New feature - [ ] Refactoring - [ ] Other ## Technical Implementation Details ### Backend - **Service Layer (`web/service/inbound.go`)**: - Added `SyncSubTotal` to propagate `SubTotal` changes across all database records sharing a `SubID`. - Implemented `GetSubTraffic` to perform high-performance database-level aggregation of stats for subscription groups. - **Controller Layer (`web/controller/inbound.go`)**: - Registered the `/panel/inbound/getSubTraffic` API endpoint. ### Frontend - **UI Logic (`inbound_info_modal.html`)**: Integrated dynamic fetch and calculation logic to display shared remaining quota. - **Forms**: Updated client forms to support the new `subTotal` field. - **Localization**: Updated all 13 translation `.toml` files with `subTotalFlow` and `subTotalFlowDesc` keys. ## Screenshots <img width="2207" height="139" alt="image" src="https://github.com/user-attachments/assets/dae8b173-2521-41e9-aa31-b8c9d5551d20" /> <img width="751" height="1126" alt="image" src="https://github.com/user-attachments/assets/91e21a40-46c0-4a5a-8a36-652c6454de87" /> <img width="2205" height="661" alt="image" src="https://github.com/user-attachments/assets/e4879992-5230-4c23-ab00-c1f9e945cfde" /> <!-- Add screenshots to illustrate the changes --> <!-- [Attach Screenshot of Client Modal with Sub. Total Flow field] --> <!-- [Attach Screenshot of Info Modal with Remained (Sub.) display] --> ## Verification - **Sync Test**: Verified that updating Client A's shared quota immediately updates Client B (same `SubID`) in the database and UI. - **Aggregation Test**: Confirmed that usage from different protocols sharing a `SubID` correctly calculates the collective remaining quota. - **Compatibility**: Verified that existing clients without a `SubID` or shared quota continue to work exactly as before without any data loss or logic changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:48:11 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5616
No description provided.