feat: rcon console
This commit is contained in:
@@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
|
use App\Services\MinecraftRconClient;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Concerns\InteractsWithForms;
|
||||||
|
use Filament\Forms\Contracts\HasForms;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Pages\Page;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
|
||||||
|
class RconConsole extends Page implements HasForms
|
||||||
|
{
|
||||||
|
use InteractsWithForms;
|
||||||
|
|
||||||
|
protected string $view = 'filament.pages.rcon-console';
|
||||||
|
|
||||||
|
public static function getNavigationIcon(): string | \BackedEnum | null
|
||||||
|
{
|
||||||
|
return 'heroicon-o-command-line';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNavigationLabel(): string
|
||||||
|
{
|
||||||
|
return 'Console RCON';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHeading(): string|\Illuminate\Contracts\Support\Htmlable
|
||||||
|
{
|
||||||
|
return 'Console RCON Minecraft';
|
||||||
|
}
|
||||||
|
|
||||||
|
public ?array $data = [];
|
||||||
|
public ?string $output = null;
|
||||||
|
|
||||||
|
public function mount(): void
|
||||||
|
{
|
||||||
|
$this->form->fill();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->schema([
|
||||||
|
TextInput::make('command')
|
||||||
|
->label('Commande RCON')
|
||||||
|
->placeholder('ex: list, say Bonjour')
|
||||||
|
->required()
|
||||||
|
->autofocus(),
|
||||||
|
])
|
||||||
|
->statePath('data');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function executeCommand(MinecraftRconClient $client): void
|
||||||
|
{
|
||||||
|
$data = $this->form->getState();
|
||||||
|
$command = $data['command'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $client->command($command);
|
||||||
|
|
||||||
|
// Format response if empty
|
||||||
|
$this->output = blank($response) ? "(Commande exécutée, aucun retour texte)" : $response;
|
||||||
|
|
||||||
|
// Clear input
|
||||||
|
$this->form->fill();
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title('Commande envoyée')
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->output = null;
|
||||||
|
Notification::make()
|
||||||
|
->title('Erreur RCON')
|
||||||
|
->body($e->getMessage())
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<x-filament-panels::page>
|
||||||
|
<form wire:submit="executeCommand">
|
||||||
|
{{ $this->form }}
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
<x-filament::button type="submit">
|
||||||
|
Exécuter
|
||||||
|
</x-filament::button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@if ($output !== null)
|
||||||
|
<div class="mt-6 space-y-2">
|
||||||
|
<h3 class="text-lg font-medium">Résultat du serveur :</h3>
|
||||||
|
<pre class="p-4 bg-gray-950 text-emerald-400 rounded-xl overflow-x-auto whitespace-pre-wrap font-mono text-sm leading-relaxed border border-gray-800 shadow-inner">{{ $output }}</pre>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</x-filament-panels::page>
|
||||||
+2
-1
@@ -3,4 +3,5 @@
|
|||||||
use App\Http\Controllers\AccessRequestsController;
|
use App\Http\Controllers\AccessRequestsController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::post('/access-requests', [AccessRequestsController::class, 'store']);
|
Route::post('/access-requests', [AccessRequestsController::class, 'store'])
|
||||||
|
->middleware('throttle:3,1'); // Limite à 3 requêtes par minute
|
||||||
|
|||||||
Reference in New Issue
Block a user