import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Play, Square, ChevronDown, Loader2, Target, Hash, Clock, Zap, Settings2, User, Lock, Globe2, Ban, Activity, Wifi, CheckCircle2, XCircle } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Switch } from '@/components/ui/switch'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Alert, AlertDescription } from '@/components/ui/alert'; import type { ScanRequest, ScanPreset } from '@/lib/api'; interface ScanFormProps { formData: ScanRequest; onFormChange: (data: ScanRequest) => void; presets: ScanPreset[]; isRunning: boolean; isStopping: boolean; loading: boolean; error: string | null; onStart: () => void; onStop: () => void; } export function ScanForm({ formData, onFormChange, presets, isRunning, isStopping, loading, error, onStart, onStop, }: ScanFormProps) { const { t, i18n } = useTranslation(); const [showAdvanced, setShowAdvanced] = useState(false); const updateField = (key: K, value: ScanRequest[K]) => { onFormChange({ ...formData, [key]: value }); }; const applyPreset = (presetId: string) => { const preset = presets.find(p => p.id === presetId); if (preset) { onFormChange({ ...formData, ports: preset.ports, scan_mode: preset.scan_mode, thread_num: preset.thread_num, timeout: preset.timeout, }); } }; const disabled = isRunning; return ( {t('scanTitle')} {isRunning ? ( ) : ( )} {error && ( {error} )} {/* Row 1: Target */}
updateField('host', e.target.value)} disabled={disabled} className="field-input-mono" />
{/* Row 2: Ports + Preset + Threads + Timeout */}
updateField('ports', e.target.value)} disabled={disabled} className="field-input-mono" />
updateField('thread_num', parseInt(e.target.value) || 600)} disabled={disabled} className="field-input-mono" />
updateField('timeout', parseInt(e.target.value) || 3)} disabled={disabled} className="field-input-mono" />
{/* Advanced Options */}
{/* Switches */}
updateField('disable_ping', checked)} disabled={disabled} />
updateField('disable_brute', checked)} disabled={disabled} />
updateField('alive_only', checked)} disabled={disabled} />
{/* Credentials */}
updateField('username', e.target.value)} disabled={disabled} className="field-input" />
updateField('password', e.target.value)} disabled={disabled} className="field-input" />
updateField('domain', e.target.value)} disabled={disabled} className="field-input" />
{/* Exclusions */}
updateField('exclude_hosts', e.target.value)} disabled={disabled} className="field-input-mono" />
updateField('exclude_ports', e.target.value)} disabled={disabled} className="field-input-mono" />
); }