wafInstalled = $this->detectWaf(); $this->wafFormData = [ 'enabled' => Setting::get('waf_enabled', '0') === '1', 'paranoia' => Setting::get('waf_paranoia', '1'), 'audit_log' => Setting::get('waf_audit_log', '1') === '1', ]; } protected function detectWaf(): bool { return file_exists('/etc/nginx/modsec/main.conf') || file_exists('/etc/nginx/modsecurity.conf'); } protected function getForms(): array { return ['wafForm']; } public function wafForm(\Filament\Schemas\Schema $schema): \Filament\Schemas\Schema { return $schema ->statePath('wafFormData') ->schema([ Section::make(__('WAF Settings')) ->schema([ Toggle::make('enabled') ->label(__('Enable ModSecurity')), Select::make('paranoia') ->label(__('Paranoia Level')) ->options([ '1' => '1 - Basic', '2' => '2 - Moderate', '3' => '3 - Strict', '4' => '4 - Very Strict', ]) ->default('1'), Toggle::make('audit_log') ->label(__('Enable Audit Log')), ]) ->columns(2), ]); } public function saveWafSettings(): void { $data = $this->wafForm->getState(); Setting::set('waf_enabled', ! empty($data['enabled']) ? '1' : '0'); Setting::set('waf_paranoia', (string) ($data['paranoia'] ?? '1')); Setting::set('waf_audit_log', ! empty($data['audit_log']) ? '1' : '0'); try { $agent = new AgentClient; $agent->wafApplySettings( ! empty($data['enabled']), (string) ($data['paranoia'] ?? '1'), ! empty($data['audit_log']) ); Notification::make() ->title(__('WAF settings applied')) ->success() ->send(); } catch (Exception $e) { Notification::make() ->title(__('WAF settings saved, but apply failed')) ->body($e->getMessage()) ->warning() ->send(); } } }