feat: Реализован API для удаления клиентов, добавлен отладочный скрипт статистики XRay и метод InstallProtocolManager::install сделан публичным.

This commit is contained in:
infosave2007
2026-01-27 16:15:00 +03:00
parent 7254bd1547
commit 0e144f2d01
4 changed files with 74 additions and 1 deletions
+5
View File
@@ -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
+1 -1
View File
@@ -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();
+33
View File
@@ -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');
+35
View File
@@ -0,0 +1,35 @@
<?php
require_once __DIR__ . '/../inc/Config.php';
require_once __DIR__ . '/../inc/DB.php';
require_once __DIR__ . '/../inc/VpnClient.php';
require_once __DIR__ . '/../inc/VpnServer.php';
$pdo = DB::conn();
$clientId = 4;
echo "Loading client $clientId...\n";
$client = new VpnClient($clientId);
$data = $client->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";
}