@lethevimlet/sshift 1.8.3 → 1.9.1

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.
@@ -12,6 +12,8 @@
12
12
  "webglRenderer": true,
13
13
  "imageAddonEnabled": true,
14
14
  "passwordHash": null,
15
+ "bookmarkEncryptionEnabled": false,
16
+ "bookmarkEncryptionSalt": null,
15
17
  "plugins": [
16
18
  {
17
19
  "name": "opencode-attention",
@@ -184,4 +186,4 @@
184
186
  ]
185
187
  }
186
188
  ]
187
- }
189
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.8.3",
3
+ "version": "1.9.1",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -1,7 +1,23 @@
1
- const { isPasswordSet, verifyPassword, setPassword, removePassword } = require('../../utils/config');
1
+ const {
2
+ hashPassword,
3
+ isPasswordSet,
4
+ loadConfig,
5
+ saveConfig,
6
+ verifyPasswordAsync
7
+ } = require('../../utils/config');
8
+ const {
9
+ clearBookmarkEncryptionKey,
10
+ decryptBookmarksWithPassword,
11
+ prepareEncryptedBookmarks,
12
+ setBookmarkEncryptionKey,
13
+ unlockBookmarkEncryption
14
+ } = require('../../utils/bookmark-encryption');
2
15
 
3
16
  const authTokens = new Map();
17
+ const loginAttempts = new Map();
4
18
  const TOKEN_TTL = 24 * 60 * 60 * 1000;
19
+ const LOGIN_WINDOW_MS = 60 * 1000;
20
+ const MAX_LOGIN_ATTEMPTS = 5;
5
21
 
6
22
  function generateToken() {
7
23
  const crypto = require('crypto');
@@ -15,12 +31,59 @@ function cleanExpiredTokens() {
15
31
  }
16
32
  }
17
33
 
