@lethevimlet/sshift 0.3.1 → 0.4.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 +2 -2
- package/package.json +1 -1
- package/src/server/endpoints/rest/index.js +3 -0
- package/src/server/endpoints/rest/utils.js +36 -0
- package/src/server/services/sftp-manager.js +3 -1
- package/src/server/services/ssh-manager.js +3 -4
- package/src/server/utils/key-converter.js +363 -0
- package/src/webapp/css/style.css +83 -5
- package/src/webapp/index.html +22 -2
- package/src/webapp/js/app.js +368 -181
- package/src/webapp/js/mobile-terminal.js +65 -36
package/src/webapp/js/app.js
CHANGED
|
@@ -573,6 +573,56 @@ class SSHIFTClient {
|
|
|
573
573
|
// Don't persist - font size is session-only
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
+
// Robust terminal fit with validation and retry.
|
|
577
|
+
// Sometimes fit() is called before the browser finishes laying out a
|
|
578
|
+
// container that just became visible (display:none -> display:flex).
|
|
579
|
+
// When that happens proposeDimensions() reads stale or zero width/height
|
|
580
|
+
// and the terminal ends up with far fewer cols than the container can hold
|
|
581
|
+
// (the "narrow column" bug). This wrapper validates the result and
|
|
582
|
+
// retries on the next animation frame when it detects a bad fit.
|
|
583
|
+
_fitTerminal(session, retryCount = 0) {
|
|
584
|
+
if (!session || !session.fitAddon || !session.terminal) return false;
|
|
585
|
+
|
|
586
|
+
const wrapper = document.getElementById(`terminal-wrapper-${session.id}`);
|
|
587
|
+
const container = document.getElementById(`terminal-${session.id}`);
|
|
588
|
+
if (!wrapper || !container) return false;
|
|
589
|
+
|
|
590
|
+
if (!wrapper.classList.contains('active')) {
|
|
591
|
+
session.needsResize = true;
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
void container.offsetHeight;
|
|
596
|
+
void wrapper.offsetHeight;
|
|
597
|
+
|
|
598
|
+
try {
|
|
599
|
+
session.fitAddon.fit();
|
|
600
|
+
} catch (e) {
|
|
601
|
+
console.warn('[SSHIFT] Could not fit terminal:', e.message);
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const terminal = session.terminal;
|
|
606
|
+
const core = terminal._core;
|
|
607
|
+
if (core) {
|
|
608
|
+
const cellWidth = core._renderService?.dimensions?.css?.cell?.width || 0;
|
|
609
|
+
const containerWidth = container.getBoundingClientRect().width;
|
|
610
|
+
if (cellWidth > 0 && containerWidth > 80) {
|
|
611
|
+
const expectedCols = Math.floor(containerWidth / cellWidth);
|
|
612
|
+
if (terminal.cols < expectedCols * 0.5 && retryCount < 3) {
|
|
613
|
+
console.warn(`[SSHIFT] Terminal fit seems incorrect (cols: ${terminal.cols}, expected: ~${expectedCols}, container: ${containerWidth}px), retrying (attempt ${retryCount + 1})...`);
|
|
614
|
+
requestAnimationFrame(() => {
|
|
615
|
+
this._fitTerminal(session, retryCount + 1);
|
|
616
|
+
});
|
|
617
|
+
return false;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
console.log('[SSHIFT] Terminal fitted, cols:', terminal.cols, 'rows:', terminal.rows);
|
|
623
|
+
return true;
|
|
624
|
+
}
|
|
625
|
+
|
|
576
626
|
// Set font size for a specific session
|
|
577
627
|
setSessionFontSize(sessionId, size) {
|
|
578
628
|
const session = this.sessions.get(sessionId);
|
|
@@ -591,9 +641,8 @@ class SSHIFTClient {
|
|
|
591
641
|
session.terminal.options.fontSize = size;
|
|
592
642
|
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
593
643
|
|
|
594
|
-
// Refit if this client is the controller
|
|
595
644
|
if (session.fitAddon && session.isController) {
|
|
596
|
-
|
|
645
|
+
this._fitTerminal(session);
|
|
597
646
|
}
|
|
598
647
|
|
|
599
648
|
// Refresh mobile selection overlay after font change
|
|
@@ -620,26 +669,21 @@ class SSHIFTClient {
|
|
|
620
669
|
if (session.terminal) {
|
|
621
670
|
session.terminal.options.fontSize = size;
|
|
622
671
|
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
672
|
if (session.fitAddon && session.isController) {
|
|
626
|
-
|
|
673
|
+
this._fitTerminal(session);
|
|
627
674
|
}
|
|
628
|
-
// Refresh mobile selection overlay
|
|
629
675
|
if (session.mobileHandler) {
|
|
630
676
|
session.mobileHandler.refreshSelection();
|
|
631
677
|
}
|
|
632
678
|
}
|
|
633
679
|
});
|
|
634
680
|
|
|
635
|
-
// Update all active SFTP terminals
|
|
636
681
|
this.sftpSessions.forEach((session) => {
|
|
637
682
|
if (session.terminal) {
|
|
638
683
|
session.terminal.options.fontSize = size;
|
|
639
684
|
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
640
|
-
// SFTP sessions don't have controller concept, always fit
|
|
641
685
|
if (session.fitAddon) {
|
|
642
|
-
|
|
686
|
+
this._fitTerminal(session);
|
|
643
687
|
}
|
|
644
688
|
}
|
|
645
689
|
});
|
|
@@ -1185,50 +1229,26 @@ class SSHIFTClient {
|
|
|
1185
1229
|
refitAllTerminals() {
|
|
1186
1230
|
console.log('[SSHIFT] Refitting all terminals');
|
|
1187
1231
|
|
|
1188
|
-
// Multiple attempts with increasing delays to ensure DOM is settled
|
|
1189
1232
|
const delays = [50, 150, 300, 500];
|
|
1190
1233
|
|
|
1191
1234
|
delays.forEach((delay, index) => {
|
|
1192
1235
|
setTimeout(() => {
|
|
1193
1236
|
console.log(`[SSHIFT] Refit attempt ${index + 1}/${delays.length}`);
|
|
1194
1237
|
|
|
1195
|
-
// Refit SSH terminals
|
|
1196
1238
|
this.sessions.forEach((session, sessionId) => {
|
|
1197
1239
|
if (session.terminal && session.fitAddon && session.isController) {
|
|
1198
1240
|
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
|
-
}
|
|
1241
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
1242
|
+
this._fitTerminal(session);
|
|
1212
1243
|
}
|
|
1213
1244
|
}
|
|
1214
1245
|
});
|
|
1215
1246
|
|
|
1216
|
-
// Refit SFTP terminals
|
|
1217
1247
|
this.sftpSessions.forEach((session, sessionId) => {
|
|
1218
1248
|
if (session.terminal && session.fitAddon) {
|
|
1219
1249
|
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
|
-
}
|
|
1250
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
1251
|
+
this._fitTerminal(session);
|
|
1232
1252
|
}
|
|
1233
1253
|
}
|
|
1234
1254
|
});
|
|
@@ -1781,7 +1801,7 @@ class SSHIFTClient {
|
|
|
1781
1801
|
sftpSession.terminal.refresh(0, sftpSession.terminal.rows - 1);
|
|
1782
1802
|
|
|
1783
1803
|
if (sftpSession.fitAddon) {
|
|
1784
|
-
|
|
1804
|
+
this._fitTerminal(sftpSession);
|
|
1785
1805
|
}
|
|
1786
1806
|
|
|
1787
1807
|
console.log('[SSHIFT] SFTP font size set to', sftpSession.fontSize, 'for session', activeSessionId);
|
|
@@ -2256,28 +2276,12 @@ class SSHIFTClient {
|
|
|
2256
2276
|
}
|
|
2257
2277
|
|
|
2258
2278
|
refitActiveTerminal() {
|
|
2259
|
-
// Refit the active terminal to fill the available space
|
|
2260
|
-
// Only fit for controllers - non-controllers will receive resize sync
|
|
2261
2279
|
if (this.activeSessionId) {
|
|
2262
2280
|
const session = this.sessions.get(this.activeSessionId);
|
|
2263
2281
|
if (session && session.fitAddon && session.terminal && session.isController) {
|
|
2264
|
-
// Small delay to allow CSS transitions to complete
|
|
2265
2282
|
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
|
|
2283
|
+
this._fitTerminal(session);
|
|
2284
|
+
}, 350);
|
|
2281
2285
|
}
|
|
2282
2286
|
}
|
|
2283
2287
|
}
|
|
@@ -3160,22 +3164,31 @@ class SSHIFTClient {
|
|
|
3160
3164
|
console.log('[SSHIFT] Control taken for session:', data.sessionId, 'by', data.controllerSocket);
|
|
3161
3165
|
const session = this.sessions.get(data.sessionId);
|
|
3162
3166
|
if (session) {
|
|
3163
|
-
// Update controller status
|
|
3164
3167
|
const wasController = session.isController;
|
|
3165
3168
|
session.isController = data.controllerSocket === this.socket.id;
|
|
3166
3169
|
session.controllerSocket = data.controllerSocket;
|
|
3167
3170
|
|
|
3168
|
-
// Update overlay visibility
|
|
3169
3171
|
this.updateControlOverlay(data.sessionId);
|
|
3170
3172
|
|
|
3171
|
-
// Show appropriate toast
|
|
3172
3173
|
if (session.isController && !wasController) {
|
|
3173
|
-
//
|
|
3174
|
-
|
|
3175
|
-
|
|
3174
|
+
// We just became the controller — resize to our container
|
|
3175
|
+
if (session.terminal && session.fitAddon) {
|
|
3176
|
+
session.isResyncing = true;
|
|
3177
|
+
if (session.resizeTimeout) {
|
|
3178
|
+
clearTimeout(session.resizeTimeout);
|
|
3179
|
+
session.resizeTimeout = null;
|
|
3180
|
+
}
|
|
3181
|
+
this._fitTerminal(session);
|
|
3182
|
+
session.isResyncing = false;
|
|
3183
|
+
this.socket.emit('ssh-resize', {
|
|
3184
|
+
sessionId: data.sessionId,
|
|
3185
|
+
cols: session.terminal.cols,
|
|
3186
|
+
rows: session.terminal.rows
|
|
3187
|
+
});
|
|
3188
|
+
console.log('[SSHIFT] Resized terminal after becoming controller:', session.terminal.cols, 'x', session.terminal.rows);
|
|
3189
|
+
}
|
|
3176
3190
|
this.showToast('You are now in control (previous controller left)', 'info');
|
|
3177
3191
|
} else if (!session.isController) {
|
|
3178
|
-
// Another client took control
|
|
3179
3192
|
this.showToast('Another device took control', 'info');
|
|
3180
3193
|
}
|
|
3181
3194
|
}
|
|
@@ -3217,7 +3230,8 @@ class SSHIFTClient {
|
|
|
3217
3230
|
}
|
|
3218
3231
|
|
|
3219
3232
|
// Fit the terminal to our container first
|
|
3220
|
-
session.
|
|
3233
|
+
session.isResyncing = true;
|
|
3234
|
+
this._fitTerminal(session);
|
|
3221
3235
|
|
|
3222
3236
|
// Clear the resyncing flag before emitting resize
|
|
3223
3237
|
session.isResyncing = false;
|
|
@@ -3594,6 +3608,28 @@ class SSHIFTClient {
|
|
|
3594
3608
|
this.togglePasswordVisibility();
|
|
3595
3609
|
});
|
|
3596
3610
|
|
|
3611
|
+
// Private key upload - connection modal
|
|
3612
|
+
document.getElementById('connKeyUploadBtn').addEventListener('click', () => {
|
|
3613
|
+
document.getElementById('connKeyFileInput').click();
|
|
3614
|
+
});
|
|
3615
|
+
document.getElementById('connKeyFileInput').addEventListener('change', (e) => {
|
|
3616
|
+
this.handleKeyFileUpload(e, 'connPrivateKey', 'connKeyFormatBadge', 'connKeyClearBtn');
|
|
3617
|
+
});
|
|
3618
|
+
document.getElementById('connKeyClearBtn').addEventListener('click', () => {
|
|
3619
|
+
this.clearKeyField('connPrivateKey', 'connKeyFormatBadge', 'connKeyClearBtn');
|
|
3620
|
+
});
|
|
3621
|
+
|
|
3622
|
+
// Private key upload - bookmark modal
|
|
3623
|
+
document.getElementById('bookmarkKeyUploadBtn').addEventListener('click', () => {
|
|
3624
|
+
document.getElementById('bookmarkKeyFileInput').click();
|
|
3625
|
+
});
|
|
3626
|
+
document.getElementById('bookmarkKeyFileInput').addEventListener('change', (e) => {
|
|
3627
|
+
this.handleKeyFileUpload(e, 'bookmarkPrivateKey', 'bookmarkKeyFormatBadge', 'bookmarkKeyClearBtn');
|
|
3628
|
+
});
|
|
3629
|
+
document.getElementById('bookmarkKeyClearBtn').addEventListener('click', () => {
|
|
3630
|
+
this.clearKeyField('bookmarkPrivateKey', 'bookmarkKeyFormatBadge', 'bookmarkKeyClearBtn');
|
|
3631
|
+
});
|
|
3632
|
+
|
|
3597
3633
|
// Bookmark modal
|
|
3598
3634
|
document.getElementById('addBookmarkBtn').addEventListener('click', () => {
|
|
3599
3635
|
this.openBookmarkModal();
|
|
@@ -3818,11 +3854,7 @@ class SSHIFTClient {
|
|
|
3818
3854
|
setTimeout(() => {
|
|
3819
3855
|
this.sessions.forEach(session => {
|
|
3820
3856
|
if (session.terminal && session.fitAddon && session.isController) {
|
|
3821
|
-
|
|
3822
|
-
session.fitAddon.fit();
|
|
3823
|
-
} catch (e) {
|
|
3824
|
-
// Ignore resize errors
|
|
3825
|
-
}
|
|
3857
|
+
this._fitTerminal(session);
|
|
3826
3858
|
}
|
|
3827
3859
|
});
|
|
3828
3860
|
}, 300);
|
|
@@ -4609,9 +4641,199 @@ class SSHIFTClient {
|
|
|
4609
4641
|
type === 'ssh' ? 'New SSH Connection' : 'New SFTP Connection';
|
|
4610
4642
|
document.getElementById('connectionForm').reset();
|
|
4611
4643
|
document.getElementById('connPort').value = '22';
|
|
4644
|
+
this.clearKeyField('connPrivateKey', 'connKeyFormatBadge', 'connKeyClearBtn');
|
|
4612
4645
|
this.openModal('connectionModal');
|
|
4613
4646
|
}
|
|
4614
4647
|
|
|
4648
|
+
async handleKeyFileUpload(event, textareaId, badgeId, clearBtnId) {
|
|
4649
|
+
const file = event.target.files[0];
|
|
4650
|
+
if (!file) return;
|
|
4651
|
+
|
|
4652
|
+
const badge = document.getElementById(badgeId);
|
|
4653
|
+
const clearBtn = document.getElementById(clearBtnId);
|
|
4654
|
+
const textarea = document.getElementById(textareaId);
|
|
4655
|
+
|
|
4656
|
+
badge.style.display = 'inline-flex';
|
|
4657
|
+
badge.textContent = 'Reading...';
|
|
4658
|
+
badge.className = 'key-format-badge';
|
|
4659
|
+
|
|
4660
|
+
try {
|
|
4661
|
+
const content = await file.text();
|
|
4662
|
+
if (!content || !content.trim()) {
|
|
4663
|
+
badge.textContent = 'Empty file';
|
|
4664
|
+
badge.classList.add('format-error');
|
|
4665
|
+
badge.style.display = 'inline-flex';
|
|
4666
|
+
return;
|
|
4667
|
+
}
|
|
4668
|
+
|
|
4669
|
+
const detectResult = await this.detectAndConvertKey(content);
|
|
4670
|
+
if (detectResult.error) {
|
|
4671
|
+
badge.textContent = detectResult.format || 'Error';
|
|
4672
|
+
badge.classList.add('format-error');
|
|
4673
|
+
badge.style.display = 'inline-flex';
|
|
4674
|
+
textarea.value = content;
|
|
4675
|
+
clearBtn.style.display = 'inline-flex';
|
|
4676
|
+
this.showToast(detectResult.error, 'error');
|
|
4677
|
+
return;
|
|
4678
|
+
}
|
|
4679
|
+
|
|
4680
|
+
textarea.value = detectResult.key;
|
|
4681
|
+
|
|
4682
|
+
let formatLabel = detectResult.format;
|
|
4683
|
+
if (detectResult.wasConverted) {
|
|
4684
|
+
formatLabel = `PPK → OpenSSH`;
|
|
4685
|
+
} else if (detectResult.format === 'openssh') {
|
|
4686
|
+
formatLabel = 'OpenSSH';
|
|
4687
|
+
} else if (detectResult.format === 'pem-rsa') {
|
|
4688
|
+
formatLabel = 'PEM (RSA)';
|
|
4689
|
+
} else if (detectResult.format === 'pem-ec') {
|
|
4690
|
+
formatLabel = 'PEM (EC)';
|
|
4691
|
+
} else if (detectResult.format === 'pem-dsa') {
|
|
4692
|
+
formatLabel = 'PEM (DSA)';
|
|
4693
|
+
} else if (detectResult.format === 'pkcs8') {
|
|
4694
|
+
formatLabel = 'PKCS8';
|
|
4695
|
+
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
4696
|
+
formatLabel = 'PKCS8 (Encrypted)';
|
|
4697
|
+
}
|
|
4698
|
+
|
|
4699
|
+
badge.textContent = formatLabel;
|
|
4700
|
+
badge.className = 'key-format-badge';
|
|
4701
|
+
if (detectResult.encrypted) {
|
|
4702
|
+
badge.classList.add('format-warning');
|
|
4703
|
+
}
|
|
4704
|
+
badge.style.display = 'inline-flex';
|
|
4705
|
+
clearBtn.style.display = 'inline-flex';
|
|
4706
|
+
|
|
4707
|
+
if (detectResult.wasConverted) {
|
|
4708
|
+
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
4709
|
+
} else if (detectResult.format === 'openssh') {
|
|
4710
|
+
this.showToast('OpenSSH key loaded', 'success');
|
|
4711
|
+
} else if (detectResult.format === 'pem-rsa' || detectResult.format === 'pem-ec' || detectResult.format === 'pem-dsa') {
|
|
4712
|
+
this.showToast('PEM key loaded', 'success');
|
|
4713
|
+
} else if (detectResult.format === 'pkcs8') {
|
|
4714
|
+
this.showToast('PKCS8 key loaded', 'success');
|
|
4715
|
+
} else if (detectResult.format === 'pkcs8-encrypted') {
|
|
4716
|
+
this.showToast('Encrypted PKCS8 key loaded - passphrase required', 'info');
|
|
4717
|
+
}
|
|
4718
|
+
} catch (err) {
|
|
4719
|
+
badge.textContent = 'Error';
|
|
4720
|
+
badge.classList.add('format-error');
|
|
4721
|
+
badge.style.display = 'inline-flex';
|
|
4722
|
+
this.showToast('Failed to read key file: ' + err.message, 'error');
|
|
4723
|
+
}
|
|
4724
|
+
|
|
4725
|
+
event.target.value = '';
|
|
4726
|
+
}
|
|
4727
|
+
|
|
4728
|
+
async detectAndConvertKey(content) {
|
|
4729
|
+
try {
|
|
4730
|
+
const response = await fetch('/api/utils/detect-key', {
|
|
4731
|
+
method: 'POST',
|
|
4732
|
+
headers: { 'Content-Type': 'application/json' },
|
|
4733
|
+
body: JSON.stringify({ content })
|
|
4734
|
+
});
|
|
4735
|
+
|
|
4736
|
+
if (!response.ok) {
|
|
4737
|
+
return { format: 'unknown', key: content, error: 'Failed to detect key format' };
|
|
4738
|
+
}
|
|
4739
|
+
|
|
4740
|
+
const info = await response.json();
|
|
4741
|
+
|
|
4742
|
+
if (info.format === 'ppk') {
|
|
4743
|
+
try {
|
|
4744
|
+
const convertResponse = await fetch('/api/utils/convert-key', {
|
|
4745
|
+
method: 'POST',
|
|
4746
|
+
headers: { 'Content-Type': 'application/json' },
|
|
4747
|
+
body: JSON.stringify({ content })
|
|
4748
|
+
});
|
|
4749
|
+
|
|
4750
|
+
if (!convertResponse.ok) {
|
|
4751
|
+
const errData = await convertResponse.json().catch(() => ({}));
|
|
4752
|
+
return {
|
|
4753
|
+
format: 'PPK',
|
|
4754
|
+
key: content,
|
|
4755
|
+
encrypted: info.encrypted,
|
|
4756
|
+
wasConverted: false,
|
|
4757
|
+
error: errData.error || 'Failed to convert PPK key. Try converting with PuTTYgen first.'
|
|
4758
|
+
};
|
|
4759
|
+
}
|
|
4760
|
+
|
|
4761
|
+
const result = await convertResponse.json();
|
|
4762
|
+
return {
|
|
4763
|
+
format: 'openssh',
|
|
4764
|
+
key: result.key,
|
|
4765
|
+
encrypted: false,
|
|
4766
|
+
wasConverted: true
|
|
4767
|
+
};
|
|
4768
|
+
} catch (e) {
|
|
4769
|
+
return {
|
|
4770
|
+
format: 'PPK',
|
|
4771
|
+
key: content,
|
|
4772
|
+
encrypted: info.encrypted,
|
|
4773
|
+
wasConverted: false,
|
|
4774
|
+
error: 'Network error converting PPK key: ' + e.message
|
|
4775
|
+
};
|
|
4776
|
+
}
|
|
4777
|
+
}
|
|
4778
|
+
|
|
4779
|
+
if (info.format === 'unknown') {
|
|
4780
|
+
if (content.includes('BEGIN')) {
|
|
4781
|
+
return { format: 'unknown', key: content, error: 'Unrecognized key format. The SSH library (ssh2) supports OpenSSH, PEM, and PKCS8 formats.' };
|
|
4782
|
+
}
|
|
4783
|
+
return { format: 'unknown', key: content, error: 'Unrecognized key format. Please upload a valid SSH private key file.' };
|
|
4784
|
+
}
|
|
4785
|
+
|
|
4786
|
+
if (info.format === 'pkcs8-encrypted') {
|
|
4787
|
+
return {
|
|
4788
|
+
format: info.format,
|
|
4789
|
+
key: content,
|
|
4790
|
+
encrypted: true
|
|
4791
|
+
};
|
|
4792
|
+
}
|
|
4793
|
+
|
|
4794
|
+
return {
|
|
4795
|
+
format: info.format,
|
|
4796
|
+
key: content,
|
|
4797
|
+
encrypted: info.encrypted || false
|
|
4798
|
+
};
|
|
4799
|
+
} catch (e) {
|
|
4800
|
+
if (content.includes('PuTTY-user-key-file')) {
|
|
4801
|
+
return {
|
|
4802
|
+
format: 'PPK',
|
|
4803
|
+
key: content,
|
|
4804
|
+
encrypted: content.includes('Encryption:') && !content.includes('Encryption: none'),
|
|
4805
|
+
wasConverted: false,
|
|
4806
|
+
error: 'Cannot convert PPK offline. Please try again when connected to the server, or convert using PuTTYgen.'
|
|
4807
|
+
};
|
|
4808
|
+
}
|
|
4809
|
+
return {
|
|
4810
|
+
format: this.detectKeyFormatOffline(content),
|
|
4811
|
+
key: content,
|
|
4812
|
+
encrypted: content.includes('ENCRYPTED') || (content.includes('Encryption:') && !content.includes('Encryption: none'))
|
|
4813
|
+
};
|
|
4814
|
+
}
|
|
4815
|
+
}
|
|
4816
|
+
|
|
4817
|
+
detectKeyFormatOffline(content) {
|
|
4818
|
+
if (content.includes('BEGIN OPENSSH PRIVATE KEY')) return 'openssh';
|
|
4819
|
+
if (content.includes('BEGIN RSA PRIVATE KEY')) return 'pem-rsa';
|
|
4820
|
+
if (content.includes('BEGIN EC PRIVATE KEY')) return 'pem-ec';
|
|
4821
|
+
if (content.includes('BEGIN DSA PRIVATE KEY')) return 'pem-dsa';
|
|
4822
|
+
if (content.includes('BEGIN PRIVATE KEY')) return 'pkcs8';
|
|
4823
|
+
if (content.includes('BEGIN ENCRYPTED PRIVATE KEY')) return 'pkcs8-encrypted';
|
|
4824
|
+
if (content.includes('PuTTY-user-key-file')) return 'ppk';
|
|
4825
|
+
return 'unknown';
|
|
4826
|
+
}
|
|
4827
|
+
|
|
4828
|
+
clearKeyField(textareaId, badgeId, clearBtnId) {
|
|
4829
|
+
document.getElementById(textareaId).value = '';
|
|
4830
|
+
const badge = document.getElementById(badgeId);
|
|
4831
|
+
badge.style.display = 'none';
|
|
4832
|
+
badge.textContent = '';
|
|
4833
|
+
badge.className = 'key-format-badge';
|
|
4834
|
+
document.getElementById(clearBtnId).style.display = 'none';
|
|
4835
|
+
}
|
|
4836
|
+
|
|
4615
4837
|
togglePasswordVisibility() {
|
|
4616
4838
|
const input = document.getElementById('connPassword');
|
|
4617
4839
|
const icon = document.querySelector('#togglePassword i');
|
|
@@ -4671,13 +4893,11 @@ class SSHIFTClient {
|
|
|
4671
4893
|
|
|
4672
4894
|
// Save bookmark if requested
|
|
4673
4895
|
if (saveBookmark) {
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
type
|
|
4680
|
-
});
|
|
4896
|
+
const bookmarkData = { name, host, port, username, type };
|
|
4897
|
+
if (password) bookmarkData.password = password;
|
|
4898
|
+
if (privateKey) bookmarkData.privateKey = privateKey;
|
|
4899
|
+
if (passphrase) bookmarkData.passphrase = passphrase;
|
|
4900
|
+
this.addBookmark(bookmarkData);
|
|
4681
4901
|
}
|
|
4682
4902
|
|
|
4683
4903
|
// Show connecting status
|
|
@@ -5505,19 +5725,13 @@ class SSHIFTClient {
|
|
|
5505
5725
|
// Only fit if this is the controller and terminal is visible
|
|
5506
5726
|
if (session.isController && session.terminal && wrapper.classList.contains('active')) {
|
|
5507
5727
|
try {
|
|
5508
|
-
// Debounce the fit calls to avoid performance issues
|
|
5509
5728
|
if (session.resizeTimeout) {
|
|
5510
5729
|
clearTimeout(session.resizeTimeout);
|
|
5511
5730
|
}
|
|
5512
5731
|
session.resizeTimeout = setTimeout(() => {
|
|
5513
5732
|
try {
|
|
5514
5733
|
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);
|
|
5734
|
+
this._fitTerminal(session);
|
|
5521
5735
|
}
|
|
5522
5736
|
} catch (e) {
|
|
5523
5737
|
console.warn('[SSHIFT] Could not refit terminal on resize:', e.message);
|
|
@@ -5580,17 +5794,12 @@ class SSHIFTClient {
|
|
|
5580
5794
|
|
|
5581
5795
|
// Send initial resize
|
|
5582
5796
|
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
|
-
}
|
|
5797
|
+
this._fitTerminal(session);
|
|
5798
|
+
this.socket.emit('ssh-resize', {
|
|
5799
|
+
sessionId: data.sessionId,
|
|
5800
|
+
cols: session.terminal.cols,
|
|
5801
|
+
rows: session.terminal.rows
|
|
5802
|
+
});
|
|
5594
5803
|
}
|
|
5595
5804
|
|
|
5596
5805
|
// Focus the terminal so user can type immediately
|
|
@@ -6044,48 +6253,43 @@ class SSHIFTClient {
|
|
|
6044
6253
|
// Only fit for controllers - non-controllers will receive resize sync
|
|
6045
6254
|
const session = this.sessions.get(sessionId);
|
|
6046
6255
|
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();
|
|
6256
|
+
// Use requestAnimationFrame to wait for the browser to finish
|
|
6257
|
+
// computing layout after the display:none -> display:flex change.
|
|
6258
|
+
// A second RAF ensures the paint is complete before we measure.
|
|
6259
|
+
requestAnimationFrame(() => {
|
|
6260
|
+
requestAnimationFrame(() => {
|
|
6261
|
+
// Restore font size for this session
|
|
6262
|
+
if (session.fontSize && session.terminal) {
|
|
6263
|
+
session.terminal.options.fontSize = session.fontSize;
|
|
6264
|
+
session.terminal.refresh(0, session.terminal.rows - 1);
|
|
6265
|
+
console.log('[SSHIFT] Restored font size', session.fontSize, 'for session', sessionId);
|
|
6078
6266
|
}
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6267
|
+
|
|
6268
|
+
if (session.needsResize || session.terminal.cols === 0 || session.terminal.rows === 0) {
|
|
6269
|
+
console.log('[SSHIFT] Terminal needs resize, fitting now');
|
|
6270
|
+
session.needsResize = false;
|
|
6271
|
+
}
|
|
6272
|
+
|
|
6273
|
+
this._fitTerminal(session);
|
|
6274
|
+
|
|
6275
|
+
// Focus the terminal so user can type
|
|
6276
|
+
if (session.terminal) {
|
|
6277
|
+
if (this.isMobile && session.mobileHandler && session.mobileHandler.hiddenTextarea) {
|
|
6278
|
+
session.mobileHandler._focusHiddenTextarea();
|
|
6279
|
+
} else {
|
|
6280
|
+
session.terminal.focus();
|
|
6281
|
+
}
|
|
6282
|
+
console.log('[SSHIFT] Terminal focused for session:', sessionId);
|
|
6283
|
+
}
|
|
6284
|
+
|
|
6285
|
+
// Request screen sync to ensure terminal is up-to-date
|
|
6286
|
+
// This is especially important for sticky sessions across different browsers
|
|
6287
|
+
if (session.connected && this.sticky) {
|
|
6288
|
+
console.log('[SSHIFT] Requesting screen sync for sticky session');
|
|
6289
|
+
this.requestScreenSync(sessionId);
|
|
6290
|
+
}
|
|
6291
|
+
});
|
|
6292
|
+
});
|
|
6089
6293
|
} else if (session && session.terminal) {
|
|
6090
6294
|
// For non-controllers, just focus the terminal and restore font size
|
|
6091
6295
|
if (session.fontSize) {
|
|
@@ -7759,6 +7963,7 @@ class SSHIFTClient {
|
|
|
7759
7963
|
|
|
7760
7964
|
openBookmarkModal(bookmark = null, folderId = null) {
|
|
7761
7965
|
document.getElementById('bookmarkForm').reset();
|
|
7966
|
+
this.clearKeyField('bookmarkPrivateKey', 'bookmarkKeyFormatBadge', 'bookmarkKeyClearBtn');
|
|
7762
7967
|
|
|
7763
7968
|
// Populate folder dropdown
|
|
7764
7969
|
const folderSelect = document.getElementById('bookmarkFolder');
|
|
@@ -7787,6 +7992,23 @@ class SSHIFTClient {
|
|
|
7787
7992
|
document.getElementById('bookmarkPassword').value = bookmark.password || '';
|
|
7788
7993
|
document.getElementById('bookmarkPrivateKey').value = bookmark.privateKey || '';
|
|
7789
7994
|
document.getElementById('bookmarkPassphrase').value = bookmark.passphrase || '';
|
|
7995
|
+
if (bookmark.privateKey) {
|
|
7996
|
+
const fmt = this.detectKeyFormatOffline(bookmark.privateKey);
|
|
7997
|
+
const badge = document.getElementById('bookmarkKeyFormatBadge');
|
|
7998
|
+
const clearBtn = document.getElementById('bookmarkKeyClearBtn');
|
|
7999
|
+
const formatLabels = {
|
|
8000
|
+
'openssh': 'OpenSSH', 'pem-rsa': 'PEM (RSA)', 'pem-ec': 'PEM (EC)',
|
|
8001
|
+
'pem-dsa': 'PEM (DSA)', 'pkcs8': 'PKCS8', 'pkcs8-encrypted': 'PKCS8 (Encrypted)',
|
|
8002
|
+
'ppk': 'PPK'
|
|
8003
|
+
};
|
|
8004
|
+
badge.textContent = formatLabels[fmt] || fmt;
|
|
8005
|
+
badge.className = 'key-format-badge';
|
|
8006
|
+
if (bookmark.privateKey.includes('ENCRYPTED') || fmt === 'pkcs8-encrypted') {
|
|
8007
|
+
badge.classList.add('format-warning');
|
|
8008
|
+
}
|
|
8009
|
+
badge.style.display = 'inline-flex';
|
|
8010
|
+
clearBtn.style.display = 'inline-flex';
|
|
8011
|
+
}
|
|
7790
8012
|
}
|
|
7791
8013
|
} else {
|
|
7792
8014
|
document.getElementById('bookmarkModalTitle').textContent = 'Add Bookmark';
|
|
@@ -8291,34 +8513,13 @@ class SSHIFTClient {
|
|
|
8291
8513
|
// Resize SSH terminals
|
|
8292
8514
|
this.sessions.forEach((session, sessionId) => {
|
|
8293
8515
|
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
8516
|
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);
|
|
8517
|
+
const wrapper = document.getElementById(`terminal-wrapper-${sessionId}`);
|
|
8518
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
8519
|
+
this._fitTerminal(session);
|
|
8520
|
+
} else if (wrapper) {
|
|
8521
|
+
session.needsResize = true;
|
|
8522
|
+
console.log(`[SSHIFT] Terminal ${sessionId} not visible, marked for resize`);
|
|
8322
8523
|
}
|
|
8323
8524
|
}
|
|
8324
8525
|
}
|
|
@@ -8327,25 +8528,11 @@ class SSHIFTClient {
|
|
|
8327
8528
|
// Resize SFTP terminals (no controller concept, always fit)
|
|
8328
8529
|
this.sftpSessions.forEach((session, sessionId) => {
|
|
8329
8530
|
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);
|
|
8531
|
+
const wrapper = document.getElementById(`terminal-wrapper-${sessionId}`);
|
|
8532
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
8533
|
+
this._fitTerminal(session);
|
|
8534
|
+
} else if (wrapper) {
|
|
8535
|
+
session.needsResize = true;
|
|
8349
8536
|
}
|
|
8350
8537
|
}
|
|
8351
8538
|
});
|