File size: 2,078 Bytes
c738408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Advanced Terminal</title>
    <style>
        body {
            font-family: monospace;
            background-color: #1e1e1e;
            color: #00ff00;
            padding: 20px;
        }
        #terminal {
            width: 100%;
            height: 400px;
            background: black;
            color: green;
            padding: 10px;
            overflow-y: scroll;
        }
        input[type="text"] {
            background: black;
            color: green;
            border: none;
            width: 100%;
            font-size: 1em;
        }
    </style>
</head>
<body>
    <div id="terminal"></div>
    <input type="text" id="command" placeholder="Enter your command here..." autofocus/>
    
    <script>
        const terminal = document.getElementById("terminal");
        const commandInput = document.getElementById("command");

        commandInput.addEventListener('keydown', function(e) {
            if (e.key === 'Enter') {
                const command = commandInput.value;
                commandInput.value = '';  // Clear input
                terminal.innerHTML += `> ${command}\n`; // Show command in terminal
                
                // Send the command to the backend
                fetch('/run_command', {
                    method: 'POST',
                    body: new URLSearchParams({ 'command': command }),
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                })
                .then(response => response.json())
                .then(data => {
                    terminal.innerHTML += `${data.output}\n`;  // Show output in terminal
                    terminal.scrollTop = terminal.scrollHeight;  // Scroll to the bottom
                })
                .catch(error => {
                    terminal.innerHTML += `Error: ${error}\n`;
                });
            }
        });
    </script>
</body>
</html>