console.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <link rel="stylesheet" href="script/xterm/xterm.css">
  7. <script src="../script/jquery.min.js"></script>
  8. <script src="../script/ao_module.js"></script>
  9. <script src="../script/applocale.js"></script>
  10. <script src="script/dockermanager.js"></script>
  11. <script src="script/xterm/xterm.js"></script>
  12. <script src="script/xterm/xterm-addon-fit.js"></script>
  13. <title>Docker Console</title>
  14. <style>
  15. html, body { height:100%; margin:0; background:#0f1419; overflow:hidden; }
  16. #bar { display:flex; align-items:center; gap:10px; padding:7px 12px; background:#171c22; border-bottom:1px solid #222;
  17. font-family:-apple-system, 'Segoe UI', system-ui, sans-serif; color:#cdd6df; font-size:12.5px; }
  18. #bar .warn { color:#ff6b5e; font-weight:600; }
  19. #bar select, #bar button { background:#222a33; color:#cdd6df; border:1px solid #333; border-radius:6px; padding:4px 8px; font-size:12px; cursor:pointer; }
  20. #term { position:absolute; top:38px; left:0; right:0; bottom:0; padding:6px 10px; overflow:hidden; background:#0f1419; }
  21. </style>
  22. </head>
  23. <body>
  24. <div id="bar">
  25. <span class="warn" locale="console/live">Live container shell</span>
  26. <span id="cname" style="font-family:ui-monospace,Menlo,Consolas,monospace;"></span>
  27. <span style="margin-left:auto;" locale="console/shell">Shell:</span>
  28. <select id="shell"><option value="sh">sh</option><option value="bash">bash</option></select>
  29. <button id="reconnect" locale="console/reconnect">Reconnect</button>
  30. </div>
  31. <div id="term"></div>
  32. <script>
  33. DM.initLocale("locale/console.json", function () {
  34. var T = DM.t;
  35. function qp(name) { var m = new RegExp("[?&]" + name + "=([^&]*)").exec(window.location.search); return m ? decodeURIComponent(m[1]) : ""; }
  36. var id = qp("id"), name = qp("name") || id;
  37. document.getElementById("cname").textContent = name;
  38. if (qp("shell")) document.getElementById("shell").value = qp("shell");
  39. if (typeof ao_module_setWindowTitle === "function") { try { ao_module_setWindowTitle(T("console/title", "Console: {name}", { name: name })); } catch (e) {} }
  40. var socket = null, term = null, fit = null;
  41. function sendResize() { if (term && socket && socket.readyState === 1) socket.send(JSON.stringify({ type: "resize", rows: term.rows, cols: term.cols })); }
  42. function connect() {
  43. if (socket) { try { socket.close(); } catch (e) {} socket = null; }
  44. if (term) { try { term.dispose(); } catch (e) {} term = null; }
  45. term = new Terminal({ cursorBlink: true, fontSize: 13, theme: { background: "#0f1419", foreground: "#d6e2ef" } });
  46. fit = new FitAddon.FitAddon(); term.loadAddon(fit);
  47. term.open(document.getElementById("term"));
  48. setTimeout(function () { try { fit.fit(); } catch (e) {} term.focus(); }, 60);
  49. socket = new WebSocket(DM.wsURL("console/exec?id=" + encodeURIComponent(id) + "&shell=" + encodeURIComponent(document.getElementById("shell").value || "sh")));
  50. socket.binaryType = "arraybuffer";
  51. socket.onopen = function () { sendResize(); };
  52. socket.onmessage = function (ev) { if (typeof ev.data === "string") term.write(ev.data); else term.write(new Uint8Array(ev.data)); };
  53. socket.onclose = function () { if (term) term.write("\r\n[" + T("console/closed", "session closed") + "]\r\n"); };
  54. term.onData(function (d) { if (socket && socket.readyState === 1) socket.send(new TextEncoder().encode(d)); });
  55. term.onResize(sendResize);
  56. }
  57. window.addEventListener("resize", function () { if (fit && term) { try { fit.fit(); } catch (e) {} } });
  58. window.addEventListener("beforeunload", function () { if (socket) { try { socket.close(); } catch (e) {} } });
  59. document.getElementById("reconnect").addEventListener("click", connect);
  60. if (id) connect(); else document.getElementById("term").textContent = T("console/missingId", "Missing container id.");
  61. });
  62. </script>
  63. </body>
  64. </html>