<?php

set_time_limit(0);

// --- Main logic to process the form on POST request ---
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $urls    = explode("\n", trim($_POST['urls']));
    $ext     = trim($_POST['ext']);
    $keyword = trim($_POST['keyword']);
    $mode    = $_POST['mode'] ?? 'normal'; // Default to 'normal'
    $found   = [];

    echo "<style>body{font-family: monospace; background-color: #121212; color: #e0e0e0;}</style>";
    echo "<h3>Scan Results (Mode: " . htmlspecialchars($mode) . ")</h3>";

    // ===================================================================
    // FAST MODE (using cURL Multi for parallel requests)
    // ===================================================================
    if ($mode === 'fast') {
        $multi_handle = curl_multi_init();
        $curl_handles = [];
        $url_map      = [];

        // 1. Initialize all cURL handles
        foreach ($urls as $url_input) {
            $url_input = trim($url_input);
            if (empty($url_input)) continue;

            if (!filter_var($url_input, FILTER_VALIDATE_URL)) {
                echo "<span style='color:orange'>[SKIP]</span> Invalid URL: " . htmlspecialchars($url_input) . "<br>";
                continue;
            }

            $target = rtrim($url_input, '/') . '/' . $ext;
            
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $target);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_TIMEOUT, 15);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36');

            curl_multi_add_handle($multi_handle, $ch);
            $curl_handles[] = $ch;
            $url_map[(string)$ch] = $target; // Map the handle resource to its target URL
        }

        // 2. Execute all requests in parallel
        $running = null;
        do {
            curl_multi_exec($multi_handle, $running);
            usleep(100);
        } while ($running > 0);

        // 3. Process the results
        foreach ($curl_handles as $ch) {
            $target     = $url_map[(string)$ch];
            $resp       = curl_multi_getcontent($ch);
            $http_code  = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            $curl_error = curl_error($ch);

            if ($curl_error) {
                echo "<span style='color:red'>[ERROR]</span> " . htmlspecialchars($target) . " <small>(cURL Error: " . htmlspecialchars($curl_error) . ")</small><br>";
            } elseif ($http_code == 200 && $resp !== false && strpos($resp, $keyword) !== false) {
                echo "<span style='color:lime'>[FOUND]</span> " . htmlspecialchars($target) . "<br>";
                $found[] = $target;
            } else {
                echo "<span style='color:red'>[MISS]</span> " . htmlspecialchars($target) . " <small>(Code: $http_code)</small><br>";
            }
            
            curl_multi_remove_handle($multi_handle, $ch);
            ob_flush();
            flush();
        }
        curl_multi_close($multi_handle);

    // ===================================================================
    // NORMAL MODE (using file_get_contents for sequential requests)
    // ===================================================================
    } else {
        foreach ($urls as $url_input) {
            $url_input = trim($url_input);
            if (empty($url_input)) continue;

            if (!filter_var($url_input, FILTER_VALIDATE_URL)) {
                echo "<span style='color:orange'>[SKIP]</span> Invalid URL: " . htmlspecialchars($url_input) . "<br>";
                continue;
            }

            $target = rtrim($url_input, '/') . '/' . $ext;
            
            $context = stream_context_create([
                "ssl" => ["verify_peer" => false, "verify_peer_name" => false],
                "http" => [
                    "timeout" => 15,
                    "user_agent" => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36'
                ]
            ]);

            $resp = @file_get_contents($target, false, $context);

            if ($resp && strpos($resp, $keyword) !== false) {
                echo "<span style='color:lime'>[FOUND]</span> " . htmlspecialchars($target) . "<br>";
                $found[] = $target;
            } else {
                echo "<span style='color:red'>[MISS]</span> " . htmlspecialchars($target) . "<br>";
            }
            ob_flush();
            flush();
        }
    }

    // Save found results to a file
    if (!empty($found)) {
        file_put_contents('found.txt', implode(PHP_EOL, $found) . PHP_EOL, FILE_APPEND);
    }
    
    echo "<br><a href='found.txt' target='_blank' style='color: #87cefa;'>Download found.txt</a>";

} else {
// ===================================================================
// HTML FORM INTERFACE
// ===================================================================
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mass Checker</title>
   <style>
    @keyframes glow {
        0% { text-shadow: 0 0 5px #ff00ff, 0 0 10px #ff00ff; }
        50% { text-shadow: 0 0 10px #ff00ff, 0 0 20px #ff00ff; }
        100% { text-shadow: 0 0 5px #ff00ff, 0 0 10px #ff00ff; }
    }

    html, body {
        margin: 0;
        padding: 0;
        height: 100%;
        font-family: 'Courier New', Courier, monospace;
        background-color: #1e1e1e;
        color: #0ff;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
    }

    h1 {
        margin-top: 40px;
        font-size: 36px;
        color: #ff00ff;
        text-align: center;
        animation: glow 2s infinite;
    }

    .container {
        width: 100%;
        max-width: 600px;
        padding: 20px;
        box-sizing: border-box;
    }

    input, textarea {
        width: 100%;
        padding: 10px 5px;
        margin-bottom: 20px;
        background-color: transparent;
        border: none;
        border-bottom: 2px solid #0ff;
        color: #0ff;
        font-size: 16px;
        outline: none;
        transition: 0.3s;
    }

    input:focus, textarea:focus {
        border-bottom: 2px solid #ff0;
        color: #ff00ff;
        box-shadow: 0 0 10px #ff00ff;
    }

    button {
        width: 100%;
        padding: 12px;
        background-color: #ff00ff;
        color: #000;
        border: none;
        cursor: pointer;
        font-weight: bold;
        transition: 0.3s;
        box-shadow: 0 0 5px #ff00ff;
    }

    button:hover {
        box-shadow: 0 0 15px #ff00ff, 0 0 30px #ff00ff;
    }

    .radio-group {
        margin-bottom: 20px;
        color: #0ff;
    }
</style>
</head>
<body>
    <div class="container">
        <h1>Mass Checker</h1>
        <form method="post">
            <textarea name="urls" rows="10" cols="60" placeholder="Enter list of URLs, one per line..."></textarea><br>
            <input name="ext" placeholder="Example: .env , 6z.htm or shell.php" size="40"><br>
            <input name="keyword" placeholder="Keyword to search for" size="40"><br>
            
            <div class="radio-group">
                <b>Select Scan Mode:</b><br>
                <label><input type="radio" name="mode" value="normal" checked> Normal Mode (Stable, Slower)</label><br>
                <label><input type="radio" name="mode" value="fast"> Fast Mode (Super Fast, requires cURL)</label><br>
            </div><br>
        
            <button type="submit">Scan Now</button>
        </form>
    </div>
</body>
</html>
<?php 
} 
?>