From 0e144f2d014371316c155c4d192bab99d74c721c Mon Sep 17 00:00:00 2001 From: infosave2007 Date: Tue, 27 Jan 2026 16:15:00 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=20API=20=D0=B4=D0=BB=D1=8F=20=D1=83?= =?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BB=D0=B8?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=BE=D0=B2,=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BE=D1=82=D0=BB=D0=B0=D0=B4=D0=BE?= =?UTF-8?q?=D1=87=D0=BD=D1=8B=D0=B9=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82?= =?UTF-8?q?=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B8?= =?UTF-8?q?=20XRay=20=D0=B8=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20InstallProt?= =?UTF-8?q?ocolManager::install=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=BF=D1=83=D0=B1=D0=BB=D0=B8=D1=87=D0=BD=D1=8B=D0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +++++ inc/InstallProtocolManager.php | 2 +- public/index.php | 33 ++++++++++++++++++++++++++++++++ scripts/debug_xray_stats.php | 35 ++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 scripts/debug_xray_stats.php diff --git a/.gitignore b/.gitignore index 34c1f77..a493424 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,8 @@ LDAP_FEATURE.md # Documentation and Tests tests/ docs/ +amnezia-web-panel.code-workspace +restore_local.php +test_protocols.php +scripts/regen_qr.php +scripts/test_xray_install.sh diff --git a/inc/InstallProtocolManager.php b/inc/InstallProtocolManager.php index f4abf95..f0d4bbe 100644 --- a/inc/InstallProtocolManager.php +++ b/inc/InstallProtocolManager.php @@ -241,7 +241,7 @@ class InstallProtocolManager return self::runScript($server, $protocol, 'detect', $options); } - private static function install(VpnServer $server, array $protocol, array $options = []): array + public static function install(VpnServer $server, array $protocol, array $options = []): array { $engine = self::getEngine($protocol); $serverId = $server->getId(); diff --git a/public/index.php b/public/index.php index f7e27f3..f5a0206 100644 --- a/public/index.php +++ b/public/index.php @@ -2199,6 +2199,39 @@ Router::post('/api/clients/{id}/restore', function ($params) { } }); +// API: Delete client +Router::delete('/api/clients/{id}/delete', function ($params) { + header('Content-Type: application/json'); + + $user = JWT::requireAuth(); + if (!$user) + return; + + $clientId = (int) $params['id']; + + try { + $client = new VpnClient($clientId); + $clientData = $client->getData(); + + // Check ownership + if ($clientData['user_id'] != $user['id'] && ($user['role'] ?? '') !== 'admin') { + http_response_code(403); + echo json_encode(['error' => 'Forbidden']); + return; + } + + if ($client->delete()) { + echo json_encode(['success' => true, 'message' => 'Client deleted']); + } else { + http_response_code(500); + echo json_encode(['error' => 'Failed to delete client']); + } + } catch (Exception $e) { + http_response_code(404); + echo json_encode(['error' => 'Client not found']); + } +}); + // API: Get server metrics Router::get('/api/servers/{id}/metrics', function ($params) { header('Content-Type: application/json'); diff --git a/scripts/debug_xray_stats.php b/scripts/debug_xray_stats.php new file mode 100644 index 0000000..25d76eb --- /dev/null +++ b/scripts/debug_xray_stats.php @@ -0,0 +1,35 @@ +getData(); + +if (!$data) { + die("Client not found\n"); +} + +echo "Client Name: " . $data['name'] . "\n"; +echo "Config: " . substr($data['config'], 0, 50) . "...\n"; + +echo "Running syncStats()...\n"; +try { + $res = $client->syncStats(); + echo "Sync Result: " . ($res ? 'TRUE' : 'FALSE') . "\n"; + + // Check DB + $fresh = new VpnClient($clientId); + $d = $fresh->getData(); + echo "Bytes Sent: " . $d['bytes_sent'] . "\n"; + echo "Bytes Recv: " . $d['bytes_received'] . "\n"; + echo "Last Handshake: " . $d['last_handshake'] . "\n"; + +} catch (Exception $e) { + echo "Error: " . $e->getMessage() . "\n"; +}