@lethevimlet/sshift 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/server/endpoints/rest/utils.js +2 -2
- package/src/server/services/sftp-manager.js +20 -13
- package/src/server/services/ssh-manager.js +20 -13
- package/src/server/utils/key-converter.js +42 -13
- package/src/webapp/css/style.css +3 -0
- package/src/webapp/js/app.js +71 -21
- package/src/webapp/js/mobile-terminal.js +37 -2
package/package.json
CHANGED
|
@@ -15,14 +15,14 @@ function registerUtilsEndpoints(app, io) {
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
app.post('/api/utils/convert-key', async (req, res) => {
|
|
18
|
-
const { content } = req.body;
|
|
18
|
+
const { content, passphrase } = req.body;
|
|
19
19
|
if (!content || !content.trim()) {
|
|
20
20
|
return res.status(400).json({ error: 'No key content provided' });
|
|
21
21
|
}
|
|
22
22
|
const info = detectKeyFormat(content);
|
|
23
23
|
if (info.format === 'ppk') {
|
|
24
24
|
try {
|
|
25
|
-
const converted = await convertPPKToOpenSSH(content);
|
|
25
|
+
const converted = await convertPPKToOpenSSH(content, passphrase);
|
|
26
26
|
res.json({ success: true, key: converted, format: 'openssh' });
|
|
27
27
|
} catch (e) {
|
|
28
28
|
res.status(400).json({ error: e.message });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { Client } = require('ssh2');
|
|
2
|
+
const { convertKeyIfNeeded } = require('../utils/key-converter');
|
|
2
3
|
|
|
3
4
|
class SFTPManager {
|
|
4
5
|
constructor() {
|
|
@@ -7,7 +8,23 @@ class SFTPManager {
|
|
|
7
8
|
this.nextUploadId = 1;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
connect(socket, options) {
|
|
11
|
+
async connect(socket, options) {
|
|
12
|
+
// Pre-process private key (auto-convert PPK to OpenSSH format)
|
|
13
|
+
if (options.privateKey && options.privateKey.length > 0) {
|
|
14
|
+
try {
|
|
15
|
+
let keyContent = options.privateKey;
|
|
16
|
+
if (!keyContent.includes('BEGIN')) {
|
|
17
|
+
keyContent = Buffer.from(keyContent, 'base64').toString('utf8');
|
|
18
|
+
}
|
|
19
|
+
options = {
|
|
20
|
+
...options,
|
|
21
|
+
privateKey: await convertKeyIfNeeded(keyContent, options.passphrase)
|
|
22
|
+
};
|
|
23
|
+
} catch (e) {
|
|
24
|
+
console.error('[SFTP] Key conversion failed:', e.message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
11
28
|
return new Promise((resolve, reject) => {
|
|
12
29
|
const conn = new Client();
|
|
13
30
|
const sessionId = options.sessionId || require('uuid').v4();
|
|
@@ -25,22 +42,12 @@ class SFTPManager {
|
|
|
25
42
|
keepaliveCountMax: options.sshKeepaliveCountMax || 1000
|
|
26
43
|
};
|
|
27
44
|
|
|
28
|
-
// Authentication method
|
|
45
|
+
// Authentication method (key already pre-processed above)
|
|
29
46
|
if (options.password && options.password.length > 0) {
|
|
30
47
|
config.password = options.password;
|
|
31
48
|
console.log('[SFTP] Using password authentication');
|
|
32
49
|
} else if (options.privateKey && options.privateKey.length > 0) {
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
if (options.privateKey.includes('BEGIN')) {
|
|
36
|
-
config.privateKey = options.privateKey;
|
|
37
|
-
} else {
|
|
38
|
-
const decoded = Buffer.from(options.privateKey, 'base64').toString('utf8');
|
|
39
|
-
config.privateKey = decoded;
|
|
40
|
-
}
|
|
41
|
-
} catch (e) {
|
|
42
|
-
config.privateKey = options.privateKey;
|
|
43
|
-
}
|
|
50
|
+
config.privateKey = options.privateKey;
|
|
44
51
|
if (options.passphrase && options.passphrase.length > 0) {
|
|
45
52
|
config.passphrase = options.passphrase;
|
|
46
53
|
}
|
|
@@ -2,6 +2,7 @@ const { Client } = require('ssh2');
|
|
|
2
2
|
const { Terminal } = require('@xterm/headless');
|
|
3
3
|
const { SerializeAddon } = require('@xterm/addon-serialize');
|
|
4
4
|
const pluginManager = require('../plugins/plugin-manager');
|
|
5
|
+
const { convertKeyIfNeeded } = require('../utils/key-converter');
|
|
5
6
|
|
|
6
7
|
class SSHManager {
|
|
7
8
|
constructor() {
|
|
@@ -18,7 +19,23 @@ class SSHManager {
|
|
|
18
19
|
this.io = io;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
connect(socket, options) {
|
|
22
|
+
async connect(socket, options) {
|
|
23
|
+
// Pre-process private key (auto-convert PPK to OpenSSH format)
|
|
24
|
+
if (options.privateKey && options.privateKey.length > 0) {
|
|
25
|
+
try {
|
|
26
|
+
let keyContent = options.privateKey;
|
|
27
|
+
if (!keyContent.includes('BEGIN')) {
|
|
28
|
+
keyContent = Buffer.from(keyContent, 'base64').toString('utf8');
|
|
29
|
+
}
|
|
30
|
+
options = {
|
|
31
|
+
...options,
|
|
32
|
+
privateKey: await convertKeyIfNeeded(keyContent, options.passphrase)
|
|
33
|
+
};
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error('[SSH] Key conversion failed:', e.message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
22
39
|
return new Promise((resolve, reject) => {
|
|
23
40
|
const conn = new Client();
|
|
24
41
|
const sessionId = options.sessionId || require('uuid').v4();
|
|
@@ -78,22 +95,12 @@ class SSHManager {
|
|
|
78
95
|
keepaliveCountMax: options.sshKeepaliveCountMax || 1000
|
|
79
96
|
};
|
|
80
97
|
|
|
81
|
-
// Authentication method
|
|
98
|
+
// Authentication method (key already pre-processed above)
|
|
82
99
|
if (options.password && options.password.length > 0) {
|
|
83
100
|
config.password = options.password;
|
|
84
101
|
console.log('[SSH] Using password authentication');
|
|
85
102
|
} else if (options.privateKey && options.privateKey.length > 0) {
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
if (options.privateKey.includes('BEGIN')) {
|
|
89
|
-
config.privateKey = options.privateKey;
|
|
90
|
-
} else {
|
|
91
|
-
const decoded = Buffer.from(options.privateKey, 'base64').toString('utf8');
|
|
92
|
-
config.privateKey = decoded;
|
|
93
|
-
}
|
|
94
|
-
} catch (e) {
|
|
95
|
-
config.privateKey = options.privateKey;
|
|
96
|
-
}
|
|
103
|
+
config.privateKey = options.privateKey;
|
|
97
104
|
if (options.passphrase && options.passphrase.length > 0) {
|
|
98
105
|
config.passphrase = options.passphrase;
|
|
99
106
|
}
|
|
@@ -51,7 +51,7 @@ function detectKeyFormat(keyContent) {
|
|
|
51
51
|
return { format: 'unknown', type: 'unknown' };
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function convertPPKViaPuttygen(ppkContent) {
|
|
54
|
+
function convertPPKViaPuttygen(ppkContent, passphrase) {
|
|
55
55
|
return new Promise((resolve, reject) => {
|
|
56
56
|
const tmpDir = os.tmpdir();
|
|
57
57
|
const inputFile = path.join(tmpDir, `sshift-ppk-${Date.now()}-${Math.random().toString(36).slice(2)}.ppk`);
|
|
@@ -63,14 +63,19 @@ function convertPPKViaPuttygen(ppkContent) {
|
|
|
63
63
|
return reject(new Error('Failed to write temporary PPK file: ' + writeErr.message));
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
const args = [inputFile, '-O', 'private-openssh-new', '-o', outputFile];
|
|
67
|
+
if (passphrase) {
|
|
68
|
+
args.splice(1, 0, '--old-passphrase', passphrase);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
execFile('puttygen', args, (err, stdout, stderr) => {
|
|
67
72
|
try { fs.unlinkSync(inputFile); } catch (e) { /* ignore */ }
|
|
68
73
|
|
|
69
74
|
if (err) {
|
|
70
75
|
try { fs.unlinkSync(outputFile); } catch (e) { /* ignore */ }
|
|
71
76
|
return reject(new Error(
|
|
72
77
|
'puttygen conversion failed: ' + (stderr || err.message) +
|
|
73
|
-
'. If the PPK file is encrypted,
|
|
78
|
+
'. If the PPK file is encrypted, provide the correct passphrase.'
|
|
74
79
|
));
|
|
75
80
|
}
|
|
76
81
|
|
|
@@ -324,31 +329,37 @@ function encodeOpenSSHPrivateKey(keyParts) {
|
|
|
324
329
|
return `-----BEGIN OPENSSH PRIVATE KEY-----\n${lines.join('\n')}\n-----END OPENSSH PRIVATE KEY-----\n`;
|
|
325
330
|
}
|
|
326
331
|
|
|
327
|
-
async function convertPPKToOpenSSH(ppkContent) {
|
|
332
|
+
async function convertPPKToOpenSSH(ppkContent, passphrase) {
|
|
328
333
|
const info = detectKeyFormat(ppkContent);
|
|
329
334
|
|
|
330
335
|
if (info.format !== 'ppk') {
|
|
331
336
|
throw new Error('Not a PPK key');
|
|
332
337
|
}
|
|
333
338
|
|
|
334
|
-
if (info.encrypted) {
|
|
339
|
+
if (info.encrypted && !passphrase) {
|
|
335
340
|
throw new Error(
|
|
336
|
-
'This PPK key is encrypted.
|
|
337
|
-
'load the PPK, enter the passphrase, then export as OpenSSH key.'
|
|
341
|
+
'This PPK key is encrypted. Provide a passphrase or decrypt it first using PuTTYgen.'
|
|
338
342
|
);
|
|
339
343
|
}
|
|
340
344
|
|
|
341
|
-
// Try puttygen first (handles all PPK versions including v3)
|
|
345
|
+
// Try puttygen first (handles all PPK versions including v3 and encrypted)
|
|
342
346
|
try {
|
|
343
|
-
const result = await convertPPKViaPuttygen(ppkContent);
|
|
344
|
-
if (result && result.includes('BEGIN
|
|
347
|
+
const result = await convertPPKViaPuttygen(ppkContent, passphrase);
|
|
348
|
+
if (result && result.includes('BEGIN')) {
|
|
345
349
|
return result;
|
|
346
350
|
}
|
|
347
351
|
} catch (e) {
|
|
348
|
-
// puttygen
|
|
352
|
+
// If puttygen failed and key is encrypted, don't try built-in (it can't handle encryption)
|
|
353
|
+
if (info.encrypted) {
|
|
354
|
+
throw new Error(
|
|
355
|
+
'Could not convert encrypted PPK key: ' + e.message +
|
|
356
|
+
'. Ensure puttygen is installed and the passphrase is correct.'
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
// puttygen not available, try built-in v2 parser for unencrypted keys
|
|
349
360
|
}
|
|
350
361
|
|
|
351
|
-
// Fall back to built-in PPK v2 converter
|
|
362
|
+
// Fall back to built-in PPK v2 converter (unencrypted only)
|
|
352
363
|
try {
|
|
353
364
|
return convertPPKV2ToOpenSSH(ppkContent);
|
|
354
365
|
} catch (e) {
|
|
@@ -360,4 +371,22 @@ async function convertPPKToOpenSSH(ppkContent) {
|
|
|
360
371
|
}
|
|
361
372
|
}
|
|
362
373
|
|
|
363
|
-
|
|
374
|
+
async function convertKeyIfNeeded(keyContent, passphrase) {
|
|
375
|
+
if (!keyContent || !keyContent.trim()) {
|
|
376
|
+
return keyContent;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const info = detectKeyFormat(keyContent);
|
|
380
|
+
if (info.format !== 'ppk') {
|
|
381
|
+
return keyContent;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
const converted = await convertPPKToOpenSSH(keyContent, passphrase);
|
|
386
|
+
return converted;
|
|
387
|
+
} catch (e) {
|
|
388
|
+
throw new Error('PPK key conversion failed: ' + e.message);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
module.exports = { detectKeyFormat, convertPPKToOpenSSH, convertKeyIfNeeded };
|
package/src/webapp/css/style.css
CHANGED
package/src/webapp/js/app.js
CHANGED
|
@@ -3358,14 +3358,17 @@ const wheelHandler = (e) => {
|
|
|
3358
3358
|
setupSocketListeners() {
|
|
3359
3359
|
this.socket.on('connect', () => {
|
|
3360
3360
|
console.log('[SSHIFT] Connected to server, socket ID:', this.socket.id);
|
|
3361
|
-
this.
|
|
3362
|
-
|
|
3361
|
+
if (!this.isUpdating) {
|
|
3362
|
+
this.showToast('Connected to server', 'success');
|
|
3363
|
+
}
|
|
3363
3364
|
this.loadBookmarks();
|
|
3364
3365
|
});
|
|
3365
3366
|
|
|
3366
3367
|
this.socket.on('disconnect', (reason) => {
|
|
3367
3368
|
console.log('[SSHIFT] Disconnected from server:', reason);
|
|
3368
|
-
this.
|
|
3369
|
+
if (!this.isUpdating) {
|
|
3370
|
+
this.showToast('Disconnected from server: ' + reason, 'error');
|
|
3371
|
+
}
|
|
3369
3372
|
});
|
|
3370
3373
|
|
|
3371
3374
|
this.socket.on('connect_error', (error) => {
|
|
@@ -3374,7 +3377,7 @@ const wheelHandler = (e) => {
|
|
|
3374
3377
|
this.authToken = null;
|
|
3375
3378
|
localStorage.removeItem('sshift_auth_token');
|
|
3376
3379
|
this.showLockScreen();
|
|
3377
|
-
} else {
|
|
3380
|
+
} else if (!this.isUpdating) {
|
|
3378
3381
|
this.showToast('Connection error: ' + error.message, 'error');
|
|
3379
3382
|
}
|
|
3380
3383
|
});
|
|
@@ -5816,6 +5819,11 @@ const wheelHandler = (e) => {
|
|
|
5816
5819
|
const clearBtn = document.getElementById(clearBtnId);
|
|
5817
5820
|
const textarea = document.getElementById(textareaId);
|
|
5818
5821
|
|
|
5822
|
+
// Derive passphrase field ID from textarea ID
|
|
5823
|
+
const passphraseId = textareaId === 'connPrivateKey' ? 'connPassphrase' : 'bookmarkPassphrase';
|
|
5824
|
+
const passphraseEl = document.getElementById(passphraseId);
|
|
5825
|
+
const passphrase = passphraseEl ? passphraseEl.value : '';
|
|
5826
|
+
|
|
5819
5827
|
badge.style.display = 'inline-flex';
|
|
5820
5828
|
badge.textContent = 'Reading...';
|
|
5821
5829
|
badge.className = 'key-format-badge';
|
|
@@ -5829,7 +5837,7 @@ const wheelHandler = (e) => {
|
|
|
5829
5837
|
return;
|
|
5830
5838
|
}
|
|
5831
5839
|
|
|
5832
|
-
const detectResult = await this.detectAndConvertKey(content);
|
|
5840
|
+
const detectResult = await this.detectAndConvertKey(content, passphrase);
|
|
5833
5841
|
if (detectResult.error) {
|
|
5834
5842
|
badge.textContent = detectResult.format || 'Error';
|
|
5835
5843
|
badge.classList.add('format-error');
|
|
@@ -5888,7 +5896,7 @@ const wheelHandler = (e) => {
|
|
|
5888
5896
|
event.target.value = '';
|
|
5889
5897
|
}
|
|
5890
5898
|
|
|
5891
|
-
async detectAndConvertKey(content) {
|
|
5899
|
+
async detectAndConvertKey(content, passphrase) {
|
|
5892
5900
|
try {
|
|
5893
5901
|
const response = await fetch('/api/utils/detect-key', {
|
|
5894
5902
|
method: 'POST',
|
|
@@ -5907,7 +5915,7 @@ const wheelHandler = (e) => {
|
|
|
5907
5915
|
const convertResponse = await fetch('/api/utils/convert-key', {
|
|
5908
5916
|
method: 'POST',
|
|
5909
5917
|
headers: { 'Content-Type': 'application/json' },
|
|
5910
|
-
body: JSON.stringify({ content })
|
|
5918
|
+
body: JSON.stringify({ content, passphrase: passphrase || '' })
|
|
5911
5919
|
});
|
|
5912
5920
|
|
|
5913
5921
|
if (!convertResponse.ok) {
|
|
@@ -5960,7 +5968,7 @@ const wheelHandler = (e) => {
|
|
|
5960
5968
|
encrypted: info.encrypted || false
|
|
5961
5969
|
};
|
|
5962
5970
|
} catch (e) {
|
|
5963
|
-
if (
|
|
5971
|
+
if (/PuTTY-User-Key-File-/i.test(content)) {
|
|
5964
5972
|
return {
|
|
5965
5973
|
format: 'PPK',
|
|
5966
5974
|
key: content,
|
|
@@ -5984,7 +5992,7 @@ const wheelHandler = (e) => {
|
|
|
5984
5992
|
if (content.includes('BEGIN DSA PRIVATE KEY')) return 'pem-dsa';
|
|
5985
5993
|
if (content.includes('BEGIN PRIVATE KEY')) return 'pkcs8';
|
|
5986
5994
|
if (content.includes('BEGIN ENCRYPTED PRIVATE KEY')) return 'pkcs8-encrypted';
|
|
5987
|
-
if (
|
|
5995
|
+
if (/PuTTY-User-Key-File-/i.test(content)) return 'ppk';
|
|
5988
5996
|
return 'unknown';
|
|
5989
5997
|
}
|
|
5990
5998
|
|
|
@@ -6763,14 +6771,6 @@ const wheelHandler = (e) => {
|
|
|
6763
6771
|
}
|
|
6764
6772
|
});
|
|
6765
6773
|
|
|
6766
|
-
// Handle binary input (control characters, etc.) that onData may not capture
|
|
6767
|
-
terminal.onBinary((data) => {
|
|
6768
|
-
const sess = this.sessions.get(sessionId);
|
|
6769
|
-
if (sess && sess.connected && sess.isController) {
|
|
6770
|
-
this.socket.emit('ssh-data', { sessionId, data: data });
|
|
6771
|
-
}
|
|
6772
|
-
});
|
|
6773
|
-
|
|
6774
6774
|
// Handle resize
|
|
6775
6775
|
terminal.onResize(({ cols, rows }) => {
|
|
6776
6776
|
const sess = this.sessions.get(sessionId);
|
|
@@ -10006,7 +10006,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10006
10006
|
}
|
|
10007
10007
|
}
|
|
10008
10008
|
|
|
10009
|
-
connectFromBookmark(bookmark) {
|
|
10009
|
+
async connectFromBookmark(bookmark) {
|
|
10010
10010
|
// Close sidebar on mobile when connecting
|
|
10011
10011
|
const isMobile = window.innerWidth <= 768;
|
|
10012
10012
|
if (isMobile) {
|
|
@@ -10024,7 +10024,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10024
10024
|
return;
|
|
10025
10025
|
}
|
|
10026
10026
|
|
|
10027
|
-
//
|
|
10027
|
+
// Build connection data from bookmark
|
|
10028
10028
|
const connectionData = {
|
|
10029
10029
|
name: bookmark.name,
|
|
10030
10030
|
host: bookmark.host,
|
|
@@ -10035,6 +10035,23 @@ async syncTabsFromServer(tabs) {
|
|
|
10035
10035
|
passphrase: bookmark.passphrase || ''
|
|
10036
10036
|
};
|
|
10037
10037
|
|
|
10038
|
+
// Auto-convert PPK keys to OpenSSH format before connecting
|
|
10039
|
+
if (connectionData.privateKey && /PuTTY-User-Key-File-/i.test(connectionData.privateKey)) {
|
|
10040
|
+
try {
|
|
10041
|
+
const convertResult = await this.detectAndConvertKey(connectionData.privateKey);
|
|
10042
|
+
if (convertResult.key && !convertResult.error) {
|
|
10043
|
+
connectionData.privateKey = convertResult.key;
|
|
10044
|
+
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
10045
|
+
} else if (convertResult.error) {
|
|
10046
|
+
this.showToast('PPK key conversion failed: ' + convertResult.error, 'error');
|
|
10047
|
+
return;
|
|
10048
|
+
}
|
|
10049
|
+
} catch (e) {
|
|
10050
|
+
this.showToast('PPK key conversion failed: ' + e.message, 'error');
|
|
10051
|
+
return;
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
10054
|
+
|
|
10038
10055
|
// Show connecting status
|
|
10039
10056
|
this.showToast(`Connecting to ${bookmark.name}...`, 'info');
|
|
10040
10057
|
|
|
@@ -10047,7 +10064,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10047
10064
|
}
|
|
10048
10065
|
}
|
|
10049
10066
|
|
|
10050
|
-
openSFTPFromBookmark(bookmark) {
|
|
10067
|
+
async openSFTPFromBookmark(bookmark) {
|
|
10051
10068
|
// Close sidebar on mobile when opening SFTP
|
|
10052
10069
|
const isMobile = window.innerWidth <= 768;
|
|
10053
10070
|
if (isMobile) {
|
|
@@ -10057,7 +10074,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10057
10074
|
if (sidebarOverlay) sidebarOverlay.classList.remove('active');
|
|
10058
10075
|
}
|
|
10059
10076
|
|
|
10060
|
-
//
|
|
10077
|
+
// Build connection data from bookmark
|
|
10061
10078
|
const connectionData = {
|
|
10062
10079
|
name: `${bookmark.name} (SFTP)`,
|
|
10063
10080
|
host: bookmark.host,
|
|
@@ -10068,6 +10085,23 @@ async syncTabsFromServer(tabs) {
|
|
|
10068
10085
|
passphrase: bookmark.passphrase || ''
|
|
10069
10086
|
};
|
|
10070
10087
|
|
|
10088
|
+
// Auto-convert PPK keys to OpenSSH format before connecting
|
|
10089
|
+
if (connectionData.privateKey && /PuTTY-User-Key-File-/i.test(connectionData.privateKey)) {
|
|
10090
|
+
try {
|
|
10091
|
+
const convertResult = await this.detectAndConvertKey(connectionData.privateKey);
|
|
10092
|
+
if (convertResult.key && !convertResult.error) {
|
|
10093
|
+
connectionData.privateKey = convertResult.key;
|
|
10094
|
+
this.showToast('PPK key converted to OpenSSH format', 'success');
|
|
10095
|
+
} else if (convertResult.error) {
|
|
10096
|
+
this.showToast('PPK key conversion failed: ' + convertResult.error, 'error');
|
|
10097
|
+
return;
|
|
10098
|
+
}
|
|
10099
|
+
} catch (e) {
|
|
10100
|
+
this.showToast('PPK key conversion failed: ' + e.message, 'error');
|
|
10101
|
+
return;
|
|
10102
|
+
}
|
|
10103
|
+
}
|
|
10104
|
+
|
|
10071
10105
|
// Show connecting status
|
|
10072
10106
|
this.showToast(`Opening SFTP for ${bookmark.name}...`, 'info');
|
|
10073
10107
|
|
|
@@ -10401,7 +10435,20 @@ async syncTabsFromServer(tabs) {
|
|
|
10401
10435
|
|
|
10402
10436
|
// Toast Notifications
|
|
10403
10437
|
showToast(message, type = 'info') {
|
|
10438
|
+
const MAX_TOASTS = 5;
|
|
10439
|
+
const DEDUP_INTERVAL = 3000;
|
|
10404
10440
|
const container = document.getElementById('toastContainer');
|
|
10441
|
+
|
|
10442
|
+
if (!this._toastDedup) this._toastDedup = new Map();
|
|
10443
|
+
const dedupKey = `${type}:${message}`;
|
|
10444
|
+
const lastShown = this._toastDedup.get(dedupKey);
|
|
10445
|
+
if (lastShown && Date.now() - lastShown < DEDUP_INTERVAL) return;
|
|
10446
|
+
this._toastDedup.set(dedupKey, Date.now());
|
|
10447
|
+
|
|
10448
|
+
while (container.children.length >= MAX_TOASTS) {
|
|
10449
|
+
container.firstChild.remove();
|
|
10450
|
+
}
|
|
10451
|
+
|
|
10405
10452
|
const toast = document.createElement('div');
|
|
10406
10453
|
toast.className = `toast ${type}`;
|
|
10407
10454
|
|
|
@@ -10564,6 +10611,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10564
10611
|
}
|
|
10565
10612
|
|
|
10566
10613
|
async executeUpdate() {
|
|
10614
|
+
this.isUpdating = true;
|
|
10567
10615
|
const updateBtn = document.getElementById('updateBtn');
|
|
10568
10616
|
const updateOverlay = document.getElementById('updateOverlay');
|
|
10569
10617
|
const updateMessage = document.getElementById('updateMessage');
|
|
@@ -10624,6 +10672,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10624
10672
|
}
|
|
10625
10673
|
} catch (error) {
|
|
10626
10674
|
console.error('Failed to execute update:', error);
|
|
10675
|
+
this.isUpdating = false;
|
|
10627
10676
|
|
|
10628
10677
|
// Hide overlay on error
|
|
10629
10678
|
if (updateOverlay) {
|
|
@@ -10765,6 +10814,7 @@ async syncTabsFromServer(tabs) {
|
|
|
10765
10814
|
}
|
|
10766
10815
|
|
|
10767
10816
|
handleUpdateError(message) {
|
|
10817
|
+
this.isUpdating = false;
|
|
10768
10818
|
const updateOverlay = document.getElementById('updateOverlay');
|
|
10769
10819
|
const updateBtn = document.getElementById('updateBtn');
|
|
10770
10820
|
|
|
@@ -57,6 +57,8 @@ class MobileTerminalHandler {
|
|
|
57
57
|
this._isComposing = false;
|
|
58
58
|
this._compositionText = '';
|
|
59
59
|
this._compositionEndTs = 0;
|
|
60
|
+
this._lastSentInput = '';
|
|
61
|
+
this._lastSentInputTs = 0;
|
|
60
62
|
this.contextMenuUserPositioned = false; // Track if user has manually positioned the menu
|
|
61
63
|
|
|
62
64
|
// Configuration
|
|
@@ -468,7 +470,21 @@ class MobileTerminalHandler {
|
|
|
468
470
|
return;
|
|
469
471
|
}
|
|
470
472
|
|
|
473
|
+
// Skip composition-related input events - they are handled by compositionend.
|
|
474
|
+
// e.isComposing is true when the event is part of an active composition.
|
|
475
|
+
// e.inputType checks catch 'insertCompositionText' and 'insertReplacementText'
|
|
476
|
+
// which some browsers fire instead of or alongside composition events.
|
|
477
|
+
if (e.isComposing) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
471
481
|
if (this._isComposing) {
|
|
482
|
+
this.hiddenTextarea.value = '';
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (e.inputType === 'insertCompositionText' || e.inputType === 'insertReplacementText') {
|
|
487
|
+
this.hiddenTextarea.value = '';
|
|
472
488
|
return;
|
|
473
489
|
}
|
|
474
490
|
|
|
@@ -483,6 +499,8 @@ class MobileTerminalHandler {
|
|
|
483
499
|
|
|
484
500
|
if (e.data && !this.touchState.isDragging) {
|
|
485
501
|
this._sendToTerminal(e.data);
|
|
502
|
+
this._lastSentInput = e.data;
|
|
503
|
+
this._lastSentInputTs = Date.now();
|
|
486
504
|
this.hiddenTextarea.value = '';
|
|
487
505
|
}
|
|
488
506
|
});
|
|
@@ -537,11 +555,28 @@ class MobileTerminalHandler {
|
|
|
537
555
|
this.hiddenTextarea.addEventListener('compositionend', (e) => {
|
|
538
556
|
this._isComposing = false;
|
|
539
557
|
this._compositionEndTs = Date.now();
|
|
540
|
-
const composed = e.data || this.
|
|
558
|
+
const composed = e.data || this._compositionText;
|
|
541
559
|
if (composed && !this.touchState.isDragging) {
|
|
542
|
-
|
|
560
|
+
// Avoid re-sending text that was already sent via an input event
|
|
561
|
+
// that fired before compositionstart (Gboard timing quirk).
|
|
562
|
+
if (this._lastSentInput && (Date.now() - this._lastSentInputTs) < 500) {
|
|
563
|
+
if (composed === this._lastSentInput) {
|
|
564
|
+
this._lastSentInput = '';
|
|
565
|
+
this._lastSentInputTs = 0;
|
|
566
|
+
} else if (composed.startsWith(this._lastSentInput)) {
|
|
567
|
+
this._sendToTerminal(composed.substring(this._lastSentInput.length));
|
|
568
|
+
this._lastSentInput = '';
|
|
569
|
+
this._lastSentInputTs = 0;
|
|
570
|
+
} else {
|
|
571
|
+
this._sendToTerminal(composed);
|
|
572
|
+
}
|
|
573
|
+
} else {
|
|
574
|
+
this._sendToTerminal(composed);
|
|
575
|
+
}
|
|
543
576
|
}
|
|
544
577
|
this._compositionText = '';
|
|
578
|
+
this._lastSentInput = '';
|
|
579
|
+
this._lastSentInputTs = 0;
|
|
545
580
|
this.hiddenTextarea.value = '';
|
|
546
581
|
});
|
|
547
582
|
}
|