@lethevimlet/sshift 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/example.config.json +1 -0
- package/package.json +1 -1
- package/src/server/endpoints/rest/auth.js +87 -0
- package/src/server/endpoints/rest/config.js +10 -10
- package/src/server/endpoints/rest/index.js +7 -5
- package/src/server/endpoints/rest/utils.js +36 -0
- package/src/server/index.js +72 -11
- package/src/server/services/sftp-manager.js +3 -1
- package/src/server/services/ssh-manager.js +3 -4
- package/src/server/utils/config.js +54 -2
- package/src/server/utils/key-converter.js +363 -0
- package/src/webapp/css/style.css +178 -5
- package/src/webapp/icons/apple-touch-icon.png +0 -0
- package/src/webapp/icons/favicon-16x16.png +0 -0
- package/src/webapp/icons/favicon-32x32.png +0 -0
- package/src/webapp/icons/icon-128x128.png +0 -0
- package/src/webapp/icons/icon-144x144.png +0 -0
- package/src/webapp/icons/icon-152x152.png +0 -0
- package/src/webapp/icons/icon-192x192.png +0 -0
- package/src/webapp/icons/icon-384x384.png +0 -0
- package/src/webapp/icons/icon-512x512.png +0 -0
- package/src/webapp/icons/icon-72x72.png +0 -0
- package/src/webapp/icons/icon-96x96.png +0 -0
- package/src/webapp/index.html +111 -3
- package/src/webapp/js/app.js +661 -184
- package/src/webapp/js/mobile-terminal.js +65 -36
- package/src/webapp/manifest.json +54 -0
- package/src/webapp/sw.js +55 -0
package/src/webapp/js/app.js
CHANGED
|
@@ -3,11 +3,13 @@ class SSHIFTClient {
|
|
|
3
3
|
constructor() {
|
|
4
4
|
console.log('[SSHIFT] Initializing client...');
|
|
5
5
|
try {
|
|
6
|
+
const authToken = localStorage.getItem('sshift_auth_token');
|
|
6
7
|
this.socket = io({
|
|
7
8
|
transports: ['websocket', 'polling'],
|
|
8
9
|
reconnection: true,
|
|
9
10
|
reconnectionAttempts: 5,
|
|
10
|
-
reconnectionDelay: 1000
|
|
11
|
+
reconnectionDelay: 1000,
|
|
12
|
+
auth: authToken ? { token: authToken } : {}
|
|
11
13
|
});
|
|
12
14
|
console.log('[SSHIFT] Socket created');
|
|
13
15
|
} catch (e) {
|
|
@@ -48,6 +50,24 @@ class SSHIFTClient {
|
|
|
48
50
|
this.altPressed = false; // Track Alt key state
|
|
49
51
|
this.currentKeyboardHeight = 0; // Track actual keyboard height for positioning
|
|
50
52
|
|
|
53
|
+
// Password protection state
|
|
54
|
+
this.passwordEnabled = false;
|
|
55
|
+
this.authToken = localStorage.getItem('sshift_auth_token') || null;
|
|
56
|
+
|
|
57
|
+
this._origFetch = window.fetch.bind(window);
|
|
58
|
+
window.fetch = (url, options = {}) => {
|
|
59
|
+
if (typeof url === 'string' && url.startsWith('/api/') && this.authToken) {
|
|
60
|
+
if (!options.headers) options.headers = {};
|
|
61
|
+
if (!(options.headers instanceof Headers)) {
|
|
62
|
+
options.headers = { ...options.headers };
|
|
63
|
+
}
|
|
64
|
+
if (typeof options.headers === 'object' && !options.headers['Authorization']) {
|
|
65
|
+
options.headers['Authorization'] = `Bearer ${this.authToken}`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return this._origFetch(url, options);
|
|
69
|
+
};
|
|
70
|
+
|
|
51
71
|
// Terminal font size (for pinch-to-zoom on mobile)
|
|
52
72
|
this.terminalFontSize = 14; // Default font size
|
|
53
73
|
this.minFontSize = 8; // Minimum font size
|
|
@@ -99,6 +119,7 @@ class SSHIFTClient {
|
|
|
99
119
|
this.sshKeepaliveCountMax = config.sshKeepaliveCountMax || 1000;
|
|
100
120
|
// Load mobile keys bar setting
|
|
101
121
|
this.mobileKeysBarEnabled = config.mobileKeysBarEnabled !== undefined ? config.mobileKeysBarEnabled : true;
|
|
122
|
+
this.passwordEnabled = config.passwordEnabled || false;
|
|
102
123
|
console.log('[SSHIFT] Loaded from server - Sticky:', this.sticky ? 'enabled' : 'disabled',
|
|
103
124
|
'Take Control Default:', this.takeControlDefault ? 'enabled' : 'disabled',
|
|
104
125
|
'Keepalive Interval:', this.sshKeepaliveInterval,
|
|
@@ -114,6 +135,241 @@ class SSHIFTClient {
|
|
|
114
135
|
}
|
|
115
136
|
}
|
|
116
137
|
|
|
138
|
+
async checkAuthStatus() {
|
|
139
|
+
const lockScreen = document.getElementById('lockScreen');
|
|
140
|
+
const lockScreenForm = document.getElementById('lockScreenForm');
|
|
141
|
+
const lockScreenSubtitle = document.getElementById('lockScreenSubtitle');
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
const response = await this._origFetch('/api/auth/status');
|
|
145
|
+
const data = await response.json();
|
|
146
|
+
this.passwordEnabled = data.passwordEnabled;
|
|
147
|
+
|
|
148
|
+
if (!this.passwordEnabled) {
|
|
149
|
+
if (lockScreen) lockScreen.style.display = 'none';
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const storedToken = localStorage.getItem('sshift_auth_token');
|
|
154
|
+
if (storedToken) {
|
|
155
|
+
try {
|
|
156
|
+
const verifyResp = await this._origFetch('/api/config', {
|
|
157
|
+
headers: { 'Authorization': `Bearer ${storedToken}` }
|
|
158
|
+
});
|
|
159
|
+
if (verifyResp.ok) {
|
|
160
|
+
this.authToken = storedToken;
|
|
161
|
+
this.updateSocketAuth();
|
|
162
|
+
if (lockScreen) lockScreen.style.display = 'none';
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
} catch (e) {}
|
|
166
|
+
localStorage.removeItem('sshift_auth_token');
|
|
167
|
+
this.authToken = null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
await this.showLockScreen();
|
|
171
|
+
} catch (err) {
|
|
172
|
+
console.error('[SSHIFT] Failed to check auth status:', err);
|
|
173
|
+
if (lockScreen) lockScreen.style.display = 'none';
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
showLockScreen() {
|
|
178
|
+
return new Promise((resolve) => {
|
|
179
|
+
const lockScreen = document.getElementById('lockScreen');
|
|
180
|
+
const lockScreenForm = document.getElementById('lockScreenForm');
|
|
181
|
+
const lockScreenPassword = document.getElementById('lockScreenPassword');
|
|
182
|
+
const lockScreenError = document.getElementById('lockScreenError');
|
|
183
|
+
const lockScreenSubtitle = document.getElementById('lockScreenSubtitle');
|
|
184
|
+
const lockScreenIcon = lockScreen ? lockScreen.querySelector('.lock-screen-icon i') : null;
|
|
185
|
+
|
|
186
|
+
if (lockScreen) lockScreen.style.display = 'flex';
|
|
187
|
+
if (lockScreenIcon) lockScreenIcon.className = 'fas fa-lock';
|
|
188
|
+
if (lockScreenSubtitle) lockScreenSubtitle.textContent = 'Password Required';
|
|
189
|
+
if (lockScreenForm) lockScreenForm.style.display = 'flex';
|
|
190
|
+
if (lockScreenError) lockScreenError.style.display = 'none';
|
|
191
|
+
if (lockScreenPassword) {
|
|
192
|
+
lockScreenPassword.value = '';
|
|
193
|
+
lockScreenPassword.focus();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const submitHandler = async (e) => {
|
|
197
|
+
e.preventDefault();
|
|
198
|
+
const password = lockScreenPassword.value;
|
|
199
|
+
if (!password) return;
|
|
200
|
+
|
|
201
|
+
lockScreenError.style.display = 'none';
|
|
202
|
+
try {
|
|
203
|
+
const resp = await this._origFetch('/api/auth/login', {
|
|
204
|
+
method: 'POST',
|
|
205
|
+
headers: { 'Content-Type': 'application/json' },
|
|
206
|
+
body: JSON.stringify({ password })
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
if (resp.ok) {
|
|
210
|
+
const data = await resp.json();
|
|
211
|
+
this.authToken = data.token;
|
|
212
|
+
localStorage.setItem('sshift_auth_token', data.token);
|
|
213
|
+
this.updateSocketAuth();
|
|
214
|
+
lockScreen.style.display = 'none';
|
|
215
|
+
this.passwordEnabled = true;
|
|
216
|
+
lockScreenForm.removeEventListener('submit', submitHandler);
|
|
217
|
+
resolve();
|
|
218
|
+
} else {
|
|
219
|
+
const data = await resp.json();
|
|
220
|
+
lockScreenError.textContent = data.error || 'Invalid password';
|
|
221
|
+
lockScreenError.style.display = 'block';
|
|
222
|
+
lockScreenPassword.value = '';
|
|
223
|
+
lockScreenPassword.focus();
|
|
224
|
+
}
|
|
225
|
+
} catch (err) {
|
|
226
|
+
lockScreenError.textContent = 'Connection error';
|
|
227
|
+
lockScreenError.style.display = 'block';
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
lockScreenForm.addEventListener('submit', submitHandler);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
updateSocketAuth() {
|
|
236
|
+
if (this.socket && this.authToken) {
|
|
237
|
+
this.socket.auth = { token: this.authToken };
|
|
238
|
+
this.socket.disconnect().connect();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async togglePasswordProtection() {
|
|
243
|
+
if (this.passwordEnabled) {
|
|
244
|
+
this._showPasswordModal({
|
|
245
|
+
title: 'Disable Password Protection',
|
|
246
|
+
label: 'Enter current password',
|
|
247
|
+
confirmText: 'Disable',
|
|
248
|
+
requireConfirm: false
|
|
249
|
+
}, async (password) => {
|
|
250
|
+
try {
|
|
251
|
+
const resp = await fetch('/api/auth/remove-password', {
|
|
252
|
+
method: 'POST',
|
|
253
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': this.authToken ? `Bearer ${this.authToken}` : '' },
|
|
254
|
+
body: JSON.stringify({ currentPassword: password })
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
if (resp.ok) {
|
|
258
|
+
localStorage.removeItem('sshift_auth_token');
|
|
259
|
+
location.reload();
|
|
260
|
+
} else {
|
|
261
|
+
const data = await resp.json();
|
|
262
|
+
this.showToast(data.error || 'Failed to disable password', 'error');
|
|
263
|
+
}
|
|
264
|
+
} catch (err) {
|
|
265
|
+
this.showToast('Failed to disable password', 'error');
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
} else {
|
|
269
|
+
this._showPasswordModal({
|
|
270
|
+
title: 'Enable Password Protection',
|
|
271
|
+
label: 'Set a password',
|
|
272
|
+
confirmText: 'Enable',
|
|
273
|
+
requireConfirm: true
|
|
274
|
+
}, async (password) => {
|
|
275
|
+
try {
|
|
276
|
+
const resp = await fetch('/api/auth/set-password', {
|
|
277
|
+
method: 'POST',
|
|
278
|
+
headers: { 'Content-Type': 'application/json' },
|
|
279
|
+
body: JSON.stringify({ newPassword: password })
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
if (resp.ok) {
|
|
283
|
+
location.reload();
|
|
284
|
+
} else {
|
|
285
|
+
const data = await resp.json();
|
|
286
|
+
this.showToast(data.error || 'Failed to enable password', 'error');
|
|
287
|
+
}
|
|
288
|
+
} catch (err) {
|
|
289
|
+
this.showToast('Failed to enable password', 'error');
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
_showPasswordModal(options, onSubmit) {
|
|
296
|
+
const modal = document.getElementById('passwordModal');
|
|
297
|
+
const title = document.getElementById('passwordModalTitle');
|
|
298
|
+
const label = document.getElementById('passwordModalLabel');
|
|
299
|
+
const input = document.getElementById('passwordModalInput');
|
|
300
|
+
const confirmInput = document.getElementById('passwordModalConfirmInput');
|
|
301
|
+
const confirmGroup = document.getElementById('confirmPasswordGroup');
|
|
302
|
+
const errorEl = document.getElementById('passwordModalError');
|
|
303
|
+
const submitBtn = document.getElementById('passwordModalSubmit');
|
|
304
|
+
const cancelBtn = document.getElementById('passwordModalCancel');
|
|
305
|
+
const closeBtn = document.getElementById('closePasswordModal');
|
|
306
|
+
|
|
307
|
+
title.innerHTML = `<i class="fas fa-lock"></i> ${options.title}`;
|
|
308
|
+
label.textContent = options.label;
|
|
309
|
+
submitBtn.innerHTML = `<i class="fas fa-check"></i> ${options.confirmText}`;
|
|
310
|
+
input.value = '';
|
|
311
|
+
confirmInput.value = '';
|
|
312
|
+
errorEl.style.display = 'none';
|
|
313
|
+
|
|
314
|
+
if (options.requireConfirm) {
|
|
315
|
+
confirmGroup.style.display = 'block';
|
|
316
|
+
} else {
|
|
317
|
+
confirmGroup.style.display = 'none';
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const cleanup = () => {
|
|
321
|
+
this.closeModal('passwordModal');
|
|
322
|
+
submitBtn.removeEventListener('click', handleSubmit);
|
|
323
|
+
cancelBtn.removeEventListener('click', handleCancel);
|
|
324
|
+
closeBtn.removeEventListener('click', handleCancel);
|
|
325
|
+
modal.removeEventListener('click', handleBackdrop);
|
|
326
|
+
input.removeEventListener('keydown', handleKeydown);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const handleSubmit = async () => {
|
|
330
|
+
const password = input.value;
|
|
331
|
+
if (!password) {
|
|
332
|
+
errorEl.textContent = 'Password cannot be empty';
|
|
333
|
+
errorEl.style.display = 'block';
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (options.requireConfirm && password !== confirmInput.value) {
|
|
337
|
+
errorEl.textContent = 'Passwords do not match';
|
|
338
|
+
errorEl.style.display = 'block';
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
cleanup();
|
|
342
|
+
await onSubmit(password);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const handleCancel = () => cleanup();
|
|
346
|
+
const handleBackdrop = (e) => { if (e.target === modal) cleanup(); };
|
|
347
|
+
const handleKeydown = (e) => { if (e.key === 'Enter') handleSubmit(); };
|
|
348
|
+
|
|
349
|
+
submitBtn.addEventListener('click', handleSubmit);
|
|
350
|
+
cancelBtn.addEventListener('click', handleCancel);
|
|
351
|
+
closeBtn.addEventListener('click', handleCancel);
|
|
352
|
+
modal.addEventListener('click', handleBackdrop);
|
|
353
|
+
input.addEventListener('keydown', handleKeydown);
|
|
354
|
+
|
|
355
|
+
this.openModal('passwordModal');
|
|
356
|
+
setTimeout(() => input.focus(), 100);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
updatePasswordToggleUI() {
|
|
360
|
+
const btn = document.getElementById('togglePasswordBtn');
|
|
361
|
+
const label = document.getElementById('togglePasswordLabel');
|
|
362
|
+
if (btn && label) {
|
|
363
|
+
if (this.passwordEnabled) {
|
|
364
|
+
btn.querySelector('i').className = 'fas fa-lock';
|
|
365
|
+
label.textContent = 'Disable Password';
|
|
366
|
+
} else {
|
|
367
|
+
btn.querySelector('i').className = 'fas fa-lock-open';
|
|
368
|
+
label.textContent = 'Enable Password';
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
117
373
|
// Update sticky checkbox to reflect loaded value
|
|
118
374
|
updateStickyCheckbox() {
|
|
119
375
|
const stickyToggle = document.getElementById('stickyToggle');
|
|
@@ -573,6 +829,56 @@ class SSHIFTClient {
|
|
|
573
829
|
// Don't persist - font size is session-only
|
|
574
830
|
}
|
|
575
831
|
|
|
832
|
+
// Robust terminal fit with validation and retry.
|
|
833
|
+
// Sometimes fit() is called before the browser finishes laying out a
|
|
834
|
+
// container that just became visible (display:none -> display:flex).
|
|
835
|
+
// When that happens proposeDimensions() reads stale or zero width/height
|
|
836
|
+
// and the terminal ends up with far fewer cols than the container can hold
|
|
837
|
+
// (the "narrow column" bug). This wrapper validates the result and
|
|
838
|
+
// retries on the next animation frame when it detects a bad fit.
|
|
839
|
+
_fitTerminal(session, retryCount = 0) {
|
|
840
|
+
if (!session || !session.fitAddon || !session.terminal) return false;
|
|
841
|
+
|
|
842
|
+
const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
|
|
843
|
+
const container = document.getElementById(`terminal-${session.id}`);
|
|
844
|
+
if (!wrapper || !container) return false;
|
|
845
|
+
|
|
846
|
+
if (!wrapper.classList.contains('active')) {
|
|
847
|
+
session.needsResize = true;
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
void container.offsetHeight;
|
|
852
|
+
void wrapper.offsetHeight;
|
|
853
|
+
|
|
854
|
+
try {
|
|
855
|
+
session.fitAddon.fit();
|
|
856
|
+
} catch (e) {
|
|
857
|
+
console.warn('[SSHIFT] Could not fit terminal:', e.message);
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
const terminal = session.terminal;
|
|
862
|
+
const core = terminal._core;
|
|
863
|
+
if (core) {
|
|
864
|
+
const cellWidth = core._renderService?.dimensions?.css?.cell?.width || 0;
|
|
865
|
+
const containerWidth = container.getBoundingClientRect().width;
|
|
866
|
+
if (cellWidth > 0 && containerWidth > 80) {
|
|
867
|
+
const expectedCols = Math.floor(containerWidth / cellWidth);
|
|
868
|
+
if (terminal.cols < expectedCols * 0.5 && retryCount < 3) {
|
|
869
|
+
console.warn(`[SSHIFT] Terminal fit seems incorrect (cols: ${terminal.cols}, expected: ~${expectedCols}, container: ${containerWidth}px), retrying (attempt ${retryCount + 1})...`);
|
|
870
|
+
requestAnimationFrame(() => {
|
|
871
|
+
this._fitTerminal(session, retryCount + 1);
|
|
872
|
+
});
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
console.log('[SSHIFT] Terminal fitted, cols:', terminal.cols, 'rows:', terminal.rows);
|
|
879
|
+
return true;
|
|
880
|
+
}
|
|
881
|
+
|
|
576
882
|
// Set font size for a specific session
|
|
577
883
|
setSessionFontSize(sessionId, size) {
|
|
578
884
|
const session = this.sessions.get(sessionId);
|
|
@@ -591,9 +897,8 @@ class SSHIFTClient {
|
|
|
591
897
|
session.terminal.options.fontSize = size;
|
|
592
898
|
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
593
899
|
|
|
594
|
-
// Refit if this client is the controller
|
|
595
900
|
if (session.fitAddon && session.isController) {
|
|
596
|
-
|
|
901
|
+
this._fitTerminal(session);
|
|
597
902
|
}
|
|
598
903
|
|
|
599
904
|
// Refresh mobile selection overlay after font change
|
|
@@ -620,26 +925,21 @@ class SSHIFTClient {
|
|
|
620
925
|
if (session.terminal) {
|
|
621
926
|
session.terminal.options.fontSize = size;
|
|
622
927
|
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
623
|
-
// Only refit if this client is the controller
|
|
624
|
-
// Non-controllers will receive resize sync from the controller
|
|
625
928
|
if (session.fitAddon && session.isController) {
|
|
626
|
-
|
|
929
|
+
this._fitTerminal(session);
|
|
627
930
|
}
|
|
628
|
-
// Refresh mobile selection overlay
|
|
629
931
|
if (session.mobileHandler) {
|
|
630
932
|
session.mobileHandler.refreshSelection();
|
|
631
933
|
}
|
|
632
934
|
}
|
|
633
935
|
});
|
|
634
936
|
|
|
635
|
-
// Update all active SFTP terminals
|
|
636
937
|
this.sftpSessions.forEach((session) => {
|
|
637
938
|
if (session.terminal) {
|
|
638
939
|
session.terminal.options.fontSize = size;
|
|
639
940
|
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
640
|
-
// SFTP sessions don't have controller concept, always fit
|
|
641
941
|
if (session.fitAddon) {
|
|
642
|
-
|
|
942
|
+
this._fitTerminal(session);
|
|
643
943
|
}
|
|
644
944
|
}
|
|
645
945
|
});
|
|
@@ -1185,50 +1485,26 @@ class SSHIFTClient {
|
|
|
1185
1485
|
refitAllTerminals() {
|
|
1186
1486
|
console.log('[SSHIFT] Refitting all terminals');
|
|
1187
1487
|
|
|
1188
|
-
// Multiple attempts with increasing delays to ensure DOM is settled
|
|
1189
1488
|
const delays = [50, 150, 300, 500];
|
|
1190
1489
|
|
|
1191
1490
|
delays.forEach((delay, index) => {
|
|
1192
1491
|
setTimeout(() => {
|
|
1193
1492
|
console.log(`[SSHIFT] Refit attempt ${index + 1}/${delays.length}`);
|
|
1194
1493
|
|
|
1195
|
-
// Refit SSH terminals
|
|
1196
1494
|
this.sessions.forEach((session, sessionId) => {
|
|
1197
1495
|
if (session.terminal && session.fitAddon && session.isController) {
|
|
1198
1496
|
const wrapper = document.getElementById(`terminal-wrapper-${sessionId}`);
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
if (wrapper && container && wrapper.classList.contains('active')) {
|
|
1202
|
-
try {
|
|
1203
|
-
// Force reflow
|
|
1204
|
-
void wrapper.offsetHeight;
|
|
1205
|
-
void container.offsetHeight;
|
|
1206
|
-
|
|
1207
|
-
session.fitAddon.fit();
|
|
1208
|
-
console.log(`[SSHIFT] Terminal ${sessionId} refitted, cols: ${session.terminal.cols}, rows: ${session.terminal.rows}`);
|
|
1209
|
-
} catch (e) {
|
|
1210
|
-
console.warn(`[SSHIFT] Failed to refit terminal ${sessionId}:`, e.message);
|
|
1211
|
-
}
|
|
1497
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
1498
|
+
this._fitTerminal(session);
|
|
1212
1499
|
}
|
|
1213
1500
|
}
|
|
1214
1501
|
});
|
|
1215
1502
|
|
|
1216
|
-
// Refit SFTP terminals
|
|
1217
1503
|
this.sftpSessions.forEach((session, sessionId) => {
|
|
1218
1504
|
if (session.terminal && session.fitAddon) {
|
|
1219
1505
|
const wrapper = document.getElementById(`terminal-wrapper-${sessionId}`);
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
if (wrapper && container && wrapper.classList.contains('active')) {
|
|
1223
|
-
try {
|
|
1224
|
-
void wrapper.offsetHeight;
|
|
1225
|
-
void container.offsetHeight;
|
|
1226
|
-
|
|
1227
|
-
session.fitAddon.fit();
|
|
1228
|
-
console.log(`[SSHIFT] SFTP terminal ${sessionId} refitted, cols: ${session.terminal.cols}, rows: ${session.terminal.rows}`);
|
|
1229
|
-
} catch (e) {
|
|
1230
|
-
console.warn(`[SSHIFT] Failed to refit SFTP terminal ${sessionId}:`, e.message);
|
|
1231
|
-
}
|
|
1506
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
1507
|
+
this._fitTerminal(session);
|
|
1232
1508
|
}
|
|
1233
1509
|
}
|
|
1234
1510
|
});
|
|
@@ -1781,7 +2057,7 @@ class SSHIFTClient {
|
|
|
1781
2057
|
sftpSession.terminal.refresh(0, sftpSession.terminal.rows - 1);
|
|
1782
2058
|
|
|
1783
2059
|
if (sftpSession.fitAddon) {
|
|
1784
|
-
|
|
2060
|
+
this._fitTerminal(sftpSession);
|
|
1785
2061
|
}
|
|
1786
2062
|
|
|
1787
2063
|
console.log('[SSHIFT] SFTP font size set to', sftpSession.fontSize, 'for session', activeSessionId);
|
|
@@ -1893,6 +2169,8 @@ class SSHIFTClient {
|
|
|
1893
2169
|
async init() {
|
|
1894
2170
|
console.log('[SSHIFT] Setting up listeners...');
|
|
1895
2171
|
|
|
2172
|
+
await this.checkAuthStatus();
|
|
2173
|
+
|
|
1896
2174
|
// Fix mobile viewport height issues
|
|
1897
2175
|
this.fixMobileViewport();
|
|
1898
2176
|
|
|
@@ -2256,28 +2534,12 @@ class SSHIFTClient {
|
|
|
2256
2534
|
}
|
|
2257
2535
|
|
|
2258
2536
|
refitActiveTerminal() {
|
|
2259
|
-
// Refit the active terminal to fill the available space
|
|
2260
|
-
// Only fit for controllers - non-controllers will receive resize sync
|
|
2261
2537
|
if (this.activeSessionId) {
|
|
2262
2538
|
const session = this.sessions.get(this.activeSessionId);
|
|
2263
2539
|
if (session && session.fitAddon && session.terminal && session.isController) {
|
|
2264
|
-
// Small delay to allow CSS transitions to complete
|
|
2265
2540
|
setTimeout(() => {
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
const terminalWrapper = document.querySelector('.terminal-wrapper.active');
|
|
2269
|
-
console.log('[SSHIFT] Terminal dimensions before fit:', {
|
|
2270
|
-
terminalAreaHeight: terminalArea?.offsetHeight,
|
|
2271
|
-
terminalWrapperHeight: terminalWrapper?.offsetHeight,
|
|
2272
|
-
terminalRows: session.terminal.rows,
|
|
2273
|
-
terminalCols: session.terminal.cols
|
|
2274
|
-
});
|
|
2275
|
-
session.fitAddon.fit();
|
|
2276
|
-
console.log('[SSHIFT] Terminal refitted after header/tabs change, rows:', session.terminal.rows);
|
|
2277
|
-
} catch (e) {
|
|
2278
|
-
console.warn('[SSHIFT] Could not refit terminal:', e.message);
|
|
2279
|
-
}
|
|
2280
|
-
}, 350); // Wait for CSS transition (300ms) + buffer
|
|
2541
|
+
this._fitTerminal(session);
|
|
2542
|
+
}, 350);
|
|
2281
2543
|
}
|
|
2282
2544
|
}
|
|
2283
2545
|
}
|
|
@@ -2833,7 +3095,13 @@ class SSHIFTClient {
|
|
|
2833
3095
|
|
|
2834
3096
|
this.socket.on('connect_error', (error) => {
|
|
2835
3097
|
console.error('[SSHIFT] Connection error:', error);
|
|
2836
|
-
|
|
3098
|
+
if (error.message === 'Authentication required') {
|
|
3099
|
+
this.authToken = null;
|
|
3100
|
+
localStorage.removeItem('sshift_auth_token');
|
|
3101
|
+
this.showLockScreen();
|
|
3102
|
+
} else {
|
|
3103
|
+
this.showToast('Connection error: ' + error.message, 'error');
|
|
3104
|
+
}
|
|
2837
3105
|
});
|
|
2838
3106
|
|
|
2839
3107
|
// Handle receiving open tabs from server (for cross-tab sync)
|
|
@@ -3160,22 +3428,31 @@ class SSHIFTClient {
|
|
|
3160
3428
|
console.log('[SSHIFT] Control taken for session:', data.sessionId, 'by', data.controllerSocket);
|
|
3161
3429
|
const session = this.sessions.get(data.sessionId);
|
|
3162
3430
|
if (session) {
|
|
3163
|
-
// Update controller status
|
|
3164
3431
|
const wasController = session.isController;
|
|
3165
3432
|
session.isController = data.controllerSocket === this.socket.id;
|
|
3166
3433
|
session.controllerSocket = data.controllerSocket;
|
|
3167
3434
|
|
|
3168
|
-
// Update overlay visibility
|
|
3169
3435
|
this.updateControlOverlay(data.sessionId);
|
|
3170
3436
|
|
|
3171
|
-
// Show appropriate toast
|
|
3172
3437
|
if (session.isController && !wasController) {
|
|
3173
|
-
//
|
|
3174
|
-
|
|
3175
|
-
|
|
3438
|
+
// We just became the controller — resize to our container
|
|
3439
|
+
if (session.terminal && session.fitAddon) {
|
|
3440
|
+
session.isResyncing = true;
|
|
3441
|
+
if (session.resizeTimeout) {
|
|
3442
|
+
clearTimeout(session.resizeTimeout);
|
|
3443
|
+
session.resizeTimeout = null;
|
|
3444
|
+
}
|
|
3445
|
+
this._fitTerminal(session);
|
|
3446
|
+
session.isResyncing = false;
|
|
3447
|
+
this.socket.emit('ssh-resize', {
|
|
3448
|
+
sessionId: data.sessionId,
|
|
3449
|
+
cols: session.terminal.cols,
|
|
3450
|
+
rows: session.terminal.rows
|
|
3451
|
+
});
|
|
3452
|
+
console.log('[SSHIFT] Resized terminal after becoming controller:', session.terminal.cols, 'x', session.terminal.rows);
|
|
3453
|
+
}
|
|
3176
3454
|
this.showToast('You are now in control (previous controller left)', 'info');
|
|
3177
3455
|
} else if (!session.isController) {
|
|
3178
|
-
// Another client took control
|
|
3179
3456
|
this.showToast('Another device took control', 'info');
|
|
3180
3457
|
}
|
|
3181
3458
|
}
|
|
@@ -3217,7 +3494,8 @@ class SSHIFTClient {
|
|
|
3217
3494
|
}
|
|
3218
3495
|
|
|
3219
3496
|
// Fit the terminal to our container first
|
|
3220
|
-
session.
|
|
3497
|
+
session.isResyncing = true;
|
|
3498
|
+
this._fitTerminal(session);
|
|
3221
3499
|
|
|
3222
3500
|
// Clear the resyncing flag before emitting resize
|
|
3223
3501
|
session.isResyncing = false;
|
|
@@ -3568,6 +3846,9 @@ class SSHIFTClient {
|
|
|
3568
3846
|
// Initialize settings modal handlers
|
|
3569
3847
|
this.initSettingsModalHandlers();
|
|
3570
3848
|
|
|
3849
|
+
// Initialize password toggle
|
|
3850
|
+
this.initPasswordToggle();
|
|
3851
|
+
|
|
3571
3852
|
// Initialize sessions modal handlers
|
|
3572
3853
|
this.initSessionsModalHandlers();
|
|
3573
3854
|
|
|
@@ -3594,6 +3875,28 @@ class SSHIFTClient {
|
|
|
3594
3875
|
this.togglePasswordVisibility();
|
|
3595
3876
|
});
|
|
3596
3877
|
|
|
3878
|
+
// Private key upload - connection modal
|
|
3879
|
+
document.getElementById('connKeyUploadBtn').addEventListener('click', () => {
|
|
3880
|
+
document.getElementById('connKeyFileInput').click();
|
|
3881
|
+
});
|
|
3882
|
+
document.getElementById('connKeyFileInput').addEventListener('change', (e) => {
|
|
3883
|
+
this.handleKeyFileUpload(e, 'connPrivateKey', 'connKeyFormatBadge', 'connKeyClearBtn');
|
|
3884
|
+
});
|
|
3885
|
+
document.getElementById('connKeyClearBtn').addEventListener('click', () => {
|
|
3886
|
+
this.clearKeyField('connPrivateKey', 'connKeyFormatBadge', 'connKeyClearBtn');
|
|
3887
|
+
});
|
|
3888
|
+
|
|
3889
|
+
// Private key upload - bookmark modal
|
|
3890
|
+
document.getElementById('bookmarkKeyUploadBtn').addEventListener('click', () => {
|
|
3891
|
+
document.getElementById('bookmarkKeyFileInput').click();
|
|
3892
|
+
});
|
|
3893
|
+
document.getElementById('bookmarkKeyFileInput').addEventListener('change', (e) => {
|
|
3894
|
+
this.handleKeyFileUpload(e, 'bookmarkPrivateKey', 'bookmarkKeyFormatBadge', 'bookmarkKeyClearBtn');
|
|
3895
|
+
});
|
|
3896
|
+
document.getElementById('bookmarkKeyClearBtn').addEventListener('click', () => {
|
|
3897
|
+
this.clearKeyField('bookmarkPrivateKey', 'bookmarkKeyFormatBadge', 'bookmarkKeyClearBtn');
|
|
3898
|
+
});
|
|
3899
|
+
|
|
3597
3900
|
// Bookmark modal
|
|
3598
3901
|
document.getElementById('addBookmarkBtn').addEventListener('click', () => {
|
|
3599
3902
|
this.openBookmarkModal();
|
|
@@ -3818,11 +4121,7 @@ class SSHIFTClient {
|
|
|
3818
4121
|
setTimeout(() => {
|
|
3819
4122
|
this.sessions.forEach(session => {
|
|
3820
4123
|
if (session.terminal && session.fitAddon && session.isController) {
|
|
3821
|
-
|
|
3822
|
-
session.fitAddon.fit();
|
|
3823
|
-
} catch (e) {
|
|
3824
|
-
// Ignore resize errors
|
|
3825
|
-
}
|
|
4124
|
+
this._fitTerminal(session);
|
|
3826
4125
|
}
|
|
3827
4126
|
});
|
|
3828
4127
|
}, 300);
|
|
@@ -3870,6 +4169,9 @@ class SSHIFTClient {
|
|
|
3870
4169
|
mobileKeysBarToggle.checked = this.mobileKeysBarEnabled;
|
|
3871
4170
|
}
|
|
3872
4171
|
|
|
4172
|
+
// Update password toggle button state
|
|
4173
|
+
this.updatePasswordToggleUI();
|
|
4174
|
+
|
|
3873
4175
|
this.openModal('settingsModal');
|
|
3874
4176
|
}
|
|
3875
4177
|
|
|
@@ -4091,6 +4393,24 @@ class SSHIFTClient {
|
|
|
4091
4393
|
}
|
|
4092
4394
|
}
|
|
4093
4395
|
|
|
4396
|
+
initPasswordToggle() {
|
|
4397
|
+
const toggleBtn = document.getElementById('togglePasswordBtn');
|
|
4398
|
+
if (toggleBtn) {
|
|
4399
|
+
toggleBtn.addEventListener('click', () => {
|
|
4400
|
+
this.togglePasswordProtection();
|
|
4401
|
+
});
|
|
4402
|
+
}
|
|
4403
|
+
const logoutBtn = document.getElementById('logoutBtn');
|
|
4404
|
+
if (logoutBtn) {
|
|
4405
|
+
if (this.passwordEnabled) logoutBtn.style.display = '';
|
|
4406
|
+
logoutBtn.addEventListener('click', () => {
|
|
4407
|
+
localStorage.removeItem('sshift_auth_token');
|
|
4408
|
+
location.reload();
|
|
4409
|
+
});
|
|
4410
|
+
}
|
|
4411
|
+
this.updatePasswordToggleUI();
|
|
4412
|
+
}
|
|
4413
|
+
|
|
4094
4414
|
initSessionsModalHandlers() {
|
|
4095
4415
|
// Close button
|
|
4096
4416
|
const closeBtn = document.getElementById('closeManageSessionsModal');
|
|
@@ -4530,9 +4850,11 @@ class SSHIFTClient {
|
|
|
4530
4850
|
localStorage.setItem('mobileKeysBarEnabled', JSON.stringify(this.mobileKeysBarEnabled));
|
|
4531
4851
|
|
|
4532
4852
|
// Save to server config
|
|
4853
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
4854
|
+
if (this.authToken) headers['Authorization'] = `Bearer ${this.authToken}`;
|
|
4533
4855
|
fetch('/api/config', {
|
|
4534
4856
|
method: 'POST',
|
|
4535
|
-
headers
|
|
4857
|
+
headers,
|
|
4536
4858
|
body: JSON.stringify({
|
|
4537
4859
|
sticky: this.sticky,
|
|
4538
4860
|
takeControlDefault: this.takeControlDefault,
|
|
@@ -4609,9 +4931,199 @@ class SSHIFTClient {
|
|
|
4609
4931
|
type === 'ssh' ? 'New SSH Connection' : 'New SFTP Connection';
|
|
4610
4932
|
document.getElementById('connectionForm').reset();
|
|
4611
4933
|
document.getElementById('connPort').value = '22';
|
|
4934
|
+
this.clearKeyField('connPrivateKey', 'connKeyFormatBadge', 'connKeyClearBtn');
|
|
4612
4935
|
this.openModal('connectionModal');
|
|
4613
4936
|
}
|
|
4614
4937
|
|
|
4938
|
+
async handleKeyFileUpload(event, textareaId, badgeId, clearBtnId) {
|
|
4939
|
+
const file = event.target.files[0];
|
|
4940
|
+
if (!file) return;
|
|
4941
|
+
|
|
4942
|
+
const badge = document.getElementById(badgeId);
|
|
4943
|
+
const clearBtn = document.getElementById(clearBtnId);
|
|
4944
|
+
const textarea = document.getElementById(textareaId);
|
|
4945
|
+
|
|
4946
|
+
badge.style.display = 'inline-flex';
|
|
4947
|
+
badge.textContent = 'Reading...';
|
|
4948
|
+
badge.className = 'key-format-badge';
|
|
4949
|
+
|
|
4950
|
+
try {
|
|
4951
|
+
const content = await file.text();
|
|
4952
|
+
if (!content || !content.trim()) {
|
|
4953
|
+
badge.textContent = 'Empty file';
|
|
4954
|
+
badge.classList.add('format-error');
|
|
4955
|
+
badge.style.display = 'inline-flex';
|
|
4956
|
+
return;
|
|
4957
|
+
}
|
|
4958
|
+
|
|
4959
|
+
const detectResult = await this.detectAndConvertKey(content);
|
|
4960
|
+
if (detectResult.error) {
|
|
4961
|
+
badge.textContent = detectResult.format || 'Error';
|
|
4962
|
+
badge.classList.add('format-error');
|
|
4963
|
+
badge.style.display = 'inline-flex';
|
|
4964
|
+
textarea.value = content;
|
|
4965
|
+
clearBtn.style.display = 'inline-flex';
|
|
4966
|
+
this.showToast(detectResult.error, 'error');
|
|
4967
|
+
return;
|
|
4968
|
+
}
|
|
4969
|
+
|
|
4970
|
+
textarea.value = detectResult.key;
|
|
4971
|
+
|
|
4972
|
+
let formatLabel = detectResult.format;
|
|
4973
|
+
if (detectResult.wasConverted) {
|
|
4974
|
+
formatLabel = `PPK → OpenSSH`;
|
|
4975
|
+
} else if (detectResult.format === 'openssh') {
|
|
4976
|
+
formatLabel = 'OpenSSH';
|
|
4977
|
+
} else if (detectResult.format === 'pem-rsa') {
|
|
4978
|
+
formatLabel = 'PEM (RSA)';
|
|
4979
|
+
} else if (detectResult.format === 'pem-ec') {
|
|
4980
|
+
formatLabel = 'PEM (EC)';
|
|
4981
|
+
} else if (detectResult.format === 'pem-dsa') {
|
|
4982
|
+
formatLabel = 'PEM (DSA)';
|
|
4983
|
+
} else if (detectResult.format === 'pkcs8') {
|
|
4984
|
+
formatLabel = 'PKCS8';
|
|
4985
|
+
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
4986
|
+
formatLabel = 'PKCS8 (Encrypted)';
|
|
4987
|
+
}
|
|
4988
|
+
|
|
4989
|
+
badge.textContent = formatLabel;
|
|
4990
|
+
badge.className = 'key-format-badge';
|
|
4991
|
+
if (detectResult.encrypted) {
|
|
4992
|
+
badge.classList.add('format-warning');
|
|
4993
|
+
}
|
|
4994
|
+
badge.style.display = 'inline-flex';
|
|
4995
|
+
clearBtn.style.display = 'inline-flex';
|
|
4996
|
+
|
|
4997
|
+
if (detectResult.wasConverted) {
|
|
4998
|
+
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
4999
|
+
} else if (detectResult.format === 'openssh') {
|
|
5000
|
+
this.showToast('OpenSSH key loaded', 'success');
|
|
5001
|
+
} else if (detectResult.format === 'pem-rsa' || detectResult.format === 'pem-ec' || detectResult.format === 'pem-dsa') {
|
|
5002
|
+
this.showToast('PEM key loaded', 'success');
|
|
5003
|
+
} else if (detectResult.format === 'pkcs8') {
|
|
5004
|
+
this.showToast('PKCS8 key loaded', 'success');
|
|
5005
|
+
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
5006
|
+
this.showToast('Encrypted PKCS8 key loaded - passphrase required', 'info');
|
|
5007
|
+
}
|
|
5008
|
+
} catch (err) {
|
|
5009
|
+
badge.textContent = 'Error';
|
|
5010
|
+
badge.classList.add('format-error');
|
|
5011
|
+
badge.style.display = 'inline-flex';
|
|
5012
|
+
this.showToast('Failed to read key file: ' + err.message, 'error');
|
|
5013
|
+
}
|
|
5014
|
+
|
|
5015
|
+
event.target.value = '';
|
|
5016
|
+
}
|
|
5017
|
+
|
|
5018
|
+
async detectAndConvertKey(content) {
|
|
5019
|
+
try {
|
|
5020
|
+
const response = await fetch('/api/utils/detect-key', {
|
|
5021
|
+
method: 'POST',
|
|
5022
|
+
headers: { 'Content-Type': 'application/json' },
|
|
5023
|
+
body: JSON.stringify({ content })
|
|
5024
|
+
});
|
|
5025
|
+
|
|
5026
|
+
if (!response.ok) {
|
|
5027
|
+
return { format: 'unknown', key: content, error: 'Failed to detect key format' };
|
|
5028
|
+
}
|
|
5029
|
+
|
|
5030
|
+
const info = await response.json();
|
|
5031
|
+
|
|
5032
|
+
if (info.format === 'ppk') {
|
|
5033
|
+
try {
|
|
5034
|
+
const convertResponse = await fetch('/api/utils/convert-key', {
|
|
5035
|
+
method: 'POST',
|
|
5036
|
+
headers: { 'Content-Type': 'application/json' },
|
|
5037
|
+
body: JSON.stringify({ content })
|
|
5038
|
+
});
|
|
5039
|
+
|
|
5040
|
+
if (!convertResponse.ok) {
|
|
5041
|
+
const errData = await convertResponse.json().catch(() => ({}));
|
|
5042
|
+
return {
|
|
5043
|
+
format: 'PPK',
|
|
5044
|
+
key: content,
|
|
5045
|
+
encrypted: info.encrypted,
|
|
5046
|
+
wasConverted: false,
|
|
5047
|
+
error: errData.error || 'Failed to convert PPK key. Try converting with PuTTYgen first.'
|
|
5048
|
+
};
|
|
5049
|
+
}
|
|
5050
|
+
|
|
5051
|
+
const result = await convertResponse.json();
|
|
5052
|
+
return {
|
|
5053
|
+
format: 'openssh',
|
|
5054
|
+
key: result.key,
|
|
5055
|
+
encrypted: false,
|
|
5056
|
+
wasConverted: true
|
|
5057
|
+
};
|
|
5058
|
+
} catch (e) {
|
|
5059
|
+
return {
|
|
5060
|
+
format: 'PPK',
|
|
5061
|
+
key: content,
|
|
5062
|
+
encrypted: info.encrypted,
|
|
5063
|
+
wasConverted: false,
|
|
5064
|
+
error: 'Network error converting PPK key: ' + e.message
|
|
5065
|
+
};
|
|
5066
|
+
}
|
|
5067
|
+
}
|
|
5068
|
+
|
|
5069
|
+
if (info.format === 'unknown') {
|
|
5070
|
+
if (content.includes('BEGIN')) {
|
|
5071
|
+
return { format: 'unknown', key: content, error: 'Unrecognized key format. The SSH library (ssh2) supports OpenSSH, PEM, and PKCS8 formats.' };
|
|
5072
|
+
}
|
|
5073
|
+
return { format: 'unknown', key: content, error: 'Unrecognized key format. Please upload a valid SSH private key file.' };
|
|
5074
|
+
}
|
|
5075
|
+
|
|
5076
|
+
if (info.format === 'pkcs8-encrypted') {
|
|
5077
|
+
return {
|
|
5078
|
+
format: info.format,
|
|
5079
|
+
key: content,
|
|
5080
|
+
encrypted: true
|
|
5081
|
+
};
|
|
5082
|
+
}
|
|
5083
|
+
|
|
5084
|
+
return {
|
|
5085
|
+
format: info.format,
|
|
5086
|
+
key: content,
|
|
5087
|
+
encrypted: info.encrypted || false
|
|
5088
|
+
};
|
|
5089
|
+
} catch (e) {
|
|
5090
|
+
if (content.includes('PuTTY-user-key-file')) {
|
|
5091
|
+
return {
|
|
5092
|
+
format: 'PPK',
|
|
5093
|
+
key: content,
|
|
5094
|
+
encrypted: content.includes('Encryption:') && !content.includes('Encryption: none'),
|
|
5095
|
+
wasConverted: false,
|
|
5096
|
+
error: 'Cannot convert PPK offline. Please try again when connected to the server, or convert using PuTTYgen.'
|
|
5097
|
+
};
|
|
5098
|
+
}
|
|
5099
|
+
return {
|
|
5100
|
+
format: this.detectKeyFormatOffline(content),
|
|
5101
|
+
key: content,
|
|
5102
|
+
encrypted: content.includes('ENCRYPTED') || (content.includes('Encryption:') && !content.includes('Encryption: none'))
|
|
5103
|
+
};
|
|
5104
|
+
}
|
|
5105
|
+
}
|
|
5106
|
+
|
|
5107
|
+
detectKeyFormatOffline(content) {
|
|
5108
|
+
if (content.includes('BEGIN OPENSSH PRIVATE KEY')) return 'openssh';
|
|
5109
|
+
if (content.includes('BEGIN RSA PRIVATE KEY')) return 'pem-rsa';
|
|
5110
|
+
if (content.includes('BEGIN EC PRIVATE KEY')) return 'pem-ec';
|
|
5111
|
+
if (content.includes('BEGIN DSA PRIVATE KEY')) return 'pem-dsa';
|
|
5112
|
+
if (content.includes('BEGIN PRIVATE KEY')) return 'pkcs8';
|
|
5113
|
+
if (content.includes('BEGIN ENCRYPTED PRIVATE KEY')) return 'pkcs8-encrypted';
|
|
5114
|
+
if (content.includes('PuTTY-user-key-file')) return 'ppk';
|
|
5115
|
+
return 'unknown';
|
|
5116
|
+
}
|
|
5117
|
+
|
|
5118
|
+
clearKeyField(textareaId, badgeId, clearBtnId) {
|
|
5119
|
+
document.getElementById(textareaId).value = '';
|
|
5120
|
+
const badge = document.getElementById(badgeId);
|
|
5121
|
+
badge.style.display = 'none';
|
|
5122
|
+
badge.textContent = '';
|
|
5123
|
+
badge.className = 'key-format-badge';
|
|
5124
|
+
document.getElementById(clearBtnId).style.display = 'none';
|
|
5125
|
+
}
|
|
5126
|
+
|
|
4615
5127
|
togglePasswordVisibility() {
|
|
4616
5128
|
const input = document.getElementById('connPassword');
|
|
4617
5129
|
const icon = document.querySelector('#togglePassword i');
|
|
@@ -4671,13 +5183,11 @@ class SSHIFTClient {
|
|
|
4671
5183
|
|
|
4672
5184
|
// Save bookmark if requested
|
|
4673
5185
|
if (saveBookmark) {
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
type
|
|
4680
|
-
});
|
|
5186
|
+
const bookmarkData = { name, host, port, username, type };
|
|
5187
|
+
if (password) bookmarkData.password = password;
|
|
5188
|
+
if (privateKey) bookmarkData.privateKey = privateKey;
|
|
5189
|
+
if (passphrase) bookmarkData.passphrase = passphrase;
|
|
5190
|
+
this.addBookmark(bookmarkData);
|
|
4681
5191
|
}
|
|
4682
5192
|
|
|
4683
5193
|
// Show connecting status
|
|
@@ -5505,19 +6015,13 @@ class SSHIFTClient {
|
|
|
5505
6015
|
// Only fit if this is the controller and terminal is visible
|
|
5506
6016
|
if (session.isController && session.terminal && wrapper.classList.contains('active')) {
|
|
5507
6017
|
try {
|
|
5508
|
-
// Debounce the fit calls to avoid performance issues
|
|
5509
6018
|
if (session.resizeTimeout) {
|
|
5510
6019
|
clearTimeout(session.resizeTimeout);
|
|
5511
6020
|
}
|
|
5512
6021
|
session.resizeTimeout = setTimeout(() => {
|
|
5513
6022
|
try {
|
|
5514
6023
|
if (session.fitAddon && session.terminal && wrapper.classList.contains('active')) {
|
|
5515
|
-
|
|
5516
|
-
void container.offsetHeight;
|
|
5517
|
-
void wrapper.offsetHeight;
|
|
5518
|
-
|
|
5519
|
-
session.fitAddon.fit();
|
|
5520
|
-
console.log('[SSHIFT] Terminal refitted due to container resize, cols:', session.terminal.cols, 'rows:', session.terminal.rows);
|
|
6024
|
+
this._fitTerminal(session);
|
|
5521
6025
|
}
|
|
5522
6026
|
} catch (e) {
|
|
5523
6027
|
console.warn('[SSHIFT] Could not refit terminal on resize:', e.message);
|
|
@@ -5580,17 +6084,12 @@ class SSHIFTClient {
|
|
|
5580
6084
|
|
|
5581
6085
|
// Send initial resize
|
|
5582
6086
|
if (session.fitAddon) {
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
rows: session.terminal.rows
|
|
5590
|
-
});
|
|
5591
|
-
} catch (e) {
|
|
5592
|
-
console.warn('[SSHIFT] Could not fit terminal on connect:', e.message);
|
|
5593
|
-
}
|
|
6087
|
+
this._fitTerminal(session);
|
|
6088
|
+
this.socket.emit('ssh-resize', {
|
|
6089
|
+
sessionId: data.sessionId,
|
|
6090
|
+
cols: session.terminal.cols,
|
|
6091
|
+
rows: session.terminal.rows
|
|
6092
|
+
});
|
|
5594
6093
|
}
|
|
5595
6094
|
|
|
5596
6095
|
// Focus the terminal so user can type immediately
|
|
@@ -6044,48 +6543,43 @@ class SSHIFTClient {
|
|
|
6044
6543
|
// Only fit for controllers - non-controllers will receive resize sync
|
|
6045
6544
|
const session = this.sessions.get(sessionId);
|
|
6046
6545
|
if (session && session.terminal && session.fitAddon && session.isController) {
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
const container = document.getElementById(`terminal-${sessionId}`);
|
|
6058
|
-
if (wrapper && container) {
|
|
6059
|
-
void wrapper.offsetHeight;
|
|
6060
|
-
void container.offsetHeight;
|
|
6061
|
-
}
|
|
6062
|
-
|
|
6063
|
-
// Check if terminal needs resize (marked during layout changes)
|
|
6064
|
-
if (session.needsResize || session.terminal.cols === 0 || session.terminal.rows === 0) {
|
|
6065
|
-
console.log('[SSHIFT] Terminal needs resize, fitting now');
|
|
6066
|
-
session.needsResize = false;
|
|
6067
|
-
}
|
|
6068
|
-
|
|
6069
|
-
session.fitAddon.fit();
|
|
6070
|
-
console.log('[SSHIFT] Terminal fitted after tab switch, cols:', session.terminal.cols, 'rows:', session.terminal.rows);
|
|
6071
|
-
|
|
6072
|
-
// Focus the terminal so user can type
|
|
6073
|
-
if (session.terminal) {
|
|
6074
|
-
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
6075
|
-
session.mobileHandler._focusHiddenTextarea();
|
|
6076
|
-
} else {
|
|
6077
|
-
session.terminal.focus();
|
|
6546
|
+
// Use requestAnimationFrame to wait for the browser to finish
|
|
6547
|
+
// computing layout after the display:none -> display:flex change.
|
|
6548
|
+
// A second RAF ensures the paint is complete before we measure.
|
|
6549
|
+
requestAnimationFrame(() => {
|
|
6550
|
+
requestAnimationFrame(() => {
|
|
6551
|
+
// Restore font size for this session
|
|
6552
|
+
if (session.fontSize && session.terminal) {
|
|
6553
|
+
session.terminal.options.fontSize = session.fontSize;
|
|
6554
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
6555
|
+
console.log('[SSHIFT] Restored font size', session.fontSize, 'for session', sessionId);
|
|
6078
6556
|
}
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6557
|
+
|
|
6558
|
+
if (session.needsResize || session.terminal.cols === 0 || session.terminal.rows === 0) {
|
|
6559
|
+
console.log('[SSHIFT] Terminal needs resize, fitting now');
|
|
6560
|
+
session.needsResize = false;
|
|
6561
|
+
}
|
|
6562
|
+
|
|
6563
|
+
this._fitTerminal(session);
|
|
6564
|
+
|
|
6565
|
+
// Focus the terminal so user can type
|
|
6566
|
+
if (session.terminal) {
|
|
6567
|
+
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
6568
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
6569
|
+
} else {
|
|
6570
|
+
session.terminal.focus();
|
|
6571
|
+
}
|
|
6572
|
+
console.log('[SSHIFT] Terminal focused for session:', sessionId);
|
|
6573
|
+
}
|
|
6574
|
+
|
|
6575
|
+
// Request screen sync to ensure terminal is up-to-date
|
|
6576
|
+
// This is especially important for sticky sessions across different browsers
|
|
6577
|
+
if (session.connected && this.sticky) {
|
|
6578
|
+
console.log('[SSHIFT] Requesting screen sync for sticky session');
|
|
6579
|
+
this.requestScreenSync(sessionId);
|
|
6580
|
+
}
|
|
6581
|
+
});
|
|
6582
|
+
});
|
|
6089
6583
|
} else if (session && session.terminal) {
|
|
6090
6584
|
// For non-controllers, just focus the terminal and restore font size
|
|
6091
6585
|
if (session.fontSize) {
|
|
@@ -7759,6 +8253,7 @@ class SSHIFTClient {
|
|
|
7759
8253
|
|
|
7760
8254
|
openBookmarkModal(bookmark = null, folderId = null) {
|
|
7761
8255
|
document.getElementById('bookmarkForm').reset();
|
|
8256
|
+
this.clearKeyField('bookmarkPrivateKey', 'bookmarkKeyFormatBadge', 'bookmarkKeyClearBtn');
|
|
7762
8257
|
|
|
7763
8258
|
// Populate folder dropdown
|
|
7764
8259
|
const folderSelect = document.getElementById('bookmarkFolder');
|
|
@@ -7787,6 +8282,23 @@ class SSHIFTClient {
|
|
|
7787
8282
|
document.getElementById('bookmarkPassword').value = bookmark.password || '';
|
|
7788
8283
|
document.getElementById('bookmarkPrivateKey').value = bookmark.privateKey || '';
|
|
7789
8284
|
document.getElementById('bookmarkPassphrase').value = bookmark.passphrase || '';
|
|
8285
|
+
if (bookmark.privateKey) {
|
|
8286
|
+
const fmt = this.detectKeyFormatOffline(bookmark.privateKey);
|
|
8287
|
+
const badge = document.getElementById('bookmarkKeyFormatBadge');
|
|
8288
|
+
const clearBtn = document.getElementById('bookmarkKeyClearBtn');
|
|
8289
|
+
const formatLabels = {
|
|
8290
|
+
'openssh': 'OpenSSH', 'pem-rsa': 'PEM (RSA)', 'pem-ec': 'PEM (EC)',
|
|
8291
|
+
'pem-dsa': 'PEM (DSA)', 'pkcs8': 'PKCS8', 'pkcs8-encrypted': 'PKCS8 (Encrypted)',
|
|
8292
|
+
'ppk': 'PPK'
|
|
8293
|
+
};
|
|
8294
|
+
badge.textContent = formatLabels[fmt] || fmt;
|
|
8295
|
+
badge.className = 'key-format-badge';
|
|
8296
|
+
if (bookmark.privateKey.includes('ENCRYPTED') || fmt === 'pkcs8-encrypted') {
|
|
8297
|
+
badge.classList.add('format-warning');
|
|
8298
|
+
}
|
|
8299
|
+
badge.style.display = 'inline-flex';
|
|
8300
|
+
clearBtn.style.display = 'inline-flex';
|
|
8301
|
+
}
|
|
7790
8302
|
}
|
|
7791
8303
|
} else {
|
|
7792
8304
|
document.getElementById('bookmarkModalTitle').textContent = 'Add Bookmark';
|
|
@@ -8291,34 +8803,13 @@ class SSHIFTClient {
|
|
|
8291
8803
|
// Resize SSH terminals
|
|
8292
8804
|
this.sessions.forEach((session, sessionId) => {
|
|
8293
8805
|
if (session.terminal && session.fitAddon) {
|
|
8294
|
-
// Only fit if this client is the controller
|
|
8295
|
-
// Non-controllers will receive resize sync from the controller
|
|
8296
|
-
// This prevents resize feedback loops between multiple clients
|
|
8297
8806
|
if (session.isController) {
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
// Check if the terminal is visible (active tab)
|
|
8305
|
-
const isVisible = wrapper.classList.contains('active');
|
|
8306
|
-
|
|
8307
|
-
if (isVisible) {
|
|
8308
|
-
// Force reflow
|
|
8309
|
-
void container.offsetHeight;
|
|
8310
|
-
void wrapper.offsetHeight;
|
|
8311
|
-
|
|
8312
|
-
session.fitAddon.fit();
|
|
8313
|
-
console.log(`[SSHIFT] Terminal ${sessionId} resized, cols: ${session.terminal.cols}, rows: ${session.terminal.rows}`);
|
|
8314
|
-
} else {
|
|
8315
|
-
// Mark for resize when tab becomes active
|
|
8316
|
-
session.needsResize = true;
|
|
8317
|
-
console.log(`[SSHIFT] Terminal ${sessionId} not visible, marked for resize`);
|
|
8318
|
-
}
|
|
8319
|
-
}
|
|
8320
|
-
} catch (e) {
|
|
8321
|
-
console.warn(`[SSHIFT] Failed to resize terminal ${sessionId}:`, e.message);
|
|
8807
|
+
const wrapper = document.getElementById(`terminal-wrapper-${sessionId}`);
|
|
8808
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
8809
|
+
this._fitTerminal(session);
|
|
8810
|
+
} else if (wrapper) {
|
|
8811
|
+
session.needsResize = true;
|
|
8812
|
+
console.log(`[SSHIFT] Terminal ${sessionId} not visible, marked for resize`);
|
|
8322
8813
|
}
|
|
8323
8814
|
}
|
|
8324
8815
|
}
|
|
@@ -8327,25 +8818,11 @@ class SSHIFTClient {
|
|
|
8327
8818
|
// Resize SFTP terminals (no controller concept, always fit)
|
|
8328
8819
|
this.sftpSessions.forEach((session, sessionId) => {
|
|
8329
8820
|
if (session.terminal && session.fitAddon) {
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
8333
|
-
|
|
8334
|
-
|
|
8335
|
-
const isVisible = wrapper.classList.contains('active');
|
|
8336
|
-
|
|
8337
|
-
if (isVisible) {
|
|
8338
|
-
void container.offsetHeight;
|
|
8339
|
-
void wrapper.offsetHeight;
|
|
8340
|
-
|
|
8341
|
-
session.fitAddon.fit();
|
|
8342
|
-
console.log(`[SSHIFT] SFTP terminal ${sessionId} resized, cols: ${session.terminal.cols}, rows: ${session.terminal.rows}`);
|
|
8343
|
-
} else {
|
|
8344
|
-
session.needsResize = true;
|
|
8345
|
-
}
|
|
8346
|
-
}
|
|
8347
|
-
} catch (e) {
|
|
8348
|
-
console.warn(`[SSHIFT] Failed to resize SFTP terminal ${sessionId}:`, e.message);
|
|
8821
|
+
const wrapper = document.getElementById(`terminal-wrapper-${sessionId}`);
|
|
8822
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
8823
|
+
this._fitTerminal(session);
|
|
8824
|
+
} else if (wrapper) {
|
|
8825
|
+
session.needsResize = true;
|
|
8349
8826
|
}
|
|
8350
8827
|
}
|
|
8351
8828
|
});
|