<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>UltyScan - Web Interface</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="assets/style.css">
</head>

<body>
    <div class="container">
        <!-- Header -->
        <header class="header">
            <h1>🔍 UltyScan</h1>
            <p class="subtitle">Attack Surface Management Platform</p>
            <div style="margin-top: 1rem; display: flex; align-items: center; justify-content: center; gap: 1rem;">
                <span id="scan-status" class="status-badge status-idle">Idle</span>
                <button id="stop-scan-btn" class="btn btn-danger" style="display: none; padding: 0.5rem 1rem; font-size: 0.85rem;" onclick="stopAllScans()">
                    ⏹ Stop Scan
                </button>
            </div>
        </header>

        <!-- Tabs -->
        <div class="tabs" style="display: flex; justify-content: space-between; align-items: center;">
            <div>
                <button class="tab active" data-tab="scan-tab">New Scan</button>
                <button class="tab" data-tab="workspaces-tab">Workspaces</button>
                <button class="tab" data-tab="console-tab">Console</button>
                <button class="tab" data-tab="settings-tab">Settings</button>
            </div>
            <div id="version-display" style="font-size: 0.75rem; color: var(--text-muted); padding-right: 1rem;">
                <!-- Loaded by JS -->
            </div>
        </div>

        <!-- Scan Tab -->
        <div id="scan-tab" class="tab-content active">
            <div class="card">
                <div class="card-header">
                    <svg class="icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
                    </svg>
                    <h2>Configure Scan</h2>
                </div>

                <form id="scan-form" onsubmit="submitScan(event)">
                    <div class="form-grid">
                        <!-- Target -->
                        <div class="form-group" id="single-target-group">
                            <label for="target">Target (Domain or IP)</label>
                            <input type="text" id="target" name="target" placeholder="example.com or 192.168.1.1" required>
                        </div>

                        <!-- Target File (for mass scans) -->
                        <div class="form-group" id="target-file-group" style="display: none;">
                            <label for="target_file">Target File (one per line)</label>
                            <textarea id="target_file" name="target_file" rows="4" placeholder="example1.com&#10;example2.com&#10;192.168.1.0/24"></textarea>
                        </div>

                        <!-- Mode -->
                        <div class="form-group">
                            <label for="mode">Scan Mode</label>
                            <select id="mode" name="mode">
                                <option value="normal">Normal - Balanced scan</option>
                                <option value="stealth">Stealth - Low profile</option>
                                <option value="web">Web - Ports 80/443 only</option>
                                <option value="webscan">WebScan - Full web app scan</option>
                                <option value="webporthttp">WebPortHTTP - HTTP on custom port</option>
                                <option value="webporthttps">WebPortHTTPS - HTTPS on custom port</option>
                                <option value="port">Port - Specific port scan</option>
                                <option value="fullportonly">FullPortOnly - All 65535 ports</option>
                                <option value="discover">Discover - Network discovery</option>
                                <option value="flyover">Flyover - Quick multi-target</option>
                                <option value="airstrike">Airstrike - Fast enumeration</option>
                                <option value="nuke">Nuke - Full aggressive audit</option>
                                <option value="massportscan">MassPortScan - Multi-target ports</option>
                                <option value="massweb">MassWeb - Multi-target web</option>
                                <option value="masswebscan">MassWebScan - Multi-target webapp</option>
                                <option value="massvulnscan">MassVulnScan - Multi-target vulns</option>
                            </select>
                        </div>

                        <!-- Workspace -->
                        <div class="form-group">
                            <label for="workspace">Workspace Name</label>
                            <input type="text" id="workspace" name="workspace" placeholder="project-alpha">
                        </div>

                        <!-- Port (for port modes) -->
                        <div class="form-group" id="port-group" style="display: none;">
                            <label for="port">Port Number</label>
                            <input type="number" id="port" name="port" min="1" max="65535" placeholder="8080">
                        </div>
                    </div>

                    <!-- Options -->
                    <div class="form-group full-width" style="margin-top: 1.5rem;">
                        <label>Additional Options</label>
                        <div class="checkbox-grid">
                            <label class="checkbox-item">
                                <input type="checkbox" name="osint" value="1">
                                <span>Enable OSINT</span>
                            </label>
                            <label class="checkbox-item">
                                <input type="checkbox" name="recon" value="1">
                                <span>Enable Recon</span>
                            </label>
                            <label class="checkbox-item">
                                <input type="checkbox" name="bruteforce" value="1">
                                <span>Enable Bruteforce</span>
                            </label>
                            <label class="checkbox-item">
                                <input type="checkbox" name="fullportscan" value="1">
                                <span>Full Port Scan</span>
                            </label>
                        </div>
                    </div>

                    <div class="btn-group">
                        <button type="submit" class="btn btn-primary">
                            <svg width="16" height="16" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z" />
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                            </svg>
                            Start Scan
                        </button>
                        <button type="reset" class="btn btn-secondary">Clear Form</button>
                    </div>
                </form>
            </div>

            <!-- Scan Mode Guide -->
            <div class="card" style="margin-top: 1.5rem;">
                <div class="card-header">
                    <svg class="icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                    </svg>
                    <h2>Scan Mode Guide</h2>
                </div>

                <div style="padding: 1rem;">
                    <p style="color: var(--text-secondary); margin-bottom: 1.5rem;">
                        Choose the right scan mode based on what you're trying to discover. Each mode is designed for different situations.
                    </p>

                    <!-- Quick Start -->
                    <div style="background: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.3); border-radius: 8px; padding: 1rem; margin-bottom: 1.5rem;">
                        <h4 style="color: var(--accent-primary); margin-bottom: 0.5rem;">🎯 Quick Recommendations</h4>
                        <ul style="color: var(--text-secondary); padding-left: 1.5rem; margin: 0;">
                            <li><strong>First time scanning a target?</strong> → Use <code>Normal</code></li>
                            <li><strong>Testing a website/web app?</strong> → Use <code>WebScan</code></li>
                            <li><strong>Need to stay undetected?</strong> → Use <code>Stealth</code></li>
                            <li><strong>Quick scan of many targets?</strong> → Use <code>Flyover</code></li>
                            <li><strong>Full security audit?</strong> → Use <code>Nuke</code></li>
                        </ul>
                    </div>

                    <!-- Single Target Modes -->
                    <h4 style="margin-bottom: 1rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem;">
                        👤 Single Target Modes
                    </h4>

                    <div class="mode-grid" style="display: grid; gap: 1rem; margin-bottom: 1.5rem;">
                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-primary);">
                            <h5 style="color: var(--accent-primary); margin-bottom: 0.25rem;">Normal</h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> General-purpose scanning when you don't know what to expect
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                Performs port scanning, service detection, basic web checks, and vulnerability scanning. Good balance of speed and coverage.
                            </p>
                        </div>

                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-secondary);">
                            <h5 style="color: var(--accent-secondary); margin-bottom: 0.25rem;">Stealth</h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> When you need to avoid detection or minimize network noise
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                Uses slower, quieter techniques. Avoids aggressive scanning that could trigger alerts. Takes longer but less likely to be noticed.
                            </p>
                        </div>

                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-success);">
                            <h5 style="color: var(--accent-success); margin-bottom: 0.25rem;">Web <span style="font-size: 0.75rem; background: rgba(16, 185, 129, 0.2); padding: 0.15rem 0.4rem; border-radius: 4px;">📸 Screenshots</span></h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> Targets you know are websites (ports 80 and 443 only)
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                Focuses only on web services. Fast because it skips non-web ports. Captures screenshots, checks technologies, and finds common web issues.
                            </p>
                        </div>

                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-warning);">
                            <h5 style="color: var(--accent-warning); margin-bottom: 0.25rem;">WebScan <span style="font-size: 0.75rem; background: rgba(245, 158, 11, 0.2); padding: 0.15rem 0.4rem; border-radius: 4px;">📸 Screenshots</span></h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> Deep web application security testing
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                Thorough web app analysis including directory brute-forcing, vulnerability scanning with Nikto/Nuclei, CMS detection, and more. Takes longer but finds more issues.
                            </p>
                        </div>

                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-info);">
                            <h5 style="color: #06b6d4; margin-bottom: 0.25rem;">Port / WebPortHTTP / WebPortHTTPS <span style="font-size: 0.75rem; background: rgba(6, 182, 212, 0.2); padding: 0.15rem 0.4rem; border-radius: 4px;">📸 WebPort modes</span></h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> Services running on non-standard ports (e.g., web server on port 8080)
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                Enter the specific port number when using these modes. Use WebPortHTTP for HTTP services or WebPortHTTPS for HTTPS services on custom ports.
                            </p>
                        </div>

                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-danger);">
                            <h5 style="color: var(--accent-danger); margin-bottom: 0.25rem;">FullPortOnly</h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> Finding services hidden on unusual ports
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                Scans all 65,535 ports. Very thorough but takes significantly longer. Use when you suspect services are running on non-standard ports.
                            </p>
                        </div>
                    </div>

                    <!-- Multi-Target Modes -->
                    <h4 style="margin-bottom: 1rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem;">
                        👥 Multi-Target Modes <span style="font-size: 0.8rem; color: var(--text-muted);">(require target file)</span>
                    </h4>

                    <div class="mode-grid" style="display: grid; gap: 1rem; margin-bottom: 1.5rem;">
                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-primary);">
                            <h5 style="color: var(--accent-primary); margin-bottom: 0.25rem;">Flyover</h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> Quick reconnaissance of many targets
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                Fast overview of multiple targets. Perfect for initial scoping to identify which targets need deeper investigation.
                            </p>
                        </div>

                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-secondary);">
                            <h5 style="color: var(--accent-secondary); margin-bottom: 0.25rem;">Airstrike</h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> Fast enumeration across many targets
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                More thorough than Flyover but still optimized for speed. Good for medium-depth scanning of a target list.
                            </p>
                        </div>

                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-danger);">
                            <h5 style="color: var(--accent-danger); margin-bottom: 0.25rem;">Nuke <span style="font-size: 0.75rem; background: rgba(239, 68, 68, 0.2); padding: 0.15rem 0.4rem; border-radius: 4px;">📸 Screenshots</span></h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> Complete security audit of multiple targets
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                ⚠️ <strong>Aggressive mode.</strong> Runs everything - all scans, all checks, maximum coverage. Very thorough but time-consuming and noisy.
                            </p>
                        </div>

                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-info);">
                            <h5 style="color: #06b6d4; margin-bottom: 0.25rem;">MassWeb / MassWebScan / MassVulnScan / MassPortScan <span style="font-size: 0.75rem; background: rgba(6, 182, 212, 0.2); padding: 0.15rem 0.4rem; border-radius: 4px;">📸 MassWeb* modes</span></h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> Running specific scan types across many targets
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                Specialized bulk scanning. MassWeb for web detection, MassWebScan for deep web analysis, MassVulnScan for vulnerability scanning, MassPortScan for port discovery.
                            </p>
                        </div>

                        <div class="mode-item" style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem; border-left: 3px solid var(--accent-success);">
                            <h5 style="color: var(--accent-success); margin-bottom: 0.25rem;">Discover</h5>
                            <p style="color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem;">
                                <strong>Best for:</strong> Network/CIDR range scanning (e.g., 192.168.1.0/24)
                            </p>
                            <p style="color: var(--text-muted); font-size: 0.85rem;">
                                Use to find live hosts on a network. Enter a network range instead of a single target to discover all active devices.
                            </p>
                        </div>
                    </div>

                    <!-- Options Explained -->
                    <h4 style="margin-bottom: 1rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem;">
                        ⚙️ Additional Options Explained
                    </h4>

                    <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem;">
                        <div style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem;">
                            <h5 style="color: var(--accent-primary); margin-bottom: 0.5rem;">✓ Enable OSINT</h5>
                            <p style="color: var(--text-secondary); font-size: 0.85rem;">
                                Searches public sources (Shodan, Censys, etc.) for information about your target. Finds exposed services, historical data, and leaked information.
                            </p>
                        </div>
                        <div style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem;">
                            <h5 style="color: var(--accent-secondary); margin-bottom: 0.5rem;">✓ Enable Recon</h5>
                            <p style="color: var(--text-secondary); font-size: 0.85rem;">
                                Discovers subdomains and DNS information. Essential for finding all assets associated with a domain (e.g., mail.example.com, dev.example.com).
                            </p>
                        </div>
                        <div style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem;">
                            <h5 style="color: var(--accent-warning); margin-bottom: 0.5rem;">✓ Enable Bruteforce</h5>
                            <p style="color: var(--text-secondary); font-size: 0.85rem;">
                                Attempts to find hidden directories and login pages. Also tries common password attacks on discovered services. ⚠️ Can be noisy.
                            </p>
                        </div>
                        <div style="background: var(--bg-secondary); border-radius: 8px; padding: 1rem;">
                            <h5 style="color: var(--accent-danger); margin-bottom: 0.5rem;">✓ Full Port Scan</h5>
                            <p style="color: var(--text-secondary); font-size: 0.85rem;">
                                Scans all 65,535 ports instead of just common ones. Takes much longer but finds services running on unusual ports.
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Workspaces Tab -->
        <div id="workspaces-tab" class="tab-content">
            <div class="card">
                <div class="card-header">
                    <svg class="icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
                    </svg>
                    <h2>Workspaces</h2>
                </div>

                <div class="btn-group" style="margin-bottom: 1.5rem;">
                    <button class="btn btn-secondary" onclick="loadWorkspaces()">
                        Refresh List
                    </button>
                </div>

                <div id="workspace-list" class="workspace-list">
                    <p style="color: var(--text-secondary);">Loading workspaces...</p>
                </div>
            </div>
        </div>

        <!-- Console Tab -->
        <div id="console-tab" class="tab-content">
            <div class="card">
                <div class="card-header">
                    <svg class="icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
                    </svg>
                    <h2>Console Output</h2>
                </div>

                <div id="console-output" class="console">UltyScan Web Interface v1.0
                    Ready to scan...</div>

                <div class="btn-group">
                    <button class="btn btn-secondary" onclick="document.getElementById('console-output').textContent = 'Console cleared.\n'">
                        Clear Console
                    </button>
                    <button class="btn btn-secondary" onclick="checkScanStatus()">
                        Refresh Status
                    </button>
                </div>
            </div>
        </div>

        <!-- Settings Tab -->
        <div id="settings-tab" class="tab-content">
            <div class="card">
                <div class="card-header">
                    <svg class="icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
                    </svg>
                    <h2>System Actions</h2>
                </div>

                <div class="btn-group">
                    <button class="btn btn-secondary" onclick="updateScanner()">
                        Update UltyScan
                    </button>
                    <button class="btn btn-danger" onclick="if(confirm('Stop all running scans?')) stopAllScans()">
                        Stop All Scans
                    </button>
                </div>

                <div style="margin-top: 2rem;">
                    <h3 style="margin-bottom: 1rem; font-size: 1rem;">Scanner Info</h3>
                    <p style="color: var(--text-secondary); font-size: 0.9rem;">
                        Install Directory: <code style="color: var(--accent-primary);">/usr/share/sniper</code><br>
                        Loot Directory: <code style="color: var(--accent-primary);">/usr/share/sniper/loot/workspace</code>
                    </p>
                </div>
            </div>
        </div>
    </div>

    <script src="assets/script.js"></script>
    <script>
        // Additional inline functions
        async function updateScanner() {
            if (!confirm('Update UltyScan to latest version from GitHub?')) return;

            const btn = event.target;
            btn.disabled = true;
            btn.textContent = 'Updating...';

            showNotification('Pulling latest changes from GitHub...', 'info');
            try {
                const response = await fetch('execute.php', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    body: 'action=update'
                });
                const result = await response.json();
                if (result.success) {
                    showNotification('Updated to commit #' + result.commit + '. Refreshing page...', 'success');
                    setTimeout(() => window.location.reload(), 2000);
                } else {
                    showNotification('Update failed: ' + (result.error || 'Unknown error'), 'error');
                    btn.disabled = false;
                    btn.textContent = 'Update UltyScan';
                }
            } catch (e) {
                showNotification('Update failed: ' + e.message, 'error');
                btn.disabled = false;
                btn.textContent = 'Update UltyScan';
            }
        }

        async function stopAllScans() {
            try {
                await fetch('execute.php', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                    body: 'action=stop'
                });
                showNotification('Stop signal sent.', 'warning');
                checkScanStatus();
            } catch (e) {
                showNotification('Failed to stop scans.', 'error');
            }
        }
    </script>
</body>

</html>