Update index.html
Browse files- index.html +170 -18
index.html
CHANGED
@@ -1,19 +1,171 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en" style="height: 100%;">
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Real Web VM Terminal</title>
|
7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
9 |
+
<style>
|
10 |
+
body {
|
11 |
+
font-family: 'Inter', sans-serif;
|
12 |
+
background-color: #1a202c; /* Dark background */
|
13 |
+
color: #e2e8f0; /* Light text */
|
14 |
+
display: flex;
|
15 |
+
justify-content: center;
|
16 |
+
align-items: center;
|
17 |
+
min-height: 100vh;
|
18 |
+
padding: 1rem;
|
19 |
+
overflow: hidden; /* Prevent body scroll */
|
20 |
+
margin: 0; /* Remove default body margin */
|
21 |
+
}
|
22 |
+
.container {
|
23 |
+
background-color: #2d3748; /* Slightly lighter dark background */
|
24 |
+
padding: 1.5rem;
|
25 |
+
border-radius: 1rem;
|
26 |
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
27 |
+
max-width: 90%; /* Responsive width */
|
28 |
+
width: 800px; /* Max width */
|
29 |
+
height: 600px; /* Fixed height for terminal container */
|
30 |
+
display: flex;
|
31 |
+
flex-direction: column;
|
32 |
+
overflow: hidden;
|
33 |
+
}
|
34 |
+
h1 {
|
35 |
+
color: #63b3ed; /* Blue for emphasis */
|
36 |
+
margin-bottom: 1rem;
|
37 |
+
font-size: 1.75rem;
|
38 |
+
font-weight: 700;
|
39 |
+
text-align: center;
|
40 |
+
}
|
41 |
+
#console-container {
|
42 |
+
flex-grow: 1; /* Terminal takes remaining space */
|
43 |
+
background-color: #000; /* Black background for terminal */
|
44 |
+
border-radius: 0.5rem;
|
45 |
+
overflow: hidden; /* Ensure content fits within */
|
46 |
+
border: 1px solid #4a5568;
|
47 |
+
color: #68d391; /* Green text for terminal output */
|
48 |
+
white-space: pre-wrap; /* Preserve whitespace and wrap lines */
|
49 |
+
font-family: 'monospace', 'Courier New', Courier, monospace; /* Monospace font for terminal */
|
50 |
+
padding: 10px;
|
51 |
+
text-align: left; /* Ensure text starts from left */
|
52 |
+
outline: none; /* Remove outline on focus */
|
53 |
+
}
|
54 |
+
#loading-message {
|
55 |
+
text-align: center;
|
56 |
+
color: #ecc94b; /* Yellow for loading */
|
57 |
+
margin-top: 1rem;
|
58 |
+
font-size: 1.1rem;
|
59 |
+
margin-bottom: 1rem; /* Add margin for spacing */
|
60 |
+
}
|
61 |
+
#error-message {
|
62 |
+
text-align: center;
|
63 |
+
color: #f56565; /* Red for error */
|
64 |
+
margin-top: 1rem;
|
65 |
+
font-size: 1.1rem;
|
66 |
+
font-weight: 600;
|
67 |
+
display: none; /* Hidden by default */
|
68 |
+
}
|
69 |
+
</style>
|
70 |
+
<!-- CheerpX Library (WebVM core) -->
|
71 |
+
<!-- This script needs to be loaded before any CheerpX. calls -->
|
72 |
+
<script src="https://cxrtnc.leaningtech.com/1.1.5/cx.js"></script>
|
73 |
+
</head>
|
74 |
+
<body style="height: 100%;">
|
75 |
+
<div class="container">
|
76 |
+
<h1>Real Web VM Terminal</h1>
|
77 |
+
<div id="loading-message">Loading Web VM... This may take a moment.</div>
|
78 |
+
<div id="error-message"></div>
|
79 |
+
<!-- The <pre> tag is used by CheerpX as the console output -->
|
80 |
+
<pre id="console-container" tabindex="0"></pre>
|
81 |
+
</div>
|
82 |
+
|
83 |
+
<script type="module">
|
84 |
+
// Import CheerpX as a module for modern JS practices
|
85 |
+
import * as CheerpX from "https://cxrtnc.leaningtech.com/1.1.5/cx.esm.js";
|
86 |
+
// Make CheerpX globally available if needed by other scripts, though not strictly necessary here
|
87 |
+
self.CheerpX = CheerpX;
|
88 |
+
|
89 |
+
const consoleContainer = document.getElementById('console-container');
|
90 |
+
const loadingMessage = document.getElementById('loading-message');
|
91 |
+
const errorMessage = document.getElementById('error-message');
|
92 |
+
|
93 |
+
async function initializeWebVM() {
|
94 |
+
try {
|
95 |
+
// Check for Cross-Origin Isolation headers
|
96 |
+
// This is crucial for SharedArrayBuffer which CheerpX uses.
|
97 |
+
// If this check fails, it means the page is not served with the necessary headers (COEP/COOP)
|
98 |
+
// or not over HTTPS, which are required by modern browsers for SharedArrayBuffer.
|
99 |
+
if (typeof SharedArrayBuffer === 'undefined') {
|
100 |
+
loadingMessage.style.display = 'none'; // Hide loading message
|
101 |
+
errorMessage.textContent = 'Error: SharedArrayBuffer is not available. This typically means your page is not served with the required Cross-Origin-Embedder-Policy (COEP) and Cross-Origin-Opener-Policy (COOP) headers, or it is not served over HTTPS. Please serve this file using a local web server (e.g., `python -m http.server`) and access it via `http://localhost:...` or `https://...`.';
|
102 |
+
errorMessage.style.display = 'block'; // Show error message
|
103 |
+
console.error('SharedArrayBuffer not available. Missing COEP/COOP headers or not HTTPS.');
|
104 |
+
return;
|
105 |
+
}
|
106 |
+
|
107 |
+
// Create a CloudDevice to load the Linux disk image from Leaning Technologies' CDN
|
108 |
+
// This is a Debian mini image.
|
109 |
+
const cloudDevice = await CheerpX.CloudDevice.create(
|
110 |
+
"wss://disks.webvm.io/debian_mini_20230519_5022088024.ext2"
|
111 |
+
);
|
112 |
+
|
113 |
+
// Create an IndexedDB device for persistent local storage of changes
|
114 |
+
// This allows changes made in the VM to persist across browser sessions
|
115 |
+
const idbDevice = await CheerpX.IDBDevice.create("webvm-disk-storage");
|
116 |
+
|
117 |
+
// Create an OverlayDevice to combine the read-only cloud image with local read-write changes
|
118 |
+
const overlayDevice = await CheerpX.OverlayDevice.create(
|
119 |
+
cloudDevice,
|
120 |
+
idbDevice
|
121 |
+
);
|
122 |
+
|
123 |
+
// Initialize the Linux environment within CheerpX
|
124 |
+
const cx = await CheerpX.Linux.create({
|
125 |
+
mounts: [
|
126 |
+
{ type: "ext2", path: "/", dev: overlayDevice }, // Mount the combined disk image as root
|
127 |
+
{ type: "devs", path: "/dev" }, // Standard device files
|
128 |
+
],
|
129 |
+
});
|
130 |
+
|
131 |
+
// Set the console output to our <pre> element
|
132 |
+
cx.setConsole(consoleContainer);
|
133 |
+
|
134 |
+
// Hide loading message and any potential previous error messages
|
135 |
+
loadingMessage.style.display = 'none';
|
136 |
+
errorMessage.style.display = 'none';
|
137 |
+
|
138 |
+
// Focus the console container to enable keyboard input
|
139 |
+
consoleContainer.focus();
|
140 |
+
|
141 |
+
// Run a full-featured bash shell in the browser
|
142 |
+
// The --login flag ensures proper shell initialization (e.g., sourcing .bashrc)
|
143 |
+
await cx.run("/bin/bash", ["--login"], {
|
144 |
+
env: [
|
145 |
+
"HOME=/root", // Set home directory
|
146 |
+
"USER=root", // Set user
|
147 |
+
"SHELL=/bin/bash",
|
148 |
+
"TERM=xterm-256color", // Set terminal type for better compatibility
|
149 |
+
"EDITOR=vi",
|
150 |
+
"LANG=en_US.UTF-8",
|
151 |
+
"LC_ALL=C",
|
152 |
+
],
|
153 |
+
cwd: "/root", // Set current working directory
|
154 |
+
uid: 0, // Run as root
|
155 |
+
gid: 0,
|
156 |
+
});
|
157 |
+
|
158 |
+
} catch (error) {
|
159 |
+
console.error("Failed to initialize Web VM:", error);
|
160 |
+
loadingMessage.style.display = 'none'; // Hide loading message
|
161 |
+
errorMessage.textContent = `Error loading Web VM: ${error.message}. Please check your browser console for more details. Ensure your internet connection is stable as disk images are streamed.`;
|
162 |
+
errorMessage.style.display = 'block'; // Show error message
|
163 |
+
errorMessage.style.color = '#f56565'; // Red error
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
// Start the Web VM initialization when the window loads
|
168 |
+
window.onload = initializeWebVM;
|
169 |
+
</script>
|
170 |
+
</body>
|
171 |
</html>
|