added support for interactive terminal session via proxy agent
This commit is contained in:
parent
bb1b013299
commit
4f0e5cdd79
|
@ -10,6 +10,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
if (!interactiveMode && event.key === "Enter") {
|
||||
const command = input.value.trim();
|
||||
if (command === "start-interactive") {
|
||||
|
||||
startInteractiveSession();
|
||||
input.value = "";
|
||||
event.preventDefault();
|
||||
|
@ -19,6 +20,30 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
}
|
||||
});
|
||||
|
||||
// Helper: get ?ip=…&port=… from the current location
|
||||
function getQueryParam(name) {
|
||||
return new URLSearchParams(window.location.search).get(name);
|
||||
}
|
||||
|
||||
function makeWsUrl() {
|
||||
const proxyIp = getQueryParam("ip"); // "10.0.0.42" if you came via /proxyAgent
|
||||
const proxyPort = getQueryParam("port"); // "8080"
|
||||
const usingProxy = proxyIp && proxyPort; // truthy only in that case
|
||||
|
||||
if (usingProxy) {
|
||||
// Build ws(s)://<main-server>/proxyAgent/terminal?ip=…&port=…
|
||||
const u = new URL("/proxyAgent/terminal", window.location);
|
||||
u.searchParams.set("ip", proxyIp);
|
||||
u.searchParams.set("port", proxyPort);
|
||||
u.protocol = u.protocol === "https:" ? "wss:" : "ws:";
|
||||
return u.toString();
|
||||
}
|
||||
// Fallback: open directly on the agent we’re already on
|
||||
const u = new URL("/terminal", window.location);
|
||||
u.protocol = u.protocol === "https:" ? "wss:" : "ws:";
|
||||
return u.toString();
|
||||
}
|
||||
|
||||
function startInteractiveSession() {
|
||||
interactiveMode = true;
|
||||
// Hide the normal terminal and input.
|
||||
|
@ -55,7 +80,8 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
console.log("Initial fit: container width =", xtermContainer.offsetWidth, "cols =", term.cols);
|
||||
}, 100);
|
||||
|
||||
interactiveWS = new WebSocket("ws://" + location.host + "/terminal");
|
||||
interactiveWS = new WebSocket(makeWsUrl());
|
||||
// interactiveWS = new WebSocket("ws://" + location.host + "/terminal");
|
||||
interactiveWS.binaryType = "arraybuffer";
|
||||
|
||||
interactiveWS.onopen = function () {
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
<script type="text/javascript" src="static/start-interactive.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/ansi_up@5.0.0/ansi_up.min.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="static/xterm.css" />
|
||||
<script rel="text/javascript" src="static/xterm.js"></script>
|
||||
<script rel="text/javascript" src="static/xterm-addon-fit.js"></script>
|
||||
<link rel="stylesheet" href="static/xterm/xterm.css" />
|
||||
<script rel="text/javascript" src="static/xterm/xterm.js"></script>
|
||||
<script rel="text/javascript" src="static/xterm/xterm-addon-fit.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="static/stylesheet.css">
|
||||
</head>
|
||||
|
|
Loading…
Reference in New Issue