@lethevimlet/sshift 1.0.4 → 1.0.6
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/package.json +1 -1
- package/src/server/endpoints/rest/sessions.js +3 -0
- package/src/server/endpoints/rest/system.js +70 -21
- package/src/server/endpoints/ws/sftp.js +3 -1
- package/src/server/endpoints/ws/ssh.js +3 -2
- package/src/server/endpoints/ws/tabs.js +2 -0
- package/src/server/index.js +60 -9
- package/src/server/services/ssh-manager.js +22 -4
- package/src/webapp/index.html +54 -53
- package/src/webapp/js/app.js +32 -6
- package/src/webapp/sw.js +46 -14
- package/sshift +44 -2
- package/sshift-install.ps1 +1 -1
- package/sshift-install.sh +1 -1
package/package.json
CHANGED
|
@@ -76,6 +76,7 @@ function registerSessionsEndpoints(app, io) {
|
|
|
76
76
|
|
|
77
77
|
// Broadcast to all clients that the session was closed
|
|
78
78
|
io.emit('tab-closed', { sessionId });
|
|
79
|
+
io.emit('sessions-updated');
|
|
79
80
|
|
|
80
81
|
res.json({ success: true, sessionId });
|
|
81
82
|
});
|
|
@@ -106,6 +107,8 @@ function registerSessionsEndpoints(app, io) {
|
|
|
106
107
|
removeTab(sessionId);
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
io.emit('sessions-updated');
|
|
111
|
+
|
|
109
112
|
res.json({ success: true, closedCount: closedSessions.length });
|
|
110
113
|
});
|
|
111
114
|
}
|
|
@@ -17,6 +17,8 @@ const UPDATE_MARKER_FILE = '.updating';
|
|
|
17
17
|
*/
|
|
18
18
|
function registerSystemEndpoints(app, io) {
|
|
19
19
|
// Clean up stale update marker from previous update attempt
|
|
20
|
+
// NOTE: Do NOT delete the update log here — the client needs to read it
|
|
21
|
+
// to detect errors. The log is cleaned up separately after a short delay.
|
|
20
22
|
const dataDir = getDataDir();
|
|
21
23
|
const staleUpdateMarker = path.join(dataDir, UPDATE_MARKER_FILE);
|
|
22
24
|
const staleUpdateScript = path.join(dataDir, '.sshift-update.sh');
|
|
@@ -36,7 +38,10 @@ function registerSystemEndpoints(app, io) {
|
|
|
36
38
|
if (fs.existsSync(staleUpdateLog)) {
|
|
37
39
|
const logContent = fs.readFileSync(staleUpdateLog, 'utf8');
|
|
38
40
|
console.log('[UPDATE] Previous update log:\n' + logContent);
|
|
39
|
-
|
|
41
|
+
// Delay log deletion so the client can read error status
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
try { fs.unlinkSync(staleUpdateLog); } catch (e) { /* ignore */ }
|
|
44
|
+
}, 30000);
|
|
40
45
|
}
|
|
41
46
|
} catch (e) {
|
|
42
47
|
console.error('[UPDATE] Failed to clean up marker file:', e.message);
|
|
@@ -156,12 +161,17 @@ function registerSystemEndpoints(app, io) {
|
|
|
156
161
|
|
|
157
162
|
// Check for update error log
|
|
158
163
|
let updateError = null;
|
|
164
|
+
let updateLog = null;
|
|
159
165
|
if (!isUpdating && fs.existsSync(updateLogPath)) {
|
|
160
166
|
try {
|
|
161
167
|
const logContent = fs.readFileSync(updateLogPath, 'utf8');
|
|
162
168
|
if (logContent.includes('npm install failed')) {
|
|
163
169
|
updateError = 'Update failed: npm install exited with an error.';
|
|
164
170
|
}
|
|
171
|
+
// Return the last 4KB of the log for debugging
|
|
172
|
+
const lastLines = logContent.slice(-4096);
|
|
173
|
+
const relevantLines = lastLines.split('\n').filter(l => l.trim()).slice(-10);
|
|
174
|
+
updateLog = relevantLines.join('\n');
|
|
165
175
|
} catch (e) {
|
|
166
176
|
// Ignore log read errors
|
|
167
177
|
}
|
|
@@ -171,7 +181,8 @@ function registerSystemEndpoints(app, io) {
|
|
|
171
181
|
version,
|
|
172
182
|
updating: isUpdating,
|
|
173
183
|
ready: !isUpdating,
|
|
174
|
-
updateError
|
|
184
|
+
updateError,
|
|
185
|
+
updateLog
|
|
175
186
|
});
|
|
176
187
|
});
|
|
177
188
|
|
|
@@ -291,53 +302,88 @@ function registerSystemEndpoints(app, io) {
|
|
|
291
302
|
const updateScriptPath = path.join(dataDir, '.sshift-update.sh');
|
|
292
303
|
const updateLogPath = path.join(dataDir, '.sshift-update.log');
|
|
293
304
|
|
|
305
|
+
// Build PATH for the update script to ensure npm and node are findable
|
|
306
|
+
const pathDirs = [];
|
|
307
|
+
if (process.env.PATH) pathDirs.push(...process.env.PATH.split(':'));
|
|
308
|
+
const nodeDir = path.dirname(process.execPath);
|
|
309
|
+
if (!pathDirs.includes(nodeDir)) pathDirs.unshift(nodeDir);
|
|
310
|
+
['/usr/local/bin', '/usr/bin', '/usr/sbin', '/bin', '/sbin'].forEach((d) => {
|
|
311
|
+
if (!pathDirs.includes(d)) pathDirs.push(d);
|
|
312
|
+
});
|
|
313
|
+
const scriptPath = pathDirs.join(':');
|
|
314
|
+
|
|
294
315
|
// Send response immediately, then update in background
|
|
295
316
|
res.json({ message: 'Update started. Server will restart automatically.' });
|
|
296
317
|
|
|
297
318
|
if (platform === 'win32') {
|
|
298
319
|
const sshiftCmd = sshiftBinPath.includes(' ') ? `& '${sshiftBinPath}'` : `sshift`;
|
|
299
320
|
const psScript = `$ErrorActionPreference = 'Continue'
|
|
321
|
+
$MarkerPath = '${updateMarker}'
|
|
322
|
+
$LogPath = '${updateLogPath}'
|
|
323
|
+
$NodeExe = '${nodeExe}'
|
|
324
|
+
$SshiftBin = '${sshiftBinPath}'
|
|
325
|
+
|
|
300
326
|
try {
|
|
301
|
-
& npm install -g @lethevimlet/sshift@latest 2>&1 | Out-File -FilePath
|
|
327
|
+
& npm install -g @lethevimlet/sshift@latest 2>&1 | Out-File -FilePath $LogPath -Append
|
|
302
328
|
if ($LASTEXITCODE -ne 0) {
|
|
303
|
-
Write-Output
|
|
329
|
+
Write-Output "npm install failed with exit code $LASTEXITCODE" | Out-File -FilePath $LogPath -Append
|
|
330
|
+
Remove-Item -Path $MarkerPath -Force -ErrorAction SilentlyContinue
|
|
331
|
+
& $NodeExe $SshiftBin
|
|
304
332
|
exit 1
|
|
305
333
|
}
|
|
306
334
|
} catch {
|
|
307
|
-
Write-Output $_.Exception.Message | Out-File -FilePath
|
|
335
|
+
Write-Output $_.Exception.Message | Out-File -FilePath $LogPath -Append
|
|
336
|
+
Remove-Item -Path $MarkerPath -Force -ErrorAction SilentlyContinue
|
|
337
|
+
& $NodeExe $SshiftBin
|
|
308
338
|
exit 1
|
|
309
339
|
}
|
|
310
|
-
Remove-Item -Path
|
|
311
|
-
&
|
|
340
|
+
Remove-Item -Path $MarkerPath -Force -ErrorAction SilentlyContinue
|
|
341
|
+
& $NodeExe $SshiftBin
|
|
312
342
|
`;
|
|
313
343
|
const psScriptPath = updateScriptPath.replace('.sh', '.ps1');
|
|
314
344
|
fs.writeFileSync(psScriptPath, psScript, 'utf8');
|
|
315
345
|
} else {
|
|
316
346
|
const updateScript = `#!/bin/sh
|
|
317
|
-
set -e
|
|
318
347
|
LOG="${updateLogPath}"
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
# Try npm install
|
|
348
|
+
MARKER="${updateMarker}"
|
|
322
349
|
NPM_BIN="${npmBinPath}"
|
|
323
|
-
|
|
350
|
+
SSHIFT_FALLBACK="${sshiftBinPath}"
|
|
351
|
+
NODE_BIN="${nodeExe}"
|
|
352
|
+
OLD_VERSION="${oldVersion}"
|
|
353
|
+
|
|
354
|
+
echo "$(date): Starting sshift update (from v${oldVersion})..." > "$LOG"
|
|
355
|
+
echo "$(date): npm path: $NPM_BIN" >> "$LOG"
|
|
356
|
+
echo "$(date): node path: $NODE_BIN" >> "$LOG"
|
|
357
|
+
echo "$(date): sshift fallback: $SSHIFT_FALLBACK" >> "$LOG"
|
|
324
358
|
|
|
359
|
+
# Find the current sshift binary before npm changes anything
|
|
360
|
+
CURRENT_SSHIFT="$(command -v sshift 2>/dev/null || which sshift 2>/dev/null || echo "$SSHIFT_FALLBACK")"
|
|
361
|
+
|
|
362
|
+
# Run npm install
|
|
363
|
+
echo "$(date): Running npm install..." >> "$LOG"
|
|
325
364
|
if ! "$NPM_BIN" install -g @lethevimlet/sshift@latest >> "$LOG" 2>&1; then
|
|
326
|
-
echo "$(date): npm install failed
|
|
327
|
-
|
|
328
|
-
|
|
365
|
+
echo "$(date): npm install failed" >> "$LOG"
|
|
366
|
+
echo "npm install failed" >> "$LOG"
|
|
367
|
+
rm -f "$MARKER"
|
|
368
|
+
# Always restart the server — the old version is still installed
|
|
369
|
+
echo "$(date): Restarting sshift (old version) from: $CURRENT_SSHIFT" >> "$LOG"
|
|
370
|
+
exec "$NODE_BIN" "$CURRENT_SSHIFT"
|
|
329
371
|
fi
|
|
330
|
-
|
|
331
372
|
echo "$(date): npm install completed successfully" >> "$LOG"
|
|
332
373
|
|
|
333
|
-
# Remove the update marker before restart
|
|
334
|
-
rm -f "$
|
|
374
|
+
# Remove the update marker before restart
|
|
375
|
+
rm -f "$MARKER"
|
|
335
376
|
|
|
336
377
|
# Find the sshift binary — prefer PATH lookup since npm just updated it
|
|
337
|
-
SSHIFT_BIN="$(command -v sshift 2>/dev/null || which sshift 2>/dev/null || echo "$
|
|
378
|
+
SSHIFT_BIN="$(command -v sshift 2>/dev/null || which sshift 2>/dev/null || echo "$SSHIFT_FALLBACK")"
|
|
379
|
+
if [ ! -x "$SSHIFT_BIN" ]; then
|
|
380
|
+
echo "$(date): ERROR: sshift binary not found or not executable at: $SSHIFT_BIN" >> "$LOG"
|
|
381
|
+
echo "$(date): Attempting to restart with fallback path" >> "$LOG"
|
|
382
|
+
SSHIFT_BIN="$SSHIFT_FALLBACK"
|
|
383
|
+
fi
|
|
338
384
|
|
|
339
385
|
echo "$(date): Restarting sshift from: $SSHIFT_BIN" >> "$LOG"
|
|
340
|
-
exec "$
|
|
386
|
+
exec "$NODE_BIN" "$SSHIFT_BIN"
|
|
341
387
|
`;
|
|
342
388
|
fs.writeFileSync(updateScriptPath, updateScript, 'utf8');
|
|
343
389
|
fs.chmodSync(updateScriptPath, 0o755);
|
|
@@ -358,11 +404,14 @@ exec "${nodeExe}" "$SSHIFT_BIN"
|
|
|
358
404
|
spawnArgs = [updateScriptPath];
|
|
359
405
|
}
|
|
360
406
|
|
|
407
|
+
const updateEnv = { ...process.env };
|
|
408
|
+
updateEnv.PATH = scriptPath;
|
|
409
|
+
|
|
361
410
|
const updateProcess = spawn(spawnCommand, spawnArgs, {
|
|
362
411
|
cwd: dataDir,
|
|
363
412
|
detached: true,
|
|
364
413
|
stdio: 'ignore',
|
|
365
|
-
env:
|
|
414
|
+
env: updateEnv
|
|
366
415
|
});
|
|
367
416
|
|
|
368
417
|
updateProcess.on('error', (err) => {
|
|
@@ -44,7 +44,6 @@ function registerSFTPHandlers(socket, io) {
|
|
|
44
44
|
sticky: sticky
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
// Broadcast to all clients that a new tab was opened
|
|
48
47
|
io.emit('tab-opened', {
|
|
49
48
|
sessionId,
|
|
50
49
|
name: data.name || 'SFTP',
|
|
@@ -52,6 +51,8 @@ function registerSFTPHandlers(socket, io) {
|
|
|
52
51
|
connectionData: data
|
|
53
52
|
});
|
|
54
53
|
|
|
54
|
+
io.emit('sessions-updated');
|
|
55
|
+
|
|
55
56
|
socket.emit('sftp-connected', { sessionId });
|
|
56
57
|
} catch (err) {
|
|
57
58
|
console.error('[SFTP] Error in sftp-connect:', err.message);
|
|
@@ -135,6 +136,7 @@ function registerSFTPHandlers(socket, io) {
|
|
|
135
136
|
|
|
136
137
|
// Broadcast to all clients that tab was closed
|
|
137
138
|
io.emit('tab-closed', { sessionId: data.sessionId });
|
|
139
|
+
io.emit('sessions-updated');
|
|
138
140
|
});
|
|
139
141
|
}
|
|
140
142
|
|
|
@@ -51,7 +51,6 @@ function registerSSHHandlers(socket, io) {
|
|
|
51
51
|
sticky: sticky
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
// Broadcast to all clients that a new tab was opened
|
|
55
54
|
io.emit('tab-opened', {
|
|
56
55
|
sessionId,
|
|
57
56
|
name: data.name || 'SSH',
|
|
@@ -59,6 +58,8 @@ function registerSSHHandlers(socket, io) {
|
|
|
59
58
|
connectionData: data
|
|
60
59
|
});
|
|
61
60
|
|
|
61
|
+
io.emit('sessions-updated');
|
|
62
|
+
|
|
62
63
|
socket.emit('ssh-connected', { sessionId });
|
|
63
64
|
} catch (err) {
|
|
64
65
|
console.error('[SSH] Connection failed:', err.message);
|
|
@@ -160,8 +161,8 @@ function registerSSHHandlers(socket, io) {
|
|
|
160
161
|
// Remove from open tabs and order
|
|
161
162
|
removeTab(data.sessionId);
|
|
162
163
|
|
|
163
|
-
// Broadcast to all clients that tab was closed
|
|
164
164
|
io.emit('tab-closed', { sessionId: data.sessionId });
|
|
165
|
+
io.emit('sessions-updated');
|
|
165
166
|
});
|
|
166
167
|
}
|
|
167
168
|
|
|
@@ -55,10 +55,12 @@ function registerTabHandlers(socket, io) {
|
|
|
55
55
|
|
|
56
56
|
// Broadcast to all clients that tab was closed
|
|
57
57
|
io.emit('tab-closed', { sessionId: data.sessionId });
|
|
58
|
+
io.emit('sessions-updated');
|
|
58
59
|
}
|
|
59
60
|
} else {
|
|
60
61
|
// Broadcast to all clients that tab was closed
|
|
61
62
|
io.emit('tab-closed', { sessionId: data.sessionId });
|
|
63
|
+
io.emit('sessions-updated');
|
|
62
64
|
}
|
|
63
65
|
});
|
|
64
66
|
|
package/src/server/index.js
CHANGED
|
@@ -295,27 +295,78 @@ async function initializeServer() {
|
|
|
295
295
|
next();
|
|
296
296
|
});
|
|
297
297
|
|
|
298
|
-
// Serve static files from the webapp directory
|
|
299
298
|
const webappPath = path.join(__dirname, '../webapp');
|
|
300
|
-
app.use(express.static(webappPath));
|
|
301
|
-
app.use('/js', express.static(path.join(webappPath, 'js')));
|
|
302
|
-
app.use('/css', express.static(path.join(webappPath, 'css')));
|
|
303
|
-
app.use('/libs', express.static(path.join(webappPath, 'libs')));
|
|
304
|
-
app.use('/tests', express.static(path.join(webappPath, 'tests')));
|
|
305
299
|
|
|
306
300
|
// Service Worker script - must be served from root with proper headers
|
|
301
|
+
// MUST come before express.static so version placeholders are replaced
|
|
302
|
+
// and no-cache headers are set. Without this, express.static serves
|
|
303
|
+
// the raw file with __VERSION__ unreplaced and default cache headers,
|
|
304
|
+
// completely breaking cache busting on updates.
|
|
307
305
|
app.get('/sw.js', (req, res) => {
|
|
308
306
|
res.setHeader('Content-Type', 'application/javascript');
|
|
309
307
|
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
308
|
+
res.setHeader('Pragma', 'no-cache');
|
|
309
|
+
res.setHeader('Expires', '0');
|
|
310
310
|
res.setHeader('Service-Worker-Allowed', '/');
|
|
311
|
-
|
|
311
|
+
const swPath = path.join(webappPath, 'sw.js');
|
|
312
|
+
fs.readFile(swPath, 'utf8', (err, data) => {
|
|
313
|
+
if (err) return res.status(500).send('/* SW load error */');
|
|
314
|
+
const version = require(path.join(__dirname, '../../package.json')).version;
|
|
315
|
+
res.send(data.replace(/__VERSION__/g, version));
|
|
316
|
+
});
|
|
312
317
|
});
|
|
313
318
|
|
|
314
|
-
// Main route
|
|
319
|
+
// Main route - no-cache so browser always checks for updates
|
|
320
|
+
// MUST come before express.static so version placeholders are replaced
|
|
321
|
+
// and no-cache headers are set. Without this, express.static serves
|
|
322
|
+
// the raw index.html with __VERSION__ unreplaced.
|
|
315
323
|
app.get('/', (req, res) => {
|
|
316
|
-
res.
|
|
324
|
+
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
325
|
+
res.setHeader('Pragma', 'no-cache');
|
|
326
|
+
res.setHeader('Expires', '0');
|
|
327
|
+
const htmlPath = path.join(webappPath, 'index.html');
|
|
328
|
+
fs.readFile(htmlPath, 'utf8', (err, data) => {
|
|
329
|
+
if (err) return res.status(500).send('Error loading page');
|
|
330
|
+
const version = require(path.join(__dirname, '../../package.json')).version;
|
|
331
|
+
res.send(data.replace(/__VERSION__/g, version));
|
|
332
|
+
});
|
|
317
333
|
});
|
|
318
334
|
|
|
335
|
+
// Serve static files from the webapp directory
|
|
336
|
+
// These come AFTER the custom / and /sw.js handlers so those routes
|
|
337
|
+
// can set proper cache headers and replace version placeholders.
|
|
338
|
+
app.use(express.static(webappPath, {
|
|
339
|
+
maxAge: '1d',
|
|
340
|
+
setHeaders: (res, filePath) => {
|
|
341
|
+
if (filePath.endsWith('.html')) {
|
|
342
|
+
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
343
|
+
res.setHeader('Pragma', 'no-cache');
|
|
344
|
+
res.setHeader('Expires', '0');
|
|
345
|
+
} else if (filePath.endsWith('.js') || filePath.endsWith('.css')) {
|
|
346
|
+
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}));
|
|
350
|
+
app.use('/js', express.static(path.join(webappPath, 'js'), {
|
|
351
|
+
maxAge: '1d',
|
|
352
|
+
setHeaders: (res) => {
|
|
353
|
+
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
|
354
|
+
}
|
|
355
|
+
}));
|
|
356
|
+
app.use('/css', express.static(path.join(webappPath, 'css'), {
|
|
357
|
+
maxAge: '1d',
|
|
358
|
+
setHeaders: (res) => {
|
|
359
|
+
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
|
360
|
+
}
|
|
361
|
+
}));
|
|
362
|
+
app.use('/libs', express.static(path.join(webappPath, 'libs'), {
|
|
363
|
+
maxAge: '1d',
|
|
364
|
+
setHeaders: (res) => {
|
|
365
|
+
res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
|
366
|
+
}
|
|
367
|
+
}));
|
|
368
|
+
app.use('/tests', express.static(path.join(webappPath, 'tests')));
|
|
369
|
+
|
|
319
370
|
// Register REST endpoints
|
|
320
371
|
rest.registerAllRestEndpoints(app, io);
|
|
321
372
|
|
|
@@ -166,10 +166,10 @@ class SSHManager {
|
|
|
166
166
|
|
|
167
167
|
stream.on('close', () => {
|
|
168
168
|
console.log(`[SSH] Stream closed: ${sessionId}`);
|
|
169
|
-
// Flush any remaining buffered data before disconnect
|
|
170
169
|
this.flushData(sessionId);
|
|
171
170
|
this.broadcastToSession(sessionId, 'ssh-disconnected', { sessionId });
|
|
172
171
|
this.disconnect(sessionId);
|
|
172
|
+
if (this.io) this.io.emit('sessions-updated');
|
|
173
173
|
});
|
|
174
174
|
|
|
175
175
|
stream.on('exit', (code, signal) => {
|
|
@@ -190,6 +190,7 @@ class SSHManager {
|
|
|
190
190
|
console.error(`[SSH] Connection error: ${err.message}`);
|
|
191
191
|
socket.emit('ssh-error', { sessionId, message: err.message });
|
|
192
192
|
this.sessions.delete(sessionId);
|
|
193
|
+
if (this.io) this.io.emit('sessions-updated');
|
|
193
194
|
reject(err);
|
|
194
195
|
});
|
|
195
196
|
|
|
@@ -197,6 +198,7 @@ class SSHManager {
|
|
|
197
198
|
console.log(`[SSH] Connection closed: ${sessionId}`);
|
|
198
199
|
this.broadcastToSession(sessionId, 'ssh-disconnected', { sessionId });
|
|
199
200
|
this.sessions.delete(sessionId);
|
|
201
|
+
if (this.io) this.io.emit('sessions-updated');
|
|
200
202
|
});
|
|
201
203
|
|
|
202
204
|
try {
|
|
@@ -357,11 +359,15 @@ class SSHManager {
|
|
|
357
359
|
socket.emit('ssh-joined', {
|
|
358
360
|
sessionId: sessionId,
|
|
359
361
|
noTerminalState: !hasTerminalState,
|
|
360
|
-
controllerSocket: session.controllerSocket,
|
|
361
|
-
isController: session.controllerSocket === socket.id,
|
|
362
|
-
socketCount: session.sockets.size
|
|
362
|
+
controllerSocket: session.controllerSocket,
|
|
363
|
+
isController: session.controllerSocket === socket.id,
|
|
364
|
+
socketCount: session.sockets.size
|
|
363
365
|
});
|
|
364
366
|
|
|
367
|
+
if (this.io) {
|
|
368
|
+
this.io.emit('sessions-updated');
|
|
369
|
+
}
|
|
370
|
+
|
|
365
371
|
return true;
|
|
366
372
|
}
|
|
367
373
|
|
|
@@ -398,6 +404,10 @@ class SSHManager {
|
|
|
398
404
|
session.controllerSocket = null;
|
|
399
405
|
}
|
|
400
406
|
}
|
|
407
|
+
|
|
408
|
+
if (this.io) {
|
|
409
|
+
this.io.emit('sessions-updated');
|
|
410
|
+
}
|
|
401
411
|
}
|
|
402
412
|
|
|
403
413
|
// Take control of a session
|
|
@@ -430,6 +440,10 @@ class SSHManager {
|
|
|
430
440
|
});
|
|
431
441
|
}
|
|
432
442
|
|
|
443
|
+
if (this.io) {
|
|
444
|
+
this.io.emit('sessions-updated');
|
|
445
|
+
}
|
|
446
|
+
|
|
433
447
|
return {
|
|
434
448
|
success: true,
|
|
435
449
|
cols: session.cols,
|
|
@@ -465,6 +479,10 @@ class SSHManager {
|
|
|
465
479
|
session.controllerSocket = null;
|
|
466
480
|
}
|
|
467
481
|
|
|
482
|
+
if (this.io) {
|
|
483
|
+
this.io.emit('sessions-updated');
|
|
484
|
+
}
|
|
485
|
+
|
|
468
486
|
return { success: true };
|
|
469
487
|
}
|
|
470
488
|
|
package/src/webapp/index.html
CHANGED
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
10
10
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
11
11
|
<meta name="apple-mobile-web-app-title" content="SSHIFT">
|
|
12
|
-
<link rel="manifest" href="/manifest.json">
|
|
12
|
+
<link rel="manifest" href="/manifest.json?v=__VERSION__">
|
|
13
13
|
<link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png">
|
|
14
14
|
<link rel="icon" type="image/png" sizes="16x16" href="/icons/favicon-16x16.png">
|
|
15
15
|
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png">
|
|
16
16
|
<title>SSHIFT - SSH & SFTP Terminal Client</title>
|
|
17
17
|
<!-- Local resources for offline support -->
|
|
18
|
-
<link rel="stylesheet" href="/libs/xterm/xterm.css">
|
|
19
|
-
<link rel="stylesheet" href="/libs/font-awesome/css/all.min.css">
|
|
20
|
-
<link rel="stylesheet" href="/css/style.css">
|
|
21
|
-
<script src="/libs/lucide/lucide.min.js"></script>
|
|
18
|
+
<link rel="stylesheet" href="/libs/xterm/xterm.css?v=__VERSION__">
|
|
19
|
+
<link rel="stylesheet" href="/libs/font-awesome/css/all.min.css?v=__VERSION__">
|
|
20
|
+
<link rel="stylesheet" href="/css/style.css?v=__VERSION__">
|
|
21
|
+
<script src="/libs/lucide/lucide.min.js?v=__VERSION__"></script>
|
|
22
22
|
</head>
|
|
23
23
|
<body>
|
|
24
24
|
<!-- Lock Screen Overlay (shown by default, hidden by JS if no password) -->
|
|
@@ -1138,16 +1138,16 @@
|
|
|
1138
1138
|
|
|
1139
1139
|
<!-- Scripts -->
|
|
1140
1140
|
<!-- xterm.js and addons - Local files for offline support -->
|
|
1141
|
-
<script src="/libs/xterm/xterm.js"></script>
|
|
1142
|
-
<script src="/libs/xterm/xterm-addon-fit.js"></script>
|
|
1143
|
-
<script src="/libs/xterm/xterm-addon-web-links.js"></script>
|
|
1144
|
-
<script src="/libs/xterm/xterm-addon-search.js"></script>
|
|
1145
|
-
<script src="/libs/xterm/xterm-addon-serialize.js"></script>
|
|
1146
|
-
<script src="/libs/xterm/xterm-addon-webgl.js"></script>
|
|
1147
|
-
<script src="/libs/xterm/xterm-addon-image.js"></script>
|
|
1141
|
+
<script src="/libs/xterm/xterm.js?v=__VERSION__"></script>
|
|
1142
|
+
<script src="/libs/xterm/xterm-addon-fit.js?v=__VERSION__"></script>
|
|
1143
|
+
<script src="/libs/xterm/xterm-addon-web-links.js?v=__VERSION__"></script>
|
|
1144
|
+
<script src="/libs/xterm/xterm-addon-search.js?v=__VERSION__"></script>
|
|
1145
|
+
<script src="/libs/xterm/xterm-addon-serialize.js?v=__VERSION__"></script>
|
|
1146
|
+
<script src="/libs/xterm/xterm-addon-webgl.js?v=__VERSION__"></script>
|
|
1147
|
+
<script src="/libs/xterm/xterm-addon-image.js?v=__VERSION__"></script>
|
|
1148
1148
|
|
|
1149
1149
|
<!-- Mobile terminal support -->
|
|
1150
|
-
<script src="/js/mobile-terminal.js"></script>
|
|
1150
|
+
<script src="/js/mobile-terminal.js?v=__VERSION__"></script>
|
|
1151
1151
|
|
|
1152
1152
|
<!-- Normalize addon exports - UMD pattern exports { FitAddon: class } not the class directly -->
|
|
1153
1153
|
<script>
|
|
@@ -1285,52 +1285,53 @@
|
|
|
1285
1285
|
</script>
|
|
1286
1286
|
|
|
1287
1287
|
<script src="/socket.io/socket.io.js"></script>
|
|
1288
|
-
<script src="/js/app.js"></script>
|
|
1288
|
+
<script src="/js/app.js?v=__VERSION__"></script>
|
|
1289
1289
|
<script>
|
|
1290
1290
|
if ('serviceWorker' in navigator) {
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
if (
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
if (!navigator.serviceWorker.controller) {
|
|
1314
|
-
window._swStatus = 'redundant';
|
|
1315
|
-
window._swError = 'Service Worker became redundant. This usually means the certificate is not trusted.';
|
|
1316
|
-
}
|
|
1291
|
+
window.addEventListener('load', () => {
|
|
1292
|
+
navigator.serviceWorker.register('/sw.js').then((reg) => {
|
|
1293
|
+
console.log('[SSHIFT] Service Worker registered, scope:', reg.scope);
|
|
1294
|
+
window._swRegistration = reg;
|
|
1295
|
+
if (reg.active) {
|
|
1296
|
+
window._swStatus = 'active';
|
|
1297
|
+
} else if (reg.installing) {
|
|
1298
|
+
window._swStatus = 'installing';
|
|
1299
|
+
} else if (reg.waiting) {
|
|
1300
|
+
window._swStatus = 'waiting';
|
|
1301
|
+
} else {
|
|
1302
|
+
window._swStatus = 'registered';
|
|
1303
|
+
}
|
|
1304
|
+
window._swError = null;
|
|
1305
|
+
reg.addEventListener('updatefound', () => {
|
|
1306
|
+
const newWorker = reg.installing;
|
|
1307
|
+
newWorker.addEventListener('statechange', () => {
|
|
1308
|
+
if (newWorker.state === 'activated') {
|
|
1309
|
+
window._swStatus = 'active';
|
|
1310
|
+
if (navigator.serviceWorker.controller) {
|
|
1311
|
+
console.log('[SSHIFT] New service worker activated, reloading for updates');
|
|
1312
|
+
window.location.reload();
|
|
1317
1313
|
}
|
|
1318
|
-
})
|
|
1314
|
+
} else if (newWorker.state === 'redundant') {
|
|
1315
|
+
if (!navigator.serviceWorker.controller) {
|
|
1316
|
+
window._swStatus = 'redundant';
|
|
1317
|
+
window._swError = 'Service Worker became redundant. This usually means the certificate is not trusted.';
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1319
1320
|
});
|
|
1320
|
-
// Also check if the page is controlled by a SW
|
|
1321
|
-
if (navigator.serviceWorker.controller) {
|
|
1322
|
-
window._swStatus = 'active';
|
|
1323
|
-
}
|
|
1324
|
-
}).catch((err) => {
|
|
1325
|
-
console.warn('[SSHIFT] Service Worker registration failed:', err.message);
|
|
1326
|
-
window._swStatus = 'failed';
|
|
1327
|
-
window._swError = err.message;
|
|
1328
1321
|
});
|
|
1322
|
+
if (navigator.serviceWorker.controller) {
|
|
1323
|
+
window._swStatus = 'active';
|
|
1324
|
+
}
|
|
1325
|
+
}).catch((err) => {
|
|
1326
|
+
console.warn('[SSHIFT] Service Worker registration failed:', err.message);
|
|
1327
|
+
window._swStatus = 'failed';
|
|
1328
|
+
window._swError = err.message;
|
|
1329
1329
|
});
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1330
|
+
});
|
|
1331
|
+
} else {
|
|
1332
|
+
window._swStatus = 'unsupported';
|
|
1333
|
+
window._swError = 'Service Workers not supported in this browser';
|
|
1334
|
+
}
|
|
1334
1335
|
</script>
|
|
1335
1336
|
</body>
|
|
1336
1337
|
</html>
|
package/src/webapp/js/app.js
CHANGED
|
@@ -3435,6 +3435,14 @@ const wheelHandler = (e) => {
|
|
|
3435
3435
|
this.handleTabClosed(data.sessionId);
|
|
3436
3436
|
});
|
|
3437
3437
|
|
|
3438
|
+
this.socket.on('sessions-updated', () => {
|
|
3439
|
+
const modal = document.getElementById('manageSessionsModal');
|
|
3440
|
+
if (modal && modal.classList.contains('active')) {
|
|
3441
|
+
if (this._sessionsUpdateTimer) clearTimeout(this._sessionsUpdateTimer);
|
|
3442
|
+
this._sessionsUpdateTimer = setTimeout(() => this.loadSessions(), 300);
|
|
3443
|
+
}
|
|
3444
|
+
});
|
|
3445
|
+
|
|
3438
3446
|
// Handle tab order update from server
|
|
3439
3447
|
this.socket.on('tab-order', (data) => {
|
|
3440
3448
|
console.log('[SSHIFT] Tab order updated:', data.order);
|
|
@@ -5107,7 +5115,6 @@ const wheelHandler = (e) => {
|
|
|
5107
5115
|
}
|
|
5108
5116
|
|
|
5109
5117
|
initSessionsModalHandlers() {
|
|
5110
|
-
// Close button
|
|
5111
5118
|
const closeBtn = document.getElementById('closeManageSessionsModal');
|
|
5112
5119
|
if (closeBtn) {
|
|
5113
5120
|
closeBtn.addEventListener('click', () => {
|
|
@@ -5115,7 +5122,13 @@ const wheelHandler = (e) => {
|
|
|
5115
5122
|
});
|
|
5116
5123
|
}
|
|
5117
5124
|
|
|
5118
|
-
|
|
5125
|
+
const closeFooterBtn = document.getElementById('closeManageSessions');
|
|
5126
|
+
if (closeFooterBtn) {
|
|
5127
|
+
closeFooterBtn.addEventListener('click', () => {
|
|
5128
|
+
this.closeModal('manageSessionsModal');
|
|
5129
|
+
});
|
|
5130
|
+
}
|
|
5131
|
+
|
|
5119
5132
|
const closeAllBtn = document.getElementById('closeAllSessions');
|
|
5120
5133
|
if (closeAllBtn) {
|
|
5121
5134
|
closeAllBtn.addEventListener('click', () => {
|
|
@@ -10427,7 +10440,8 @@ async syncTabsFromServer(tabs) {
|
|
|
10427
10440
|
|
|
10428
10441
|
// Check for update error from server
|
|
10429
10442
|
if (data.updateError) {
|
|
10430
|
-
|
|
10443
|
+
const logMsg = data.updateLog ? '\n\n' + data.updateLog : '';
|
|
10444
|
+
this.handleUpdateError(data.updateError + logMsg);
|
|
10431
10445
|
return;
|
|
10432
10446
|
}
|
|
10433
10447
|
|
|
@@ -10463,9 +10477,8 @@ async syncTabsFromServer(tabs) {
|
|
|
10463
10477
|
statusEl.textContent = `New version: ${data.version}`;
|
|
10464
10478
|
}
|
|
10465
10479
|
|
|
10466
|
-
// Reload page after a short delay
|
|
10467
10480
|
setTimeout(() => {
|
|
10468
|
-
|
|
10481
|
+
this.forceReloadAfterUpdate();
|
|
10469
10482
|
}, 1000);
|
|
10470
10483
|
} else if (data.ready && data.version === oldVersion) {
|
|
10471
10484
|
// Server is back and ready. Same version could mean:
|
|
@@ -10485,7 +10498,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10485
10498
|
}
|
|
10486
10499
|
|
|
10487
10500
|
setTimeout(() => {
|
|
10488
|
-
|
|
10501
|
+
this.forceReloadAfterUpdate();
|
|
10489
10502
|
}, 1000);
|
|
10490
10503
|
} else {
|
|
10491
10504
|
// Unexpected state
|
|
@@ -10536,6 +10549,19 @@ async syncTabsFromServer(tabs) {
|
|
|
10536
10549
|
updateBtn.innerHTML = '<i class="fas fa-download"></i> Update';
|
|
10537
10550
|
}
|
|
10538
10551
|
}
|
|
10552
|
+
|
|
10553
|
+
forceReloadAfterUpdate() {
|
|
10554
|
+
const cleanup = [];
|
|
10555
|
+
if ('caches' in window) {
|
|
10556
|
+
cleanup.push(caches.keys().then((names) => Promise.all(names.map((name) => caches.delete(name)))));
|
|
10557
|
+
}
|
|
10558
|
+
if ('serviceWorker' in navigator) {
|
|
10559
|
+
cleanup.push(navigator.serviceWorker.getRegistrations().then((regs) => Promise.all(regs.map((r) => r.unregister()))));
|
|
10560
|
+
}
|
|
10561
|
+
Promise.all(cleanup).catch(() => {}).finally(() => {
|
|
10562
|
+
window.location.href = window.location.origin + window.location.pathname + '?v=' + Date.now();
|
|
10563
|
+
});
|
|
10564
|
+
}
|
|
10539
10565
|
}
|
|
10540
10566
|
|
|
10541
10567
|
// Initialize application
|
package/src/webapp/sw.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
const CACHE_NAME = 'sshift-
|
|
1
|
+
const CACHE_NAME = 'sshift-__VERSION__';
|
|
2
|
+
const VERSION = '__VERSION__';
|
|
2
3
|
|
|
3
4
|
const PRECACHE_URLS = [
|
|
4
|
-
'/
|
|
5
|
-
'/
|
|
6
|
-
'/libs/
|
|
7
|
-
'/libs/
|
|
8
|
-
'/
|
|
9
|
-
'/manifest.json'
|
|
5
|
+
'/css/style.css?v=' + VERSION,
|
|
6
|
+
'/libs/xterm/xterm.css?v=' + VERSION,
|
|
7
|
+
'/libs/font-awesome/css/all.min.css?v=' + VERSION,
|
|
8
|
+
'/libs/lucide/lucide.min.js?v=' + VERSION,
|
|
9
|
+
'/manifest.json?v=' + VERSION
|
|
10
10
|
];
|
|
11
11
|
|
|
12
|
+
const NAV_CACHE = CACHE_NAME + '-nav';
|
|
13
|
+
|
|
12
14
|
self.addEventListener('install', (event) => {
|
|
13
15
|
event.waitUntil(
|
|
14
16
|
caches.open(CACHE_NAME).then((cache) => {
|
|
@@ -29,7 +31,7 @@ self.addEventListener('activate', (event) => {
|
|
|
29
31
|
caches.keys().then((cacheNames) =>
|
|
30
32
|
Promise.all(
|
|
31
33
|
cacheNames
|
|
32
|
-
.filter((name) => name !== CACHE_NAME)
|
|
34
|
+
.filter((name) => name !== CACHE_NAME && name !== NAV_CACHE)
|
|
33
35
|
.map((name) => caches.delete(name))
|
|
34
36
|
)
|
|
35
37
|
)
|
|
@@ -42,21 +44,51 @@ self.addEventListener('fetch', (event) => {
|
|
|
42
44
|
|
|
43
45
|
const url = new URL(event.request.url);
|
|
44
46
|
|
|
45
|
-
if (url.protocol
|
|
46
|
-
|
|
47
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') return;
|
|
48
|
+
|
|
49
|
+
if (url.pathname.startsWith('/socket.io/')) return;
|
|
50
|
+
if (url.pathname.startsWith('/api/')) return;
|
|
51
|
+
if (url.pathname === '/sw.js') return;
|
|
52
|
+
|
|
53
|
+
const isNavigation = event.request.mode === 'navigate';
|
|
54
|
+
|
|
55
|
+
if (isNavigation) {
|
|
56
|
+
event.respondWith(
|
|
57
|
+
fetch(event.request)
|
|
58
|
+
.then((response) => {
|
|
59
|
+
if (response && response.status === 200) {
|
|
60
|
+
const clone = response.clone();
|
|
61
|
+
caches.open(NAV_CACHE).then((cache) => cache.put(event.request, clone));
|
|
62
|
+
}
|
|
63
|
+
return response;
|
|
64
|
+
})
|
|
65
|
+
.catch(() => caches.match(event.request))
|
|
66
|
+
);
|
|
67
|
+
return;
|
|
47
68
|
}
|
|
48
69
|
|
|
49
70
|
event.respondWith(
|
|
50
71
|
caches.match(event.request).then((cached) => {
|
|
51
|
-
|
|
72
|
+
if (cached) {
|
|
73
|
+
return cached;
|
|
74
|
+
}
|
|
75
|
+
return fetch(event.request).then((response) => {
|
|
52
76
|
if (response && response.status === 200 && response.type === 'basic') {
|
|
53
77
|
const clone = response.clone();
|
|
54
78
|
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
|
55
79
|
}
|
|
56
80
|
return response;
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
return cached || fetched;
|
|
81
|
+
});
|
|
60
82
|
})
|
|
61
83
|
);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
self.addEventListener('message', (event) => {
|
|
87
|
+
if (event.data && event.data.type === 'CLEAR_CACHES') {
|
|
88
|
+
caches.keys().then((names) => {
|
|
89
|
+
for (const name of names) {
|
|
90
|
+
caches.delete(name);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
62
94
|
});
|
package/sshift
CHANGED
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
|
|
33
33
|
const path = require('path');
|
|
34
34
|
const fs = require('fs');
|
|
35
|
-
const
|
|
35
|
+
const os = require('os');
|
|
36
36
|
|
|
37
37
|
// Get the directory where this script is located
|
|
38
38
|
const scriptDir = __dirname;
|
|
39
39
|
const serverPath = path.join(scriptDir, 'src', 'server', 'index.js');
|
|
40
|
-
const pidFile = path.join(
|
|
40
|
+
const pidFile = path.join(os.homedir(), '.local', 'share', 'sshift', '.sshift.pid');
|
|
41
41
|
|
|
42
42
|
// CLI argument parsing
|
|
43
43
|
const args = process.argv.slice(2);
|
|
@@ -131,6 +131,34 @@ if (!fs.existsSync(serverPath)) {
|
|
|
131
131
|
process.exit(1);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
// Helper: Ensure PID file directory exists
|
|
135
|
+
function ensurePidDir() {
|
|
136
|
+
const dir = path.dirname(pidFile);
|
|
137
|
+
if (!fs.existsSync(dir)) {
|
|
138
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Helper: Write current PID to file
|
|
143
|
+
function writePidFile() {
|
|
144
|
+
ensurePidDir();
|
|
145
|
+
fs.writeFileSync(pidFile, process.pid.toString(), { mode: 0o644 });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Helper: Remove PID file
|
|
149
|
+
function cleanupPidFile() {
|
|
150
|
+
try {
|
|
151
|
+
if (fs.existsSync(pidFile)) {
|
|
152
|
+
const storedPid = parseInt(fs.readFileSync(pidFile, 'utf8').trim(), 10);
|
|
153
|
+
if (isNaN(storedPid) || storedPid === process.pid) {
|
|
154
|
+
fs.unlinkSync(pidFile);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
} catch (e) {
|
|
158
|
+
// Ignore cleanup errors
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
134
162
|
// Helper: Check if sshift is running
|
|
135
163
|
function isRunning() {
|
|
136
164
|
if (fs.existsSync(pidFile)) {
|
|
@@ -265,5 +293,19 @@ if (options.dev) {
|
|
|
265
293
|
process.env.NODE_ENV = 'development';
|
|
266
294
|
}
|
|
267
295
|
|
|
296
|
+
// Write PID file before starting
|
|
297
|
+
writePidFile();
|
|
298
|
+
|
|
299
|
+
// Clean up PID file on exit
|
|
300
|
+
process.on('exit', cleanupPidFile);
|
|
301
|
+
process.on('SIGTERM', () => {
|
|
302
|
+
cleanupPidFile();
|
|
303
|
+
process.exit(0);
|
|
304
|
+
});
|
|
305
|
+
process.on('SIGINT', () => {
|
|
306
|
+
cleanupPidFile();
|
|
307
|
+
process.exit(0);
|
|
308
|
+
});
|
|
309
|
+
|
|
268
310
|
// Start the server
|
|
269
311
|
require(serverPath);
|
package/sshift-install.ps1
CHANGED
package/sshift-install.sh
CHANGED