@lethevimlet/sshift 0.9.3 → 0.9.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 +6 -8
- package/example.config.json +3 -0
- package/package.json +8 -1
- package/src/server/endpoints/rest/config.js +21 -1
- package/src/server/endpoints/rest/system.js +36 -0
- package/src/server/endpoints/ws/ssh.js +6 -2
- package/src/server/index.js +39 -9
- package/src/server/plugins/plugin-manager.js +7 -1
- package/src/server/services/ssh-manager.js +50 -29
- package/src/server/utils/config.js +40 -13
- package/src/server/utils/env-loader.js +6 -17
- package/src/webapp/css/style.css +87 -29
- package/src/webapp/index.html +187 -29
- package/src/webapp/js/app.js +647 -108
- package/src/webapp/js/mobile-terminal.js +6 -0
- package/src/webapp/js/terminal-worker.js +211 -0
- package/src/webapp/libs/xterm/xterm-addon-fit.js +2 -2
- package/src/webapp/libs/xterm/xterm-addon-image.js +3 -0
- package/src/webapp/libs/xterm/xterm-addon-search.js +2 -2
- package/src/webapp/libs/xterm/xterm-addon-serialize-worker.js +2 -0
- package/src/webapp/libs/xterm/xterm-addon-web-links.js +2 -2
- package/src/webapp/libs/xterm/xterm-addon-webgl.js +2 -0
- package/src/webapp/libs/xterm/xterm-headless-prefix.js +6 -0
- package/src/webapp/libs/xterm/xterm-headless.js +2 -0
- package/src/webapp/libs/xterm/xterm.css +81 -5
- package/src/webapp/libs/xterm/xterm.js +1 -1
- package/src/webapp/sw.js +11 -4
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
1
3
|
# SSHIFT - Web-based SSH/SFTP Terminal Client for the AI Stack
|
|
2
4
|
|
|
3
5
|
[](https://lethevimlet.github.io/sshift/)
|
|
@@ -7,8 +9,6 @@
|
|
|
7
9
|
|
|
8
10
|
A modern, responsive web-based SSH and SFTP terminal client built with Node.js, Express, and xterm.js. Designed for the AI coding workflow — featuring tab flash notifications that alert you when AI tools like OpenCode or Claude are waiting for your input, so you never miss a prompt while multitasking. Also features excellent TUI support, tabbed sessions, bookmarks, and mobile-friendly design.
|
|
9
11
|
|
|
10
|
-

|
|
11
|
-
|
|
12
12
|
## 📸 Screenshots
|
|
13
13
|
|
|
14
14
|
<div align="center">
|
|
@@ -119,12 +119,10 @@ SSHIFT uses a priority-based configuration system. Config files are searched in
|
|
|
119
119
|
|
|
120
120
|
| Priority | Path | Notes |
|
|
121
121
|
|----------|------|-------|
|
|
122
|
-
| 1 |
|
|
123
|
-
| 2 |
|
|
124
|
-
| 3 | `~/.local/share/sshift/config.json` | User install
|
|
125
|
-
| 4 | `~/.local/share/
|
|
126
|
-
| 5 | `<PACKAGE_DIR>/.env/config.json` | NPM package directory |
|
|
127
|
-
| 6 | `<PACKAGE_DIR>/config.json` | NPM package root (fallback) |
|
|
122
|
+
| 1 | `<PACKAGE_DIR>/.env/config.json` | NPM package directory |
|
|
123
|
+
| 2 | `<PACKAGE_DIR>/config.json` | NPM package root (fallback) |
|
|
124
|
+
| 3 | `~/.local/share/sshift/.env/config.json` | User install location |
|
|
125
|
+
| 4 | `~/.local/share/sshift/config.json` | User install (no `.env` subdir) |
|
|
128
126
|
|
|
129
127
|
### Port Priority
|
|
130
128
|
|
package/example.config.json
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
"devPort": 3000,
|
|
4
4
|
"bind": "0.0.0.0",
|
|
5
5
|
"enableHttps": true,
|
|
6
|
+
"httpRedirect": true,
|
|
6
7
|
"certPath": null,
|
|
7
8
|
"keyPath": null,
|
|
8
9
|
"sticky": true,
|
|
9
10
|
"sshKeepaliveInterval": 15000,
|
|
10
11
|
"sshKeepaliveCountMax": 500,
|
|
12
|
+
"webglRenderer": true,
|
|
13
|
+
"imageAddonEnabled": true,
|
|
11
14
|
"passwordHash": null,
|
|
12
15
|
"plugins": [
|
|
13
16
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lethevimlet/sshift",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
|
|
5
5
|
"main": "src/server/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -19,10 +19,17 @@
|
|
|
19
19
|
"prepublishOnly": "echo 'Publishing to npm...'"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@xterm/addon-fit": "^0.11.0",
|
|
23
|
+
"@xterm/addon-image": "^0.9.0",
|
|
24
|
+
"@xterm/addon-search": "^0.16.0",
|
|
22
25
|
"@xterm/addon-serialize": "^0.14.0",
|
|
26
|
+
"@xterm/addon-web-links": "^0.12.0",
|
|
27
|
+
"@xterm/addon-webgl": "^0.19.0",
|
|
23
28
|
"@xterm/headless": "^6.0.0",
|
|
29
|
+
"@xterm/xterm": "^6.0.0",
|
|
24
30
|
"dotenv": "^17.4.0",
|
|
25
31
|
"express": "^4.18.2",
|
|
32
|
+
"httpolyglot": "^0.1.2",
|
|
26
33
|
"lucide": "^1.7.0",
|
|
27
34
|
"selfsigned": "^5.5.0",
|
|
28
35
|
"socket.io": "^4.7.2",
|
|
@@ -18,6 +18,8 @@ function registerConfigEndpoints(app, io) {
|
|
|
18
18
|
sshKeepaliveInterval: config.sshKeepaliveInterval || 10000,
|
|
19
19
|
sshKeepaliveCountMax: config.sshKeepaliveCountMax || 1000,
|
|
20
20
|
mobileKeysBarEnabled: config.mobileKeysBarEnabled !== false,
|
|
21
|
+
webglRenderer: config.webglRenderer !== false,
|
|
22
|
+
imageAddonEnabled: config.imageAddonEnabled !== false,
|
|
21
23
|
layouts: config.layouts || null,
|
|
22
24
|
passwordEnabled: !!config.passwordHash
|
|
23
25
|
});
|
|
@@ -46,6 +48,21 @@ function registerConfigEndpoints(app, io) {
|
|
|
46
48
|
config.sshKeepaliveCountMax = parseInt(req.body.sshKeepaliveCountMax) || 1000;
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
// Update mobile keys bar setting if provided
|
|
52
|
+
if (req.body.hasOwnProperty('mobileKeysBarEnabled')) {
|
|
53
|
+
config.mobileKeysBarEnabled = req.body.mobileKeysBarEnabled;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Update WebGL renderer setting if provided
|
|
57
|
+
if (req.body.hasOwnProperty('webglRenderer')) {
|
|
58
|
+
config.webglRenderer = req.body.webglRenderer;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Update image addon setting if provided
|
|
62
|
+
if (req.body.hasOwnProperty('imageAddonEnabled')) {
|
|
63
|
+
config.imageAddonEnabled = req.body.imageAddonEnabled;
|
|
64
|
+
}
|
|
65
|
+
|
|
49
66
|
// Save config
|
|
50
67
|
const saved = saveConfig(config);
|
|
51
68
|
if (saved) {
|
|
@@ -54,7 +71,10 @@ function registerConfigEndpoints(app, io) {
|
|
|
54
71
|
sticky: config.sticky !== false,
|
|
55
72
|
takeControlDefault: config.takeControlDefault !== false,
|
|
56
73
|
sshKeepaliveInterval: config.sshKeepaliveInterval || 10000,
|
|
57
|
-
sshKeepaliveCountMax: config.sshKeepaliveCountMax || 1000
|
|
74
|
+
sshKeepaliveCountMax: config.sshKeepaliveCountMax || 1000,
|
|
75
|
+
mobileKeysBarEnabled: config.mobileKeysBarEnabled !== false,
|
|
76
|
+
webglRenderer: config.webglRenderer !== false,
|
|
77
|
+
imageAddonEnabled: config.imageAddonEnabled !== false
|
|
58
78
|
});
|
|
59
79
|
} else {
|
|
60
80
|
res.status(500).json({ error: 'Failed to save config' });
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const path = require('path');
|
|
7
|
+
const { getDataDir } = require('../../utils/config');
|
|
8
|
+
|
|
9
|
+
const SSL_CERT_FILE = 'ssl-cert.pem';
|
|
10
|
+
const SSL_KEY_FILE = 'ssl-key.pem';
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Register system endpoints
|
|
@@ -131,6 +135,38 @@ function registerSystemEndpoints(app, io) {
|
|
|
131
135
|
});
|
|
132
136
|
});
|
|
133
137
|
|
|
138
|
+
// API: Download SSL certificate
|
|
139
|
+
app.get('/api/cert', (req, res) => {
|
|
140
|
+
const dataDir = getDataDir();
|
|
141
|
+
const certPath = path.join(dataDir, SSL_CERT_FILE);
|
|
142
|
+
|
|
143
|
+
if (!fs.existsSync(certPath)) {
|
|
144
|
+
return res.status(404).json({ error: 'Certificate not found' });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
res.setHeader('Content-Type', 'application/x-pem-file');
|
|
148
|
+
res.setHeader('Content-Disposition', 'attachment; filename="sshift-ca.crt"');
|
|
149
|
+
fs.createReadStream(certPath).pipe(res);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// API: Get security context info
|
|
153
|
+
app.get('/api/security-info', (req, res) => {
|
|
154
|
+
const dataDir = getDataDir();
|
|
155
|
+
const certPath = path.join(dataDir, SSL_CERT_FILE);
|
|
156
|
+
const hasCert = fs.existsSync(certPath);
|
|
157
|
+
const protocol = req.protocol;
|
|
158
|
+
const isSecure = req.secure || protocol === 'https';
|
|
159
|
+
const isLocalhost = req.hostname === 'localhost' || req.hostname === '127.0.0.1' || req.hostname === '::1';
|
|
160
|
+
|
|
161
|
+
res.json({
|
|
162
|
+
isSecure,
|
|
163
|
+
isLocalhost,
|
|
164
|
+
protocol,
|
|
165
|
+
certAvailable: hasCert,
|
|
166
|
+
hostname: req.hostname
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
134
170
|
// API: Trigger update
|
|
135
171
|
app.post('/api/update', async (req, res) => {
|
|
136
172
|
try {
|
|
@@ -84,11 +84,15 @@ function registerSSHHandlers(socket, io) {
|
|
|
84
84
|
console.log('[SSH] ssh-request-sync event received for session:', data.sessionId);
|
|
85
85
|
const state = sshManager.getTerminalState(data.sessionId);
|
|
86
86
|
if (state) {
|
|
87
|
+
// Base64 encode to avoid Socket.IO binary detection issues
|
|
88
|
+
const base64State = Buffer.from(state.state, 'utf-8').toString('base64');
|
|
87
89
|
socket.emit('ssh-screen-sync', {
|
|
88
90
|
sessionId: data.sessionId,
|
|
89
|
-
state:
|
|
91
|
+
state: base64State,
|
|
90
92
|
cols: state.cols,
|
|
91
|
-
rows: state.rows
|
|
93
|
+
rows: state.rows,
|
|
94
|
+
encoded: true,
|
|
95
|
+
partial: false
|
|
92
96
|
});
|
|
93
97
|
} else {
|
|
94
98
|
socket.emit('ssh-error', { message: 'Session not found', sessionId: data.sessionId });
|
package/src/server/index.js
CHANGED
|
@@ -16,9 +16,10 @@ const fs = require('fs');
|
|
|
16
16
|
const path = require('path');
|
|
17
17
|
const socketIO = require('socket.io');
|
|
18
18
|
const selfsigned = require('selfsigned');
|
|
19
|
+
const httpolyglot = require('httpolyglot');
|
|
19
20
|
|
|
20
21
|
// Import utilities
|
|
21
|
-
const { ensureConfig, loadConfig, getPort, getBindAddress, getEnableHttps, getCertPath, getKeyPath, getDataDir, isPasswordSet } = require('./utils/config');
|
|
22
|
+
const { ensureConfig, loadConfig, getPort, getBindAddress, getEnableHttps, getHttpRedirect, getCertPath, getKeyPath, getDataDir, isPasswordSet } = require('./utils/config');
|
|
22
23
|
|
|
23
24
|
// Import services
|
|
24
25
|
const { sshManager, sftpManager } = require('./services');
|
|
@@ -151,9 +152,11 @@ const app = express();
|
|
|
151
152
|
|
|
152
153
|
// Determine if HTTPS should be enabled
|
|
153
154
|
const enableHttps = getEnableHttps();
|
|
155
|
+
const enableHttpRedirect = enableHttps && getHttpRedirect();
|
|
154
156
|
let server;
|
|
155
|
-
let io;
|
|
157
|
+
let io;
|
|
156
158
|
let sslCredentials = null;
|
|
159
|
+
let actuallyHttps = false;
|
|
157
160
|
|
|
158
161
|
// Async initialization function
|
|
159
162
|
async function initializeServer() {
|
|
@@ -162,11 +165,30 @@ async function initializeServer() {
|
|
|
162
165
|
if (enableHttps) {
|
|
163
166
|
try {
|
|
164
167
|
sslCredentials = await getSSLCredentials();
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
|
|
169
|
+
if (enableHttpRedirect) {
|
|
170
|
+
server = httpolyglot.createServer({
|
|
171
|
+
key: sslCredentials.key,
|
|
172
|
+
cert: sslCredentials.cert
|
|
173
|
+
}, app);
|
|
174
|
+
server.on('request', (req, res) => {
|
|
175
|
+
if (!req.socket.encrypted) {
|
|
176
|
+
const host = req.headers.host ? req.headers.host.split(':')[0] : 'localhost';
|
|
177
|
+
const port = getPort();
|
|
178
|
+
res.writeHead(301, { Location: `https://${host}:${port}${req.url}` });
|
|
179
|
+
res.end();
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
actuallyHttps = true;
|
|
183
|
+
console.log('[HTTPS] HTTPS server created with HTTP redirect enabled (dual-protocol)');
|
|
184
|
+
} else {
|
|
185
|
+
server = https.createServer({
|
|
186
|
+
key: sslCredentials.key,
|
|
187
|
+
cert: sslCredentials.cert
|
|
188
|
+
}, app);
|
|
189
|
+
actuallyHttps = true;
|
|
190
|
+
console.log('[HTTPS] HTTPS server created with self-signed certificate');
|
|
191
|
+
}
|
|
170
192
|
} catch (err) {
|
|
171
193
|
console.error('[HTTPS] Failed to create HTTPS server, falling back to HTTP:', err.message);
|
|
172
194
|
server = http.createServer(app);
|
|
@@ -233,6 +255,14 @@ async function initializeServer() {
|
|
|
233
255
|
app.use('/libs', express.static(path.join(webappPath, 'libs')));
|
|
234
256
|
app.use('/tests', express.static(path.join(webappPath, 'tests')));
|
|
235
257
|
|
|
258
|
+
// Service Worker script - must be served from root with proper headers
|
|
259
|
+
app.get('/sw.js', (req, res) => {
|
|
260
|
+
res.setHeader('Content-Type', 'application/javascript');
|
|
261
|
+
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
262
|
+
res.setHeader('Service-Worker-Allowed', '/');
|
|
263
|
+
res.sendFile(path.join(webappPath, 'sw.js'));
|
|
264
|
+
});
|
|
265
|
+
|
|
236
266
|
// Main route
|
|
237
267
|
app.get('/', (req, res) => {
|
|
238
268
|
res.sendFile(path.join(webappPath, 'index.html'));
|
|
@@ -302,13 +332,13 @@ async function initializeServer() {
|
|
|
302
332
|
|
|
303
333
|
server.listen(PORT, BIND, () => {
|
|
304
334
|
const address = BIND === '0.0.0.0' || BIND === '::' ? 'localhost' : BIND;
|
|
305
|
-
const protocol =
|
|
335
|
+
const protocol = actuallyHttps ? 'https' : 'http';
|
|
306
336
|
console.log(`Web SSH/SFTP Client running at ${protocol}://${address}:${PORT}`);
|
|
307
337
|
// OSC 8 hyperlink: ESC ] 8 ; ; URL BEL text ESC ] 8 ; ; BEL
|
|
308
338
|
const ESC = '\x1b';
|
|
309
339
|
console.log(`${ESC}]8;;${protocol}://${address}:${PORT}${ESC}\\Open in browser${ESC}]8;;${ESC}\\`);
|
|
310
340
|
|
|
311
|
-
|
|
341
|
+
if (actuallyHttps) {
|
|
312
342
|
console.log('[HTTPS] Note: Using self-signed certificate. Your browser may show a security warning.');
|
|
313
343
|
console.log('[HTTPS] For mobile devices, you may need to accept the certificate warning to use native text selection.');
|
|
314
344
|
}
|
|
@@ -93,13 +93,19 @@ class PluginManager {
|
|
|
93
93
|
this._lineBuffers.clear();
|
|
94
94
|
this.flashingSessions.clear();
|
|
95
95
|
|
|
96
|
+
this._loadPlugins();
|
|
97
|
+
|
|
96
98
|
if (this.io) {
|
|
97
99
|
for (const [, socket] of this.io.sockets.sockets) {
|
|
98
100
|
this.syncFlashState(socket);
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
this.
|
|
104
|
+
if (this.sshManager) {
|
|
105
|
+
for (const sessionId of this.sshManager.sessions.keys()) {
|
|
106
|
+
this.emit('onSessionConnect', sessionId, {});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
init({ io, sshManager, tabManager, config }) {
|
|
@@ -7,8 +7,8 @@ class SSHManager {
|
|
|
7
7
|
constructor() {
|
|
8
8
|
this.sessions = new Map();
|
|
9
9
|
// Data batching configuration
|
|
10
|
-
this.batchInterval =
|
|
11
|
-
this.batchMaxSize =
|
|
10
|
+
this.batchInterval = 4; // ~240fps - low latency for responsive rendering
|
|
11
|
+
this.batchMaxSize = 128 * 1024; // 128KB max batch size - send immediately if exceeded
|
|
12
12
|
// Socket.io instance (set via setIO method)
|
|
13
13
|
this.io = null;
|
|
14
14
|
}
|
|
@@ -29,10 +29,13 @@ class SSHManager {
|
|
|
29
29
|
const rows = options.rows || 24;
|
|
30
30
|
|
|
31
31
|
// Create a headless terminal to maintain state
|
|
32
|
+
// Use scrollback 5000 to preserve full history for screen sync on reload
|
|
32
33
|
const terminal = new Terminal({
|
|
33
34
|
cols: cols,
|
|
34
35
|
rows: rows,
|
|
35
|
-
|
|
36
|
+
scrollback: 5000,
|
|
37
|
+
allowProposedApi: true,
|
|
38
|
+
logLevel: 'off'
|
|
36
39
|
});
|
|
37
40
|
|
|
38
41
|
// Create serialize addon for terminal state
|
|
@@ -146,7 +149,7 @@ class SSHManager {
|
|
|
146
149
|
stream.on('data', (data) => {
|
|
147
150
|
const dataStr = data.toString('utf8');
|
|
148
151
|
|
|
149
|
-
// Write to headless terminal
|
|
152
|
+
// Write to headless terminal for state sync (join/resume)
|
|
150
153
|
session.terminal.write(dataStr);
|
|
151
154
|
|
|
152
155
|
// Buffer data for batched broadcast
|
|
@@ -156,7 +159,7 @@ class SSHManager {
|
|
|
156
159
|
stream.stderr.on('data', (data) => {
|
|
157
160
|
const dataStr = data.toString('utf8');
|
|
158
161
|
|
|
159
|
-
// Write to headless terminal
|
|
162
|
+
// Write to headless terminal for state sync
|
|
160
163
|
session.terminal.write(dataStr);
|
|
161
164
|
|
|
162
165
|
// Buffer data for batched broadcast
|
|
@@ -280,40 +283,54 @@ class SSHManager {
|
|
|
280
283
|
|
|
281
284
|
// Send current terminal state to the joining socket BEFORE joining the room
|
|
282
285
|
// This ensures the client gets the full state before receiving any new data
|
|
283
|
-
// This provides the complete screen state for TUIs
|
|
284
286
|
if (session.terminal && session.serializeAddon) {
|
|
285
287
|
try {
|
|
286
|
-
//
|
|
287
|
-
|
|
288
|
-
let serializedState = session.serializeAddon.serialize({
|
|
289
|
-
mode: 'normal' // Only current viewport, not full scrollback
|
|
290
|
-
});
|
|
288
|
+
// Try to serialize full scrollback buffer first (includes all history)
|
|
289
|
+
let serializedState = session.serializeAddon.serialize({ mode: 'all' });
|
|
291
290
|
|
|
292
|
-
//
|
|
291
|
+
// Validate it's a string
|
|
293
292
|
if (typeof serializedState !== 'string') {
|
|
294
293
|
serializedState = String(serializedState);
|
|
295
294
|
}
|
|
296
295
|
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
296
|
+
// If full state is too large, fall back to viewport-only
|
|
297
|
+
const fullMaxSize = 256 * 1024; // 256KB for full scrollback
|
|
298
|
+
const viewportMaxSize = 50 * 1024; // 50KB fallback for viewport only
|
|
299
|
+
|
|
300
|
+
if (serializedState.length > fullMaxSize) {
|
|
301
|
+
console.warn(`[SSH] Full terminal state too large (${serializedState.length} bytes), falling back to viewport-only`);
|
|
302
|
+
serializedState = session.serializeAddon.serialize({ mode: 'normal' });
|
|
303
|
+
if (typeof serializedState !== 'string') {
|
|
304
|
+
serializedState = String(serializedState);
|
|
305
|
+
}
|
|
304
306
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
+
if (serializedState.length > viewportMaxSize) {
|
|
308
|
+
console.warn(`[SSH] Viewport state also too large (${serializedState.length} bytes), skipping sync`);
|
|
309
|
+
} else {
|
|
310
|
+
// Send viewport-only state
|
|
311
|
+
const base64State = Buffer.from(serializedState, 'utf-8').toString('base64');
|
|
312
|
+
socket.emit('ssh-screen-sync', {
|
|
313
|
+
sessionId: sessionId,
|
|
314
|
+
state: base64State,
|
|
315
|
+
cols: session.cols,
|
|
316
|
+
rows: session.rows,
|
|
317
|
+
encoded: true,
|
|
318
|
+
partial: true
|
|
319
|
+
});
|
|
320
|
+
hasTerminalState = true;
|
|
321
|
+
}
|
|
322
|
+
} else {
|
|
323
|
+
// Send full state including scrollback
|
|
307
324
|
const base64State = Buffer.from(serializedState, 'utf-8').toString('base64');
|
|
325
|
+
console.log(`[SSH] Sending full serialized terminal state to socket ${socket.id}, size: ${serializedState.length}, base64: ${base64State.length}`);
|
|
308
326
|
|
|
309
|
-
// Send the serialized state to the joining client
|
|
310
|
-
// Use a plain object with primitive values only
|
|
311
327
|
socket.emit('ssh-screen-sync', {
|
|
312
328
|
sessionId: sessionId,
|
|
313
329
|
state: base64State,
|
|
314
330
|
cols: session.cols,
|
|
315
331
|
rows: session.rows,
|
|
316
|
-
encoded: true
|
|
332
|
+
encoded: true,
|
|
333
|
+
partial: false
|
|
317
334
|
});
|
|
318
335
|
|
|
319
336
|
hasTerminalState = true;
|
|
@@ -479,14 +496,18 @@ class SSHManager {
|
|
|
479
496
|
}
|
|
480
497
|
|
|
481
498
|
try {
|
|
482
|
-
//
|
|
483
|
-
|
|
499
|
+
// Serialize full scrollback buffer to preserve history on reload
|
|
500
|
+
let serializedState = session.serializeAddon.serialize({ mode: 'all' });
|
|
484
501
|
|
|
485
|
-
// Validate size
|
|
502
|
+
// Validate size - allow up to 1MB for manual sync requests
|
|
486
503
|
const maxSize = 1024 * 1024; // 1MB max
|
|
487
504
|
if (serializedState.length > maxSize) {
|
|
488
|
-
console.warn(`[SSH] Terminal state too large (${serializedState.length} bytes),
|
|
489
|
-
|
|
505
|
+
console.warn(`[SSH] Terminal state too large (${serializedState.length} bytes), falling back to viewport-only`);
|
|
506
|
+
serializedState = session.serializeAddon.serialize({ mode: 'normal' });
|
|
507
|
+
if (serializedState.length > maxSize) {
|
|
508
|
+
console.warn(`[SSH] Viewport state also too large (${serializedState.length} bytes), returning null`);
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
490
511
|
}
|
|
491
512
|
|
|
492
513
|
return {
|
|
@@ -11,23 +11,16 @@ const crypto = require('crypto');
|
|
|
11
11
|
// Get user's home directory
|
|
12
12
|
const HOME_DIR = os.homedir();
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
const
|
|
16
|
-
// Linux/macOS
|
|
17
|
-
path.join(HOME_DIR, '.local', 'share', 'sshift'),
|
|
18
|
-
// Windows
|
|
19
|
-
path.join(HOME_DIR, '.local', 'share', 'sshift'),
|
|
20
|
-
// Alternative locations
|
|
21
|
-
path.join(HOME_DIR, '.local', 'share', 'bin'),
|
|
22
|
-
];
|
|
14
|
+
// User install directory for config
|
|
15
|
+
const USER_INSTALL_DIR = path.join(HOME_DIR, '.local', 'share', 'sshift');
|
|
23
16
|
|
|
24
|
-
// Config paths - prioritize
|
|
17
|
+
// Config paths - prioritize package directory, then user install directory
|
|
25
18
|
const PACKAGE_DIR = path.join(__dirname, '..', '..', '..');
|
|
26
19
|
const ENV_CONFIG_PATHS = [
|
|
27
|
-
...DEFAULT_INSTALL_DIRS.map(dir => path.join(dir, '.env', 'config.json')),
|
|
28
|
-
...DEFAULT_INSTALL_DIRS.map(dir => path.join(dir, 'config.json')),
|
|
29
20
|
path.join(PACKAGE_DIR, '.env', 'config.json'),
|
|
30
21
|
path.join(PACKAGE_DIR, 'config.json'),
|
|
22
|
+
path.join(USER_INSTALL_DIR, '.env', 'config.json'),
|
|
23
|
+
path.join(USER_INSTALL_DIR, 'config.json'),
|
|
31
24
|
];
|
|
32
25
|
|
|
33
26
|
// Default config structure
|
|
@@ -36,6 +29,7 @@ const defaultConfig = {
|
|
|
36
29
|
devPort: 3000,
|
|
37
30
|
bind: '0.0.0.0',
|
|
38
31
|
enableHttps: true,
|
|
32
|
+
httpRedirect: true,
|
|
39
33
|
sticky: true,
|
|
40
34
|
sshKeepaliveInterval: 15000,
|
|
41
35
|
sshKeepaliveCountMax: 500,
|
|
@@ -44,7 +38,9 @@ const defaultConfig = {
|
|
|
44
38
|
plugins: [],
|
|
45
39
|
bookmarks: [],
|
|
46
40
|
folders: [],
|
|
47
|
-
passwordHash: null
|
|
41
|
+
passwordHash: null,
|
|
42
|
+
webglRenderer: true,
|
|
43
|
+
imageAddonEnabled: true
|
|
48
44
|
};
|
|
49
45
|
|
|
50
46
|
/**
|
|
@@ -207,6 +203,24 @@ function getMobileKeysBarEnabled() {
|
|
|
207
203
|
return config.mobileKeysBarEnabled !== false; // Default to true
|
|
208
204
|
}
|
|
209
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Get WebGL renderer setting from config
|
|
208
|
+
* @returns {boolean} WebGL renderer setting
|
|
209
|
+
*/
|
|
210
|
+
function getWebglRenderer() {
|
|
211
|
+
const config = loadConfig();
|
|
212
|
+
return config.webglRenderer !== false; // Default to true
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Get image addon setting from config
|
|
217
|
+
* @returns {boolean} Image addon setting
|
|
218
|
+
*/
|
|
219
|
+
function getImageAddonEnabled() {
|
|
220
|
+
const config = loadConfig();
|
|
221
|
+
return config.imageAddonEnabled !== false; // Default to true
|
|
222
|
+
}
|
|
223
|
+
|
|
210
224
|
/**
|
|
211
225
|
* Get layouts from config
|
|
212
226
|
* @returns {Object|null} Layouts object or null
|
|
@@ -225,6 +239,16 @@ function getEnableHttps() {
|
|
|
225
239
|
return config.enableHttps !== false; // Default to true
|
|
226
240
|
}
|
|
227
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Get HTTP redirect setting from config
|
|
244
|
+
* Only meaningful when HTTPS is enabled - redirects HTTP requests to HTTPS
|
|
245
|
+
* @returns {boolean} Enable HTTP redirect setting
|
|
246
|
+
*/
|
|
247
|
+
function getHttpRedirect() {
|
|
248
|
+
const config = loadConfig();
|
|
249
|
+
return config.httpRedirect !== false; // Default to true
|
|
250
|
+
}
|
|
251
|
+
|
|
228
252
|
/**
|
|
229
253
|
* Get custom certificate path from config
|
|
230
254
|
* @returns {string|null} Path to custom certificate file, or null
|
|
@@ -299,8 +323,11 @@ module.exports = {
|
|
|
299
323
|
getStickySetting,
|
|
300
324
|
getTakeControlDefault,
|
|
301
325
|
getMobileKeysBarEnabled,
|
|
326
|
+
getWebglRenderer,
|
|
327
|
+
getImageAddonEnabled,
|
|
302
328
|
getLayouts,
|
|
303
329
|
getEnableHttps,
|
|
330
|
+
getHttpRedirect,
|
|
304
331
|
getCertPath,
|
|
305
332
|
getKeyPath,
|
|
306
333
|
getDataDir,
|
|
@@ -15,29 +15,18 @@ function loadEnvFiles() {
|
|
|
15
15
|
// Get user's home directory
|
|
16
16
|
const HOME_DIR = os.homedir();
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
const DEFAULT_INSTALL_DIRS = [
|
|
20
|
-
// Linux/macOS
|
|
21
|
-
path.join(HOME_DIR, '.local', 'share', 'sshift'),
|
|
22
|
-
// Windows
|
|
23
|
-
path.join(HOME_DIR, '.local', 'share', 'sshift'),
|
|
24
|
-
// Alternative locations
|
|
25
|
-
path.join(HOME_DIR, '.local', 'share', 'bin'),
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
// Package directory (for development)
|
|
18
|
+
const USER_INSTALL_DIR = path.join(HOME_DIR, '.local', 'share', 'sshift');
|
|
29
19
|
const PACKAGE_DIR = path.join(__dirname, '..', '..', '..');
|
|
30
20
|
|
|
31
|
-
// Build env paths - prioritize user install directory, then package directory
|
|
32
21
|
const envPaths = [
|
|
33
|
-
...DEFAULT_INSTALL_DIRS.map(dir => path.join(dir, '.env', '.env.local')),
|
|
34
|
-
...DEFAULT_INSTALL_DIRS.map(dir => path.join(dir, '.env.local')),
|
|
35
|
-
...DEFAULT_INSTALL_DIRS.map(dir => path.join(dir, '.env', '.env')),
|
|
36
|
-
...DEFAULT_INSTALL_DIRS.map(dir => path.join(dir, '.env')),
|
|
37
22
|
path.join(PACKAGE_DIR, '.env', '.env.local'),
|
|
38
23
|
path.join(PACKAGE_DIR, '.env.local'),
|
|
39
24
|
path.join(PACKAGE_DIR, '.env', '.env'),
|
|
40
|
-
path.join(PACKAGE_DIR, '.env')
|
|
25
|
+
path.join(PACKAGE_DIR, '.env'),
|
|
26
|
+
path.join(USER_INSTALL_DIR, '.env', '.env.local'),
|
|
27
|
+
path.join(USER_INSTALL_DIR, '.env.local'),
|
|
28
|
+
path.join(USER_INSTALL_DIR, '.env', '.env'),
|
|
29
|
+
path.join(USER_INSTALL_DIR, '.env')
|
|
41
30
|
];
|
|
42
31
|
|
|
43
32
|
envPaths.forEach(envPath => {
|