forked from leaningtech/webvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
319 lines (290 loc) · 11.5 KB
/
index.html
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html lang="en" style="height:100%;">
<head>
<!-- Google Tag Manager -->
<script>
(function (w, d, s, l, i) {w[l] = w[l] || []; w[l].push({'gtm.start': new Date().getTime(),event: 'gtm.js'});var f = d.getElementsByTagName(s)[0],j = d.createElement(s),dl = l != 'dataLayer' ? '&l=' + l : '';j.async = true;j.src ='https://www.googletagmanager.com/gtm.js?id=' + i + dl;f.parentNode.insertBefore(j, f);})(window, document, 'script', 'dataLayer', 'GTM-5GBJM42');
</script>
<!-- End Google Tag Manager -->
<meta charset="utf-8">
<title>WebVM</title>
<meta name="description" content="Welcome to WebVM - a server-less virtual Linux environment running fully client-side in HTML5/WebAssembly."
<meta name="keywords" content="WebVM, Bash, CheerpX, WebAssembly">
<meta property="og:title" content="WebVM" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="WebVM"/>
<meta property="og:url" content="/">
<meta property="og:image" content="https://webvm.io/assets/webvm.jpeg" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@leaningtech" />
<meta name="twitter:title" content="WebVM" />
<meta name="twitter:description" content="Welcome to WebVM - a server-less virtual Linux environment running fully client-side in HTML5/WebAssembly."
<meta name="twitter:image" content="https://webvm.io/assets/webvm.jpeg" />
<link rel="shortcut icon" href="/favicon.ico">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/xterm/xterm.css" />
<script src="/xterm/xterm.js"></script>
<script src="/xterm/xterm-addon-fit.js"></script>
</head>
<body style="margin:0;height:100%;background:black;color:white;overflow:hidden;">
<!-- Google Tag Manager (noscript) -->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5GBJM42" height="0" width="0"
style="display:none;visibility:hidden"></iframe>
</noscript>
<!-- End Google Tag Manager (noscript) -->
<main style="display: flex; flex-direction: row; justify-content: space-between; margin:0; height:100%;">
<div style="flex-grow:1; height:100%;display:inline-block;margin:0;" id="console">
</div>
</main>
<script>
//Utility namespace to group all functionality related to printing (both error and non error) messages
const color= "\x1b[1;35m";
const bold= "\x1b[1;37m";
const underline= "\x1b[94;4m";
const normal= "\x1b[0m";
var printOnTerm = {
getAsciiTitle: function ()
{
var title = [
color + " __ __ _ __ ____ __ " + normal,
color + " \\ \\ / /__| |_\\ \\ / / \\/ | " + normal,
color + " \\ \\/\\/ / -_) '_ \\ V /| |\\/| | " + normal,
color + " \\_/\\_/\\___|_.__/\\_/ |_| |_| " + normal,
];
return title;
},
getAsciiText: function ()
{
var text = [
" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+",
" | |",
" | WebVM is a server-less virtual Linux environment running fully client-side |",
" | in HTML5/WebAssembly. |",
" | |",
" | In this demo, it runs an unmodified Debian distribution including many |",
" | native development toolchains. |",
" | |",
" | WebVM is powered by the CheerpX virtualization engine, and enables safe, |",
" | sandboxed client-side execution of x86 binaries on any browser. |",
" | |",
" | CheerpX includes an x86-to-WebAssembly JIT compiler, a virtual block-based |",
" | file system, and a Linux syscall emulator. |",
" | |",
" | For more information: " + underline + "https://medium.com/p/40a60170b361" + normal + " |",
" | |",
" | " +
underline + "GitHub" + normal + " | " +
underline + "Issues" + normal + " | " +
underline + "Gitter" + normal + " | " +
underline + "Twitter" + normal + " | " +
underline + "Latest News" + normal + " | " +
underline + "About CheerpX" + normal + " |",
" | |",
" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+",
"",
" Welcome to WebVM (build 20220201). If unsure, try these examples:",
"",
" python3 examples/python3/fibonacci.py ",
" gcc -o helloworld examples/c/helloworld.c && ./helloworld",
" objdump -d ./helloworld | less -M",
" vim examples/c/helloworld.c",
"",
];
return text;
},
getSharedArrayBufferMissingMessage: function ()
{
const text = [
"",
"",
color + "CheerpX could not start" + normal,
"",
"CheerpX depends on JavaScript's SharedArrayBuffer, that your browser",
" does not support.",
"",
"SharedArrayBuffer is currently enabled by default on recent",
" versions of Chrome, Edge, Firefox and Safari.",
"",
"",
"Give it a try from another browser!",
]
return text;
},
getErrorMessage: function (error_message)
{
const text = [
"",
"",
color + "CheerpX could not start" + normal,
"",
"CheerpX internal error message is:",
error_message,
"",
"",
"CheerpX is expected to work with recent desktop versions of Chrome, Edge, Firefox and Safari",
"",
"",
"Give it a try from a desktop version / another browser!",
]
return text;
},
printMessage: function (text) {
for (var i=0; i<text.length; i++)
{
term.write(text[i]);
term.write('\n');
}
},
printError: function (message)
{
this.printMessage(message);
term.write("\n\n");
function writeCustom(something)
{
term.write(something);
}
},
};
var consoleDiv = document.getElementById("console");
//xterm.js related logic
var term = new Terminal({cursorBlink:true,convertEol:true, fontFamily:"'Roboto Mono', monospace", fontWeight: 400, fontWeightBold: 700});
var fitAddon = new FitAddon.FitAddon();
term.loadAddon(fitAddon);
term.open(consoleDiv);
term.scrollToTop();
fitAddon.fit();
window.addEventListener("resize", function(ev){fitAddon.fit();}, false);
term.focus();
var cxReadFunc = null;
function writeData(buf)
{
term.write(new Uint8Array(buf));
}
function readData(str)
{
if(cxReadFunc == null)
return;
for(var i=0;i<str.length;i++)
cxReadFunc(str.charCodeAt(i));
}
term.onData(readData);
//Actual CheerpX and bash specific logic
function runBash()
{
const structure = {
name: "bash",
cmd: "/bin/bash",
args: ["--login"],
env: ["HOME=/home/user", "TERM=xterm", "USER=user", "SHELL=/bin/bash", "EDITOR=vim", "LANG=en_US.UTF-8", "LC_ALL=C"],
expectedPrompt: ">",
versionOpt: "--version",
comment_line: "#",
description_line: "The original Bourne Again SHell",
}
if (typeof SharedArrayBuffer === "undefined")
{
printOnTerm.printError(printOnTerm.getSharedArrayBufferMissingMessage());
return;
}
async function runTest(cx)
{
term.scrollToBottom();
async function cxLogAndRun(cheerpx, cmd, args, env)
{
await cheerpx.run(cmd, args, env);
printOnTerm.printMessage(" ");
}
cxReadFunc = cx.setCustomConsole(writeData, term.cols, term.rows);
function preventDefaults (e) {
e.preventDefault()
e.stopPropagation()
}
consoleDiv.addEventListener("dragover", preventDefaults, false);
consoleDiv.addEventListener("dragenter", preventDefaults, false);
consoleDiv.addEventListener("dragleave", preventDefaults, false);
consoleDiv.addEventListener("drop", preventDefaults, false);
var opts = {env:structure.env, cwd:"/home/user"};
while (true)
{
await cxLogAndRun(cx, structure.cmd, structure.args, opts);
}
}
function failCallback(err)
{
printOnTerm.printError(printOnTerm.getErrorMessage(err));
}
CheerpXApp.create({devices:[{type:"block",url:"https://disks.leaningtech.com/webvm_20220131.ext2",name:"block1"}],mounts:[{type:"ext2",dev:"block1",path:"/"},{type:"cheerpOS",dev:"/app",path:"/bootstrap"},{type:"devs",dev:"",path:"/dev"}]}).then(runTest, failCallback);
}
function initialMessage()
{
printOnTerm.printMessage(printOnTerm.getAsciiTitle());
printOnTerm.printMessage(["\n"]);
printOnTerm.printMessage(printOnTerm.getAsciiText());
term.registerLinkMatcher(/https:\/\/medium\.com\/p\/40a60170b361/, function(mouseEvent, matchedString) {
window.open(matchedString, "_blank")
});
const textArray = new Array(6);
const linksArray = new Array(6);
const rangesArray = new Array(6);
var last = 0;
const textLinkLine = " | GitHub | Issues | Gitter | Twitter | Latest News | About CheerpX |";
const lineWithLinks = 23;
function addLink(text, website)
{
var index = textLinkLine.indexOf(text);
const start_x = index+1;
const end_x = index + text.length;
rangesArray[last] = {start: {x:start_x, y:lineWithLinks}, end: {x:end_x, y:lineWithLinks}};
linksArray[last] = website;
last++;
}
addLink("GitHub", "https://github.com/leaningtech/webvm");
addLink("Issues", "https://github.com/leaningtech/webvm/issues");
addLink("Gitter", "https://gitter.im/leaningtech/cheerpx");
addLink("Twitter", "https://twitter.com/leaningtech");
addLink("Latest News", "https://medium.com/leaningtech");
addLink("About CheerpX", "https://leaningtech.com/cheerpx");
var provider = {
provideLinks(bufferLineNum, callback) {
switch(bufferLineNum)
{
case lineWithLinks:
{
callback([
{range: rangesArray[0], activate() {window.open('' + linksArray[0], '_blank');}},
{range: rangesArray[1], activate() {window.open('' + linksArray[1], '_blank');}},
{range: rangesArray[2], activate() {window.open('' + linksArray[2], '_blank');}},
{range: rangesArray[3], activate() {window.open('' + linksArray[3], '_blank');}},
{range: rangesArray[4], activate() {window.open('' + linksArray[4], '_blank');}},
{range: rangesArray[5], activate() {window.open('' + linksArray[5], '_blank');}},
]);
break;
}
}
}
};
term.registerLinkProvider(provider);
console.log("Welcome. We appreciate curiosity, but be warned that keeping the DevTools open causes significant performance degradation and crashes.");
}
initialMessage();
var script = document.createElement('script');
script.type = 'text/javascript';
var cxFile = "https://cheerpxdemos.leaningtech.com/publicdeploy/";
const isMobile = navigator.userAgent.toLowerCase().match(/mobile/i);
if (isMobile)
{
printOnTerm.printMessage(["Loading mobile version...\n"]);
cxFile += '20220131_500/cx.js';
}
else
{
cxFile += '20220131_700/cx.js';
}
script.src = cxFile;
script.addEventListener("load", runBash, false);
document.head.appendChild(script);
</script>
</body>
</html>