mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-24 20:17:32 +08:00
feat: machine mode, ECH subscriptions, batch ops & security hardening
This commit is contained in:
+48
-37
@@ -124,6 +124,7 @@ class Server extends Model
|
||||
'last_check_at' => 'integer',
|
||||
'last_push_at' => 'integer',
|
||||
'show' => 'boolean',
|
||||
'enabled' => 'boolean',
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp',
|
||||
'rate_time_ranges' => 'array',
|
||||
@@ -131,6 +132,7 @@ class Server extends Model
|
||||
'transfer_enable' => 'integer',
|
||||
'u' => 'integer',
|
||||
'd' => 'integer',
|
||||
'machine_id' => 'integer',
|
||||
];
|
||||
|
||||
private const MULTIPLEX_CONFIGURATION = [
|
||||
@@ -179,6 +181,38 @@ class Server extends Model
|
||||
]
|
||||
];
|
||||
|
||||
private const ECH_CONFIGURATION = [
|
||||
'ech' => [
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'enabled' => ['type' => 'boolean', 'default' => false],
|
||||
'config' => ['type' => 'string', 'default' => null],
|
||||
'query_server_name' => ['type' => 'string', 'default' => null],
|
||||
'key' => ['type' => 'string', 'default' => null],
|
||||
'key_path' => ['type' => 'string', 'default' => null],
|
||||
'config_path' => ['type' => 'string', 'default' => null],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
private const TLS_SETTINGS_CONFIGURATION = [
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'server_name' => ['type' => 'string', 'default' => null],
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false],
|
||||
...self::ECH_CONFIGURATION,
|
||||
]
|
||||
];
|
||||
|
||||
private const TLS_CONFIGURATION = [
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'server_name' => ['type' => 'string', 'default' => null],
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false],
|
||||
...self::ECH_CONFIGURATION,
|
||||
]
|
||||
];
|
||||
|
||||
private const PROTOCOL_CONFIGURATIONS = [
|
||||
self::TYPE_TROJAN => [
|
||||
'tls' => ['type' => 'integer', 'default' => 1],
|
||||
@@ -186,6 +220,7 @@ class Server extends Model
|
||||
'network_settings' => ['type' => 'array', 'default' => null],
|
||||
'server_name' => ['type' => 'string', 'default' => null],
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false],
|
||||
'tls_settings' => self::TLS_SETTINGS_CONFIGURATION,
|
||||
...self::REALITY_CONFIGURATION,
|
||||
...self::MULTIPLEX_CONFIGURATION,
|
||||
...self::UTLS_CONFIGURATION
|
||||
@@ -195,13 +230,13 @@ class Server extends Model
|
||||
'network' => ['type' => 'string', 'default' => null],
|
||||
'rules' => ['type' => 'array', 'default' => null],
|
||||
'network_settings' => ['type' => 'array', 'default' => null],
|
||||
'tls_settings' => ['type' => 'array', 'default' => null],
|
||||
'tls_settings' => self::TLS_SETTINGS_CONFIGURATION,
|
||||
...self::MULTIPLEX_CONFIGURATION,
|
||||
...self::UTLS_CONFIGURATION
|
||||
],
|
||||
self::TYPE_VLESS => [
|
||||
'tls' => ['type' => 'integer', 'default' => 0],
|
||||
'tls_settings' => ['type' => 'array', 'default' => null],
|
||||
'tls_settings' => self::TLS_SETTINGS_CONFIGURATION,
|
||||
'flow' => ['type' => 'string', 'default' => null],
|
||||
'encryption' => [
|
||||
'type' => 'object',
|
||||
@@ -242,13 +277,7 @@ class Server extends Model
|
||||
'password' => ['type' => 'string', 'default' => null]
|
||||
]
|
||||
],
|
||||
'tls' => [
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'server_name' => ['type' => 'string', 'default' => null],
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false]
|
||||
]
|
||||
],
|
||||
'tls' => self::TLS_CONFIGURATION,
|
||||
'hop_interval' => ['type' => 'integer', 'default' => null]
|
||||
],
|
||||
self::TYPE_TUIC => [
|
||||
@@ -256,13 +285,7 @@ class Server extends Model
|
||||
'congestion_control' => ['type' => 'string', 'default' => 'cubic'],
|
||||
'alpn' => ['type' => 'array', 'default' => ['h3']],
|
||||
'udp_relay_mode' => ['type' => 'string', 'default' => 'native'],
|
||||
'tls' => [
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'server_name' => ['type' => 'string', 'default' => null],
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false]
|
||||
]
|
||||
]
|
||||
'tls' => self::TLS_CONFIGURATION
|
||||
],
|
||||
self::TYPE_ANYTLS => [
|
||||
'padding_scheme' => [
|
||||
@@ -279,36 +302,19 @@ class Server extends Model
|
||||
"7=500-1000"
|
||||
]
|
||||
],
|
||||
'tls' => [
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'server_name' => ['type' => 'string', 'default' => null],
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false]
|
||||
]
|
||||
]
|
||||
'tls' => self::TLS_CONFIGURATION
|
||||
],
|
||||
self::TYPE_SOCKS => [
|
||||
'tls' => ['type' => 'integer', 'default' => 0],
|
||||
'tls_settings' => [
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false]
|
||||
]
|
||||
]
|
||||
'tls_settings' => self::TLS_SETTINGS_CONFIGURATION
|
||||
],
|
||||
self::TYPE_NAIVE => [
|
||||
'tls' => ['type' => 'integer', 'default' => 0],
|
||||
'tls_settings' => ['type' => 'array', 'default' => null]
|
||||
'tls_settings' => self::TLS_SETTINGS_CONFIGURATION
|
||||
],
|
||||
self::TYPE_HTTP => [
|
||||
'tls' => ['type' => 'integer', 'default' => 0],
|
||||
'tls_settings' => [
|
||||
'type' => 'object',
|
||||
'fields' => [
|
||||
'allow_insecure' => ['type' => 'boolean', 'default' => false],
|
||||
'server_name' => ['type' => 'string', 'default' => null]
|
||||
]
|
||||
]
|
||||
'tls_settings' => self::TLS_SETTINGS_CONFIGURATION
|
||||
],
|
||||
self::TYPE_MIERU => [
|
||||
'transport' => ['type' => 'string', 'default' => 'TCP'],
|
||||
@@ -416,6 +422,11 @@ class Server extends Model
|
||||
return $this->hasMany(StatServer::class, 'server_id', 'id');
|
||||
}
|
||||
|
||||
public function machine(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ServerMachine::class, 'machine_id');
|
||||
}
|
||||
|
||||
public function groups()
|
||||
{
|
||||
return ServerGroup::whereIn('id', $this->group_ids)->get();
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* App\Models\ServerMachine
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name 机器名称
|
||||
* @property string $token 认证 Token
|
||||
* @property string|null $notes 备注
|
||||
* @property bool $is_active 是否启用
|
||||
* @property int|null $last_seen_at 最后心跳时间
|
||||
* @property array|null $load_status 负载状态
|
||||
* @property \Illuminate\Support\Carbon $created_at
|
||||
* @property \Illuminate\Support\Carbon $updated_at
|
||||
*
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, Server> $servers 关联的节点
|
||||
*/
|
||||
class ServerMachine extends Model
|
||||
{
|
||||
protected $table = 'v2_server_machine';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'last_seen_at' => 'integer',
|
||||
'load_status' => 'array',
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp',
|
||||
];
|
||||
|
||||
protected $hidden = ['token'];
|
||||
|
||||
public function servers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Server::class, 'machine_id');
|
||||
}
|
||||
|
||||
public function loadHistory(): HasMany
|
||||
{
|
||||
return $this->hasMany(ServerMachineLoadHistory::class, 'machine_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成新的随机 Token
|
||||
*/
|
||||
public static function generateToken(): string
|
||||
{
|
||||
return Str::random(32);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新最后心跳时间
|
||||
*/
|
||||
public function updateHeartbeat(): bool
|
||||
{
|
||||
return $this->forceFill(['last_seen_at' => now()->timestamp])->save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ServerMachineLoadHistory extends Model
|
||||
{
|
||||
protected $table = 'v2_server_machine_load_history';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $casts = [
|
||||
'cpu' => 'float',
|
||||
'mem_total' => 'integer',
|
||||
'mem_used' => 'integer',
|
||||
'disk_total' => 'integer',
|
||||
'disk_used' => 'integer',
|
||||
'recorded_at' => 'integer',
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp',
|
||||
];
|
||||
|
||||
public function machine(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ServerMachine::class, 'machine_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user