[PR #3635] [CLOSED] feat: 3X-UI(3.0.0) Multi-Node Architecture, Client Management, HWID Tracking, Host Management, Glass Morphism UI & Redis Cache #5492

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/3635
Author: @konstpic
Created: 1/6/2026
Status: ❌ Closed

Base: main ← Head: node-mode


📝 Commits (10+)

  • d7175e7 multi-node support
  • cdd90de edit nodes config,api,checks,dash
  • 09c5c05 edit nodes config,api,checks,dash
  • 37906b7 edit nodes config,api,checks,dash
  • 3d3ad23 edit nodes config,api,checks,dash
  • 8a5c270 Merge branch 'main' into node-mode
  • 5d355f9 Remove unnecessary files from PR
  • 42b28a5 Restore dokcer-compose.yml
  • b6f336a translate to eng
  • 66662af feat: add geo files to nodes and fix func inbounds

📊 Changes

86 files changed (+14439 additions, -1123 deletions)

View changed files

➕ README_node_mode.md (+172 -0)
📝 database/db.go (+7 -0)
📝 database/model/model.go (+130 -0)
📝 docker-compose.yml (+5 -0)
📝 go.mod (+14 -0)
📝 go.sum (+10 -0)
📝 logger/logger.go (+34 -5)
📝 main.go (+7 -0)
➕ node/Dockerfile (+124 -0)
➕ node/README.md (+79 -0)
➕ node/api/server.go (+303 -0)
➕ node/bin/config.json (+1 -0)
➕ node/config/config.go (+156 -0)
➕ node/docker-compose.yml (+23 -0)
➕ node/logs/pusher.go (+346 -0)
➕ node/main.go (+114 -0)
➕ node/xray/manager.go (+541 -0)
📝 sub/subController.go (+13 -5)
📝 sub/subJsonService.go (+15 -1)
📝 sub/subService.go (+1364 -217)

...and 66 more files

📄 Description

Multi-Node Architecture, Client Management, HWID Tracking, Host Management, Glass Morphism UI & Redis Cache

Description

This pull request introduces a comprehensive architectural overhaul of the 3x-ui panel, adding support for distributed multi-node architecture, independent client management with many-to-many relationships, hardware ID tracking, host management for load balancing, a modern Glass Morphism UI theme, and Redis caching for improved performance.

What Changed?

1. Node Mechanism (Multi-Node Architecture)

Overview

The panel now supports distributed architecture with multiple worker nodes. Instead of running XRAY Core locally, the panel can manage multiple remote nodes running XRAY Core instances.

Node Registration and Interaction

Node Registration Process:

  1. Adding a Node: Users can add nodes through the UI by providing:

  2. Automatic API Key Validation: When adding or updating a node, the system:

    • Validates the API key by making a test request to the node
    • Checks node availability before saving
    • Verifies the node responds correctly to health checks
  3. Node Health Monitoring:

    • Automatic health checks every 5 minutes (CheckNodeHealthJob)
    • Manual health check via UI button
    • Status indicators: online (green), offline (orange), unknown (gray)
    • Response time measurement in milliseconds

Node Interaction

API Endpoints on Panel:

  • GET /panel/node/list - Get list of all nodes
  • GET /panel/node/get/:id - Get information about a specific node
  • POST /panel/node/add - Add a new node (with validation)
  • POST /panel/node/update/:id - Update a node (supports partial updates)
  • POST /panel/node/del/:id - Delete a node
  • POST /panel/node/check/:id - Check health of a specific node
  • POST /panel/node/checkAll - Check health of all nodes
  • POST /panel/node/reload/:id - Reload XRAY on a node
  • POST /panel/node/reloadAll - Reload XRAY on all nodes
  • GET /panel/node/status/:id - Get detailed status of a node

Node Service API (on Worker Nodes):

  • POST /api/v1/apply - Apply XRAY configuration
  • POST /api/v1/reload - Reload XRAY
  • POST /api/v1/force-reload - Force reload XRAY
  • GET /api/v1/status - Get XRAY status
  • GET /api/v1/stats - Get traffic statistics and online clients
  • GET /health - Health check endpoint (no authentication required)

Configuration Synchronization:

  • When an inbound is created/updated, configuration is sent to all assigned nodes
  • Configurations are sent in parallel using goroutines for performance
  • Each node receives only the inbounds assigned to it
  • Automatic retry logic for failed requests

Statistics Collection:

  • Automatic collection every 30 seconds (CollectNodeStatsJob)
  • Traffic statistics aggregated by client email across all nodes
  • Online client information collected from each node
  • Statistics stored directly in ClientEntity table

2. Client Entities (Many-to-Many with Inbounds)

Overview

Clients are now independent entities stored in a separate client_entities table. A single client can be assigned to multiple inbounds, enabling flexible configuration management.

Client Entity Structure

type ClientEntity struct {
    Id         int     // Unique identifier
    UserId     int     // Associated user ID
    Email      string  // Client email (unique per user)
    UUID       string  // UUID for VMESS/VLESS
    Password   string  // Password for Trojan/Shadowsocks
    Security   string  // Encryption method
    Flow       string  // Flow control (XTLS)
    LimitIP    int     // IP limit
    TotalGB    float64 // Traffic limit in GB (supports decimals like 0.01)
    ExpiryTime int64   // Expiration timestamp
    Enable     bool    // Whether client is enabled
    Status     string  // Status: active, expired_traffic, expired_time
    
    // Traffic statistics stored directly in ClientEntity
    Up         int64   // Upload traffic in bytes
    Down       int64   // Download traffic in bytes
    AllTime    int64   // All-time traffic usage
    LastOnline int64   // Last online timestamp
    
    // HWID restrictions
    HWIDEnabled bool   // Whether HWID tracking is enabled
    MaxHWID     int    // Maximum allowed devices (0 = unlimited)
    
    // Relations (loaded via JOIN, not stored in table)
    InboundIds []int   // Inbound IDs this client is assigned to
}

Many-to-Many Relationship

ClientInboundMapping Table:

type ClientInboundMapping struct {
    Id        int // Unique identifier
    ClientId  int // Client ID
    InboundId int // Inbound ID
}

How It Works:

  • One client can be assigned to multiple inbounds
  • One inbound can have multiple clients
  • When a client is created/updated, ClientInboundMapping records are created/updated
  • Inbound.Settings is automatically regenerated from all assigned ClientEntity records

Benefits:

  • Reuse clients across multiple inbounds
  • Centralized client management
  • Traffic statistics aggregated per client (not per inbound-client pair)
  • Easier client updates (change once, applies to all inbounds)

API Endpoints

  • GET /panel/client/list - Get all clients for user
  • GET /panel/client/get/:id - Get client by ID
  • POST /panel/client/add - Add new client (with inbound assignments)
  • POST /panel/client/update/:id - Update client (updates all related inbounds)
  • POST /panel/client/del/:id - Delete client (removes from all inbounds)

3. Inbound Entities (Many-to-Many with Nodes)

Overview

Inbounds can now be assigned to multiple nodes, enabling load distribution and redundancy.

Inbound Structure

type Inbound struct {
    Id       int
    UserId   int
    Port     int
    Protocol Protocol
    
    // Settings is automatically generated from ClientEntity
    Settings string // JSON with clients, generated from ClientEntity
    
    // Node assignments (loaded via JOIN)
    NodeIds  []int  // Node IDs where this inbound runs
    
    // Client statistics (from Xray API, not from DB)
    ClientStats []xray.ClientTraffic
}

Many-to-Many Relationship

InboundNodeMapping Table:

type InboundNodeMapping struct {
    Id        int // Unique identifier
    InboundId int // Inbound ID
    NodeId    int // Node ID
}

How It Works:

  • One inbound can run on multiple nodes simultaneously
  • One node can serve multiple inbounds
  • When creating/updating an inbound, specify NodeIds array
  • Configuration is sent to all assigned nodes in parallel
  • Subscription links are generated with node addresses (not panel address)

Example:

  • Inbound №1 (VMESS, port 443) → Node 1, Node 2, Node 3
  • Inbound 2 (VLESS, port 80) → Node 2
  • Result: Inbound 1 configuration sent to 3 nodes, Inbound 2 to 1 node

Work Modes

Single-Mode (Default):

  • XRAY Core runs locally on panel server
  • Inbounds without assigned nodes work locally
  • Subscriptions generated with panel address

Multi-Mode:

  • XRAY Core does not run locally
  • All inbounds must be assigned to nodes
  • Configurations sent to nodes via REST API
  • Subscriptions generated with node addresses
  • Statistics collected from nodes periodically

4. Host Management (Address Override for Load Balancing)

Overview

Hosts allow overriding the endpoint address in subscription links, useful for load balancing, CDN integration, or custom routing.

Host Structure

type Host struct {
    Id         int    // Unique identifier
    UserId     int    // Associated user ID
    Name       string // Host name/identifier
    Address    string // Host address (IP or domain)
    Port       int    // Host port (0 = use inbound port)
    Protocol   string // Protocol override (optional)
    Remark     string // Description
    Enable     bool   // Whether host is enabled
    InboundIds []int  // Inbound IDs this host applies to
}

Many-to-Many Relationship

HostInboundMapping Table:

type HostInboundMapping struct {
    Id        int // Unique identifier
    HostId    int // Host ID
    InboundId int // Inbound ID
}

How It Works:

  • One host can apply to multiple inbounds
  • One inbound can have multiple hosts
  • When generating subscription, host address is used instead of node/panel address
  • Useful for:
    • Load balancing across multiple nodes
    • CDN integration
    • Custom domain routing
    • Port forwarding scenarios

Example:

  • Node 1 has IP: 192.168.1.100
  • Host "cdn.example.com" applies to Inbound 1
  • Subscription for Inbound 1 contains cdn.example.com instead of 192.168.1.100

API Endpoints

  • GET /panel/host/list - Get all hosts for user
  • GET /panel/host/get/:id - Get host by ID
  • POST /panel/host/add - Add new host (with inbound assignments)
  • POST /panel/host/update/:id - Update host
  • POST /panel/host/del/:id - Delete host

5. HWID Tracking (Hardware ID Tracking)

Overview

HWID tracking allows limiting the number of devices that can simultaneously use a client account, preventing unauthorized credential sharing and controlling resource usage.

HWID Structure

type ClientHWID struct {
    Id          int    // Unique identifier
    ClientId    int    // Client ID
    HWID        string // Hardware ID (provided by client via x-hwid header)
    DeviceOS    string // Device OS (from x-device-os header)
    DeviceModel string // Device model (from x-device-model header)
    OSVersion   string // OS version (from x-ver-os header)
    IPAddress   string // Last known IP address
    FirstSeenIP string // IP address when first seen
    UserAgent   string // User-Agent string
    FirstSeenAt int64  // First seen timestamp
    LastSeenAt  int64  // Last seen timestamp
    IsActive    bool   // Whether HWID is active
    BlockedAt   *int64 // Block timestamp (if blocked)
    BlockReason string // Block reason
}

How It Works

Registration Process:

  1. Client application sends x-hwid header when requesting subscription
  2. Server registers HWID and links it to client
  3. If HWIDEnabled is true and MaxHWID is set, device limit is checked
  4. If limit exceeded, new device is blocked
  5. History of all devices stored in client_hw_ids table

Modes:

  • off - HWID tracking disabled
  • client_header - Explicit registration via header (recommended)
  • ip_based - Generate HWID from IP (deprecated)

Features:

  • Device limit enforcement per client
  • Device history tracking
  • Block/unblock devices
  • Device metadata (OS, model, version)
  • IP address tracking per device

API Endpoints

  • GET /panel/client/hwid/list/:clientId - Get all HWIDs for client
  • POST /panel/client/hwid/register - Register HWID (via subscription request)
  • POST /panel/client/hwid/del/:id - Delete HWID
  • POST /panel/client/hwid/block/:id - Block HWID
  • POST /panel/client/hwid/unblock/:id - Unblock HWID

Background Jobs

  • CheckClientHWIDJob - Periodic check of HWID limits and status updates

6. Glass Morphism UI Theme

Overview

A modern Glass Morphism design theme has been added to the panel, providing a sleek, translucent glass-like appearance with backdrop blur effects.

Features

Visual Design:

  • Translucent glass-like panels with backdrop blur
  • Smooth gradients and shadows
  • Modern card-based layout
  • Enhanced visual hierarchy
  • Improved readability with proper contrast

Theme Switching:

  • Glass Morphism can be enabled/disabled via theme switcher
  • Mutually exclusive with dark theme (when Glass Morphism is enabled, dark theme is disabled)
  • Default theme: Glass Morphism enabled
  • Settings persisted in localStorage

Implementation:

  • CSS variables for easy customization
  • Responsive design for all screen sizes
  • Smooth transitions and animations
  • Consistent styling across all pages

UI Components Updated:

  • Dashboard cards with glass effect
  • Navigation sidebar
  • Modal windows
  • Tables and forms
  • Buttons and inputs
  • Status indicators
  • Tooltips and popovers

Pages with Glass Morphism:

  • Main dashboard
  • Inbounds page
  • Clients page
  • Nodes page
  • Hosts page
  • Settings page
  • All modal windows

7. Redis Cache Integration

Overview

Redis caching has been integrated to significantly improve panel performance by caching frequently accessed data.

Cache Implementation

Cache Layer:

  • web/cache/cache.go - Cache interface
  • web/cache/redis.go - Redis implementation
  • web/cache/redisstore.go - Redis store for sessions

Cached Data:

  • Client lists (30 seconds TTL)
  • Inbound lists (30 seconds TTL)
  • Node lists (30 seconds TTL)
  • Host lists (30 seconds TTL)
  • System settings

Cache Invalidation:

  • Automatic invalidation on data changes
  • Manual invalidation via API
  • Cache keys prefixed by entity type

Middleware:

  • web/middleware/cache.go - Cache middleware for HTTP requests
  • Automatic cache hit/miss handling
  • Cache warming on startup

Performance Benefits

  • Reduced Database Load: Frequently accessed data served from cache
  • Faster Response Times: Cache hits return data in milliseconds
  • Scalability: Redis can be shared across multiple panel instances
  • Session Storage: Redis used for session management

Configuration

Redis connection configured via environment variables or settings:

  • Redis address
  • Redis password (optional)
  • Redis database number
  • Connection pool settings

Database Changes

New Tables

  1. client_entities - Client table

    • All client data and traffic statistics
    • Indexes: user_id, email (unique per user), sub_id
  2. client_inbound_mappings - Client-Inbound mapping

    • Unique index: (client_id, inbound_id)
  3. nodes - Node table

    • Node information and status
  4. inbound_node_mappings - Inbound-Node mapping

    • Unique index: (inbound_id, node_id)
  5. client_hw_ids - HWID table

    • Index: (client_id, hwid)
  6. hosts - Host table

    • Host configurations
  7. host_inbound_mappings - Host-Inbound mapping

    • Unique index: (host_id, inbound_id)

Updated Tables

  • inbounds - Settings now auto-generated from ClientEntity

Backend (Go)

New Services

  • NodeService: Node management, health checks, API validation
  • ClientService: Client CRUD operations, inbound assignments
  • ClientHWIDService: HWID tracking and management
  • ClientTrafficService: Client traffic statistics
  • HostService: Host management and subscription address override

New Controllers

  • NodeController: Node API endpoints
  • ClientController: Client API endpoints
  • ClientHWIDController: HWID API endpoints
  • HostController: Host API endpoints

New Background Jobs

  • CheckNodeHealthJob: Health checks every 5 minutes
  • CollectNodeStatsJob: Statistics collection every 30 seconds
  • CheckClientHWIDJob: HWID limit checks

Updated Services

  • InboundService: Updated for multi-node and client entity support
  • XrayService: Multi-node configuration distribution
  • SubService: Node address and host override support
  • ServerService: Node availability in system status

Frontend (Vue.js/HTML)

New Pages

  • nodes.html: Node management interface
  • clients.html: Client management interface
  • hosts.html: Host management interface

New Modals

  • node_modal.html: Node add/edit modal
  • client_entity_modal.html: Client add/edit modal
  • host_modal.html: Host add/edit modal

Updated Pages

  • inbounds.html: Multi-node selection, client entity integration
  • index.html: Nodes availability speedometer, Glass Morphism
  • settings.html: Multi-Node mode toggle, Glass Morphism settings

Updated Components

  • aThemeSwitch.html: Glass Morphism toggle
  • aSidebar.html: Glass Morphism styling
  • aClientTable.html: Client entity display

Node Service (New Component)

Structure

node/
├── main.go              # Entry point
├── api/
│   └── server.go        # REST API server
├── xray/
│   └── manager.go       # Xray process management
├── logs/
│   └── pusher.go        # Log forwarding
├── config/
│   └── config.go        # Configuration
├── Dockerfile           # Docker image
└── docker-compose.yml   # Docker Compose config

Features

  • Automatic config.json loading on startup
  • API inbound auto-creation if missing
  • Health check endpoint
  • Statistics collection endpoint
  • Configuration application endpoint
  • Xray reload without container restart

Localization

  • Added translations for all new UI elements
  • Russian and English translations
  • Translation keys for:
    • Nodes management
    • Client management
    • Host management
    • HWID tracking
    • Glass Morphism theme
    • Multi-Node mode

Technical Details

Architecture

  • Many-to-Many Relationships: Clients↔Inbounds, Inbounds↔Nodes, Hosts↔Inbounds
  • Pull-based Statistics: Panel polls nodes for statistics
  • Health Checks: Automatic node availability monitoring
  • Backward Compatibility: Support for old nodeId field

Security

  • API key validation for nodes
  • Node availability checks
  • Authentication via API keys for all node requests
  • HWID limit enforcement
  • Input validation and sanitization

Performance

  • Redis caching for frequently accessed data
  • Parallel node request processing (goroutines)
  • Optimized database queries with indexes
  • Cache invalidation on data changes
  • Statistics aggregation optimization

Type of Changes

  • New Feature
  • Database Changes
  • API Changes
  • UI Changes
  • Performance Improvements
  • Localization

Affected Parts of Application

  • Frontend
  • Backend
  • Database
  • Node Service (new component)
  • Caching Layer

Testing

  • Node registration and management
  • Client creation and assignment to multiple inbounds
  • Inbound assignment to multiple nodes
  • Host configuration and address override
  • HWID registration and limit enforcement
  • Glass Morphism theme switching
  • Redis cache functionality
  • Statistics collection from nodes
  • Health checks
  • Configuration synchronization

Migration

When updating an existing installation:

  1. Database automatically creates new tables
  2. Old inbounds without assigned nodes continue working in local mode
  3. Old clients in Settings are automatically converted to ClientEntity
  4. To migrate to Multi-Node mode:
    • Add nodes through the interface
    • Enable Multi-Node Mode in settings
    • Assign inbounds to nodes
  5. Redis cache is optional but recommended for performance

Notes

  • Multi-Node mode is completely optional - panel works in local mode by default
  • When Multi-Node is enabled, local XRAY Core stops
  • All configurations are automatically synchronized with assigned nodes
  • Glass Morphism is enabled by default but can be disabled
  • Redis cache significantly improves performance, especially with many clients/inbounds
  • HWID tracking helps prevent credential sharing
  • Host management enables advanced load balancing scenarios

🔄 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/3635 **Author:** [@konstpic](https://github.com/konstpic) **Created:** 1/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `node-mode` --- ### 📝 Commits (10+) - [`d7175e7`](https://github.com/MHSanaei/3x-ui/commit/d7175e7803b521b99d039323e20df7e0c2646943) multi-node support - [`cdd90de`](https://github.com/MHSanaei/3x-ui/commit/cdd90de099973045c7de032fcaf134c6601298f1) edit nodes config,api,checks,dash - [`09c5c05`](https://github.com/MHSanaei/3x-ui/commit/09c5c05691cd698689a9db3a1dae3abb51131bd8) edit nodes config,api,checks,dash - [`37906b7`](https://github.com/MHSanaei/3x-ui/commit/37906b73120e387a0c6c06a3dc67393c6698fc2a) edit nodes config,api,checks,dash - [`3d3ad23`](https://github.com/MHSanaei/3x-ui/commit/3d3ad2358e1ad8070b735dc53780a27cb8a47910) edit nodes config,api,checks,dash - [`8a5c270`](https://github.com/MHSanaei/3x-ui/commit/8a5c2708f486dff1e7bb3e24ee5a969a7a8609e3) Merge branch 'main' into node-mode - [`5d355f9`](https://github.com/MHSanaei/3x-ui/commit/5d355f9c3681aa34de448a47b52409f78f4a138e) Remove unnecessary files from PR - [`42b28a5`](https://github.com/MHSanaei/3x-ui/commit/42b28a59e4dc3eadaba141bf9bfa8a83e45ebbbb) Restore dokcer-compose.yml - [`b6f336a`](https://github.com/MHSanaei/3x-ui/commit/b6f336a15c3851b84657b93e47136efd676d98fc) translate to eng - [`66662af`](https://github.com/MHSanaei/3x-ui/commit/66662afa4de9583c372f9f92fdb20ed120958f75) feat: add geo files to nodes and fix func inbounds ### 📊 Changes **86 files changed** (+14439 additions, -1123 deletions) <details> <summary>View changed files</summary> ➕ `README_node_mode.md` (+172 -0) 📝 `database/db.go` (+7 -0) 📝 `database/model/model.go` (+130 -0) 📝 `docker-compose.yml` (+5 -0) 📝 `go.mod` (+14 -0) 📝 `go.sum` (+10 -0) 📝 `logger/logger.go` (+34 -5) 📝 `main.go` (+7 -0) ➕ `node/Dockerfile` (+124 -0) ➕ `node/README.md` (+79 -0) ➕ `node/api/server.go` (+303 -0) ➕ `node/bin/config.json` (+1 -0) ➕ `node/config/config.go` (+156 -0) ➕ `node/docker-compose.yml` (+23 -0) ➕ `node/logs/pusher.go` (+346 -0) ➕ `node/main.go` (+114 -0) ➕ `node/xray/manager.go` (+541 -0) 📝 `sub/subController.go` (+13 -5) 📝 `sub/subJsonService.go` (+15 -1) 📝 `sub/subService.go` (+1364 -217) _...and 66 more files_ </details> ### 📄 Description # Multi-Node Architecture, Client Management, HWID Tracking, Host Management, Glass Morphism UI & Redis Cache ## Description This pull request introduces a comprehensive architectural overhaul of the 3x-ui panel, adding support for distributed multi-node architecture, independent client management with many-to-many relationships, hardware ID tracking, host management for load balancing, a modern Glass Morphism UI theme, and Redis caching for improved performance. ## What Changed? ### 1. Node Mechanism (Multi-Node Architecture) #### Overview The panel now supports distributed architecture with multiple worker nodes. Instead of running XRAY Core locally, the panel can manage multiple remote nodes running XRAY Core instances. #### Node Registration and Interaction **Node Registration Process:** 1. **Adding a Node**: Users can add nodes through the UI by providing: - Node name (e.g., "Node-1", "US-East") - Node API address (e.g., "http://192.168.1.100:8080" or "https://node.example.com") - API key for authentication - Optional TLS settings (certificate paths, insecure TLS flag) 2. **Automatic API Key Validation**: When adding or updating a node, the system: - Validates the API key by making a test request to the node - Checks node availability before saving - Verifies the node responds correctly to health checks 3. **Node Health Monitoring**: - Automatic health checks every 5 minutes (`CheckNodeHealthJob`) - Manual health check via UI button - Status indicators: `online` (green), `offline` (orange), `unknown` (gray) - Response time measurement in milliseconds #### Node Interaction **API Endpoints on Panel:** - `GET /panel/node/list` - Get list of all nodes - `GET /panel/node/get/:id` - Get information about a specific node - `POST /panel/node/add` - Add a new node (with validation) - `POST /panel/node/update/:id` - Update a node (supports partial updates) - `POST /panel/node/del/:id` - Delete a node - `POST /panel/node/check/:id` - Check health of a specific node - `POST /panel/node/checkAll` - Check health of all nodes - `POST /panel/node/reload/:id` - Reload XRAY on a node - `POST /panel/node/reloadAll` - Reload XRAY on all nodes - `GET /panel/node/status/:id` - Get detailed status of a node **Node Service API (on Worker Nodes):** - `POST /api/v1/apply` - Apply XRAY configuration - `POST /api/v1/reload` - Reload XRAY - `POST /api/v1/force-reload` - Force reload XRAY - `GET /api/v1/status` - Get XRAY status - `GET /api/v1/stats` - Get traffic statistics and online clients - `GET /health` - Health check endpoint (no authentication required) **Configuration Synchronization:** - When an inbound is created/updated, configuration is sent to all assigned nodes - Configurations are sent in parallel using goroutines for performance - Each node receives only the inbounds assigned to it - Automatic retry logic for failed requests **Statistics Collection:** - Automatic collection every 30 seconds (`CollectNodeStatsJob`) - Traffic statistics aggregated by client email across all nodes - Online client information collected from each node - Statistics stored directly in `ClientEntity` table ### 2. Client Entities (Many-to-Many with Inbounds) #### Overview Clients are now independent entities stored in a separate `client_entities` table. A single client can be assigned to multiple inbounds, enabling flexible configuration management. #### Client Entity Structure ```go type ClientEntity struct { Id int // Unique identifier UserId int // Associated user ID Email string // Client email (unique per user) UUID string // UUID for VMESS/VLESS Password string // Password for Trojan/Shadowsocks Security string // Encryption method Flow string // Flow control (XTLS) LimitIP int // IP limit TotalGB float64 // Traffic limit in GB (supports decimals like 0.01) ExpiryTime int64 // Expiration timestamp Enable bool // Whether client is enabled Status string // Status: active, expired_traffic, expired_time // Traffic statistics stored directly in ClientEntity Up int64 // Upload traffic in bytes Down int64 // Download traffic in bytes AllTime int64 // All-time traffic usage LastOnline int64 // Last online timestamp // HWID restrictions HWIDEnabled bool // Whether HWID tracking is enabled MaxHWID int // Maximum allowed devices (0 = unlimited) // Relations (loaded via JOIN, not stored in table) InboundIds []int // Inbound IDs this client is assigned to } ``` #### Many-to-Many Relationship **ClientInboundMapping Table:** ```go type ClientInboundMapping struct { Id int // Unique identifier ClientId int // Client ID InboundId int // Inbound ID } ``` **How It Works:** - One client can be assigned to multiple inbounds - One inbound can have multiple clients - When a client is created/updated, `ClientInboundMapping` records are created/updated - `Inbound.Settings` is automatically regenerated from all assigned `ClientEntity` records **Benefits:** - Reuse clients across multiple inbounds - Centralized client management - Traffic statistics aggregated per client (not per inbound-client pair) - Easier client updates (change once, applies to all inbounds) #### API Endpoints - `GET /panel/client/list` - Get all clients for user - `GET /panel/client/get/:id` - Get client by ID - `POST /panel/client/add` - Add new client (with inbound assignments) - `POST /panel/client/update/:id` - Update client (updates all related inbounds) - `POST /panel/client/del/:id` - Delete client (removes from all inbounds) ### 3. Inbound Entities (Many-to-Many with Nodes) #### Overview Inbounds can now be assigned to multiple nodes, enabling load distribution and redundancy. #### Inbound Structure ```go type Inbound struct { Id int UserId int Port int Protocol Protocol // Settings is automatically generated from ClientEntity Settings string // JSON with clients, generated from ClientEntity // Node assignments (loaded via JOIN) NodeIds []int // Node IDs where this inbound runs // Client statistics (from Xray API, not from DB) ClientStats []xray.ClientTraffic } ``` #### Many-to-Many Relationship **InboundNodeMapping Table:** ```go type InboundNodeMapping struct { Id int // Unique identifier InboundId int // Inbound ID NodeId int // Node ID } ``` **How It Works:** - One inbound can run on multiple nodes simultaneously - One node can serve multiple inbounds - When creating/updating an inbound, specify `NodeIds` array - Configuration is sent to all assigned nodes in parallel - Subscription links are generated with node addresses (not panel address) **Example:** - Inbound №1 (VMESS, port 443) → Node 1, Node 2, Node 3 - Inbound 2 (VLESS, port 80) → Node 2 - Result: Inbound 1 configuration sent to 3 nodes, Inbound 2 to 1 node #### Work Modes **Single-Mode (Default):** - XRAY Core runs locally on panel server - Inbounds without assigned nodes work locally - Subscriptions generated with panel address **Multi-Mode:** - XRAY Core does not run locally - All inbounds must be assigned to nodes - Configurations sent to nodes via REST API - Subscriptions generated with node addresses - Statistics collected from nodes periodically ### 4. Host Management (Address Override for Load Balancing) #### Overview Hosts allow overriding the endpoint address in subscription links, useful for load balancing, CDN integration, or custom routing. #### Host Structure ```go type Host struct { Id int // Unique identifier UserId int // Associated user ID Name string // Host name/identifier Address string // Host address (IP or domain) Port int // Host port (0 = use inbound port) Protocol string // Protocol override (optional) Remark string // Description Enable bool // Whether host is enabled InboundIds []int // Inbound IDs this host applies to } ``` #### Many-to-Many Relationship **HostInboundMapping Table:** ```go type HostInboundMapping struct { Id int // Unique identifier HostId int // Host ID InboundId int // Inbound ID } ``` **How It Works:** - One host can apply to multiple inbounds - One inbound can have multiple hosts - When generating subscription, host address is used instead of node/panel address - Useful for: - Load balancing across multiple nodes - CDN integration - Custom domain routing - Port forwarding scenarios **Example:** - Node 1 has IP: 192.168.1.100 - Host "cdn.example.com" applies to Inbound 1 - Subscription for Inbound 1 contains `cdn.example.com` instead of `192.168.1.100` #### API Endpoints - `GET /panel/host/list` - Get all hosts for user - `GET /panel/host/get/:id` - Get host by ID - `POST /panel/host/add` - Add new host (with inbound assignments) - `POST /panel/host/update/:id` - Update host - `POST /panel/host/del/:id` - Delete host ### 5. HWID Tracking (Hardware ID Tracking) #### Overview HWID tracking allows limiting the number of devices that can simultaneously use a client account, preventing unauthorized credential sharing and controlling resource usage. #### HWID Structure ```go type ClientHWID struct { Id int // Unique identifier ClientId int // Client ID HWID string // Hardware ID (provided by client via x-hwid header) DeviceOS string // Device OS (from x-device-os header) DeviceModel string // Device model (from x-device-model header) OSVersion string // OS version (from x-ver-os header) IPAddress string // Last known IP address FirstSeenIP string // IP address when first seen UserAgent string // User-Agent string FirstSeenAt int64 // First seen timestamp LastSeenAt int64 // Last seen timestamp IsActive bool // Whether HWID is active BlockedAt *int64 // Block timestamp (if blocked) BlockReason string // Block reason } ``` #### How It Works **Registration Process:** 1. Client application sends `x-hwid` header when requesting subscription 2. Server registers HWID and links it to client 3. If `HWIDEnabled` is true and `MaxHWID` is set, device limit is checked 4. If limit exceeded, new device is blocked 5. History of all devices stored in `client_hw_ids` table **Modes:** - `off` - HWID tracking disabled - `client_header` - Explicit registration via header (recommended) - `ip_based` - Generate HWID from IP (deprecated) **Features:** - Device limit enforcement per client - Device history tracking - Block/unblock devices - Device metadata (OS, model, version) - IP address tracking per device #### API Endpoints - `GET /panel/client/hwid/list/:clientId` - Get all HWIDs for client - `POST /panel/client/hwid/register` - Register HWID (via subscription request) - `POST /panel/client/hwid/del/:id` - Delete HWID - `POST /panel/client/hwid/block/:id` - Block HWID - `POST /panel/client/hwid/unblock/:id` - Unblock HWID #### Background Jobs - `CheckClientHWIDJob` - Periodic check of HWID limits and status updates ### 6. Glass Morphism UI Theme #### Overview A modern Glass Morphism design theme has been added to the panel, providing a sleek, translucent glass-like appearance with backdrop blur effects. #### Features **Visual Design:** - Translucent glass-like panels with backdrop blur - Smooth gradients and shadows - Modern card-based layout - Enhanced visual hierarchy - Improved readability with proper contrast **Theme Switching:** - Glass Morphism can be enabled/disabled via theme switcher - Mutually exclusive with dark theme (when Glass Morphism is enabled, dark theme is disabled) - Default theme: Glass Morphism enabled - Settings persisted in localStorage **Implementation:** - CSS variables for easy customization - Responsive design for all screen sizes - Smooth transitions and animations - Consistent styling across all pages **UI Components Updated:** - Dashboard cards with glass effect - Navigation sidebar - Modal windows - Tables and forms - Buttons and inputs - Status indicators - Tooltips and popovers **Pages with Glass Morphism:** - Main dashboard - Inbounds page - Clients page - Nodes page - Hosts page - Settings page - All modal windows ### 7. Redis Cache Integration #### Overview Redis caching has been integrated to significantly improve panel performance by caching frequently accessed data. #### Cache Implementation **Cache Layer:** - `web/cache/cache.go` - Cache interface - `web/cache/redis.go` - Redis implementation - `web/cache/redisstore.go` - Redis store for sessions **Cached Data:** - Client lists (30 seconds TTL) - Inbound lists (30 seconds TTL) - Node lists (30 seconds TTL) - Host lists (30 seconds TTL) - System settings **Cache Invalidation:** - Automatic invalidation on data changes - Manual invalidation via API - Cache keys prefixed by entity type **Middleware:** - `web/middleware/cache.go` - Cache middleware for HTTP requests - Automatic cache hit/miss handling - Cache warming on startup #### Performance Benefits - **Reduced Database Load**: Frequently accessed data served from cache - **Faster Response Times**: Cache hits return data in milliseconds - **Scalability**: Redis can be shared across multiple panel instances - **Session Storage**: Redis used for session management #### Configuration Redis connection configured via environment variables or settings: - Redis address - Redis password (optional) - Redis database number - Connection pool settings ### Database Changes #### New Tables 1. **`client_entities`** - Client table - All client data and traffic statistics - Indexes: `user_id`, `email` (unique per user), `sub_id` 2. **`client_inbound_mappings`** - Client-Inbound mapping - Unique index: `(client_id, inbound_id)` 3. **`nodes`** - Node table - Node information and status 4. **`inbound_node_mappings`** - Inbound-Node mapping - Unique index: `(inbound_id, node_id)` 5. **`client_hw_ids`** - HWID table - Index: `(client_id, hwid)` 6. **`hosts`** - Host table - Host configurations 7. **`host_inbound_mappings`** - Host-Inbound mapping - Unique index: `(host_id, inbound_id)` #### Updated Tables - **`inbounds`** - Settings now auto-generated from ClientEntity ### Backend (Go) #### New Services - **`NodeService`**: Node management, health checks, API validation - **`ClientService`**: Client CRUD operations, inbound assignments - **`ClientHWIDService`**: HWID tracking and management - **`ClientTrafficService`**: Client traffic statistics - **`HostService`**: Host management and subscription address override #### New Controllers - **`NodeController`**: Node API endpoints - **`ClientController`**: Client API endpoints - **`ClientHWIDController`**: HWID API endpoints - **`HostController`**: Host API endpoints #### New Background Jobs - **`CheckNodeHealthJob`**: Health checks every 5 minutes - **`CollectNodeStatsJob`**: Statistics collection every 30 seconds - **`CheckClientHWIDJob`**: HWID limit checks #### Updated Services - **`InboundService`**: Updated for multi-node and client entity support - **`XrayService`**: Multi-node configuration distribution - **`SubService`**: Node address and host override support - **`ServerService`**: Node availability in system status ### Frontend (Vue.js/HTML) #### New Pages - **`nodes.html`**: Node management interface - **`clients.html`**: Client management interface - **`hosts.html`**: Host management interface #### New Modals - **`node_modal.html`**: Node add/edit modal - **`client_entity_modal.html`**: Client add/edit modal - **`host_modal.html`**: Host add/edit modal #### Updated Pages - **`inbounds.html`**: Multi-node selection, client entity integration - **`index.html`**: Nodes availability speedometer, Glass Morphism - **`settings.html`**: Multi-Node mode toggle, Glass Morphism settings #### Updated Components - **`aThemeSwitch.html`**: Glass Morphism toggle - **`aSidebar.html`**: Glass Morphism styling - **`aClientTable.html`**: Client entity display ### Node Service (New Component) #### Structure ``` node/ ├── main.go # Entry point ├── api/ │ └── server.go # REST API server ├── xray/ │ └── manager.go # Xray process management ├── logs/ │ └── pusher.go # Log forwarding ├── config/ │ └── config.go # Configuration ├── Dockerfile # Docker image └── docker-compose.yml # Docker Compose config ``` #### Features - Automatic config.json loading on startup - API inbound auto-creation if missing - Health check endpoint - Statistics collection endpoint - Configuration application endpoint - Xray reload without container restart ### Localization - Added translations for all new UI elements - Russian and English translations - Translation keys for: - Nodes management - Client management - Host management - HWID tracking - Glass Morphism theme - Multi-Node mode ## Technical Details ### Architecture - **Many-to-Many Relationships**: Clients↔Inbounds, Inbounds↔Nodes, Hosts↔Inbounds - **Pull-based Statistics**: Panel polls nodes for statistics - **Health Checks**: Automatic node availability monitoring - **Backward Compatibility**: Support for old `nodeId` field ### Security - API key validation for nodes - Node availability checks - Authentication via API keys for all node requests - HWID limit enforcement - Input validation and sanitization ### Performance - Redis caching for frequently accessed data - Parallel node request processing (goroutines) - Optimized database queries with indexes - Cache invalidation on data changes - Statistics aggregation optimization ## Type of Changes - [x] New Feature - [x] Database Changes - [x] API Changes - [x] UI Changes - [x] Performance Improvements - [x] Localization ## Affected Parts of Application - [x] Frontend - [x] Backend - [x] Database - [x] Node Service (new component) - [x] Caching Layer ## Testing - [x] Node registration and management - [x] Client creation and assignment to multiple inbounds - [x] Inbound assignment to multiple nodes - [x] Host configuration and address override - [x] HWID registration and limit enforcement - [x] Glass Morphism theme switching - [x] Redis cache functionality - [x] Statistics collection from nodes - [x] Health checks - [x] Configuration synchronization ## Migration When updating an existing installation: 1. Database automatically creates new tables 2. Old inbounds without assigned nodes continue working in local mode 3. Old clients in Settings are automatically converted to ClientEntity 4. To migrate to Multi-Node mode: - Add nodes through the interface - Enable Multi-Node Mode in settings - Assign inbounds to nodes 5. Redis cache is optional but recommended for performance ## Notes - Multi-Node mode is completely optional - panel works in local mode by default - When Multi-Node is enabled, local XRAY Core stops - All configurations are automatically synchronized with assigned nodes - Glass Morphism is enabled by default but can be disabled - Redis cache significantly improves performance, especially with many clients/inbounds - HWID tracking helps prevent credential sharing - Host management enables advanced load balancing scenarios --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:47:20 +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#5492
No description provided.