You've already forked Atomcms-edit
cbe189fd96
- Create EmulatorControlAction and NitroControlAction classes - Extract business logic from Commandocentrum controller methods - Add Blade components for status cards, diagnostics, and summary cards - Replace shell_exec with file_get_contents in config reading - Remove duplicate methods and unused code - Commandocentrum reduced from 2033 to 1780 lines
88 lines
2.5 KiB
PHP
Executable File
88 lines
2.5 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Commandocentrum;
|
|
|
|
use App\Services\EmulatorUpdateService;
|
|
use App\Services\RconService;
|
|
use App\Services\SettingsService;
|
|
use Illuminate\Support\Facades\Process;
|
|
|
|
class EmulatorControlAction
|
|
{
|
|
public function __construct(
|
|
private readonly SettingsService $settings,
|
|
private readonly EmulatorUpdateService $updateService,
|
|
) {}
|
|
|
|
public function start(): array
|
|
{
|
|
$serviceName = $this->settings->getOrDefault('emulator_service_name', 'arcturus');
|
|
$result = Process::timeout(30)->run("systemctl start {$serviceName} 2>&1");
|
|
|
|
return [
|
|
'success' => $result->successful(),
|
|
'message' => $result->successful() ? 'Emulator gestart!' : ($result->output() ?: 'Kon emulator niet starten'),
|
|
];
|
|
}
|
|
|
|
public function stop(): array
|
|
{
|
|
$serviceName = $this->settings->getOrDefault('emulator_service_name', 'arcturus');
|
|
$result = Process::timeout(30)->run("systemctl stop {$serviceName} 2>&1");
|
|
|
|
return [
|
|
'success' => $result->successful(),
|
|
'message' => $result->successful() ? 'Emulator gestopt!' : ($result->output() ?: 'Kon emulator niet stoppen'),
|
|
];
|
|
}
|
|
|
|
public function restart(): array
|
|
{
|
|
$serviceName = $this->settings->getOrDefault('emulator_service_name', 'arcturus');
|
|
$result = Process::timeout(60)->run("systemctl restart {$serviceName} 2>&1");
|
|
|
|
return [
|
|
'success' => $result->successful(),
|
|
'message' => $result->successful() ? 'Emulator herstart!' : ($result->output() ?: 'Kon emulator niet herstarten'),
|
|
];
|
|
}
|
|
|
|
public function sendAlert(string $message): array
|
|
{
|
|
if (empty($message)) {
|
|
return ['success' => false, 'message' => 'Bericht mag niet leeg zijn'];
|
|
}
|
|
|
|
app(RconService::class)->sendCommand('alert', ['message' => $message]);
|
|
|
|
return ['success' => true, 'message' => 'Alert verstuurd naar alle gebruikers!'];
|
|
}
|
|
|
|
public function build(): array
|
|
{
|
|
return $this->updateService->buildFromSource();
|
|
}
|
|
|
|
public function update(): array
|
|
{
|
|
return $this->updateService->updateEmulator();
|
|
}
|
|
|
|
public function runSqlUpdates(): array
|
|
{
|
|
return $this->updateService->runSqlUpdates();
|
|
}
|
|
|
|
public function getBackups(): array
|
|
{
|
|
return $this->updateService->getBackupList();
|
|
}
|
|
|
|
public function restoreBackup(string $backupName): array
|
|
{
|
|
return $this->updateService->restoreBackup($backupName);
|
|
}
|
|
}
|