can('manage-fleet'), 403); } public function title(): string { return __('terminal.title'); } /** Mint a single-use token for the host shell and hand it to the xterm island via an event. */ public function open(): void { abort_unless(Auth::user()?->can('manage-fleet'), 403); // With no host login configured yet, open the setup form instead of minting a dead session. if (HostCredential::current() === null) { $this->configureHost(); return; } $token = Str::random(48); TerminalSession::create([ 'token' => $token, 'user_id' => Auth::id(), 'kind' => 'host', 'server_id' => null, 'expires_at' => now()->addSeconds(60), 'created_at' => now(), ]); $this->dispatch('terminal-open', token: $token, title: __('terminal.host_label')); } /** Open the modal that stores the Clusev host SSH login. */ public function configureHost(): void { abort_unless(Auth::user()?->can('manage-fleet'), 403); $this->dispatch('openModal', component: 'modals.host-shell'); } /** The host-login modal saved/removed — re-render so the tile reflects the new state. */ #[On('hostShellSaved')] public function hostShellSaved(): void { // No state to set; the empty handler simply triggers a re-render. } public function render() { $host = HostCredential::current(); return view('livewire.terminal.index', [ 'hostConfigured' => $host !== null, 'hostTarget' => $host?->username, ])->title($this->title()); } }