merge: sync upstream/master from cedar2025/Xboard
合并上游 cedar2025/Xboard 的 master,并按交互决策保留本地改动。
This commit is contained in:
@@ -27,7 +27,9 @@ class ServerService
|
||||
'is_online',
|
||||
'available_status',
|
||||
'cache_key',
|
||||
'load_status'
|
||||
'load_status',
|
||||
'metrics',
|
||||
'online_conn'
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -54,6 +56,7 @@ class ServerService
|
||||
$server->port = (int) $server->port;
|
||||
}
|
||||
$server->password = $server->generateServerPassword($user);
|
||||
$server->rate = $server->getCurrentRate();
|
||||
return $server;
|
||||
})->toArray();
|
||||
|
||||
@@ -92,6 +95,174 @@ class ServerService
|
||||
return $routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update node metrics and load status
|
||||
*/
|
||||
public static function updateMetrics(Server $node, array $metrics): void
|
||||
{
|
||||
$nodeType = strtoupper($node->type);
|
||||
$nodeId = $node->id;
|
||||
$cacheTime = max(300, (int) admin_setting('server_push_interval', 60) * 3);
|
||||
|
||||
$metricsData = [
|
||||
'uptime' => (int) ($metrics['uptime'] ?? 0),
|
||||
'goroutines' => (int) ($metrics['goroutines'] ?? 0),
|
||||
'active_connections' => (int) ($metrics['active_connections'] ?? 0),
|
||||
'total_connections' => (int) ($metrics['total_connections'] ?? 0),
|
||||
'total_users' => (int) ($metrics['total_users'] ?? 0),
|
||||
'active_users' => (int) ($metrics['active_users'] ?? 0),
|
||||
'inbound_speed' => (int) ($metrics['inbound_speed'] ?? 0),
|
||||
'outbound_speed' => (int) ($metrics['outbound_speed'] ?? 0),
|
||||
'cpu_per_core' => $metrics['cpu_per_core'] ?? [],
|
||||
'load' => $metrics['load'] ?? [],
|
||||
'speed_limiter' => $metrics['speed_limiter'] ?? [],
|
||||
'gc' => $metrics['gc'] ?? [],
|
||||
'api' => $metrics['api'] ?? [],
|
||||
'ws' => $metrics['ws'] ?? [],
|
||||
'limits' => $metrics['limits'] ?? [],
|
||||
'updated_at' => now()->timestamp,
|
||||
'kernel_status' => (bool) ($metrics['kernel_status'] ?? false),
|
||||
];
|
||||
|
||||
\Illuminate\Support\Facades\Cache::put(
|
||||
\App\Utils\CacheKey::get('SERVER_' . $nodeType . '_METRICS', $nodeId),
|
||||
$metricsData,
|
||||
$cacheTime
|
||||
);
|
||||
}
|
||||
|
||||
public static function buildNodeConfig(Server $node): array
|
||||
{
|
||||
$nodeType = $node->type;
|
||||
$protocolSettings = $node->protocol_settings;
|
||||
$serverPort = $node->server_port;
|
||||
$host = $node->host;
|
||||
|
||||
$baseConfig = [
|
||||
'protocol' => $nodeType,
|
||||
'listen_ip' => '0.0.0.0',
|
||||
'server_port' => (int) $serverPort,
|
||||
'network' => data_get($protocolSettings, 'network'),
|
||||
'networkSettings' => data_get($protocolSettings, 'network_settings') ?: null,
|
||||
];
|
||||
|
||||
$response = match ($nodeType) {
|
||||
'shadowsocks' => [
|
||||
...$baseConfig,
|
||||
'cipher' => $protocolSettings['cipher'],
|
||||
'plugin' => $protocolSettings['plugin'],
|
||||
'plugin_opts' => $protocolSettings['plugin_opts'],
|
||||
'server_key' => match ($protocolSettings['cipher']) {
|
||||
'2022-blake3-aes-128-gcm' => Helper::getServerKey($node->created_at, 16),
|
||||
'2022-blake3-aes-256-gcm' => Helper::getServerKey($node->created_at, 32),
|
||||
default => null,
|
||||
},
|
||||
],
|
||||
'vmess' => [
|
||||
...$baseConfig,
|
||||
'tls' => (int) $protocolSettings['tls'],
|
||||
'multiplex' => data_get($protocolSettings, 'multiplex'),
|
||||
],
|
||||
'trojan' => [
|
||||
...$baseConfig,
|
||||
'host' => $host,
|
||||
'server_name' => $protocolSettings['server_name'],
|
||||
'multiplex' => data_get($protocolSettings, 'multiplex'),
|
||||
],
|
||||
'vless' => [
|
||||
...$baseConfig,
|
||||
'tls' => (int) $protocolSettings['tls'],
|
||||
'flow' => $protocolSettings['flow'],
|
||||
'tls_settings' => match ((int) $protocolSettings['tls']) {
|
||||
2 => $protocolSettings['reality_settings'],
|
||||
default => $protocolSettings['tls_settings'],
|
||||
},
|
||||
'multiplex' => data_get($protocolSettings, 'multiplex'),
|
||||
],
|
||||
'hysteria' => [
|
||||
...$baseConfig,
|
||||
'server_port' => (int) $serverPort,
|
||||
'version' => (int) $protocolSettings['version'],
|
||||
'host' => $host,
|
||||
'server_name' => $protocolSettings['tls']['server_name'],
|
||||
'up_mbps' => (int) $protocolSettings['bandwidth']['up'],
|
||||
'down_mbps' => (int) $protocolSettings['bandwidth']['down'],
|
||||
...match ((int) $protocolSettings['version']) {
|
||||
1 => ['obfs' => $protocolSettings['obfs']['password'] ?? null],
|
||||
2 => [
|
||||
'obfs' => $protocolSettings['obfs']['open'] ? $protocolSettings['obfs']['type'] : null,
|
||||
'obfs-password' => $protocolSettings['obfs']['password'] ?? null,
|
||||
],
|
||||
default => [],
|
||||
},
|
||||
],
|
||||
'tuic' => [
|
||||
...$baseConfig,
|
||||
'version' => (int) $protocolSettings['version'],
|
||||
'server_port' => (int) $serverPort,
|
||||
'server_name' => $protocolSettings['tls']['server_name'],
|
||||
'congestion_control' => $protocolSettings['congestion_control'],
|
||||
'tls_settings' => data_get($protocolSettings, 'tls_settings'),
|
||||
'auth_timeout' => '3s',
|
||||
'zero_rtt_handshake' => false,
|
||||
'heartbeat' => '3s',
|
||||
],
|
||||
'anytls' => [
|
||||
...$baseConfig,
|
||||
'server_port' => (int) $serverPort,
|
||||
'server_name' => $protocolSettings['tls']['server_name'],
|
||||
'padding_scheme' => $protocolSettings['padding_scheme'],
|
||||
],
|
||||
'socks' => [
|
||||
...$baseConfig,
|
||||
'server_port' => (int) $serverPort,
|
||||
],
|
||||
'naive' => [
|
||||
...$baseConfig,
|
||||
'server_port' => (int) $serverPort,
|
||||
'tls' => (int) $protocolSettings['tls'],
|
||||
'tls_settings' => $protocolSettings['tls_settings'],
|
||||
],
|
||||
'http' => [
|
||||
...$baseConfig,
|
||||
'server_port' => (int) $serverPort,
|
||||
'tls' => (int) $protocolSettings['tls'],
|
||||
'tls_settings' => $protocolSettings['tls_settings'],
|
||||
],
|
||||
'mieru' => [
|
||||
...$baseConfig,
|
||||
'server_port' => (int) $serverPort,
|
||||
'transport' => data_get($protocolSettings, 'transport', 'TCP'),
|
||||
'traffic_pattern' => $protocolSettings['traffic_pattern'],
|
||||
// 'multiplex' => data_get($protocolSettings, 'multiplex'),
|
||||
],
|
||||
default => [],
|
||||
};
|
||||
|
||||
$response = array_filter(
|
||||
$response,
|
||||
static fn ($value) => $value !== null
|
||||
);
|
||||
|
||||
if (!empty($node['route_ids'])) {
|
||||
$response['routes'] = self::getRoutes($node['route_ids']);
|
||||
}
|
||||
|
||||
if (!empty($node['custom_outbounds'])) {
|
||||
$response['custom_outbounds'] = $node['custom_outbounds'];
|
||||
}
|
||||
|
||||
if (!empty($node['custom_routes'])) {
|
||||
$response['custom_routes'] = $node['custom_routes'];
|
||||
}
|
||||
|
||||
if (!empty($node['cert_config'])) {
|
||||
$response['cert_config'] = $node['cert_config'];
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据协议类型和标识获取服务器
|
||||
* @param int $serverId
|
||||
|
||||
Reference in New Issue
Block a user