termbeam 1.2.4 → 1.2.5
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/README.md +12 -1
- package/package.json +1 -1
- package/public/sw.js +35 -33
- package/src/cli.js +15 -2
- package/src/logger.js +3 -2
- package/src/server.js +38 -2
- package/src/sessions.js +8 -2
- package/src/tunnel.js +19 -7
package/README.md
CHANGED
|
@@ -15,6 +15,16 @@ I built this because I kept needing to run quick commands on my dev machine whil
|
|
|
15
15
|
|
|
16
16
|
https://github.com/user-attachments/assets/9dd4f3d7-f017-4314-9b3a-f6a5688e3671
|
|
17
17
|
|
|
18
|
+
### Mobile UI
|
|
19
|
+
|
|
20
|
+
<table align="center">
|
|
21
|
+
<tr>
|
|
22
|
+
<td align="center"><img src="docs/assets/screenshots/mobile-session-hub.jpeg" alt="Session hub on mobile" width="250" /></td>
|
|
23
|
+
<td align="center"><img src="docs/assets/screenshots/mobile-session-preview.jpeg" alt="Session preview on mobile" width="250" /></td>
|
|
24
|
+
<td align="center"><img src="docs/assets/screenshots/mobile-terminal.jpeg" alt="Terminal on mobile" width="250" /></td>
|
|
25
|
+
</tr>
|
|
26
|
+
</table>
|
|
27
|
+
|
|
18
28
|
## Quick Start
|
|
19
29
|
|
|
20
30
|
```bash
|
|
@@ -102,9 +112,10 @@ termbeam --host 127.0.0.1 # restrict to localhost (default: 0.0.0.0)
|
|
|
102
112
|
| `--password <pw>` | Set access password (also accepts `--password=<pw>`) | Auto-generated |
|
|
103
113
|
| `--no-password` | Disable password | — |
|
|
104
114
|
| `--generate-password` | Auto-generate a secure password | On |
|
|
105
|
-
| `--tunnel` | Create an ephemeral devtunnel URL
|
|
115
|
+
| `--tunnel` | Create an ephemeral devtunnel URL (private) | On |
|
|
106
116
|
| `--no-tunnel` | Disable tunnel (LAN-only) | — |
|
|
107
117
|
| `--persisted-tunnel` | Create a reusable devtunnel URL | Off |
|
|
118
|
+
| `--public` | Allow public tunnel access | Off |
|
|
108
119
|
| `--port <port>` | Server port | `3456` |
|
|
109
120
|
| `--host <addr>` | Bind address | `0.0.0.0` |
|
|
110
121
|
| `--log-level <level>` | Log verbosity (error/warn/info/debug) | `info` |
|
package/package.json
CHANGED
package/public/sw.js
CHANGED
|
@@ -2,17 +2,17 @@ const CACHE_NAME = 'termbeam-v5';
|
|
|
2
2
|
const SHELL_URLS = ['/', '/terminal'];
|
|
3
3
|
|
|
4
4
|
self.addEventListener('install', (event) => {
|
|
5
|
-
event.waitUntil(
|
|
6
|
-
caches.open(CACHE_NAME).then((cache) => cache.addAll(SHELL_URLS))
|
|
7
|
-
);
|
|
5
|
+
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(SHELL_URLS)));
|
|
8
6
|
self.skipWaiting();
|
|
9
7
|
});
|
|
10
8
|
|
|
11
9
|
self.addEventListener('activate', (event) => {
|
|
12
10
|
event.waitUntil(
|
|
13
|
-
caches
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
caches
|
|
12
|
+
.keys()
|
|
13
|
+
.then((keys) =>
|
|
14
|
+
Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k))),
|
|
15
|
+
),
|
|
16
16
|
);
|
|
17
17
|
self.clients.claim();
|
|
18
18
|
});
|
|
@@ -21,11 +21,7 @@ self.addEventListener('fetch', (event) => {
|
|
|
21
21
|
const url = new URL(event.request.url);
|
|
22
22
|
|
|
23
23
|
// Don't cache WebSocket upgrades
|
|
24
|
-
if (
|
|
25
|
-
event.request.mode === 'websocket' ||
|
|
26
|
-
url.protocol === 'ws:' ||
|
|
27
|
-
url.protocol === 'wss:'
|
|
28
|
-
) {
|
|
24
|
+
if (event.request.mode === 'websocket' || url.protocol === 'ws:' || url.protocol === 'wss:') {
|
|
29
25
|
return;
|
|
30
26
|
}
|
|
31
27
|
|
|
@@ -42,7 +38,7 @@ self.addEventListener('fetch', (event) => {
|
|
|
42
38
|
}
|
|
43
39
|
return response;
|
|
44
40
|
});
|
|
45
|
-
})
|
|
41
|
+
}),
|
|
46
42
|
);
|
|
47
43
|
}
|
|
48
44
|
return;
|
|
@@ -50,37 +46,43 @@ self.addEventListener('fetch', (event) => {
|
|
|
50
46
|
|
|
51
47
|
// Network-first for API calls
|
|
52
48
|
if (url.pathname.startsWith('/api/')) {
|
|
53
|
-
event.respondWith(
|
|
54
|
-
fetch(event.request).catch(() => caches.match(event.request))
|
|
55
|
-
);
|
|
49
|
+
event.respondWith(fetch(event.request).catch(() => caches.match(event.request)));
|
|
56
50
|
return;
|
|
57
51
|
}
|
|
58
52
|
|
|
59
53
|
// Network-first for HTML pages (always get latest code)
|
|
60
|
-
if (
|
|
54
|
+
if (
|
|
55
|
+
event.request.mode === 'navigate' ||
|
|
56
|
+
event.request.headers.get('accept')?.includes('text/html')
|
|
57
|
+
) {
|
|
61
58
|
event.respondWith(
|
|
62
|
-
fetch(event.request)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
fetch(event.request)
|
|
60
|
+
.then((response) => {
|
|
61
|
+
if (response.ok) {
|
|
62
|
+
const clone = response.clone();
|
|
63
|
+
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
|
64
|
+
}
|
|
65
|
+
return response;
|
|
66
|
+
})
|
|
67
|
+
.catch(() => caches.match(event.request)),
|
|
69
68
|
);
|
|
70
69
|
return;
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
// Cache-first for static assets (JS, CSS, images)
|
|
74
73
|
event.respondWith(
|
|
75
|
-
caches
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
caches
|
|
75
|
+
.match(event.request)
|
|
76
|
+
.then((cached) => {
|
|
77
|
+
if (cached) return cached;
|
|
78
|
+
return fetch(event.request).then((response) => {
|
|
79
|
+
if (response.ok) {
|
|
80
|
+
const clone = response.clone();
|
|
81
|
+
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
|
82
|
+
}
|
|
83
|
+
return response;
|
|
84
|
+
});
|
|
85
|
+
})
|
|
86
|
+
.catch(() => new Response('Offline', { status: 503, statusText: 'Service Unavailable' })),
|
|
85
87
|
);
|
|
86
88
|
});
|
package/src/cli.js
CHANGED
|
@@ -15,9 +15,10 @@ Options:
|
|
|
15
15
|
--password <pw> Set access password (or TERMBEAM_PASSWORD env var)
|
|
16
16
|
--generate-password Auto-generate a secure password (default: auto)
|
|
17
17
|
--no-password Disable password authentication
|
|
18
|
-
--tunnel Create a
|
|
18
|
+
--tunnel Create a devtunnel URL (default: on, private access)
|
|
19
19
|
--no-tunnel Disable tunnel (LAN-only mode)
|
|
20
20
|
--persisted-tunnel Create a reusable devtunnel URL (stable across restarts)
|
|
21
|
+
--public Allow public tunnel access (default: private, owner-only)
|
|
21
22
|
--port <port> Set port (default: 3456, or PORT env var)
|
|
22
23
|
--host <addr> Bind address (default: 0.0.0.0)
|
|
23
24
|
--log-level <level> Set log verbosity: error, warn, info, debug (default: info)
|
|
@@ -26,7 +27,9 @@ Options:
|
|
|
26
27
|
|
|
27
28
|
Defaults:
|
|
28
29
|
By default, TermBeam enables tunnel + auto-generated password for secure
|
|
29
|
-
mobile access (clipboard, HTTPS).
|
|
30
|
+
mobile access (clipboard, HTTPS). Tunnels are private (owner-only via
|
|
31
|
+
Microsoft login). Use --public for public access, or
|
|
32
|
+
--no-tunnel for LAN-only mode.
|
|
30
33
|
|
|
31
34
|
Examples:
|
|
32
35
|
termbeam Start with tunnel + auto password
|
|
@@ -227,6 +230,7 @@ function parseArgs() {
|
|
|
227
230
|
let useTunnel = true;
|
|
228
231
|
let noTunnel = false;
|
|
229
232
|
let persistedTunnel = false;
|
|
233
|
+
let anonymousTunnel = false;
|
|
230
234
|
let explicitPassword = !!password;
|
|
231
235
|
|
|
232
236
|
const args = process.argv.slice(2);
|
|
@@ -243,6 +247,8 @@ function parseArgs() {
|
|
|
243
247
|
} else if (args[i] === '--persisted-tunnel') {
|
|
244
248
|
useTunnel = true;
|
|
245
249
|
persistedTunnel = true;
|
|
250
|
+
} else if (args[i] === '--public') {
|
|
251
|
+
anonymousTunnel = true;
|
|
246
252
|
} else if (args[i].startsWith('--password=')) {
|
|
247
253
|
password = args[i].split('=')[1];
|
|
248
254
|
explicitPassword = true;
|
|
@@ -278,6 +284,12 @@ function parseArgs() {
|
|
|
278
284
|
// --no-tunnel disables the default tunnel
|
|
279
285
|
if (noTunnel) useTunnel = false;
|
|
280
286
|
|
|
287
|
+
// --public requires a tunnel
|
|
288
|
+
if (anonymousTunnel && !useTunnel) {
|
|
289
|
+
console.error('Error: --public requires a tunnel. Remove --no-tunnel or remove --public.');
|
|
290
|
+
process.exit(1);
|
|
291
|
+
}
|
|
292
|
+
|
|
281
293
|
const shell = filteredArgs[0] || defaultShell;
|
|
282
294
|
const shellArgs = filteredArgs.slice(1);
|
|
283
295
|
|
|
@@ -290,6 +302,7 @@ function parseArgs() {
|
|
|
290
302
|
password,
|
|
291
303
|
useTunnel,
|
|
292
304
|
persistedTunnel,
|
|
305
|
+
anonymousTunnel,
|
|
293
306
|
shell,
|
|
294
307
|
shellArgs,
|
|
295
308
|
cwd,
|
package/src/logger.js
CHANGED
|
@@ -13,10 +13,11 @@ const log = {
|
|
|
13
13
|
if (l !== undefined) currentLevel = l;
|
|
14
14
|
},
|
|
15
15
|
getLevel() {
|
|
16
|
-
return Object.keys(LEVELS).find(k => LEVELS[k] === currentLevel);
|
|
16
|
+
return Object.keys(LEVELS).find((k) => LEVELS[k] === currentLevel);
|
|
17
17
|
},
|
|
18
18
|
error(...args) {
|
|
19
|
-
if (currentLevel >= LEVELS.error)
|
|
19
|
+
if (currentLevel >= LEVELS.error)
|
|
20
|
+
console.error(`[${timestamp()}]`, `[${LABELS.error}]`, ...args);
|
|
20
21
|
},
|
|
21
22
|
warn(...args) {
|
|
22
23
|
if (currentLevel >= LEVELS.warn) console.warn(`[${timestamp()}]`, `[${LABELS.warn}]`, ...args);
|
package/src/server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const os = require('os');
|
|
3
3
|
const path = require('path');
|
|
4
|
+
const readline = require('readline');
|
|
4
5
|
const express = require('express');
|
|
5
6
|
const cookieParser = require('cookie-parser');
|
|
6
7
|
const http = require('http');
|
|
@@ -26,6 +27,16 @@ function getLocalIP() {
|
|
|
26
27
|
return '127.0.0.1';
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
function confirmAnonymousTunnel() {
|
|
31
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
rl.question(' Do you want to continue with anonymous access? (y/N): ', (answer) => {
|
|
34
|
+
rl.close();
|
|
35
|
+
resolve(answer.trim().toLowerCase() === 'y');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
/**
|
|
30
41
|
* Create a TermBeam server instance without starting it.
|
|
31
42
|
* @param {object} [overrides] - Optional overrides
|
|
@@ -78,7 +89,7 @@ function createTermBeamServer(overrides = {}) {
|
|
|
78
89
|
wss.close();
|
|
79
90
|
}
|
|
80
91
|
|
|
81
|
-
function start() {
|
|
92
|
+
async function start() {
|
|
82
93
|
// Fail early if tunnel mode is on but devtunnel CLI is not installed
|
|
83
94
|
if (config.useTunnel && !findDevtunnel()) {
|
|
84
95
|
log.error('❌ devtunnel CLI is not installed.');
|
|
@@ -102,6 +113,28 @@ function createTermBeamServer(overrides = {}) {
|
|
|
102
113
|
process.exit(1);
|
|
103
114
|
}
|
|
104
115
|
|
|
116
|
+
// Warn and require consent for anonymous tunnel access
|
|
117
|
+
if (config.useTunnel && config.anonymousTunnel) {
|
|
118
|
+
const rd = '\x1b[31m';
|
|
119
|
+
const yl = '\x1b[33m';
|
|
120
|
+
const rs = '\x1b[0m';
|
|
121
|
+
const bd = '\x1b[1m';
|
|
122
|
+
console.log('');
|
|
123
|
+
console.log(` ${rd}${bd}⚠️ DANGER: Public tunnel access requested${rs}`);
|
|
124
|
+
console.log('');
|
|
125
|
+
console.log(` ${yl}This will make your terminal accessible to ANYONE with the URL.${rs}`);
|
|
126
|
+
console.log(` ${yl}No Microsoft login will be required to reach the tunnel.${rs}`);
|
|
127
|
+
console.log(` ${yl}Only the TermBeam password will protect your terminal.${rs}`);
|
|
128
|
+
console.log('');
|
|
129
|
+
const confirmed = await confirmAnonymousTunnel();
|
|
130
|
+
if (!confirmed) {
|
|
131
|
+
console.log('');
|
|
132
|
+
console.log(' Aborted. Restart without --public for private access.');
|
|
133
|
+
console.log('');
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
105
138
|
return new Promise((resolve) => {
|
|
106
139
|
server.listen(config.port, config.host, async () => {
|
|
107
140
|
const ip = getLocalIP();
|
|
@@ -146,7 +179,10 @@ function createTermBeamServer(overrides = {}) {
|
|
|
146
179
|
|
|
147
180
|
let publicUrl = null;
|
|
148
181
|
if (config.useTunnel) {
|
|
149
|
-
const tunnel = await startTunnel(config.port, {
|
|
182
|
+
const tunnel = await startTunnel(config.port, {
|
|
183
|
+
persisted: config.persistedTunnel,
|
|
184
|
+
anonymous: config.anonymousTunnel,
|
|
185
|
+
});
|
|
150
186
|
if (tunnel) {
|
|
151
187
|
publicUrl = tunnel.url;
|
|
152
188
|
state.shareBaseUrl = publicUrl;
|
package/src/sessions.js
CHANGED
|
@@ -3,8 +3,14 @@ const pty = require('node-pty');
|
|
|
3
3
|
const log = require('./logger');
|
|
4
4
|
|
|
5
5
|
const SESSION_COLORS = [
|
|
6
|
-
'#4a9eff',
|
|
7
|
-
'#
|
|
6
|
+
'#4a9eff',
|
|
7
|
+
'#4ade80',
|
|
8
|
+
'#fbbf24',
|
|
9
|
+
'#c084fc',
|
|
10
|
+
'#f87171',
|
|
11
|
+
'#22d3ee',
|
|
12
|
+
'#fb923c',
|
|
13
|
+
'#f472b6',
|
|
8
14
|
];
|
|
9
15
|
|
|
10
16
|
class SessionManager {
|
package/src/tunnel.js
CHANGED
|
@@ -186,13 +186,25 @@ async function startTunnel(port, options = {}) {
|
|
|
186
186
|
{ stdio: 'pipe' },
|
|
187
187
|
);
|
|
188
188
|
} catch {}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
189
|
+
// Set tunnel access: public (anonymous) or private (owner-only via Microsoft login)
|
|
190
|
+
if (options.anonymous) {
|
|
191
|
+
try {
|
|
192
|
+
execFileSync(
|
|
193
|
+
devtunnelCmd,
|
|
194
|
+
['access', 'create', tunnelId, '-p', String(port), '--anonymous'],
|
|
195
|
+
{ stdio: 'pipe' },
|
|
196
|
+
);
|
|
197
|
+
} catch {}
|
|
198
|
+
log.info('Tunnel access: public (anonymous)');
|
|
199
|
+
} else {
|
|
200
|
+
// Remove any existing anonymous access to ensure the tunnel is private
|
|
201
|
+
try {
|
|
202
|
+
execFileSync(devtunnelCmd, ['access', 'reset', tunnelId], {
|
|
203
|
+
stdio: 'pipe',
|
|
204
|
+
});
|
|
205
|
+
} catch {}
|
|
206
|
+
log.info('Tunnel access: private (owner-only via Microsoft login)');
|
|
207
|
+
}
|
|
196
208
|
|
|
197
209
|
const hostProc = spawn(devtunnelCmd, ['host', tunnelId], {
|
|
198
210
|
stdio: ['pipe', 'pipe', 'pipe'],
|