From e200146dc095bc9390efb14746af44347fdbdd4e Mon Sep 17 00:00:00 2001 From: infosave2007 Date: Fri, 30 Jan 2026 21:45:05 +0300 Subject: [PATCH] feat: Enforce single IP per user for Xray servers and update protocol checks --- bin/collect_metrics.php | 6 ++++++ inc/ServerMonitoring.php | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bin/collect_metrics.php b/bin/collect_metrics.php index 49f4acb..34909d8 100644 --- a/bin/collect_metrics.php +++ b/bin/collect_metrics.php @@ -55,6 +55,12 @@ while (true) { $monitoring = new ServerMonitoring($server['id']); + // Enforce single IP per user for Xray servers + $containerName = $server['container_name'] ?? ''; + if (strpos($containerName, 'xray') !== false) { + $monitoring->enforceXraySingleIpPerUser(); + } + // Collect server metrics $serverMetrics = $monitoring->collectMetrics(); echo " Server: CPU={$serverMetrics['cpu_percent']}% RAM={$serverMetrics['ram_used_mb']}/{$serverMetrics['ram_total_mb']}MB "; diff --git a/inc/ServerMonitoring.php b/inc/ServerMonitoring.php index 1e7e5a0..52425c1 100644 --- a/inc/ServerMonitoring.php +++ b/inc/ServerMonitoring.php @@ -275,9 +275,9 @@ class ServerMonitoring $bytesReceived = 0; $bytesSent = 0; - $slug = $this->serverData['slug']; // Assuming 'slug' is available in serverData + $protocol = $this->serverData['install_protocol'] ?? ''; - if ($slug === 'xray' || $slug === 'vless') { + if (strpos($protocol, 'xray') !== false || strpos($protocol, 'vless') !== false) { // Retrieve DELTA from cache if ($this->xrayStatsFetched) { // Try to find by UUID first (if we tracked it) or Email/Name @@ -556,9 +556,9 @@ class ServerMonitoring if (stripos($containerName, 'xray') !== false) { return $containerName; } - // Also check slug - $slug = $this->serverData['slug'] ?? ''; - if (stripos($slug, 'xray') !== false || stripos($slug, 'vless') !== false) { + // Also check protocol + $protocol = $this->serverData['install_protocol'] ?? ''; + if (stripos($protocol, 'xray') !== false || stripos($protocol, 'vless') !== false) { return $containerName ?: 'amnezia-xray'; } return null; @@ -598,7 +598,15 @@ class ServerMonitoring $ipsToBlock = []; foreach ($data['users'] as $user) { - $email = $user['email'] ?? null; + // Format: "user>>>email>>>online" + if (!is_string($user)) { + continue; + } + $parts = explode('>>>', $user); + if (count($parts) < 2) { + continue; + } + $email = $parts[1]; if (!$email) { continue; }