34
+ function getLoginAttemptKey(req) {
35
+ return req.ip || req.socket?.remoteAddress || 'unknown';
36
+ }
37
+
38
+ function isLoginRateLimited(req) {
39
+ const key = getLoginAttemptKey(req);
40
+ const now = Date.now();
41
+ const attempts = (loginAttempts.get(key) || []).filter(time => now - time < LOGIN_WINDOW_MS);
42
+ if (attempts.length === 0) loginAttempts.delete(key);
43
+ else loginAttempts.set(key, attempts);
44
+ return attempts.length >= MAX_LOGIN_ATTEMPTS;
45
+ }
46
+
47
+ function reserveLoginAttempt(req) {
48
+ const key = getLoginAttemptKey(req);
49
+ const attempts = loginAttempts.get(key) || [];
50
+ attempts.push(Date.now());
51
+ loginAttempts.set(key, attempts);
52
+ }
53
+
54
+ function clearFailedLogins(req) {
55
+ loginAttempts.delete(getLoginAttemptKey(req));
56
+ }
57
+
58
+ function notifyEncryptionState(io, enabled) {
59
+ if (io && typeof io.emit === 'function') {
60
+ io.emit('bookmark-encryption-changed', { enabled });
61
+ }
62
+ }
63
+
64
+ function notifyAuthState(io, passwordEnabled) {
65
+ if (io && typeof io.emit === 'function') {
66
+ io.emit('auth-state-changed', { passwordEnabled });
67
+ }
68
+ }
69
+
70
+ function revokeAuthenticatedClients(io) {
71
+ authTokens.clear();
72
+ if (io && typeof io.disconnectSockets === 'function') {
73
+ setTimeout(() => io.disconnectSockets(true), 50);
74
+ }
75
+ }
76
+
18
77
  function registerAuthEndpoints(app, io) {
19
78
  app.get('/api/auth/status', (req, res) => {
20
- res.json({ passwordEnabled: isPasswordSet() });
79
+ const config = loadConfig();
80
+ res.json({
81
+ passwordEnabled: !!config.passwordHash,
82
+ bookmarkEncryptionEnabled: config.bookmarkEncryptionEnabled === true
83
+ });
21
84
  });
22
85
 
23
- app.post('/api/auth/login', (req, res) => {
86
+ app.post('/api/auth/login', async (req, res) => {
24
87
  const { password } = req.body;
25
88
  if (!isPasswordSet()) {
26
89
  return res.json({ success: true, authenticated: true });
@@ -28,48 +91,154 @@ function registerAuthEndpoints(app, io) {
28
91
  if (!password) {
29
92
  return res.status(400).json({ error: 'Password required' });
30
93
  }
31
- if (!verifyPassword(password)) {
94
+ if (isLoginRateLimited(req)) {
95
+ return res.status(429).json({ error: 'Too many login attempts; try again shortly' });
96
+ }
97
+ // Reserve a slot before starting scrypt so concurrent bursts cannot all
98
+ // pass the limit while earlier password checks are still in flight.
99
+ reserveLoginAttempt(req);
100
+ if (!await verifyPasswordAsync(password)) {
32
101
  return res.status(401).json({ error: 'Invalid password' });
33
102
  }
103
+ clearFailedLogins(req);
104
+ try {
105
+ unlockBookmarkEncryption(loadConfig(), password);
106
+ } catch (err) {
107
+ console.error('[AUTH] Failed to unlock encrypted bookmarks:', err.message);
108
+ return res.status(500).json({ error: 'Encrypted bookmarks could not be unlocked' });
109
+ }
34
110
  const token = generateToken();
35
111
  authTokens.set(token, Date.now() + TOKEN_TTL);
36
112
  cleanExpiredTokens();
37
113
  res.json({ success: true, token });
38
114
  });
39
115
 
40
- app.post('/api/auth/set-password', (req, res) => {
116
+ app.post('/api/auth/set-password', async (req, res) => {
41
117
  const { currentPassword, newPassword } = req.body;
42
118
  if (isPasswordSet()) {
43
- if (!currentPassword || !verifyPassword(currentPassword)) {
119
+ if (!currentPassword || !await verifyPasswordAsync(currentPassword)) {
44
120
  return res.status(401).json({ error: 'Current password is incorrect' });
45
121
  }
46
122
  }
47
123
  if (!newPassword || newPassword.length < 1) {
48
124
  return res.status(400).json({ error: 'Password cannot be empty' });
49
125
  }
50
- const result = setPassword(newPassword);
51
- if (result) {
126
+ const config = loadConfig();
127
+ const encryptionRequested = req.body.encryptBookmarks === undefined
128
+ ? config.bookmarkEncryptionEnabled === true
129
+ : req.body.encryptBookmarks === true;
130
+
131
+ try {
132
+ let bookmarks = config.bookmarks || [];
133
+ if (config.bookmarkEncryptionEnabled) {
134
+ bookmarks = decryptBookmarksWithPassword(config, currentPassword).bookmarks;
135
+ }
136
+
137
+ let nextKey = null;
138
+ if (encryptionRequested) {
139
+ const encrypted = prepareEncryptedBookmarks(bookmarks, newPassword);
140
+ config.bookmarks = encrypted.bookmarks;
141
+ config.bookmarkEncryptionEnabled = true;
142
+ config.bookmarkEncryptionSalt = encrypted.salt;
143
+ nextKey = encrypted.key;
144
+ } else {
145
+ config.bookmarks = bookmarks;
146
+ config.bookmarkEncryptionEnabled = false;
147
+ config.bookmarkEncryptionSalt = null;
148
+ }
149
+ config.passwordHash = hashPassword(newPassword);
150
+
151
+ if (!saveConfig(config)) {
152
+ return res.status(500).json({ error: 'Failed to save password' });
153
+ }
154
+ setBookmarkEncryptionKey(nextKey);
155
+ notifyEncryptionState(io, encryptionRequested);
156
+ notifyAuthState(io, true);
157
+ revokeAuthenticatedClients(io);
52
158
  res.json({ success: true });
53
- } else {
54
- res.status(500).json({ error: 'Failed to save password' });
159
+ } catch (err) {
160
+ console.error('[AUTH] Failed to configure password protection:', err.message);
161
+ res.status(500).json({ error: 'Failed to configure bookmark encryption' });
55
162
  }
56
163
  });
57
164
 
58
- app.post('/api/auth/remove-password', (req, res) => {
165
+ app.post('/api/auth/remove-password', async (req, res) => {
59
166
  const { currentPassword } = req.body;
60
167
  if (!isPasswordSet()) {
61
168
  return res.json({ success: true });
62
169
  }
63
- if (!currentPassword || !verifyPassword(currentPassword)) {
170
+ if (!currentPassword || !await verifyPasswordAsync(currentPassword)) {
64
171
  return res.status(401).json({ error: 'Current password is incorrect' });
65
172
  }
66
- const result = removePassword();
67
- if (result) {
173
+ const config = loadConfig();
174
+ try {
175
+ if (config.bookmarkEncryptionEnabled) {
176
+ config.bookmarks = decryptBookmarksWithPassword(config, currentPassword).bookmarks;
177
+ config.bookmarkEncryptionEnabled = false;
178
+ config.bookmarkEncryptionSalt = null;
179
+ }
180
+ config.passwordHash = null;
181
+ if (!saveConfig(config)) {
182
+ return res.status(500).json({ error: 'Failed to remove password' });
183
+ }
184
+ clearBookmarkEncryptionKey();
185
+ notifyEncryptionState(io, false);
186
+ notifyAuthState(io, false);
187
+ revokeAuthenticatedClients(io);
68
188
  res.json({ success: true });
69
- } else {
70
- res.status(500).json({ error: 'Failed to remove password' });
189
+ } catch (err) {
190
+ console.error('[AUTH] Failed to disable password protection:', err.message);
191
+ res.status(500).json({ error: 'Failed to decrypt bookmarks before removing password' });
71
192
  }
72
193
  });
194
+
195
+ app.post('/api/auth/bookmark-encryption', async (req, res) => {
196
+ const { currentPassword, enabled } = req.body;
197
+ if (!isPasswordSet()) {
198
+ return res.status(400).json({ error: 'Password protection must be enabled first' });
199
+ }
200
+ if (!currentPassword || !await verifyPasswordAsync(currentPassword)) {
201
+ return res.status(401).json({ error: 'Current password is incorrect' });
202
+ }
203
+
204
+ const config = loadConfig();
205
+ try {
206
+ if (enabled) {
207
+ if (!config.bookmarkEncryptionEnabled) {
208
+ const encrypted = prepareEncryptedBookmarks(config.bookmarks || [], currentPassword);
209
+ config.bookmarks = encrypted.bookmarks;
210
+ config.bookmarkEncryptionEnabled = true;
211
+ config.bookmarkEncryptionSalt = encrypted.salt;
212
+ if (!saveConfig(config)) {
213
+ return res.status(500).json({ error: 'Failed to enable bookmark encryption' });
214
+ }
215
+ setBookmarkEncryptionKey(encrypted.key);
216
+ } else {
217
+ unlockBookmarkEncryption(config, currentPassword);
218
+ }
219
+ } else if (config.bookmarkEncryptionEnabled) {
220
+ const decrypted = decryptBookmarksWithPassword(config, currentPassword);
221
+ config.bookmarks = decrypted.bookmarks;
222
+ config.bookmarkEncryptionEnabled = false;
223
+ config.bookmarkEncryptionSalt = null;
224
+ if (!saveConfig(config)) {
225
+ return res.status(500).json({ error: 'Failed to disable bookmark encryption' });
226
+ }
227
+ clearBookmarkEncryptionKey();
228
+ }
229
+ notifyEncryptionState(io, enabled === true);
230
+ res.json({ success: true, bookmarkEncryptionEnabled: enabled === true });
231
+ } catch (err) {
232
+ console.error('[AUTH] Failed to update bookmark encryption:', err.message);
233
+ res.status(500).json({ error: 'Failed to update bookmark encryption' });
234
+ }
235
+ });
236
+
237
+ app.post('/api/auth/logout', (req, res) => {
238
+ const token = req.headers.authorization?.replace('Bearer ', '');
239
+ if (token) authTokens.delete(token);
240
+ res.json({ success: true });
241
+ });
73
242
  }
74
243
 
75
244
  function isValidAuthToken(token) {
@@ -84,4 +253,4 @@ function isValidAuthToken(token) {
84
253
  return true;
85
254
  }
86
255
 
87
- module.exports = { registerAuthEndpoints, isValidAuthToken };
256
+ module.exports = { registerAuthEndpoints, isValidAuthToken };
@@ -3,6 +3,19 @@
3
3
  */
4
4
 
5
5
  const { loadConfig, saveConfig } = require('../../utils/config');
6
+ const {
7
+ BookmarkEncryptionLockedError,
8
+ getDecryptedBookmarks,
9
+ storeBookmarks
10
+ } = require('../../utils/bookmark-encryption');
11
+
12
+ function handleBookmarkError(res, err) {
13
+ if (err instanceof BookmarkEncryptionLockedError) {
14
+ return res.status(423).json({ error: 'Encrypted bookmarks are locked; sign in again' });
15
+ }
16
+ console.error('[BOOKMARKS] Failed to process bookmarks:', err.message);
17
+ return res.status(500).json({ error: 'Failed to process bookmarks' });
18
+ }
6
19
 
7
20
  /**
8
21
  * Register bookmark endpoints
@@ -12,8 +25,12 @@ const { loadConfig, saveConfig } = require('../../utils/config');
12
25
  function registerBookmarkEndpoints(app, io) {
13
26
  // API: Get bookmarks
14
27
  app.get('/api/bookmarks', (req, res) => {
15
- const config = loadConfig();
16
- res.json(config.bookmarks);
28
+ try {
29
+ const config = loadConfig();
30
+ res.json(getDecryptedBookmarks(config));
31
+ } catch (err) {
32
+ handleBookmarkError(res, err);
33
+ }
17
34
  });
18
35
 
19
36
  // API: Add bookmark
@@ -40,48 +57,62 @@ function registerBookmarkEndpoints(app, io) {
40
57
  if (req.body.passphrase) bookmark.passphrase = req.body.passphrase;
41
58
  if (req.body.folderId) bookmark.folderId = req.body.folderId;
42
59
 
43
- config.bookmarks.push(bookmark);
44
- if (saveConfig(config)) {
60
+ try {
61
+ const bookmarks = getDecryptedBookmarks(config);
62
+ bookmarks.push(bookmark);
63
+ storeBookmarks(config, bookmarks);
64
+ if (!saveConfig(config)) {
65
+ return res.status(500).json({ error: 'Failed to save bookmark' });
66
+ }
45
67
  // Broadcast to all clients
46
68
  io.emit('bookmark-added', bookmark);
47
69
  res.json(bookmark);
48
- } else {
49
- res.status(500).json({ error: 'Failed to save bookmark' });
70
+ } catch (err) {
71
+ handleBookmarkError(res, err);
50
72
  }
51
73
  });
52
74
 
53
75
  // API: Delete bookmark
54
76
  app.delete('/api/bookmarks/:id', (req, res) => {
55
77
  const config = loadConfig();
56
- config.bookmarks = config.bookmarks.filter(b => b.id !== req.params.id);
57
- if (saveConfig(config)) {
78
+ try {
79
+ const bookmarks = getDecryptedBookmarks(config).filter(b => b.id !== req.params.id);
80
+ storeBookmarks(config, bookmarks);
81
+ if (!saveConfig(config)) {
82
+ return res.status(500).json({ error: 'Failed to delete bookmark' });
83
+ }
58
84
  // Broadcast to all clients
59
85
  io.emit('bookmark-deleted', { id: req.params.id });
60
86
  res.json({ success: true });
61
- } else {
62
- res.status(500).json({ error: 'Failed to delete bookmark' });
87
+ } catch (err) {
88
+ handleBookmarkError(res, err);
63
89
  }
64
90
  });
65
91
 
66
92
  // API: Update bookmark
67
93
  app.put('/api/bookmarks/:id', (req, res) => {
68
94
  const config = loadConfig();
69
- const index = config.bookmarks.findIndex(b => b.id === req.params.id);
70
- if (index !== -1) {
71
- config.bookmarks[index] = {
72
- ...config.bookmarks[index],
95
+ try {
96
+ const bookmarks = getDecryptedBookmarks(config);
97
+ const index = bookmarks.findIndex(b => b.id === req.params.id);
98
+ if (index === -1) {
99
+ return res.status(404).json({ error: 'Bookmark not found' });
100
+ }
101
+ bookmarks[index] = {
102
+ ...bookmarks[index],
73
103
  ...req.body,
74
104
  id: req.params.id
75
105
  };
76
- if (saveConfig(config)) {
77
- // Broadcast to all clients
78
- io.emit('bookmark-updated', config.bookmarks[index]);
79
- res.json(config.bookmarks[index]);
80
- } else {
81
- res.status(500).json({ error: 'Failed to update bookmark' });
106
+ delete bookmarks[index].encryptedConnection;
107
+ storeBookmarks(config, bookmarks);
108
+ if (!saveConfig(config)) {
109
+ return res.status(500).json({ error: 'Failed to update bookmark' });
82
110
  }
83
- } else {
84
- res.status(404).json({ error: 'Bookmark not found' });
111
+ // Broadcast decrypted data only to authenticated, connected clients.
112
+ io.emit('bookmark-updated', bookmarks[index]);
113
+ res.json(bookmarks[index]);
114
+ } catch (err) {
115
+ handleBookmarkError(res, err);
85
116
  }
86
117
  });
87
118
 
@@ -103,4 +134,4 @@ function registerBookmarkEndpoints(app, io) {
103
134
  });
104
135
  }
105
136
 
106
- module.exports = { registerBookmarkEndpoints };
137
+ module.exports = { registerBookmarkEndpoints };
@@ -22,7 +22,8 @@ function registerConfigEndpoints(app, io) {
22
22
  webglRenderer: config.webglRenderer !== false,
23
23
  imageAddonEnabled: config.imageAddonEnabled !== false,
24
24
  layouts: config.layouts || null,
25
- passwordEnabled: !!config.passwordHash
25
+ passwordEnabled: !!config.passwordHash,
26
+ bookmarkEncryptionEnabled: config.bookmarkEncryptionEnabled === true
26
27
  });
27
28
  });
28
29
 
@@ -89,4 +90,4 @@ function registerConfigEndpoints(app, io) {
89
90
  });
90
91
  }
91
92
 
92
- module.exports = { registerConfigEndpoints };
93
+ module.exports = { registerConfigEndpoints };
@@ -3,11 +3,92 @@
3
3
  */
4
4
 
5
5
  const fs = require('fs');
6
+ const https = require('https');
6
7
  const path = require('path');
7
8
  const { getDataDir, getCertPath, getKeyPath, getConfigPath } = require('../../utils/config');
8
9
 
9
10
  const { SSL_CERT_FILE, SSL_KEY_FILE, SSL_CA_CERT_FILE } = require('../../utils/certs');
10
11
  const UPDATE_MARKER_FILE = '.updating';
12
+ const VERSION_PATTERN = /^\d+\.\d+\.\d+$/;
13
+
14
+ function fetchJson(options, request = https.request) {
15
+ return new Promise((resolve, reject) => {
16
+ const req = request(options, (response) => {
17
+ let body = '';
18
+
19
+ response.on('data', (chunk) => {
20
+ body += chunk;
21
+ if (body.length > 1024 * 1024) {
22
+ req.destroy(new Error('Update metadata response is too large'));
23
+ }
24
+ });
25
+ response.on('end', () => {
26
+ if (response.statusCode !== 200) {
27
+ reject(new Error(`${options.hostname} returned ${response.statusCode}`));
28
+ return;
29
+ }
30
+
31
+ try {
32
+ resolve(JSON.parse(body));
33
+ } catch (error) {
34
+ reject(new Error(`Invalid JSON from ${options.hostname}: ${error.message}`));
35
+ }
36
+ });
37
+ });
38
+
39
+ req.on('error', reject);
40
+ req.setTimeout(10000, () => req.destroy(new Error(`${options.hostname} request timed out`)));
41
+ req.end();
42
+ });
43
+ }
44
+
45
+ async function getLatestPublishedVersion(request = https.request) {
46
+ try {
47
+ const npmPackage = await fetchJson({
48
+ hostname: 'registry.npmjs.org',
49
+ path: '/%40lethevimlet%2Fsshift/latest',
50
+ method: 'GET',
51
+ headers: {
52
+ 'User-Agent': 'sshift-update-checker',
53
+ 'Accept': 'application/json'
54
+ }
55
+ }, request);
56
+
57
+ if (!VERSION_PATTERN.test(npmPackage.version)) {
58
+ throw new Error('npm returned an invalid version');
59
+ }
60
+ return npmPackage.version;
61
+ } catch (npmError) {
62
+ console.warn('[UPDATE] npm version check failed, trying GitHub:', npmError.message);
63
+ }
64
+
65
+ const githubResponse = await fetchJson({
66
+ hostname: 'api.github.com',
67
+ path: '/repos/lethevimlet/sshift/contents/package.json',
68
+ method: 'GET',
69
+ headers: {
70
+ 'User-Agent': 'sshift-update-checker',
71
+ 'Accept': 'application/vnd.github.v3+json'
72
+ }
73
+ }, request);
74
+ const content = Buffer.from(githubResponse.content, 'base64').toString('utf8');
75
+ const githubVersion = JSON.parse(content).version;
76
+ if (!VERSION_PATTERN.test(githubVersion)) {
77
+ throw new Error('GitHub returned an invalid version');
78
+ }
79
+ return githubVersion;
80
+ }
81
+
82
+ function compareVersions(v1, v2) {
83
+ const parts1 = v1.split('.').map(Number);
84
+ const parts2 = v2.split('.').map(Number);
85
+
86
+ for (let i = 0; i < 3; i++) {
87
+ if (parts1[i] < parts2[i]) return -1;
88
+ if (parts1[i] > parts2[i]) return 1;
89
+ }
90
+ return 0;
91
+ }
11
92
 
12
93
  /**
13
94
  * Register system endpoints
@@ -61,78 +142,18 @@ function registerSystemEndpoints(app, io) {
61
142
  // API: Check for updates
62
143
  app.get('/api/check-update', async (req, res) => {
63
144
  try {
64
- const https = require('https');
65
-
66
145
  // Get local version
67
146
  const packagePath = path.join(__dirname, '../../../../package.json');
68
147
  const packageData = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
69
148
  const localVersion = packageData.version;
70
-
71
- // Get remote version from GitHub
72
- const options = {
73
- hostname: 'api.github.com',
74
- path: '/repos/lethevimlet/sshift/contents/package.json',
75
- method: 'GET',
76
- headers: {
77
- 'User-Agent': 'sshift-update-checker',
78
- 'Accept': 'application/vnd.github.v3+json'
79
- }
80
- };
81
-
82
- const githubRequest = https.request(options, (githubResponse) => {
83
- let data = '';
84
-
85
- githubResponse.on('data', (chunk) => {
86
- data += chunk;
87
- });
88
-
89
- githubResponse.on('end', () => {
90
- try {
91
- if (githubResponse.statusCode !== 200) {
92
- console.error('GitHub API error:', githubResponse.statusCode, data);
93
- res.status(500).json({ error: 'Failed to check for updates' });
94
- return;
95
- }
96
-
97
- const response = JSON.parse(data);
98
- const content = Buffer.from(response.content, 'base64').toString('utf8');
99
- const remotePackage = JSON.parse(content);
100
- const remoteVersion = remotePackage.version;
101
-
102
- // Compare versions
103
- const compareVersions = (v1, v2) => {
104
- const parts1 = v1.split('.').map(Number);
105
- const parts2 = v2.split('.').map(Number);
106
-
107
- for (let i = 0; i < 3; i++) {
108
- if (parts1[i] < parts2[i]) return -1;
109
- if (parts1[i] > parts2[i]) return 1;
110
- }
111
- return 0;
112
- };
113
-
114
- const comparison = compareVersions(localVersion, remoteVersion);
115
- const updateAvailable = comparison < 0;
116
-
117
- res.json({
118
- localVersion,
119
- remoteVersion,
120
- updateAvailable,
121
- checkedAt: new Date().toISOString()
122
- });
123
- } catch (err) {
124
- console.error('Error parsing GitHub response:', err);
125
- res.status(500).json({ error: 'Failed to parse update information' });
126
- }
127
- });
128
- });
129
-
130
- githubRequest.on('error', (err) => {
131
- console.error('Error checking for updates:', err);
132
- res.status(500).json({ error: 'Failed to check for updates' });
149
+ const remoteVersion = await getLatestPublishedVersion();
150
+
151
+ res.json({
152
+ localVersion,
153
+ remoteVersion,
154
+ updateAvailable: compareVersions(localVersion, remoteVersion) < 0,
155
+ checkedAt: new Date().toISOString()
133
156
  });
134
-
135
- githubRequest.end();
136
157
  } catch (err) {
137
158
  console.error('Error in check-update:', err);
138
159
  res.status(500).json({ error: 'Failed to check for updates' });
@@ -258,7 +279,6 @@ function registerSystemEndpoints(app, io) {
258
279
  let targetVersion = 'latest';
259
280
  const currentPkg = require('../../../../package.json');
260
281
  try {
261
- const https = require('https');
262
282
  const githubVersion = await new Promise((resolve, reject) => {
263
283
  const opts = {
264
284
  hostname: 'api.github.com',
@@ -691,4 +711,4 @@ fi
691
711
  });
692
712
  }
693
713
 
694
- module.exports = { registerSystemEndpoints };
714
+ module.exports = { compareVersions, getLatestPublishedVersion, registerSystemEndpoints };
@@ -15,6 +15,7 @@ const {
15
15
  updateTabName,
16
16
  updateTabPanel,
17
17
  setActiveTab,
18
+ setActiveSession,
18
19
  getOpenTabs
19
20
  } = require('../../utils/tab-manager');
20
21
  const { sshManager, sftpManager } = require('../../services');
@@ -136,6 +137,7 @@ function registerTabHandlers(socket, io) {
136
137
  }
137
138
  }
138
139
  });
140
+ setActiveSession(data.activeSessionId);
139
141
  }
140
142
  // Don't update tab order for empty tab lists — a new client syncing
141
143
  // before receiving server tabs would wipe the server-side tab order.
@@ -146,7 +148,8 @@ function registerTabHandlers(socket, io) {
146
148
  if (data.tabs && data.tabs.length > 0) {
147
149
  socket.broadcast.emit('tabs-sync', {
148
150
  tabs: data.tabs,
149
- layout: data.layout
151
+ layout: data.layout,
152
+ activeSessionId: data.activeSessionId
150
153
  });
151
154
  }
152
155
  });
@@ -225,4 +228,4 @@ function handleTabDisconnect(socket, io) {
225
228
  };
226
229
  }
227
230
 
228
- module.exports = { registerTabHandlers, handleTabDisconnect };
231
+ module.exports = { registerTabHandlers, handleTabDisconnect };
@@ -282,7 +282,7 @@ async function initializeServer() {
282
282
  // localStorage (they survive server restarts and can differ per
283
283
  // device). Broadcasting them here used to clobber every new client's
284
284
  // own preference with the server's in-memory copy.
285
- const { getOpenTabs, getTabOrder, getActiveTabsByPanel } = require('./utils/tab-manager');
285
+ const { getOpenTabs, getTabOrder, getActiveTabsByPanel, getActiveSession } = require('./utils/tab-manager');
286
286
 
287
287
  const openTabs = getOpenTabs();
288
288
  const tabOrder = getTabOrder();
@@ -330,7 +330,8 @@ async function initializeServer() {
330
330
 
331
331
  socket.emit('open-tabs', {
332
332
  tabs: orderedTabs,
333
- activeTabsByPanel
333
+ activeTabsByPanel,
334
+ activeSessionId: getActiveSession()
334
335
  });
335
336
 
336
337
  // Sync flash state for tabs that need attention
@@ -371,4 +372,4 @@ initializeServer().catch(err => {
371
372
  });
372
373
 
373
374
  // Export for testing
374
- module.exports = { app, server, io };
375
+ module.exports = { app, server, io };