Skip to content

feat: Implement Per-Node Data Limits & Subscription Variables#215

Open
Rerowros wants to merge 11 commits intoPasarGuard:devfrom
Rerowros:feature/per-node-data-limits
Open

feat: Implement Per-Node Data Limits & Subscription Variables#215
Rerowros wants to merge 11 commits intoPasarGuard:devfrom
Rerowros:feature/per-node-data-limits

Conversation

@Rerowros
Copy link
Contributor

Summary

This PR implements full support for per-node data limits (user_data_limit), allowing granular traffic control for users on specific nodes. It also adds dynamic variables for subscription hosts.

Key Changes

  • Database: Added NodeUserLimit model and migrations. Added user_data_limit to Node
  • Logic:
    • Implemented priority system: Individual Limit > Template Limit > Node Default.
    • Added logic to propagate Node.user_data_limit changes to relevant users.
    • Fixed user creation/modification from templates to correctly apply node limits.
  • API:
    • Added endpoints for managing node user limits.
    • Added POST /api/user/{username}/reset-usage-by-node endpoint.
  • UI:
    • Added "User Limits" manager in User Modal.
    • Added "Traffic by Node" breakdown.
    • Added per-node settings in Node Modal.
  • Subscription:
    • Added per-node variables for Hosts (Remarks/Address/Path):
      • {NODE_USAGE_N}, {NODE_LIMIT_N}, {NODE_LEFT_N} (where N is node ID).
      • {NODE_NAME_N}.

Related PRs

Closes #212

…mits

- Add NodeUserLimit model for per-user per-node traffic limits
- Add node_user_limits field to UserTemplate model
- Add user_data_limit, user_data_limit_reset_strategy, user_reset_time to Node model
- Add migrations for all schema changes
- Add node_user_limit.py with get, create, modify, delete, upsert functions
- Add reset_user_node_usage to user.py for per-node usage reset
- Update user create to apply Node.user_data_limit defaults
- Add node_user_limits field handling to user_template
- Add _apply_node_limits_from_template using upsert for template priority
- Add _propagate_user_data_limit_change for Node.user_data_limit updates
- Add reset_user_node_usage operation method
- Fix MissingGreenlet errors with awaitable_attrs and proper refresh
- Update core_users to filter users by per-node limits
- Add /api/node-user-limits router with CRUD endpoints
- Add /api/user/{username}/reset-usage-by-node endpoint
- Add /api/user/{username}/node-limits and node-traffic endpoints
- Add ResetNodeUsageRequest model
- Add limit_enforcer settings to General model
- Add NodeLimitsManager component for user modal
- Add node-user-limits table and dialog components
- Add reset-usage-dialog for per-node usage reset
- Add traffic-modal for viewing node traffic breakdown
- Update node-modal with user_data_limit fields
- Update user-template-modal with node_user_limits support
- Add translations for en and ru locales
- Add test_template_fix.py for node_user_limits template tests
- Add test_limits_fix.py for node data limit tests
- Update conftest and helpers for test infrastructure
- Add _apply_node_limits_from_template call to modify_user_with_template
- Add traffic_by_node translation to en.json and ru.json
- Add NODE_USAGE_N, NODE_LIMIT_N, NODE_LEFT_N, NODE_NAME_N variables
- Add node_traffic field to UsersResponseWithInbounds
- Load per-node usage and limits in validated_user
- Variables can be used in host remarks like {NODE_USAGE_1}/{ NODE_LIMIT_1}
@coderabbitai
Copy link

coderabbitai bot commented Jan 17, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

for limit in limits
]
etag_content = json.dumps(limits_data, sort_keys=True)
etag = f'"{hashlib.md5(etag_content.encode()).hexdigest()}"'

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic hashing algorithm on sensitive data High

Sensitive data (id)
is used in a hashing algorithm (MD5) that is insecure.
@M03ED
Copy link
Contributor

M03ED commented Jan 31, 2026

thanks for your effort
this can be good feature but its huge changes and need lots of improvements
first thing is behavior when a user reach limit on a node you restart the whole xray to just sync a single user, this is the main problem for now
users must be transferred to node same as other functions not using sync_users method and refresh the whole process
also there is changes on node it self and doing Node->Panel request and i don't understand it completely, node is not allowed for this
also i don't think node and change (or even node_bridge package)
all of this can be handled inside panel with much simpler logic
also you have bunch of errors in test and formatting
stick with this and fix the problems, i check it again
but i should say were not going to accept this before nats-io branch get completed, because we don't want to face conflict at this point

@M03ED M03ED force-pushed the dev branch 2 times, most recently from ecaae08 to be80f83 Compare February 15, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants