Integração Pangolin Proxy
This commit is contained in:
@@ -72,6 +72,17 @@ class ClientController
|
||||
'client_id' => $clientId
|
||||
]);
|
||||
|
||||
// Pangolin Integration
|
||||
try {
|
||||
$pangolinService = new \App\Services\PangolinService();
|
||||
if ($pangolinService->isEnabled()) {
|
||||
$pangolinService->syncClient($clientId, 'add');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Log error silently, don't break the flow
|
||||
error_log("Pangolin Sync Error (Create): " . $e->getMessage());
|
||||
}
|
||||
|
||||
View::redirect('/admin/clients');
|
||||
}
|
||||
|
||||
@@ -131,19 +142,64 @@ class ClientController
|
||||
$stmtUser = $conn->prepare($sqlUser);
|
||||
$stmtUser->execute($paramsUser);
|
||||
|
||||
// Cascade Deactivate Servers
|
||||
// Pangolin Integration - Buscar IPs dos servidores ATIVOS ANTES de desativá-los
|
||||
$serverIpsToRemove = [];
|
||||
if ($_POST['status'] === 'inactive') {
|
||||
$stmtIps = $conn->prepare("SELECT ip_v4, ip_v6 FROM servers WHERE client_id = :client_id AND status = 'active'");
|
||||
$stmtIps->execute(['client_id' => $id]);
|
||||
$servers = $stmtIps->fetchAll(\PDO::FETCH_ASSOC);
|
||||
foreach ($servers as $server) {
|
||||
if (!empty($server['ip_v4'])) {
|
||||
$serverIpsToRemove[] = $server['ip_v4'];
|
||||
}
|
||||
if (!empty($server['ip_v6'])) {
|
||||
$serverIpsToRemove[] = $server['ip_v6'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cascade Deactivate Servers quando cliente é desativado
|
||||
if ($_POST['status'] === 'inactive') {
|
||||
$sqlServers = "UPDATE servers SET status = 'inactive' WHERE client_id = :client_id";
|
||||
$stmtServers = $conn->prepare($sqlServers);
|
||||
$stmtServers->execute(['client_id' => $id]);
|
||||
}
|
||||
|
||||
// Pangolin Integration - Sincroniza com base no status
|
||||
try {
|
||||
$pangolinService = new \App\Services\PangolinService();
|
||||
if ($pangolinService->isEnabled()) {
|
||||
if ($_POST['status'] === 'active') {
|
||||
$pangolinService->syncClient($id, 'add');
|
||||
} else {
|
||||
// Remove os IPs que foram coletados antes de desativar os servidores
|
||||
if (!empty($serverIpsToRemove)) {
|
||||
$pangolinService->removeServerIps($serverIpsToRemove);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log("Pangolin Sync Error (Update): " . $e->getMessage());
|
||||
}
|
||||
|
||||
View::redirect('/admin/clients');
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$clientModel = new Client();
|
||||
|
||||
// Pangolin Integration (Remove before delete to get ASN)
|
||||
try {
|
||||
$client = $clientModel->find($id);
|
||||
if ($client && $client['status'] === 'active') {
|
||||
$pangolinService = new \App\Services\PangolinService();
|
||||
$pangolinService->syncClient($id, 'remove');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log("Pangolin Sync Error (Delete): " . $e->getMessage());
|
||||
}
|
||||
|
||||
$clientModel->delete($id);
|
||||
View::redirect('/admin/clients');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user