index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <!DOCTYPE html>
  2. <html lang="en" style="height:100%;">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>WebVM - Linux virtualization in WebAssembly</title>
  6. <meta name="description" content="Server-less virtual machine, networking included, running browser-side in HTML5/WebAssembly. Code in any programming language inside this Linux terminal.">
  7. <meta name="keywords" content="WebVM, Virtual Machine, CheerpX, x86 virtualization, WebAssembly, Tailscale, JIT">
  8. <meta property="og:title" content="WebVM - Linux virtualization in WebAssembly" />
  9. <meta property="og:type" content="website" />
  10. <meta property="og:site_name" content="WebVM"/>
  11. <meta property="og:url" content="/">
  12. <meta property="og:image" content="https://webvm.io/assets/welcome_to_WebVM_.png" />
  13. <meta name="twitter:card" content="summary_large_image" />
  14. <meta name="twitter:site" content="@leaningtech" />
  15. <meta name="twitter:title" content="WebVM - Linux virtualization in WebAssembly" />
  16. <meta name="twitter:description" content="Server-less virtual machine, networking included, running browser-side in HTML5/WebAssembly. Code in any programming language inside this Linux terminal.">
  17. <meta name="twitter:image" content="https://webvm.io/assets/welcome_to_WebVM_.png" />
  18. <!-- Apple iOS web clip compatibility tags -->
  19. <meta name="application-name" content="WebVM" />
  20. <meta name="apple-mobile-web-app-title" content="WebVM" />
  21. <meta name="apple-mobile-web-app-capable" content="yes" />
  22. <meta name="mobile-web-app-capable" content="yes" />
  23. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  24. <link rel="shortcut icon" href="./tower.ico">
  25. <link rel="preconnect" href="https://fonts.googleapis.com">
  26. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  27. <link rel="stylesheet" id="us-fonts-css" href="https://fonts.googleapis.com/css?family=Montserrat%3A300%2C400%2C500%2C600%2C700&amp;display=swap&amp;ver=6.0.2" media="all">
  28. <link rel="stylesheet" href="./xterm/xterm.css" />
  29. <link rel="stylesheet" href="./scrollbar.css" />
  30. <script src="./xterm/xterm.js"></script>
  31. <script src="./xterm/xterm-addon-fit.js"></script>
  32. <script>
  33. window.networkInterface = { bind: null, connect: null, listen: null, ready: false };
  34. </script>
  35. <script type="module" src="network.js"></script>
  36. </head>
  37. <body style="margin:0;height:100%;background:black;color:white;overflow:hidden; display:flex; flex-direction: column; justify-content: space-between; height: 100%;">
  38. <header style="flex-grow:0; flex-srink: 0;height:80px; width: 100%; margin: 2px 0 2px 0;">
  39. <div style="display: flex; flex-direction: row; justify-content: space-between; width: 100%;">
  40. <div style="display: flex; flex-direction: row;">
  41. <a href="https://leaningtech.com/" target="_blank">
  42. <img src="./assets/leaningtech.png" style="margin-left: 10px; height: 60px; margin-top: 10px;">
  43. </a>
  44. </div>
  45. <div style="display: flex; flex-direction: row; justify-content: space-before;">
  46. <li style=" margin-right: 50px; height: 100%; display: flex; align-items: center;">
  47. <a href="https://discord.leaningtech.com" target="_blank" style="text-decoration: none">
  48. <div style="color: white; font-family: montserrat; font-weight: 700; font-size: large;">Discord</div>
  49. </a>
  50. </li>
  51. <li style=" margin-right: 50px; height: 100%; display: flex; align-items: center;">
  52. <a href="https://github.com/leaningtech/webvm" target="_blank" style="text-decoration: none" >
  53. <div style="color: white; font-family: montserrat; font-weight: 700; font-size: large;">Github</div>
  54. </a>
  55. </li>
  56. <li style=" margin-right: 50px; height: 100%; display: flex; align-items: center;">
  57. <a id="loginLink" style="text-decoration: none; cursor:not-allowed;">
  58. <div id="networkStatus" style="color: grey; font-family: montserrat; font-weight: 700; font-size: large;">Tailscale Login</div>
  59. </a>
  60. </li>
  61. </div>
  62. </div>
  63. </header>
  64. <div style="flex-grow:0; flex-shrink: 0; height:1px; width: 100%; background-color: white;">
  65. </div>
  66. <main style="display: flex; flex-direction: row; justify-content: space-between; margin:0; height:100%;">
  67. <div style="flex-grow:1; height:100%;display:inline-block;margin:0;" class="scrollbar" id="console">
  68. </div>
  69. </main>
  70. <script>
  71. //Utility namespace to group all functionality related to printing (both error and non error) messages
  72. const color= "\x1b[1;35m";
  73. const bold= "\x1b[1;37m";
  74. const underline= "\x1b[94;4m";
  75. const normal= "\x1b[0m";
  76. var printOnTerm = {
  77. getAsciiTitle: function ()
  78. {
  79. var title = [
  80. color + " __ __ _ __ ____ __ " + normal,
  81. color + " \\ \\ / /__| |_\\ \\ / / \\/ | " + normal,
  82. color + " \\ \\/\\/ / -_) '_ \\ V /| |\\/| | " + normal,
  83. color + " \\_/\\_/\\___|_.__/\\_/ |_| |_| " + normal,
  84. ];
  85. return title;
  86. },
  87. getAsciiText: function ()
  88. {
  89. var text = [
  90. "+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+",
  91. "| |",
  92. "| WebVM is a server-less virtual Linux environment running fully client-side |",
  93. "| in HTML5/WebAssembly. |",
  94. "| |",
  95. "| WebVM is powered by the CheerpX virtualization engine, which enables safe, |",
  96. "| sandboxed client-side execution of x86 binaries on any browser. |",
  97. "| |",
  98. "| CheerpX includes an x86-to-WebAssembly JIT compiler, a virtual block-based |",
  99. "| file system, and a Linux syscall emulator. |",
  100. "| |",
  101. "| [NEW!] WebVM now supports full TCP and UDP networking via Tailscale! |",
  102. "| Click on 'Tailscale Login' to enable it. Read the announcement: |",
  103. "| |",
  104. "| " + underline + "https://leaningtech.com/webvm-virtual-machine-with-networking-via-tailscale" + normal +" |",
  105. "| |",
  106. "+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+",
  107. "",
  108. " Welcome to WebVM (build CX_VERSION). If unsure, try these examples:",
  109. "",
  110. " python3 examples/python3/fibonacci.py ",
  111. " gcc -o helloworld examples/c/helloworld.c && ./helloworld",
  112. " objdump -d ./helloworld | less -M",
  113. " vim examples/c/helloworld.c",
  114. " curl --max-time 15 parrot.live # requires networking",
  115. "",
  116. ];
  117. return text;
  118. },
  119. getSharedArrayBufferMissingMessage: function ()
  120. {
  121. const text = [
  122. "",
  123. "",
  124. color + "CheerpX could not start" + normal,
  125. "",
  126. "CheerpX depends on JavaScript's SharedArrayBuffer, that your browser",
  127. " does not support.",
  128. "",
  129. "SharedArrayBuffer is currently enabled by default on recent",
  130. " versions of Chrome, Edge, Firefox and Safari.",
  131. "",
  132. "",
  133. "Give it a try from another browser!",
  134. ]
  135. return text;
  136. },
  137. getErrorMessage: function (error_message)
  138. {
  139. const text = [
  140. "",
  141. "",
  142. color + "CheerpX could not start" + normal,
  143. "",
  144. "CheerpX internal error message is:",
  145. error_message,
  146. "",
  147. "",
  148. "CheerpX is expected to work with recent desktop versions of Chrome, Edge, Firefox and Safari",
  149. "",
  150. "",
  151. "Give it a try from a desktop version / another browser!",
  152. ]
  153. return text;
  154. },
  155. printMessage: function (text) {
  156. for (var i=0; i<text.length; i++)
  157. {
  158. term.write(text[i]);
  159. term.write('\n');
  160. }
  161. },
  162. printError: function (message)
  163. {
  164. this.printMessage(message);
  165. term.write("\n\n");
  166. function writeCustom(something)
  167. {
  168. term.write(something);
  169. }
  170. },
  171. };
  172. var consoleDiv = document.getElementById("console");
  173. //xterm.js related logic
  174. var term = new Terminal({cursorBlink:true,convertEol:true, fontFamily:"monospace", fontWeight: 400, fontWeightBold: 700});
  175. var fitAddon = new FitAddon.FitAddon();
  176. term.loadAddon(fitAddon);
  177. term.open(consoleDiv);
  178. term.scrollToTop();
  179. fitAddon.fit();
  180. window.addEventListener("resize", function(ev){fitAddon.fit();}, false);
  181. term.focus();
  182. var cxReadFunc = null;
  183. function writeData(buf)
  184. {
  185. term.write(new Uint8Array(buf));
  186. }
  187. function readData(str)
  188. {
  189. if(cxReadFunc == null)
  190. return;
  191. for(var i=0;i<str.length;i++)
  192. cxReadFunc(str.charCodeAt(i));
  193. }
  194. term.onData(readData);
  195. //Actual CheerpX and bash specific logic
  196. function runBash()
  197. {
  198. const structure = {
  199. name: "bash",
  200. cmd: "/bin/bash",
  201. args: ["--login"],
  202. env: ["HOME=/home/user", "TERM=xterm", "USER=user", "SHELL=/bin/bash", "EDITOR=vim", "LANG=en_US.UTF-8", "LC_ALL=C"],
  203. expectedPrompt: ">",
  204. versionOpt: "--version",
  205. comment_line: "#",
  206. description_line: "The original Bourne Again SHell",
  207. }
  208. if (typeof SharedArrayBuffer === "undefined")
  209. {
  210. printOnTerm.printError(printOnTerm.getSharedArrayBufferMissingMessage());
  211. return;
  212. }
  213. async function runTest(cx)
  214. {
  215. term.scrollToBottom();
  216. async function cxLogAndRun(cheerpx, cmd, args, env)
  217. {
  218. await cheerpx.run(cmd, args, env);
  219. printOnTerm.printMessage(" ");
  220. }
  221. cxReadFunc = cx.setCustomConsole(writeData, term.cols, term.rows);
  222. function preventDefaults (e) {
  223. e.preventDefault()
  224. e.stopPropagation()
  225. }
  226. consoleDiv.addEventListener("dragover", preventDefaults, false);
  227. consoleDiv.addEventListener("dragenter", preventDefaults, false);
  228. consoleDiv.addEventListener("dragleave", preventDefaults, false);
  229. consoleDiv.addEventListener("drop", preventDefaults, false);
  230. var opts = {env:structure.env, cwd:"/home/user"};
  231. while (true)
  232. {
  233. await cxLogAndRun(cx, structure.cmd, structure.args, opts);
  234. }
  235. }
  236. function failCallback(err)
  237. {
  238. printOnTerm.printError(printOnTerm.getErrorMessage(err));
  239. }
  240. CheerpXApp.create({devices:[{type:"block",url:"https://disks.leaningtech.com/webvm_20221004.ext2",name:"block1"}],mounts:[{type:"ext2",dev:"block1",path:"/"},{type:"cheerpOS",dev:"/app",path:"/app"},{type:"cheerpOS",dev:"/str",path:"/data"},{type:"devs",dev:"",path:"/dev"}], networkInterface}).then(runTest, failCallback);
  241. }
  242. function initialMessage()
  243. {
  244. printOnTerm.printMessage(printOnTerm.getAsciiTitle());
  245. printOnTerm.printMessage([""]);
  246. printOnTerm.printMessage(printOnTerm.getAsciiText());
  247. term.registerLinkMatcher(/https:\/\/leaningtech.com\/webvm-virtual-machine-with-networking-via-tailscale/, function(mouseEvent, matchedString) {
  248. window.open(matchedString, "_blank")
  249. });
  250. console.log("Welcome. We appreciate curiosity, but be warned that keeping the DevTools open causes significant performance degradation and crashes.");
  251. }
  252. initialMessage();
  253. var script = document.createElement('script');
  254. script.type = 'text/javascript';
  255. var cxFile = "https://cheerpxdemos.leaningtech.com/publicdeploy/CX_VERSION/cx.js";
  256. script.src = cxFile;
  257. script.addEventListener("load", runBash, false);
  258. document.head.appendChild(script);
  259. </script>
  260. <!-- Google tag (gtag.js) -->
  261. <script defer src="https://www.googletagmanager.com/gtag/js?id=G-818T3Y0PEY"></script>
  262. <script defer>
  263. window.dataLayer = window.dataLayer || [];
  264. function gtag(){dataLayer.push(arguments);}
  265. gtag('js', new Date());
  266. gtag('config', 'G-818T3Y0PEY');
  267. </script>
  268. </body>
  269. </html>