File size: 3,943 Bytes
3b405b9
 
 
 
 
2ffe902
 
3b405b9
2ffe902
 
 
 
3b405b9
2ffe902
3b405b9
2ffe902
 
 
 
 
3b405b9
2ffe902
3b405b9
2ffe902
 
 
 
 
 
 
 
 
 
 
3b405b9
2ffe902
 
 
 
 
12c761b
2ffe902
3b405b9
2ffe902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b405b9
 
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
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Upload and Command Execution</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
    <script>
        async function handleUpload(event) {
            event.preventDefault();
            let formData = new FormData(document.getElementById('uploadForm'));
            let response = await fetch('/upload', {
                method: 'POST',
                body: formData
            });
            let result = await response.json();
            document.getElementById('uploadStatus').innerText = result.message || '';
            if (result.download_url) {
                document.getElementById('downloadLink').href = result.download_url;
                document.getElementById('downloadLink').style.display = 'inline';
            }
        }

        async function executeCommand(event) {
            event.preventDefault();
            let formData = new FormData();
            formData.append('command', document.getElementById('commandInput').value);
            let response = await fetch('/execute_command', {
                method: 'POST',
                body: formData
            });
            let result = await response.json();
            document.getElementById('commandOutput').innerText = result.log_output || '';
        }

        async function refreshCpuInfo() {
            let response = await fetch('/cpu_info');
            let result = await response.json();
            document.getElementById('cpuInfo').innerText = result.cpu_info || '';
        }

        setInterval(refreshCpuInfo, 2000);
    </script>
</head>
<body class="bg-gray-100 flex flex-col items-center justify-center min-h-screen py-6">
    <div class="w-full max-w-4xl bg-white p-6 rounded-lg shadow-lg">
        <h1 class="text-2xl font-bold mb-4">Upload Files and Run Python Code</h1>
        <form id="uploadForm" class="space-y-4" onsubmit="handleUpload(event)">
            <div>
                <label class="block text-sm font-medium text-gray-700">Upload Files:</label>
                <input type="file" name="file" multiple class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700">Python Script:</label>
                <textarea name="script_content" rows="6" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"></textarea>
            </div>
            <button type="submit" class="mt-4 px-4 py-2 bg-indigo-600 text-white font-semibold rounded-lg shadow-md hover:bg-indigo-700">Run Script</button>
            <p id="uploadStatus" class="mt-2 text-red-600"></p>
            <a id="downloadLink" href="#" class="mt-4 text-indigo-600" style="display:none">Download Output</a>
        </form>
        <h2 class="text-xl font-bold mt-8">Execute Commands</h2>
        <form id="commandForm" class="space-y-4 mt-4" onsubmit="executeCommand(event)">
            <div>
                <label class="block text-sm font-medium text-gray-700">Command:</label>
                <input id="commandInput" type="text" name="command" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" />
            </div>
            <button type="submit" class="mt-4 px-4 py-2 bg-green-600 text-white font-semibold rounded-lg shadow-md hover:bg-green-700">Execute Command</button>
            <p id="commandOutput" class="mt-2 text-gray-700"></p>
        </form>
        <h2 class="text-xl font-bold mt-8">CPU Information</h2>
        <pre id="cpuInfo" class="mt-4 bg-gray-200 p-4 rounded-md"></pre>
    </div>
</body>
</html>