mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-28 06:47:24 +08:00
feat: new xboard
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
# Online Device Limit Design
|
||||
|
||||
## Overview
|
||||
|
||||
This document describes the design and implementation of the online device limit feature in Xboard.
|
||||
|
||||
## Design Goals
|
||||
|
||||
1. Accurate Control
|
||||
- Precise counting of online devices
|
||||
- Real-time monitoring of device status
|
||||
- Accurate device identification
|
||||
|
||||
2. Performance Optimization
|
||||
- Minimal impact on system performance
|
||||
- Efficient device tracking
|
||||
- Optimized resource usage
|
||||
|
||||
3. User Experience
|
||||
- Smooth connection experience
|
||||
- Clear error messages
|
||||
- Graceful handling of limit exceeded cases
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### 1. Device Identification
|
||||
|
||||
#### Device ID Generation
|
||||
```php
|
||||
public function generateDeviceId($user, $request) {
|
||||
return md5(
|
||||
$user->id .
|
||||
$request->header('User-Agent') .
|
||||
$request->ip()
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
#### Device Information Storage
|
||||
```php
|
||||
[
|
||||
'device_id' => 'unique_device_hash',
|
||||
'user_id' => 123,
|
||||
'ip' => '192.168.1.1',
|
||||
'user_agent' => 'Mozilla/5.0...',
|
||||
'last_active' => '2024-03-21 10:00:00'
|
||||
]
|
||||
```
|
||||
|
||||
### 2. Connection Management
|
||||
|
||||
#### Connection Check
|
||||
```php
|
||||
public function checkDeviceLimit($user, $deviceId) {
|
||||
$onlineDevices = $this->getOnlineDevices($user->id);
|
||||
|
||||
if (count($onlineDevices) >= $user->device_limit) {
|
||||
if (!in_array($deviceId, $onlineDevices)) {
|
||||
throw new DeviceLimitExceededException();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
#### Device Status Update
|
||||
```php
|
||||
public function updateDeviceStatus($userId, $deviceId) {
|
||||
Redis::hset(
|
||||
"user:{$userId}:devices",
|
||||
$deviceId,
|
||||
json_encode([
|
||||
'last_active' => now(),
|
||||
'status' => 'online'
|
||||
])
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Cleanup Mechanism
|
||||
|
||||
#### Inactive Device Cleanup
|
||||
```php
|
||||
public function cleanupInactiveDevices() {
|
||||
$inactiveThreshold = now()->subMinutes(30);
|
||||
|
||||
foreach ($this->getUsers() as $user) {
|
||||
$devices = $this->getOnlineDevices($user->id);
|
||||
|
||||
foreach ($devices as $deviceId => $info) {
|
||||
if ($info['last_active'] < $inactiveThreshold) {
|
||||
$this->removeDevice($user->id, $deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
### Error Types
|
||||
1. Device Limit Exceeded
|
||||
```php
|
||||
class DeviceLimitExceededException extends Exception {
|
||||
protected $message = 'Device limit exceeded';
|
||||
protected $code = 4001;
|
||||
}
|
||||
```
|
||||
|
||||
2. Invalid Device
|
||||
```php
|
||||
class InvalidDeviceException extends Exception {
|
||||
protected $message = 'Invalid device';
|
||||
protected $code = 4002;
|
||||
}
|
||||
```
|
||||
|
||||
### Error Messages
|
||||
```php
|
||||
return [
|
||||
'device_limit_exceeded' => 'Maximum number of devices reached',
|
||||
'invalid_device' => 'Device not recognized',
|
||||
'device_expired' => 'Device session expired'
|
||||
];
|
||||
```
|
||||
|
||||
## Performance Considerations
|
||||
|
||||
1. Cache Strategy
|
||||
- Use Redis for device tracking
|
||||
- Implement cache expiration
|
||||
- Optimize cache structure
|
||||
|
||||
2. Database Operations
|
||||
- Minimize database queries
|
||||
- Use batch operations
|
||||
- Implement query optimization
|
||||
|
||||
3. Memory Management
|
||||
- Efficient data structure
|
||||
- Regular cleanup of expired data
|
||||
- Memory usage monitoring
|
||||
|
||||
## Security Measures
|
||||
|
||||
1. Device Verification
|
||||
- Validate device information
|
||||
- Check for suspicious patterns
|
||||
- Implement rate limiting
|
||||
|
||||
2. Data Protection
|
||||
- Encrypt sensitive information
|
||||
- Implement access control
|
||||
- Regular security audits
|
||||
|
||||
## Future Improvements
|
||||
|
||||
1. Enhanced Features
|
||||
- Device management interface
|
||||
- Device activity history
|
||||
- Custom device names
|
||||
|
||||
2. Performance Optimization
|
||||
- Improved caching strategy
|
||||
- Better cleanup mechanism
|
||||
- Reduced memory usage
|
||||
|
||||
3. Security Enhancements
|
||||
- Advanced device fingerprinting
|
||||
- Fraud detection
|
||||
- Improved encryption
|
||||
|
||||
## Conclusion
|
||||
|
||||
This design provides a robust and efficient solution for managing online device limits while maintaining good performance and user experience. Regular monitoring and updates will ensure the system remains effective and secure.
|
||||
@@ -0,0 +1,100 @@
|
||||
# Performance Comparison Report
|
||||
|
||||
## Test Environment
|
||||
|
||||
### Hardware Configuration
|
||||
- CPU: AMD EPYC 7K62 48-Core Processor
|
||||
- Memory: 4GB
|
||||
- Disk: NVMe SSD
|
||||
- Network: 1Gbps
|
||||
|
||||
### Software Environment
|
||||
- OS: Ubuntu 22.04 LTS
|
||||
- PHP: 8.2
|
||||
- MySQL: 5.7
|
||||
- Redis: 7.0
|
||||
- Docker: Latest stable version
|
||||
|
||||
## Test Scenarios
|
||||
|
||||
### 1. User Login Performance
|
||||
- Concurrent users: 100
|
||||
- Test duration: 60 seconds
|
||||
- Request type: POST
|
||||
- Target endpoint: `/api/v1/passport/auth/login`
|
||||
|
||||
Results:
|
||||
- Average response time: 156ms
|
||||
- 95th percentile: 245ms
|
||||
- Maximum response time: 412ms
|
||||
- Requests per second: 642
|
||||
|
||||
### 2. User Dashboard Loading
|
||||
- Concurrent users: 100
|
||||
- Test duration: 60 seconds
|
||||
- Request type: GET
|
||||
- Target endpoint: `/api/v1/user/dashboard`
|
||||
|
||||
Results:
|
||||
- Average response time: 89ms
|
||||
- 95th percentile: 167ms
|
||||
- Maximum response time: 289ms
|
||||
- Requests per second: 1121
|
||||
|
||||
### 3. Node List Query
|
||||
- Concurrent users: 100
|
||||
- Test duration: 60 seconds
|
||||
- Request type: GET
|
||||
- Target endpoint: `/api/v1/user/server/nodes`
|
||||
|
||||
Results:
|
||||
- Average response time: 134ms
|
||||
- 95th percentile: 223ms
|
||||
- Maximum response time: 378ms
|
||||
- Requests per second: 745
|
||||
|
||||
## Performance Optimization Measures
|
||||
|
||||
1. Database Optimization
|
||||
- Added indexes for frequently queried fields
|
||||
- Optimized slow queries
|
||||
- Implemented query caching
|
||||
|
||||
2. Cache Strategy
|
||||
- Using Redis for session storage
|
||||
- Caching frequently accessed data
|
||||
- Implementing cache warming
|
||||
|
||||
3. Code Optimization
|
||||
- Reduced database queries
|
||||
- Optimized database connection pool
|
||||
- Improved error handling
|
||||
|
||||
## Comparison with Previous Version
|
||||
|
||||
| Metric | Previous Version | Current Version | Improvement |
|
||||
|--------|-----------------|-----------------|-------------|
|
||||
| Login Response | 289ms | 156ms | 46% |
|
||||
| Dashboard Loading | 178ms | 89ms | 50% |
|
||||
| Node List Query | 256ms | 134ms | 48% |
|
||||
|
||||
## Future Optimization Plans
|
||||
|
||||
1. Infrastructure Level
|
||||
- Implement horizontal scaling
|
||||
- Add load balancing
|
||||
- Optimize network configuration
|
||||
|
||||
2. Application Level
|
||||
- Further optimize database queries
|
||||
- Implement more efficient caching strategies
|
||||
- Reduce memory usage
|
||||
|
||||
3. Monitoring and Maintenance
|
||||
- Add performance monitoring
|
||||
- Implement automatic scaling
|
||||
- Regular performance testing
|
||||
|
||||
## Conclusion
|
||||
|
||||
The current version shows significant performance improvements compared to the previous version, with an average improvement of 48% in response times. The optimization measures implemented have effectively enhanced the system's performance and stability.
|
||||
@@ -0,0 +1,176 @@
|
||||
# Quick Deployment Guide for 1Panel
|
||||
|
||||
This guide explains how to deploy Xboard using 1Panel.
|
||||
|
||||
## 1. Environment Preparation
|
||||
|
||||
Install 1Panel:
|
||||
```bash
|
||||
curl -sSL https://resource.fit2cloud.com/1panel/package/quick_start.sh -o quick_start.sh && \
|
||||
sudo bash quick_start.sh
|
||||
```
|
||||
|
||||
## 2. Environment Configuration
|
||||
|
||||
1. Install from App Store:
|
||||
- OpenResty (any version)
|
||||
- ⚠️ Check "External Port Access" to open firewall
|
||||
- MySQL 5.7 (Use MariaDB for ARM architecture)
|
||||
|
||||
2. Create Database:
|
||||
- Database name: `xboard`
|
||||
- Username: `xboard`
|
||||
- Access rights: All hosts (%)
|
||||
- Save the database password for installation
|
||||
|
||||
## 3. Deployment Steps
|
||||
|
||||
1. Add Website:
|
||||
- Go to "Website" > "Create Website" > "Reverse Proxy"
|
||||
- Domain: Enter your domain
|
||||
- Code: `xboard`
|
||||
- Proxy address: `127.0.0.1:7001`
|
||||
|
||||
2. Configure Reverse Proxy:
|
||||
```nginx
|
||||
location ^~ / {
|
||||
proxy_pass http://127.0.0.1:7001;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Real-PORT $remote_port;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header Scheme $scheme;
|
||||
proxy_set_header Server-Protocol $server_protocol;
|
||||
proxy_set_header Server-Name $server_name;
|
||||
proxy_set_header Server-Addr $server_addr;
|
||||
proxy_set_header Server-Port $server_port;
|
||||
proxy_cache off;
|
||||
}
|
||||
```
|
||||
|
||||
3. Install Xboard:
|
||||
```bash
|
||||
# Enter site directory
|
||||
cd /opt/1panel/apps/openresty/openresty/www/sites/xboard/index
|
||||
|
||||
# Install Git (if not installed)
|
||||
## Ubuntu/Debian
|
||||
apt update && apt install -y git
|
||||
## CentOS/RHEL
|
||||
yum update && yum install -y git
|
||||
|
||||
# Clone repository
|
||||
git clone -b compose --depth 1 https://github.com/cedar2025/Xboard ./
|
||||
|
||||
# Configure Docker Compose
|
||||
```
|
||||
|
||||
4. Edit docker-compose.yml:
|
||||
```yaml
|
||||
services:
|
||||
web:
|
||||
image: ghcr.io/cedar2025/xboard:latest
|
||||
volumes:
|
||||
- ./.docker/.data/redis/:/data/
|
||||
- ./.env:/www/.env
|
||||
- ./.docker/.data/:/www/.docker/.data
|
||||
- ./storage/logs:/www/storage/logs
|
||||
- ./storage/theme:/www/storage/theme
|
||||
environment:
|
||||
- docker=true
|
||||
depends_on:
|
||||
- redis
|
||||
command: php artisan octane:start --host=0.0.0.0 --port=7001
|
||||
restart: on-failure
|
||||
ports:
|
||||
- 7001:7001
|
||||
networks:
|
||||
- 1panel-network
|
||||
|
||||
horizon:
|
||||
image: ghcr.io/cedar2025/xboard:latest
|
||||
volumes:
|
||||
- ./.docker/.data/redis/:/data/
|
||||
- ./.env:/www/.env
|
||||
- ./.docker/.data/:/www/.docker/.data
|
||||
- ./storage/logs:/www/storage/logs
|
||||
restart: on-failure
|
||||
command: php artisan horizon
|
||||
networks:
|
||||
- 1panel-network
|
||||
depends_on:
|
||||
- redis
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
command: redis-server --unixsocket /data/redis.sock --unixsocketperm 777 --save 900 1 --save 300 10 --save 60 10000
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- 1panel-network
|
||||
volumes:
|
||||
- ./.docker/.data/redis:/data
|
||||
|
||||
networks:
|
||||
1panel-network:
|
||||
external: true
|
||||
```
|
||||
|
||||
5. Initialize Installation:
|
||||
```bash
|
||||
# Install dependencies and initialize
|
||||
docker compose run -it --rm web php artisan xboard:install
|
||||
```
|
||||
|
||||
⚠️ Important Configuration Notes:
|
||||
1. Database Configuration
|
||||
- Database Host: Choose based on your deployment:
|
||||
1. If database and Xboard are in the same network, use `mysql`
|
||||
2. If connection fails, go to: Database -> Select Database -> Connection Info -> Container Connection, and use the "Host" value
|
||||
3. If using external database, enter your actual database host
|
||||
- Database Port: `3306` (default port unless configured otherwise)
|
||||
- Database Name: `xboard` (the database created earlier)
|
||||
- Database User: `xboard` (the user created earlier)
|
||||
- Database Password: Enter the password saved earlier
|
||||
|
||||
2. Redis Configuration
|
||||
- Choose to use built-in Redis
|
||||
- No additional configuration needed
|
||||
|
||||
3. Administrator Information
|
||||
- Save the admin credentials displayed after installation
|
||||
- Note down the admin panel access URL
|
||||
|
||||
After configuration, start the services:
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
6. Start Services:
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## 4. Version Update
|
||||
|
||||
> 💡 Important Note: The update command varies depending on your installation version:
|
||||
> - If you installed recently (new version), use this command:
|
||||
```bash
|
||||
docker compose pull && \
|
||||
docker compose run -it --rm web php artisan xboard:update && \
|
||||
docker compose up -d
|
||||
```
|
||||
> - If you installed earlier (old version), replace `web` with `xboard`:
|
||||
```bash
|
||||
docker compose pull && \
|
||||
docker compose run -it --rm xboard php artisan xboard:update && \
|
||||
docker compose up -d
|
||||
```
|
||||
> 🤔 Not sure which to use? Try the new version command first, if it fails, use the old version command.
|
||||
|
||||
## Important Notes
|
||||
|
||||
- ⚠️ Ensure firewall is enabled to prevent port 7001 exposure to public
|
||||
- Service restart is required after code modifications
|
||||
- SSL certificate configuration is recommended for secure access
|
||||
Reference in New Issue
Block a user