Integração Pangolin Proxy
This commit is contained in:
@@ -68,6 +68,16 @@ class ServerController
|
||||
$stmt = \App\Config\Database::getInstance()->getConnection()->prepare($sql);
|
||||
$stmt->execute($data);
|
||||
|
||||
// Pangolin Integration - Sincroniza o cliente após adicionar servidor
|
||||
try {
|
||||
$pangolinService = new \App\Services\PangolinService();
|
||||
if ($pangolinService->isEnabled() && $client['status'] === 'active') {
|
||||
$pangolinService->syncClient($_POST['client_id'], 'add');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log("Pangolin Sync Error (Server Create): " . $e->getMessage());
|
||||
}
|
||||
|
||||
View::redirect('/admin/servers');
|
||||
}
|
||||
|
||||
@@ -113,6 +123,12 @@ class ServerController
|
||||
}
|
||||
}
|
||||
|
||||
// Guardar IPs antigos para remover do Pangolin se mudaram
|
||||
$oldIpV4 = $server['ip_v4'];
|
||||
$oldIpV6 = $server['ip_v6'];
|
||||
$oldClientId = $server['client_id'];
|
||||
$oldStatus = $server['status'];
|
||||
|
||||
$data = [
|
||||
'id' => $id,
|
||||
'client_id' => $_POST['client_id'],
|
||||
@@ -126,13 +142,88 @@ class ServerController
|
||||
$stmt = \App\Config\Database::getInstance()->getConnection()->prepare($sql);
|
||||
$stmt->execute($data);
|
||||
|
||||
// Pangolin Integration - Sincroniza se IP, status ou cliente mudou
|
||||
try {
|
||||
$pangolinService = new \App\Services\PangolinService();
|
||||
if ($pangolinService->isEnabled()) {
|
||||
$clientModel = new Client();
|
||||
$client = $clientModel->find($_POST['client_id']);
|
||||
|
||||
// Coletar IPs que mudaram para remover
|
||||
$ipsToRemove = [];
|
||||
if ($oldIpV4 !== $_POST['ip_v4']) {
|
||||
$ipsToRemove[] = $oldIpV4;
|
||||
}
|
||||
if ($oldIpV6 !== ($_POST['ip_v6'] ?? null)) {
|
||||
$ipsToRemove[] = $oldIpV6;
|
||||
}
|
||||
|
||||
// Se o servidor era ativo e agora está inativo, remove os IPs
|
||||
if ($oldStatus === 'active' && $_POST['status'] === 'inactive') {
|
||||
$pangolinService->removeServerIps([$_POST['ip_v4'], $_POST['ip_v6'] ?? null]);
|
||||
}
|
||||
// Se o servidor era inativo e agora está ativo, adiciona os IPs
|
||||
elseif ($oldStatus === 'inactive' && $_POST['status'] === 'active') {
|
||||
if ($client && $client['status'] === 'active') {
|
||||
$pangolinService->syncClient($_POST['client_id'], 'add');
|
||||
}
|
||||
}
|
||||
// Se os IPs mudaram
|
||||
elseif (!empty($ipsToRemove) && $_POST['status'] === 'active') {
|
||||
$pangolinService->removeServerIps($ipsToRemove);
|
||||
if ($client && $client['status'] === 'active') {
|
||||
$pangolinService->syncClient($_POST['client_id'], 'add');
|
||||
}
|
||||
}
|
||||
|
||||
// Se o cliente mudou, sincroniza o cliente antigo também
|
||||
if ($oldClientId != $_POST['client_id']) {
|
||||
$oldClient = $clientModel->find($oldClientId);
|
||||
if ($oldClient && $oldClient['status'] === 'active') {
|
||||
$pangolinService->removeServerIps([$oldIpV4, $oldIpV6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log("Pangolin Sync Error (Server Update): " . $e->getMessage());
|
||||
}
|
||||
|
||||
View::redirect('/admin/servers');
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$serverModel = new Server();
|
||||
$server = $serverModel->find($id);
|
||||
|
||||
if (!$server) {
|
||||
View::redirect('/admin/servers');
|
||||
return;
|
||||
}
|
||||
|
||||
// Capturar IPs antes de deletar
|
||||
$ipsToRemove = [$server['ip_v4']];
|
||||
if (!empty($server['ip_v6'])) {
|
||||
$ipsToRemove[] = $server['ip_v6'];
|
||||
}
|
||||
|
||||
// Pangolin Integration - Remove os IPs do servidor antes de deletá-lo
|
||||
try {
|
||||
$pangolinService = new \App\Services\PangolinService();
|
||||
if ($pangolinService->isEnabled() && $server['status'] === 'active') {
|
||||
$clientModel = new Client();
|
||||
$client = $clientModel->find($server['client_id']);
|
||||
if ($client && $client['status'] === 'active') {
|
||||
$pangolinService->removeServerIps($ipsToRemove);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
error_log("Pangolin Sync Error (Server Delete): " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Delete the server
|
||||
$serverModel->delete($id);
|
||||
|
||||
View::redirect('/admin/servers');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user