@abhiseck/zssh 1.1.0 → 1.2.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/dist/commands/add.js +5 -2
- package/dist/commands/connect.js +48 -1
- package/dist/commands/list.js +2 -0
- package/package.json +1 -1
- package/src/commands/add.ts +9 -2
- package/src/commands/connect.ts +51 -1
- package/src/commands/list.ts +2 -0
- package/test-ppk.js +4 -0
package/dist/commands/add.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.addCommand = addCommand;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
-
const uuid_1 = require("uuid");
|
|
10
9
|
async function addCommand(configManager) {
|
|
11
10
|
console.log(chalk_1.default.blue("Adding new SSH connection..."));
|
|
12
11
|
const answers = await inquirer_1.default.prompt([
|
|
@@ -60,8 +59,12 @@ async function addCommand(configManager) {
|
|
|
60
59
|
message: "Description (optional):",
|
|
61
60
|
},
|
|
62
61
|
]);
|
|
62
|
+
const connections = configManager.getConnections();
|
|
63
|
+
const nextId = connections.length > 0
|
|
64
|
+
? (Math.max(...connections.map((c) => parseInt(c.id) || 0)) + 1).toString()
|
|
65
|
+
: "1";
|
|
63
66
|
const connection = {
|
|
64
|
-
id:
|
|
67
|
+
id: nextId,
|
|
65
68
|
alias: answers.alias,
|
|
66
69
|
host: answers.host,
|
|
67
70
|
port: parseInt(answers.port),
|
package/dist/commands/connect.js
CHANGED
|
@@ -6,6 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.connectCommand = connectCommand;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const ssh2_1 = require("ssh2");
|
|
9
13
|
async function isSshpassInstalled() {
|
|
10
14
|
return new Promise((resolve) => {
|
|
11
15
|
const isWin = process.platform === "win32";
|
|
@@ -29,7 +33,50 @@ async function connectCommand(configManager, idOrAlias) {
|
|
|
29
33
|
}
|
|
30
34
|
// Identity file
|
|
31
35
|
if (conn.privateKeyPath) {
|
|
32
|
-
|
|
36
|
+
let keyPath = conn.privateKeyPath;
|
|
37
|
+
if (keyPath.toLowerCase().endsWith(".ppk")) {
|
|
38
|
+
try {
|
|
39
|
+
let realPath = keyPath;
|
|
40
|
+
if (realPath.startsWith("~/")) {
|
|
41
|
+
realPath = path_1.default.join(os_1.default.homedir(), realPath.slice(2));
|
|
42
|
+
}
|
|
43
|
+
const keyData = fs_1.default.readFileSync(realPath);
|
|
44
|
+
const parsedKeys = ssh2_1.utils.parseKey(keyData);
|
|
45
|
+
if (parsedKeys instanceof Error) {
|
|
46
|
+
console.log(chalk_1.default.red(`Failed to parse PPK file: ${parsedKeys.message}`));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const parsedKey = Array.isArray(parsedKeys)
|
|
50
|
+
? parsedKeys[0]
|
|
51
|
+
: parsedKeys;
|
|
52
|
+
const tempKeyPath = path_1.default.join(os_1.default.tmpdir(), `sshc_key_${conn.id}.pem`);
|
|
53
|
+
fs_1.default.writeFileSync(tempKeyPath, parsedKey.getPrivatePEM(), {
|
|
54
|
+
mode: 0o600,
|
|
55
|
+
});
|
|
56
|
+
keyPath = tempKeyPath;
|
|
57
|
+
const cleanUp = () => {
|
|
58
|
+
try {
|
|
59
|
+
if (fs_1.default.existsSync(tempKeyPath))
|
|
60
|
+
fs_1.default.unlinkSync(tempKeyPath);
|
|
61
|
+
}
|
|
62
|
+
catch (e) { }
|
|
63
|
+
};
|
|
64
|
+
process.on("exit", cleanUp);
|
|
65
|
+
process.on("SIGINT", () => {
|
|
66
|
+
cleanUp();
|
|
67
|
+
process.exit(0);
|
|
68
|
+
});
|
|
69
|
+
process.on("SIGTERM", () => {
|
|
70
|
+
cleanUp();
|
|
71
|
+
process.exit(0);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
console.log(chalk_1.default.red(`Error processing PPK file: ${err.message}`));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
args.push("-i", keyPath);
|
|
33
80
|
}
|
|
34
81
|
// Destination
|
|
35
82
|
args.push(`${conn.username}@${conn.host}`);
|
package/dist/commands/list.js
CHANGED
|
@@ -19,6 +19,7 @@ async function listCommand(configManager) {
|
|
|
19
19
|
chalk_1.default.cyan("Host"),
|
|
20
20
|
chalk_1.default.cyan("User"),
|
|
21
21
|
chalk_1.default.cyan("Port"),
|
|
22
|
+
chalk_1.default.cyan("Description"),
|
|
22
23
|
],
|
|
23
24
|
style: { head: [], border: [] },
|
|
24
25
|
});
|
|
@@ -29,6 +30,7 @@ async function listCommand(configManager) {
|
|
|
29
30
|
conn.host,
|
|
30
31
|
conn.username,
|
|
31
32
|
conn.port,
|
|
33
|
+
conn.description || "",
|
|
32
34
|
]);
|
|
33
35
|
});
|
|
34
36
|
console.log(table.toString());
|
package/package.json
CHANGED
package/src/commands/add.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import inquirer from "inquirer";
|
|
3
|
-
import { v4 as uuidv4 } from "uuid";
|
|
4
3
|
import { ConfigManager } from "../lib/config";
|
|
5
4
|
import { SSHConnection } from "../lib/types";
|
|
6
5
|
|
|
@@ -60,8 +59,16 @@ export async function addCommand(configManager: ConfigManager) {
|
|
|
60
59
|
},
|
|
61
60
|
]);
|
|
62
61
|
|
|
62
|
+
const connections = configManager.getConnections();
|
|
63
|
+
const nextId =
|
|
64
|
+
connections.length > 0
|
|
65
|
+
? (
|
|
66
|
+
Math.max(...connections.map((c) => parseInt(c.id) || 0)) + 1
|
|
67
|
+
).toString()
|
|
68
|
+
: "1";
|
|
69
|
+
|
|
63
70
|
const connection: SSHConnection = {
|
|
64
|
-
id:
|
|
71
|
+
id: nextId,
|
|
65
72
|
alias: answers.alias,
|
|
66
73
|
host: answers.host,
|
|
67
74
|
port: parseInt(answers.port),
|
package/src/commands/connect.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { exec, spawn } from "child_process";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import os from "os";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { utils } from "ssh2";
|
|
3
7
|
import { ConfigManager } from "../lib/config";
|
|
4
8
|
|
|
5
9
|
async function isSshpassInstalled(): Promise<boolean> {
|
|
@@ -39,7 +43,53 @@ export async function connectCommand(
|
|
|
39
43
|
|
|
40
44
|
// Identity file
|
|
41
45
|
if (conn.privateKeyPath) {
|
|
42
|
-
|
|
46
|
+
let keyPath = conn.privateKeyPath;
|
|
47
|
+
if (keyPath.toLowerCase().endsWith(".ppk")) {
|
|
48
|
+
try {
|
|
49
|
+
let realPath = keyPath;
|
|
50
|
+
if (realPath.startsWith("~/")) {
|
|
51
|
+
realPath = path.join(os.homedir(), realPath.slice(2));
|
|
52
|
+
}
|
|
53
|
+
const keyData = fs.readFileSync(realPath);
|
|
54
|
+
const parsedKeys = utils.parseKey(keyData);
|
|
55
|
+
|
|
56
|
+
if (parsedKeys instanceof Error) {
|
|
57
|
+
console.log(
|
|
58
|
+
chalk.red(`Failed to parse PPK file: ${parsedKeys.message}`),
|
|
59
|
+
);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const parsedKey = Array.isArray(parsedKeys)
|
|
64
|
+
? parsedKeys[0]
|
|
65
|
+
: parsedKeys;
|
|
66
|
+
const tempKeyPath = path.join(os.tmpdir(), `sshc_key_${conn.id}.pem`);
|
|
67
|
+
|
|
68
|
+
fs.writeFileSync(tempKeyPath, parsedKey.getPrivatePEM(), {
|
|
69
|
+
mode: 0o600,
|
|
70
|
+
});
|
|
71
|
+
keyPath = tempKeyPath;
|
|
72
|
+
|
|
73
|
+
const cleanUp = () => {
|
|
74
|
+
try {
|
|
75
|
+
if (fs.existsSync(tempKeyPath)) fs.unlinkSync(tempKeyPath);
|
|
76
|
+
} catch (e) {}
|
|
77
|
+
};
|
|
78
|
+
process.on("exit", cleanUp);
|
|
79
|
+
process.on("SIGINT", () => {
|
|
80
|
+
cleanUp();
|
|
81
|
+
process.exit(0);
|
|
82
|
+
});
|
|
83
|
+
process.on("SIGTERM", () => {
|
|
84
|
+
cleanUp();
|
|
85
|
+
process.exit(0);
|
|
86
|
+
});
|
|
87
|
+
} catch (err: any) {
|
|
88
|
+
console.log(chalk.red(`Error processing PPK file: ${err.message}`));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
args.push("-i", keyPath);
|
|
43
93
|
}
|
|
44
94
|
|
|
45
95
|
// Destination
|
package/src/commands/list.ts
CHANGED
|
@@ -19,6 +19,7 @@ export async function listCommand(configManager: ConfigManager) {
|
|
|
19
19
|
chalk.cyan("Host"),
|
|
20
20
|
chalk.cyan("User"),
|
|
21
21
|
chalk.cyan("Port"),
|
|
22
|
+
chalk.cyan("Description"),
|
|
22
23
|
],
|
|
23
24
|
style: { head: [], border: [] },
|
|
24
25
|
});
|
|
@@ -30,6 +31,7 @@ export async function listCommand(configManager: ConfigManager) {
|
|
|
30
31
|
conn.host,
|
|
31
32
|
conn.username,
|
|
32
33
|
conn.port,
|
|
34
|
+
conn.description || "",
|
|
33
35
|
]);
|
|
34
36
|
});
|
|
35
37
|
|
package/test-ppk.js
ADDED