cmux-ssh-here 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +5 -2
- package/bin.js +73 -12
- package/package.json +9 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Viktor Silakov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -15,7 +15,9 @@ Output:
|
|
|
15
15
|
https://cmux.com/deeplink/ssh?host=192.168.1.42&port=52968&user=wudUKicRFRw3&host-key-policy=accept-new&title=your-mac
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Open the link — cmux connects on its own. `Ctrl-C`
|
|
18
|
+
Open the link — cmux connects on its own. The server terminal shows a live dashboard: the current link, a countdown until it regenerates, and the list of connected sessions. `Ctrl-C` stops the server.
|
|
19
|
+
|
|
20
|
+
The link (and its token) is valid for **3 minutes**, then a fresh one is generated — already-connected sessions stay alive; only new connections need the new link.
|
|
19
21
|
|
|
20
22
|
## How it works
|
|
21
23
|
|
|
@@ -40,4 +42,5 @@ Open the link — cmux connects on its own. `Ctrl-C` in the terminal stops the s
|
|
|
40
42
|
## Options
|
|
41
43
|
|
|
42
44
|
- `PORT=2222 npx cmux-ssh-here` — fixed port (random free port by default).
|
|
43
|
-
- `
|
|
45
|
+
- `CMUX_SSH_TTL=600 npx cmux-ssh-here` — link/token lifetime in seconds before regeneration (default 180).
|
|
46
|
+
- `CMUX_SSH_DEBUG=1 npx cmux-ssh-here` — log incoming auth/env/exec/shell requests to stderr (disables the live dashboard).
|
package/bin.js
CHANGED
|
@@ -31,7 +31,18 @@ const { default: pty } = await import("node-pty");
|
|
|
31
31
|
|
|
32
32
|
// ponytail: hex (not base64url) — cmux rejects a user that starts with "-",
|
|
33
33
|
// and an ssh client treats a leading-dash username as a flag. Hex is URL/ssh-safe.
|
|
34
|
-
const
|
|
34
|
+
const TTL_SECONDS = Number(process.env.CMUX_SSH_TTL) || 180; // link/token lifetime before regeneration
|
|
35
|
+
let token; // secret carried in user=<token>; rotated every TTL_SECONDS
|
|
36
|
+
let remaining; // seconds until the next regeneration
|
|
37
|
+
const regenerateToken = () => {
|
|
38
|
+
token = randomBytes(12).toString("hex");
|
|
39
|
+
remaining = TTL_SECONDS;
|
|
40
|
+
};
|
|
41
|
+
regenerateToken();
|
|
42
|
+
|
|
43
|
+
// Active authenticated connections, shown live in the server terminal.
|
|
44
|
+
const sessions = new Map();
|
|
45
|
+
let nextSid = 0;
|
|
35
46
|
const { privateKey } = generateKeyPairSync("rsa", {
|
|
36
47
|
// ponytail: rsa PEM parses cleanly in ssh2 (ed25519 PKCS8 is hit-or-miss)
|
|
37
48
|
modulusLength: 2048,
|
|
@@ -233,11 +244,21 @@ function attachSFTP(accept) {
|
|
|
233
244
|
|
|
234
245
|
const serverCfg = { hostKeys: [privateKey] };
|
|
235
246
|
if (process.env.CMUX_SSH2_DEBUG) serverCfg.debug = (m) => { if (/SFTP|CHANNEL|EOF|CLOSE/.test(m)) console.error("[ssh2]", m); };
|
|
236
|
-
|
|
247
|
+
let render = () => {}; // assigned once the server is listening (knows ip/port)
|
|
248
|
+
const server = new Server(serverCfg, (client, info) => {
|
|
237
249
|
client.on("authentication", (ctx) => {
|
|
238
250
|
debug("auth", ctx.method, ctx.username);
|
|
239
251
|
return ctx.username === token ? ctx.accept() : ctx.reject();
|
|
240
252
|
});
|
|
253
|
+
client.on("ready", () => {
|
|
254
|
+
const id = nextSid++;
|
|
255
|
+
sessions.set(id, { ip: info?.ip || "?", since: Date.now() });
|
|
256
|
+
render();
|
|
257
|
+
client.on("close", () => {
|
|
258
|
+
sessions.delete(id);
|
|
259
|
+
render();
|
|
260
|
+
});
|
|
261
|
+
});
|
|
241
262
|
client.on("session", (accept) => {
|
|
242
263
|
const session = accept();
|
|
243
264
|
const term = { term: "xterm-256color", cols: 80, rows: 24, env: {} };
|
|
@@ -289,14 +310,54 @@ server.listen(PORT, "0.0.0.0", function () {
|
|
|
289
310
|
process.exit(1);
|
|
290
311
|
}
|
|
291
312
|
const port = this.address().port;
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
313
|
+
const user = os.userInfo().username;
|
|
314
|
+
const buildLink = () => {
|
|
315
|
+
const params = new URLSearchParams({
|
|
316
|
+
host: ip,
|
|
317
|
+
port: String(port),
|
|
318
|
+
user: token,
|
|
319
|
+
"host-key-policy": "accept-new",
|
|
320
|
+
title: os.hostname(),
|
|
321
|
+
});
|
|
322
|
+
return `https://cmux.com/deeplink/ssh?${params}`;
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// ponytail: in debug mode skip the screen-clearing UI so logs stay readable;
|
|
326
|
+
// just print the link whenever it rotates.
|
|
327
|
+
const liveUI = !process.env.CMUX_SSH_DEBUG;
|
|
328
|
+
const ago = (since) => `${Math.floor((Date.now() - since) / 1000)}s`;
|
|
329
|
+
|
|
330
|
+
render = () => {
|
|
331
|
+
if (!liveUI) return;
|
|
332
|
+
const lines = [
|
|
333
|
+
"",
|
|
334
|
+
` cmux-ssh-here — shell as ${user} over the LAN`,
|
|
335
|
+
"",
|
|
336
|
+
` Open in cmux (regenerates in ${remaining}s):`,
|
|
337
|
+
` ${buildLink()}`,
|
|
338
|
+
"",
|
|
339
|
+
];
|
|
340
|
+
if (sessions.size) {
|
|
341
|
+
lines.push(` Connected sessions (${sessions.size}):`);
|
|
342
|
+
for (const s of sessions.values()) lines.push(` • ${s.ip} connected ${ago(s.since)} ago`);
|
|
343
|
+
} else {
|
|
344
|
+
lines.push(" No active sessions yet.");
|
|
345
|
+
}
|
|
346
|
+
lines.push("", " Ctrl-C to stop.", "");
|
|
347
|
+
// Clear screen + home, then redraw.
|
|
348
|
+
process.stdout.write(`\x1b[2J\x1b[3J\x1b[H${lines.join("\n")}\n`);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
if (liveUI) render();
|
|
352
|
+
else console.log(`\n Open in cmux (regenerates in ${remaining}s):\n ${buildLink()}\n`);
|
|
353
|
+
|
|
354
|
+
// Tick once a second: count down, regenerate on expiry, refresh the UI.
|
|
355
|
+
setInterval(() => {
|
|
356
|
+
remaining--;
|
|
357
|
+
if (remaining <= 0) {
|
|
358
|
+
regenerateToken();
|
|
359
|
+
if (!liveUI) console.log(`\n [link regenerated]\n ${buildLink()}\n`);
|
|
360
|
+
}
|
|
361
|
+
render();
|
|
362
|
+
}, 1000);
|
|
302
363
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cmux-ssh-here",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Spin up a token-auth SSH server and print a cmux deep link to connect over LAN",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
"remote"
|
|
19
19
|
],
|
|
20
20
|
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/viktor-silakov/cmux-ssh-here.git"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/viktor-silakov/cmux-ssh-here#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/viktor-silakov/cmux-ssh-here/issues"
|
|
28
|
+
},
|
|
21
29
|
"engines": {
|
|
22
30
|
"node": ">=18"
|
|
23
31
|
},
|