feat: dashboard version local, bottom nav simplificado, services+actions tabs
- Dashboard muestra version del gradle (no API) - Header sin iconos duplicados (notifications solo en bottom nav) - Bottom nav: Dashboard, Servers, Alerts (sin Profile ni Logout) - ServerDetail: tab Services con lista de systemd services - ServerDetail: tab Actions con Test/Reboot/Shutdown - Backend: API endpoints para services, reboot, shutdown, test
This commit is contained in:
@@ -553,6 +553,138 @@ class ApiController
|
||||
$this->view->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function serverServices(int $id): void
|
||||
{
|
||||
$user = $this->authenticateRequest();
|
||||
|
||||
$serverModel = new Server();
|
||||
if (!$serverModel->canView($id, (int) $user['id'])) {
|
||||
$this->view->json(['error' => 'Server not found'], 404);
|
||||
}
|
||||
|
||||
$server = $serverModel->findById($id);
|
||||
if (!$server) {
|
||||
$this->view->json(['error' => 'Server not found'], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
$ssh = new SSHService();
|
||||
if (!$ssh->connect($server)) {
|
||||
throw new \RuntimeException('SSH connection failed');
|
||||
}
|
||||
|
||||
$output = $ssh->exec('systemctl list-units --type=service --no-pager --no-legend 2>/dev/null | head -50');
|
||||
$ssh->disconnect();
|
||||
|
||||
$services = [];
|
||||
if ($output['exit_status'] === 0) {
|
||||
foreach (explode("\n", trim($output['output'])) as $line) {
|
||||
if (preg_match('/^\s*([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/', $line, $m)) {
|
||||
$services[] = [
|
||||
'name' => trim($m[1]),
|
||||
'load' => trim($m[2]),
|
||||
'status' => trim($m[3]),
|
||||
'description' => trim($m[4] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->json([
|
||||
'success' => true,
|
||||
'data' => $services,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
$this->view->json([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function serverReboot(int $id): void
|
||||
{
|
||||
$this->executeServerAction($id, 'reboot', '/sbin/reboot');
|
||||
}
|
||||
|
||||
public function serverShutdown(int $id): void
|
||||
{
|
||||
$this->executeServerAction($id, 'shutdown', '/sbin/shutdown -h now');
|
||||
}
|
||||
|
||||
public function serverTestConnection(int $id): void
|
||||
{
|
||||
$user = $this->authenticateRequest();
|
||||
|
||||
$serverModel = new Server();
|
||||
if (!$serverModel->canView($id, (int) $user['id'])) {
|
||||
$this->view->json(['error' => 'Server not found'], 404);
|
||||
}
|
||||
|
||||
$server = $serverModel->findById($id);
|
||||
if (!$server) {
|
||||
$this->view->json(['error' => 'Server not found'], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
$ssh = new SSHService();
|
||||
$connected = $ssh->connect($server);
|
||||
if ($connected) {
|
||||
$ssh->disconnect();
|
||||
}
|
||||
$this->view->json([
|
||||
'success' => true,
|
||||
'data' => ['connected' => $connected],
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
$this->view->json([
|
||||
'success' => true,
|
||||
'data' => ['connected' => false, 'error' => $e->getMessage()],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function executeServerAction(int $id, string $action, string $command): void
|
||||
{
|
||||
$user = $this->authenticateRequest();
|
||||
|
||||
$serverModel = new Server();
|
||||
if (!$serverModel->canManage($id, (int) $user['id'])) {
|
||||
$this->view->json(['error' => 'Forbidden'], 403);
|
||||
}
|
||||
|
||||
$server = $serverModel->findById($id);
|
||||
if (!$server) {
|
||||
$this->view->json(['error' => 'Server not found'], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
$ssh = new SSHService();
|
||||
if (!$ssh->connect($server)) {
|
||||
throw new \RuntimeException('SSH connection failed');
|
||||
}
|
||||
$result = $ssh->exec($command);
|
||||
$ssh->disconnect();
|
||||
|
||||
$auditService = new AuditService();
|
||||
$auditService->log("server_{$action}", 'server', $id, ['name' => $server['name']]);
|
||||
|
||||
$this->view->json([
|
||||
'success' => true,
|
||||
'message' => ucfirst($action) . ' command executed.',
|
||||
'data' => [
|
||||
'output' => $result['output'],
|
||||
'exit_status' => $result['exit_status'],
|
||||
],
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
$this->view->json([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function login(): void
|
||||
{
|
||||
$input = json_decode(file_get_contents('php://input'), true) ?? $_POST;
|
||||
|
||||
Reference in New Issue
Block a user