*/ public array $jails = []; public string $jail = ''; public string $ip = ''; public ?string $error = null; /** * @param array $jails */ public function mount(int $serverId, array $jails = []): void { $this->serverId = $serverId; $this->jails = array_values($jails); $this->jail = $this->jails[0] ?? 'sshd'; } public static function modalMaxWidth(): string { return 'lg'; } public function save(Fail2banService $fail2ban): void { $this->error = null; $server = Server::find($this->serverId); if (! $server) { $this->error = __('common.server_not_found'); return; } try { $res = $fail2ban->ban($server, $this->jail, trim($this->ip)); } catch (Throwable $e) { $this->error = $e->getMessage(); return; } if (! $res['ok']) { $this->error = $res['output'] !== '' ? $res['output'] : __('modals.fail2ban_ban.error_ban_failed'); return; } AuditEvent::create([ 'user_id' => Auth::id(), 'server_id' => $server->id, 'actor' => Auth::user()?->name ?? 'system', 'action' => 'fail2ban.ban', 'target' => trim($this->ip).' · '.$this->jail.' · '.$server->name, 'ip' => request()->ip(), ]); $this->dispatch('fail2banChanged'); $this->dispatch('notify', message: __('modals.fail2ban_ban.notify_banned', ['ip' => trim($this->ip)])); $this->closeModal(); } public function render() { return view('livewire.modals.fail2ban-ban'); } }