128 lines
6.6 KiB
PHP
128 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Services;
|
|
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.app')]
|
|
#[Title('Dienste — Clusev')]
|
|
class Index extends Component
|
|
{
|
|
/** active server (mock until the multi-server switcher + SSH layer land) */
|
|
public string $server = 'web-01';
|
|
|
|
/** wire:model search over service name + description */
|
|
public string $search = '';
|
|
|
|
/**
|
|
* Mock systemd units for the active server. Replaced by the SSH layer
|
|
* (systemctl list-units / show) via SshClient later.
|
|
*
|
|
* @var array<int, array{name:string,status:string,desc:string,enabled:bool}>
|
|
*/
|
|
public array $services = [];
|
|
|
|
/**
|
|
* Mock journalctl tail. Replaced by a streamed `journalctl -n … -f` read later.
|
|
*
|
|
* @var array<int, array{time:string,unit:string,level:string,text:string}>
|
|
*/
|
|
public array $journal = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->services = [
|
|
['name' => 'nginx.service', 'status' => 'online', 'enabled' => true, 'desc' => 'A high performance web server and a reverse proxy server'],
|
|
['name' => 'mariadb.service', 'status' => 'online', 'enabled' => true, 'desc' => 'MariaDB 11 database server'],
|
|
['name' => 'redis-server.service', 'status' => 'online', 'enabled' => true, 'desc' => 'Advanced key-value store'],
|
|
['name' => 'php8.3-fpm.service', 'status' => 'warning', 'enabled' => true, 'desc' => 'The PHP 8.3 FastCGI Process Manager'],
|
|
['name' => 'ssh.service', 'status' => 'online', 'enabled' => true, 'desc' => 'OpenBSD Secure Shell server'],
|
|
['name' => 'cron.service', 'status' => 'online', 'enabled' => true, 'desc' => 'Regular background program processing daemon'],
|
|
['name' => 'fail2ban.service', 'status' => 'offline', 'enabled' => false, 'desc' => 'Ban hosts that cause multiple authentication errors'],
|
|
['name' => 'docker.service', 'status' => 'online', 'enabled' => true, 'desc' => 'Docker Application Container Engine'],
|
|
['name' => 'systemd-timesyncd.service', 'status' => 'online', 'enabled' => true, 'desc' => 'Network Time Synchronization'],
|
|
['name' => 'rsyslog.service', 'status' => 'warning', 'enabled' => true, 'desc' => 'System Logging Service'],
|
|
];
|
|
|
|
$this->journal = [
|
|
['time' => 'Jun 12 09:41:07', 'unit' => 'nginx', 'level' => 'info', 'text' => 'Reloading nginx configuration'],
|
|
['time' => 'Jun 12 09:41:07', 'unit' => 'nginx', 'level' => 'info', 'text' => 'signal process started'],
|
|
['time' => 'Jun 12 09:40:55', 'unit' => 'php8.3-fpm', 'level' => 'warn', 'text' => '[pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers)'],
|
|
['time' => 'Jun 12 09:40:31', 'unit' => 'systemd', 'level' => 'info', 'text' => 'Started php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager.'],
|
|
['time' => 'Jun 12 09:40:30', 'unit' => 'systemd', 'level' => 'info', 'text' => 'Stopping php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager...'],
|
|
['time' => 'Jun 12 09:39:18', 'unit' => 'fail2ban', 'level' => 'error', 'text' => 'Failed to start fail2ban.service - exit code 255'],
|
|
['time' => 'Jun 12 09:39:18', 'unit' => 'fail2ban', 'level' => 'error', 'text' => 'Found no accessible config files for "filter sshd"'],
|
|
['time' => 'Jun 12 09:38:02', 'unit' => 'mariadb', 'level' => 'info', 'text' => "mariadbd: ready for connections. Version: '11.4.2-MariaDB' socket: '/run/mysqld/mysqld.sock' port: 3306"],
|
|
['time' => 'Jun 12 09:37:44', 'unit' => 'rsyslog', 'level' => 'warn', 'text' => 'imjournal: journal files changed, reloading...'],
|
|
['time' => 'Jun 12 09:36:09', 'unit' => 'sshd', 'level' => 'info', 'text' => 'Accepted publickey for admin from 10.10.90.10 port 51422 ssh2'],
|
|
['time' => 'Jun 12 09:35:51', 'unit' => 'redis-server', 'level' => 'info', 'text' => 'Background saving terminated with success'],
|
|
['time' => 'Jun 12 09:35:00', 'unit' => 'cron', 'level' => 'info', 'text' => '(root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Service control (R5): opens the wire-elements/modal confirm dialog. The
|
|
* modal writes the AuditEvent and re-dispatches `serviceConfirmed`, which
|
|
* applyService() handles. SSH exec (systemctl) is wired in behind this later.
|
|
*/
|
|
public function confirm(string $op, string $name): void
|
|
{
|
|
[$heading, $phrase, $label, $action, $icon] = match ($op) {
|
|
'start' => ['Dienst starten', 'wird gestartet', 'Starten', 'service.start', 'power'],
|
|
'stop' => ['Dienst stoppen', 'wird gestoppt', 'Stoppen', 'service.stop', 'power'],
|
|
default => ['Dienst neu starten', 'wird neu gestartet', 'Neu starten', 'service.restart', 'rotate'],
|
|
};
|
|
|
|
$this->dispatch('openModal',
|
|
component: 'modals.confirm-action',
|
|
arguments: [
|
|
'heading' => $heading,
|
|
'body' => "{$name} {$phrase}. Ausgeführt über systemctl auf {$this->server}.",
|
|
'confirmLabel' => $label,
|
|
'danger' => $op === 'stop',
|
|
'icon' => $icon,
|
|
'auditAction' => $action,
|
|
'auditTarget' => "{$name} · {$this->server}",
|
|
'event' => 'serviceConfirmed',
|
|
'params' => ['op' => $op, 'name' => $name],
|
|
'notify' => "{$name}: {$label} ausgeführt.",
|
|
],
|
|
);
|
|
}
|
|
|
|
/** Applies the confirmed service state change (mock until SSH exec lands). */
|
|
#[On('serviceConfirmed')]
|
|
public function applyService(string $op, string $name): void
|
|
{
|
|
foreach ($this->services as $i => $svc) {
|
|
if ($svc['name'] === $name) {
|
|
$this->services[$i]['status'] = $op === 'stop' ? 'offline' : 'online';
|
|
}
|
|
}
|
|
}
|
|
|
|
/** @return array<int, array{name:string,status:string,desc:string,enabled:bool}> */
|
|
public function getFilteredServicesProperty(): array
|
|
{
|
|
$q = trim(mb_strtolower($this->search));
|
|
|
|
if ($q === '') {
|
|
return $this->services;
|
|
}
|
|
|
|
return array_values(array_filter(
|
|
$this->services,
|
|
fn (array $s): bool => str_contains(mb_strtolower($s['name']), $q)
|
|
|| str_contains(mb_strtolower($s['desc']), $q)
|
|
));
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.services.index');
|
|
}
|
|
}
|