<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TEST</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #141414;
            color: #fff;
            font-family: Arial, sans-serif;
        }

        .password-section {
            display: block;
            text-align: center;
            margin-top: 50px;
        }

        .password-section input {
            padding: 10px;
            font-size: 16px;
            width: 300px;
            background: #333;
            color: #fff;
            border: 1px solid #555;
            border-radius: 5px;
        }

        .password-section button {
            padding: 10px 20px;
            background: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
            border-radius: 5px;
            margin-top: 10px;
        }

        .password-section button:hover {
            background: #45a049;
        }

        #term {
            display: none;
            margin: 20px auto;
            width: 80%;
            height: 400px;
            background: #000;
            color: #fff;
            font-family: monospace;
            padding: 10px;
            border-radius: 10px;
            overflow-y: auto;
        }

        #inputField {
            margin-top: 10px;
            padding: 10px;
            font-size: 16px;
            width: 80%;
            background: #333;
            color: #fff;
            border: 1px solid #555;
            border-radius: 5px;
        }

        #fileUpload {
            display: none;
        }

        #uploadLabel {
            display: inline-block;
            margin-top: 10px;
            padding: 10px 20px;
            background: #4CAF50;
            color: white;
            border-radius: 5px;
            cursor: pointer;
        }

        #downloadButton {
            display: none;
            margin-top: 10px;
            padding: 10px 20px;
            background: #4CAF50;
            color: white;
            border-radius: 5px;
            cursor: pointer;
        }

        footer {
            text-align: center;
            color: #bbb;
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="password-section">
        <h2>Enter Password</h2>
        <input type="password" id="password" placeholder="Enter password" />
        <button onclick="checkPassword()">Submit</button>
    </div>

    <div id="term">
        <h3>Terminal</h3>
        <div id="terminal-output"></div>
        <input type="text" id="inputField" placeholder="Type a command" />
        <input type="file" id="fileUpload" />
        <label id="uploadLabel" for="fileUpload">Upload File</label>
        <button id="downloadButton">Download Updated File</button>
    </div>

    <footer>
        <p>Author: Kuhujiban1a</p>
    </footer>

    <script>
        const encryptedPassword = "e67c539503e36030721628dcec7fc7b932eba6f51a8a52302c876c7167625561"; 

        // Function to hash the entered password and compare it with the stored hash
        async function sha256(str) {
            const encoder = new TextEncoder();
            const data = encoder.encode(str);
            const hashBuffer = await crypto.subtle.digest('SHA-256', data);
            const hashArray = Array.from(new Uint8Array(hashBuffer));
            const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');
            return hashHex;
        }

        // Function to check the entered password
        async function checkPassword() {
            const passwordField = document.getElementById('password');
            const password = passwordField.value;

            // Hash the entered password and compare with the stored hash
            const hashedPassword = await sha256(password);

            if (hashedPassword === encryptedPassword) {
                // Correct password, show the terminal
                document.querySelector('.password-section').style.display = 'none';
                document.getElementById('term').style.display = 'block';
                alert('Password correct! Access granted.');
            } else {
                // Incorrect password
                alert('Incorrect password.');
            }
        }

        const terminalOutput = document.getElementById('terminal-output');
        const inputField = document.getElementById('inputField');
        const fileUpload = document.getElementById('fileUpload');
        const downloadButton = document.getElementById('downloadButton');
        let uploadedFileContent = '';
        let updatedFileContent = '';

        // Simulate Shell Commands
        function simulateShellCommand(command) {
            return new Promise((resolve) => {
                setTimeout(() => {
                    if (command === 'ls') {
                        resolve('file1.txt  file2.txt  directory1/');
                    } else if (command === 'pwd') {
                        resolve('/home/user');
                    } else if (command.startsWith('echo ')) {
                        resolve(command.slice(5));
                    } else if (command === 'clear') {
                        resolve('clear');
                    } else if (command === 'find_domains') {
                        fileUpload.click();
                        resolve('Upload a file to find domains.');
                    } else if (command.startsWith('add_domain ')) {
                        const domain = command.split(' ')[1];
                        if (domain) {
                            addDomainToFile(domain);
                            resolve(`Domain ${domain} added to file.`);
                        } else {
                            resolve('Please provide a domain to add.');
                        }
                    } else {
                        resolve(`Unknown command: ${command}`);
                    }
                }, 500);
            });
        }

        // Extract Domains from File Content
        function extractDomains(content) {
            const domainRegex = /\b(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}\b/g;
            const domains = content.match(domainRegex);
            return domains ? [...new Set(domains)] : [];
        }

        // Add Domain to File Content
        function addDomainToFile(domain) {
            updatedFileContent += `${domain}\n`;
        }

        // Handle File Upload for Domain Finder
        fileUpload.addEventListener('change', () => {
            const file = fileUpload.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = () => {
                    uploadedFileContent = reader.result;
                    updatedFileContent = uploadedFileContent; // Initialize with original content
                    const domains = extractDomains(uploadedFileContent);
                    if (domains.length > 0) {
                        terminalOutput.innerHTML += `<div>&gt; Found Domains:</div>`;
                        domains.forEach(domain => {
                            terminalOutput.innerHTML += `<div>${domain}</div>`;
                        });
                    } else {
                        terminalOutput.innerHTML += `<div>&gt; No domains found.</div>`;
                    }
                    terminalOutput.scrollTop = terminalOutput.scrollHeight; // Auto-scroll
                    downloadButton.style.display = 'inline-block'; // Show download button
                };
                reader.readAsText(file);
            }
        });

        // Handle File Download
        downloadButton.addEventListener('click', () => {
            const blob = new Blob([updatedFileContent], { type: 'text/plain' });
            const link = document.createElement('a');
            link.href = URL.createObjectURL(blob);
            link.download = 'updated_domains.txt';
            link.click();
        });

        // Handle Terminal Input
        inputField.addEventListener('keydown', async (e) => {
            if (e.key === 'Enter') {
                const command = inputField.value.trim();
                if (command) {
                    terminalOutput.innerHTML += `<div>&gt; ${command}</div>`;
                    inputField.value = '';
                    const response = await simulateShellCommand(command);
                    if (response === 'clear') {
                        terminalOutput.innerHTML = '';
                    } else {
                        terminalOutput.innerHTML += `<div>${response}</div>`;
                    }
                    terminalOutput.scrollTop = terminalOutput.scrollHeight; // Auto-scroll
                }
            }
        });
    </script>
</body>
</html>
