mcp-ssh-manager 3.8.7 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +5 -0
- package/.gitattributes +5 -0
- package/CHANGELOG.md +371 -6
- package/CLAUDE.md +6 -0
- package/CODE_OF_CONDUCT.md +18 -0
- package/CONTRIBUTING.md +30 -0
- package/Formula/ssh-manager.rb +60 -0
- package/README.md +484 -964
- package/ROADMAP-V4.md +451 -0
- package/brand/README.md +43 -0
- package/brand/icon.svg +32 -0
- package/brand/mark.svg +18 -0
- package/brand/wordmark.svg +30 -0
- package/cli/app.js +230 -0
- package/cli/control.js +116 -0
- package/cli/lib/colors.sh +15 -0
- package/cli/lib/menu.sh +145 -96
- package/cli/portability.js +186 -0
- package/cli/ssh-manager +197 -91
- package/cli/ssh-manager.js +14 -0
- package/cli/style.js +17 -0
- package/cli/vault.js +411 -0
- package/desktop/ControlPlaneApp.swift +219 -0
- package/desktop/build.sh +58 -0
- package/desktop/electron/after-pack.cjs +39 -0
- package/desktop/electron/electron-builder.yml +148 -0
- package/desktop/electron/finalize-artifacts.mjs +83 -0
- package/desktop/electron/main.js +815 -0
- package/desktop/electron/package-lock.json +3656 -0
- package/desktop/electron/package.json +30 -0
- package/desktop/electron/prepare-engine.mjs +84 -0
- package/desktop/electron/resources/entitlements.mac.plist +22 -0
- package/desktop/electron/resources/icon.png +0 -0
- package/desktop/electron/resources/trayTemplate.png +0 -0
- package/desktop/electron/resources/trayTemplate@2x.png +0 -0
- package/desktop/electron/smoke-test.mjs +184 -0
- package/dist/ui/app.css +1 -0
- package/dist/ui/app.js +501 -0
- package/dist/ui/assets/Forum-Regular.woff2 +0 -0
- package/dist/ui/assets/JetBrainsMono-Bold.woff2 +0 -0
- package/dist/ui/assets/JetBrainsMono-Regular.woff2 +0 -0
- package/dist/ui/assets/Karla-Variable.woff2 +0 -0
- package/dist/ui/index.html +16 -0
- package/docs/DISTRIBUTION.md +136 -0
- package/docs/FINAL-TEST-V4.md +209 -0
- package/docs/MIGRATION.md +334 -0
- package/docs/TESTING-V4.md +119 -0
- package/docs/superpowers/specs/2026-10-08-desktop-from-npm-and-cli-design.md +187 -0
- package/docs/videos/control-plane.mp4 +0 -0
- package/package.json +61 -30
- package/scripts/build-interface.mjs +73 -0
- package/scripts/capture-screenshots.mjs +191 -0
- package/scripts/demo-env.mjs +461 -0
- package/scripts/frame-screenshots.py +176 -0
- package/scripts/macbook-mockup.py +296 -0
- package/scripts/make-tray-icon.py +61 -0
- package/scripts/preview-candidate.mjs +291 -0
- package/scripts/publish-desktop.mjs +46 -0
- package/scripts/record-demo.mjs +229 -0
- package/scripts/release-version.mjs +32 -0
- package/scripts/render-cli-menu.py +157 -0
- package/scripts/requirements-dev.in +12 -0
- package/scripts/requirements-dev.txt +424 -0
- package/scripts/run-ui-regression.mjs +48 -0
- package/scripts/setup-hooks.sh +7 -13
- package/scripts/smoke-desktop.mjs +80 -0
- package/scripts/test-drag-and-drop.mjs +114 -0
- package/scripts/test-first-run.mjs +5 -0
- package/scripts/test-import-ui.mjs +5 -0
- package/scripts/test-preferences-persist.mjs +5 -0
- package/scripts/test-upgrade-from-published.mjs +226 -0
- package/scripts/verify-mac-build.sh +153 -0
- package/scripts/verify-windows-build.ps1 +15 -0
- package/server.json +3 -3
- package/skills/README.md +42 -0
- package/skills/ssh-incident/SKILL.md +55 -0
- package/skills/ssh-operations/SKILL.md +62 -0
- package/skills/ssh-restricted/SKILL.md +57 -0
- package/src/agent-clients.js +482 -0
- package/src/approval.js +291 -0
- package/src/audit.js +11 -1
- package/src/command-log.js +162 -0
- package/src/config-loader.js +119 -4
- package/src/config-paths.js +101 -0
- package/src/control-plane.js +2730 -0
- package/src/desktop-install.js +747 -0
- package/src/index.js +179 -213
- package/src/live-stream.js +261 -0
- package/src/saved-commands.js +150 -0
- package/src/secret-store.js +573 -0
- package/src/server-aliases.js +8 -7
- package/src/server-config-manager.js +33 -7
- package/src/server-export.js +106 -0
- package/src/server-groups.js +82 -21
- package/src/server-import.js +477 -0
- package/src/shell-quote.js +9 -2
- package/src/ssh-connection.js +155 -0
- package/src/ssh-manager.js +186 -13
- package/src/tunnel-manager.js +79 -0
- package/src/vault-recovery.js +206 -0
- package/src/xlsx.js +322 -0
- package/docs/images/social-preview.png +0 -0
- package/docs/images/social-preview@2x.png +0 -0
- package/docs/images/ssh-manager-cli-menu.png +0 -0
package/cli/lib/menu.sh
CHANGED
|
@@ -1,71 +1,140 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
# Interactive menu library for ssh-manager CLI
|
|
3
3
|
|
|
4
|
+
# --- the home screen ---------------------------------------------------------
|
|
5
|
+
# Where things stand, then every action one key away, in the desktop app's
|
|
6
|
+
# orange and without emoji. The numbers keep the meaning they have had since
|
|
7
|
+
# 3.1 (0 still quits and 8 still opens the help, though the screen shows q and
|
|
8
|
+
# ?); the letters are new.
|
|
9
|
+
|
|
10
|
+
# The desktop app's state, from `ssh-manager app --status`. Read when the menu
|
|
11
|
+
# opens and after the app key, not on every redraw; nothing when it cannot be.
|
|
12
|
+
# Shown only when the app is installed: someone who uses the CLI alone is not
|
|
13
|
+
# told, every time, about an application they chose not to have.
|
|
14
|
+
refresh_desktop_status() {
|
|
15
|
+
MENU_DESKTOP_STATUS=""
|
|
16
|
+
if [ -n "${SCRIPT_DIR:-}" ] && [ -f "$SCRIPT_DIR/app.js" ] && command -v node >/dev/null 2>&1; then
|
|
17
|
+
MENU_DESKTOP_STATUS="$(node "$SCRIPT_DIR/app.js" --status 2>/dev/null || true)"
|
|
18
|
+
case "$MENU_DESKTOP_STATUS" in
|
|
19
|
+
*"not installed"*|*"not available"*) MENU_DESKTOP_STATUS="" ;;
|
|
20
|
+
esac
|
|
21
|
+
fi
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# "63 servers · ~/.ssh-manager/.env · desktop app 4.0.0 installed", wrapped
|
|
25
|
+
# between parts to fit $1 columns. Each part is left out rather than slowing
|
|
26
|
+
# or breaking the menu.
|
|
27
|
+
menu_status_line() {
|
|
28
|
+
local width="${1:-80}" parts=() count line="" part tilde='~'
|
|
29
|
+
if [ -f "$SSH_MANAGER_ENV" ]; then
|
|
30
|
+
count="$(load_servers 2>/dev/null | grep -c . || true)"
|
|
31
|
+
if [ "${count:-0}" = "1" ]; then parts+=("1 server"); else parts+=("${count:-0} servers"); fi
|
|
32
|
+
parts+=("${SSH_MANAGER_ENV/#"$HOME"/$tilde}")
|
|
33
|
+
else
|
|
34
|
+
parts+=("no servers yet")
|
|
35
|
+
fi
|
|
36
|
+
if [ -n "${MENU_DESKTOP_STATUS:-}" ]; then parts+=("$MENU_DESKTOP_STATUS"); fi
|
|
37
|
+
for part in "${parts[@]}"; do
|
|
38
|
+
if [ -n "$line" ] && [ $(( ${#line} + 3 + ${#part} )) -gt "$width" ]; then
|
|
39
|
+
printf '%s\n' "$line"
|
|
40
|
+
line="$part"
|
|
41
|
+
else
|
|
42
|
+
line="${line:+$line · }$part"
|
|
43
|
+
fi
|
|
44
|
+
done
|
|
45
|
+
printf '%s' "$line"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# One cell of the home screen: "#TITLE" a heading, "k|Label" a key, "@" the
|
|
49
|
+
# help and quit pair, "" nothing. $2, when given, pads it to that width.
|
|
50
|
+
menu_cell() {
|
|
51
|
+
local cell="$1" width="${2:-0}" plain="" text=""
|
|
52
|
+
case "$cell" in
|
|
53
|
+
'#'*) plain="${cell#\#}"; text="${ACCENT}${BOLD}${plain}${NC}" ;;
|
|
54
|
+
'@') plain="? Help q Quit"; text="${ACCENT}${BOLD}?${NC} Help ${ACCENT}${BOLD}q${NC} Quit" ;;
|
|
55
|
+
?'|'*) plain="${cell%%|*} ${cell#*|}"; text="${ACCENT}${BOLD}${cell%%|*}${NC} ${cell#*|}" ;;
|
|
56
|
+
esac
|
|
57
|
+
printf '%s' "$text"
|
|
58
|
+
if [ "$width" -gt "${#plain}" ]; then printf '%*s' "$((width - ${#plain}))" ''; fi
|
|
59
|
+
}
|
|
60
|
+
|
|
4
61
|
# Display main menu
|
|
5
62
|
show_main_menu() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
echo
|
|
18
|
-
echo
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
echo
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
63
|
+
# Kept once when asked, so a test can read the screen it draws.
|
|
64
|
+
if [ -n "${SSH_MANAGER_KEEP_SCREEN:-}" ]; then
|
|
65
|
+
unset SSH_MANAGER_KEEP_SCREEN
|
|
66
|
+
else
|
|
67
|
+
clear
|
|
68
|
+
fi
|
|
69
|
+
local cols="${COLUMNS:-}" status line cell i
|
|
70
|
+
[ -n "$cols" ] || cols="$(tput cols 2>/dev/null || true)"
|
|
71
|
+
[[ "$cols" =~ ^[0-9]+$ ]] || cols=80
|
|
72
|
+
status="$(menu_status_line "$((cols - 2))")"
|
|
73
|
+
|
|
74
|
+
echo
|
|
75
|
+
echo " ${ACCENT}${BOLD}▲ SSH Manager ${VERSION}${NC}"
|
|
76
|
+
while IFS= read -r line; do
|
|
77
|
+
if [ -n "$line" ]; then echo " ${GRAY}${line}${NC}"; fi
|
|
78
|
+
done <<< "$status"
|
|
79
|
+
echo
|
|
80
|
+
|
|
81
|
+
local left=("#SERVERS" "1|List, test, add, edit" "2|Connect (SSH session)" "6|Run a command" "5|Health" ""
|
|
82
|
+
"#SETTINGS" "7|Configuration" "t|MCP tools" "v|Encrypted vault" "i|Import servers")
|
|
83
|
+
local right=("#FILES" "3|Sync (rsync)" "4|Tunnels" "" "#AGENTS" "9|Watch what they run"
|
|
84
|
+
"a|Desktop app (open / install)" "" "" "" "@")
|
|
85
|
+
if [ "$cols" -ge 72 ]; then
|
|
86
|
+
for i in "${!left[@]}"; do
|
|
87
|
+
printf ' '
|
|
88
|
+
if [ -n "${right[$i]}" ]; then
|
|
89
|
+
menu_cell "${left[$i]}" 33
|
|
90
|
+
menu_cell "${right[$i]}"
|
|
91
|
+
else
|
|
92
|
+
menu_cell "${left[$i]}"
|
|
93
|
+
fi
|
|
94
|
+
echo
|
|
95
|
+
done
|
|
96
|
+
else
|
|
97
|
+
for cell in "${left[@]:0:6}" "${right[@]:0:4}" "${right[@]:4:3}" "" "${left[@]:6}" "" "@"; do
|
|
98
|
+
if [ -n "$cell" ]; then printf ' '; menu_cell "$cell"; fi
|
|
99
|
+
echo
|
|
100
|
+
done
|
|
101
|
+
fi
|
|
26
102
|
echo
|
|
27
|
-
|
|
28
|
-
|
|
103
|
+
printf ' %s›%s ' "$ACCENT" "$NC"
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# A sub-menu's heading, in the home screen's palette.
|
|
107
|
+
print_menu_header() {
|
|
29
108
|
echo
|
|
30
|
-
echo
|
|
31
|
-
echo " View help and examples"
|
|
109
|
+
echo " ${ACCENT}${BOLD}▲ SSH Manager${NC} ${GRAY}›${NC} ${BOLD}$1${NC}"
|
|
32
110
|
echo
|
|
33
|
-
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
# One sub-menu entry: its key, its label, and a dimmed line under it.
|
|
114
|
+
menu_item() {
|
|
115
|
+
echo " ${ACCENT}${BOLD}$1${NC} $2"
|
|
116
|
+
if [ -n "${3:-}" ]; then echo " ${GRAY}$3${NC}"; fi
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
# A sub-menu's prompt, after its entries.
|
|
120
|
+
menu_prompt() {
|
|
34
121
|
echo
|
|
35
|
-
|
|
36
|
-
echo -n "Choose an option [0-8]: "
|
|
122
|
+
printf ' %s›%s %s ' "$ACCENT" "$NC" "$1"
|
|
37
123
|
}
|
|
38
124
|
|
|
39
125
|
# Server management submenu
|
|
40
126
|
show_server_menu() {
|
|
41
127
|
clear
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
echo
|
|
53
|
-
echo -e " ${CYAN}4)${NC} ${INFO} Show Server Details"
|
|
54
|
-
echo " Display server configuration"
|
|
55
|
-
echo
|
|
56
|
-
echo -e " ${CYAN}5)${NC} ${PENCIL} Edit Server"
|
|
57
|
-
echo " Modify server settings"
|
|
58
|
-
echo
|
|
59
|
-
echo -e " ${CYAN}6)${NC} ${CROSS} Remove Server"
|
|
60
|
-
echo " Delete server configuration"
|
|
61
|
-
echo
|
|
62
|
-
echo -e " ${CYAN}7)${NC} ${NOTE} Edit Config File"
|
|
63
|
-
echo " Directly edit .env file"
|
|
64
|
-
echo
|
|
65
|
-
echo -e " ${CYAN}0)${NC} ← Back to Main Menu"
|
|
66
|
-
echo
|
|
67
|
-
echo -e "${GRAY}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
68
|
-
echo -n "Choose an option [0-7]: "
|
|
128
|
+
print_menu_header "Servers"
|
|
129
|
+
menu_item 1 "Add New Server" "Configure a new SSH server"
|
|
130
|
+
menu_item 2 "List All Servers" "Show configured servers"
|
|
131
|
+
menu_item 3 "Test Connection" "Test server connectivity"
|
|
132
|
+
menu_item 4 "Show Server Details" "Display server configuration"
|
|
133
|
+
menu_item 5 "Edit Server" "Modify server settings"
|
|
134
|
+
menu_item 6 "Remove Server" "Delete server configuration"
|
|
135
|
+
menu_item 7 "Edit Config File" "Directly edit .env file"
|
|
136
|
+
menu_item 0 "Back to the home screen"
|
|
137
|
+
menu_prompt "Choose an option [0-7]:"
|
|
69
138
|
}
|
|
70
139
|
|
|
71
140
|
# Enhanced server add wizard
|
|
@@ -403,28 +472,21 @@ select_server_menu() {
|
|
|
403
472
|
fi
|
|
404
473
|
|
|
405
474
|
clear
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
475
|
+
print_menu_header "$prompt_text"
|
|
476
|
+
|
|
409
477
|
local i=1
|
|
410
478
|
for server in "${servers[@]}"; do
|
|
411
479
|
local host=$(get_server_config "$server" "HOST")
|
|
412
480
|
local user=$(get_server_config "$server" "USER")
|
|
413
481
|
local desc=$(get_server_config "$server" "DESCRIPTION")
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
echo " $user@$host"
|
|
417
|
-
if [ -n "$desc" ]; then
|
|
418
|
-
echo " ${GRAY}$desc${NC}"
|
|
419
|
-
fi
|
|
420
|
-
echo
|
|
482
|
+
|
|
483
|
+
menu_item "$i" "$server ${GRAY}$user@$host${NC}" "$desc"
|
|
421
484
|
((i++))
|
|
422
485
|
done
|
|
423
|
-
|
|
424
|
-
echo -e " ${CYAN}0)${NC} Cancel"
|
|
486
|
+
|
|
425
487
|
echo
|
|
426
|
-
|
|
427
|
-
|
|
488
|
+
menu_item 0 "Cancel"
|
|
489
|
+
menu_prompt "Choose server [0-${#servers[@]}]:"
|
|
428
490
|
|
|
429
491
|
read choice
|
|
430
492
|
if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#servers[@]} ]; then
|
|
@@ -446,17 +508,13 @@ show_sync_menu() {
|
|
|
446
508
|
|
|
447
509
|
local server="$selected_server"
|
|
448
510
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
echo
|
|
457
|
-
echo -e " ${CYAN}0)${NC} Cancel"
|
|
458
|
-
echo
|
|
459
|
-
read -p "Choose direction [0-2]: " direction
|
|
511
|
+
clear
|
|
512
|
+
print_menu_header "Sync with $server"
|
|
513
|
+
menu_item 1 "Push (Local → Remote)" "Upload files to $server"
|
|
514
|
+
menu_item 2 "Pull (Remote → Local)" "Download files from $server"
|
|
515
|
+
menu_item 0 "Cancel"
|
|
516
|
+
menu_prompt "Choose direction [0-2]:"
|
|
517
|
+
read direction
|
|
460
518
|
|
|
461
519
|
case "$direction" in
|
|
462
520
|
1)
|
|
@@ -510,23 +568,14 @@ wizard_create_tunnel() {
|
|
|
510
568
|
|
|
511
569
|
local server="$selected_server"
|
|
512
570
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
echo " Example: Let remote access your local web server"
|
|
522
|
-
echo
|
|
523
|
-
echo -e " ${CYAN}3)${NC} Dynamic (SOCKS Proxy)"
|
|
524
|
-
echo " Create SOCKS5 proxy for secure browsing"
|
|
525
|
-
echo " Example: Route browser through SSH server"
|
|
526
|
-
echo
|
|
527
|
-
echo -e " ${CYAN}0)${NC} Cancel"
|
|
528
|
-
echo
|
|
529
|
-
read -p "Choose type [0-3]: " tunnel_type
|
|
571
|
+
clear
|
|
572
|
+
print_menu_header "Tunnel through $server"
|
|
573
|
+
menu_item 1 "Local Port Forwarding" "Access a remote service on a local port, e.g. MySQL on 3307"
|
|
574
|
+
menu_item 2 "Remote Port Forwarding" "Expose a local service to the server, e.g. your web server"
|
|
575
|
+
menu_item 3 "Dynamic (SOCKS Proxy)" "A SOCKS5 proxy to route a browser through the server"
|
|
576
|
+
menu_item 0 "Cancel"
|
|
577
|
+
menu_prompt "Choose type [0-3]:"
|
|
578
|
+
read tunnel_type
|
|
530
579
|
|
|
531
580
|
case "$tunnel_type" in
|
|
532
581
|
1)
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `ssh-manager import` and `ssh-manager export`.
|
|
3
|
+
//
|
|
4
|
+
// Implemented in Node rather than bash because it writes to the same SecretStore
|
|
5
|
+
// the MCP server reads from: one code path for writing and reading, so the CLI
|
|
6
|
+
// and the engine can never disagree about what a server is.
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
import os from 'os';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import readline from 'readline';
|
|
11
|
+
import { SecretStore } from '../src/secret-store.js';
|
|
12
|
+
import { ConfigLoader } from '../src/config-loader.js';
|
|
13
|
+
import { READERS, WELL_KNOWN, importFile, readTransmit, plan } from '../src/server-import.js';
|
|
14
|
+
import { toCsv, toXlsx, template } from '../src/server-export.js';
|
|
15
|
+
import { GREEN, YELLOW, RED, DIM, BOLD, RESET } from './style.js';
|
|
16
|
+
|
|
17
|
+
const ask = question => new Promise(resolve => {
|
|
18
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
19
|
+
rl.question(question, answer => { rl.close(); resolve(answer.trim().toLowerCase()); });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function usage() {
|
|
23
|
+
console.log(`
|
|
24
|
+
${BOLD}ssh-manager import${RESET} — bring servers in from somewhere else
|
|
25
|
+
|
|
26
|
+
ssh-manager import <file> read a file, working out what it is
|
|
27
|
+
ssh-manager import --from <tool> read where that tool keeps its list
|
|
28
|
+
ssh-manager import --template [file] write a spreadsheet to fill in
|
|
29
|
+
ssh-manager import <file> --format <id> when detection guesses wrong
|
|
30
|
+
ssh-manager import <file> --replace overwrite servers of the same name
|
|
31
|
+
|
|
32
|
+
${BOLD}tools:${RESET} ssh-config · filezilla · transmit
|
|
33
|
+
${BOLD}formats:${RESET} ${READERS.map(r => r.id).join(' · ')}
|
|
34
|
+
|
|
35
|
+
${BOLD}ssh-manager export${RESET} — take them out again
|
|
36
|
+
|
|
37
|
+
ssh-manager export servers.xlsx a spreadsheet
|
|
38
|
+
ssh-manager export servers.csv a CSV
|
|
39
|
+
ssh-manager export servers.env a .env
|
|
40
|
+
ssh-manager export servers.toml TOML, for Codex
|
|
41
|
+
|
|
42
|
+
${DIM}Passwords are never written to an export, and never read from an import.${RESET}
|
|
43
|
+
`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Everything currently configured, from every source, plus the loader that read
|
|
48
|
+
* it — `exportToEnv` and `exportToToml` are methods on the loaded instance.
|
|
49
|
+
*
|
|
50
|
+
* @returns {Promise<{servers: any[], loader: ConfigLoader}>}
|
|
51
|
+
*/
|
|
52
|
+
async function currentServers() {
|
|
53
|
+
const loader = new ConfigLoader();
|
|
54
|
+
const servers = [...(await loader.load()).values()];
|
|
55
|
+
return { servers, loader };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function doImport(args) {
|
|
59
|
+
const flag = name => {
|
|
60
|
+
const at = args.indexOf(`--${name}`);
|
|
61
|
+
return at < 0 ? undefined : (args[at + 1] || '');
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (args.includes('--template')) {
|
|
65
|
+
const target = path.resolve(flag('template') || 'ssh-manager-servers.xlsx');
|
|
66
|
+
fs.writeFileSync(target, template());
|
|
67
|
+
console.log(`\n${GREEN}Written:${RESET} ${target}`);
|
|
68
|
+
console.log(`${DIM}Fill it in, then: ssh-manager import ${path.basename(target)}${RESET}\n`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @type {string[]} */
|
|
73
|
+
const warnings = [];
|
|
74
|
+
let servers = [];
|
|
75
|
+
let source = '';
|
|
76
|
+
const tool = flag('from');
|
|
77
|
+
|
|
78
|
+
if (tool === 'transmit') {
|
|
79
|
+
servers = readTransmit(warnings);
|
|
80
|
+
source = 'Transmit favourites';
|
|
81
|
+
} else if (tool) {
|
|
82
|
+
const candidates = WELL_KNOWN[tool];
|
|
83
|
+
if (!candidates) {
|
|
84
|
+
console.error(`${RED}Unknown tool: ${tool}${RESET}`);
|
|
85
|
+
console.error(`${DIM}Try: ${Object.keys(WELL_KNOWN).join(', ')}, transmit${RESET}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
const found = candidates().find(file => fs.existsSync(file));
|
|
89
|
+
if (!found) {
|
|
90
|
+
console.error(`${RED}Nothing found for ${tool}.${RESET} Looked in:`);
|
|
91
|
+
for (const c of candidates()) console.error(` ${c.replace(os.homedir(), '~')}`);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
const result = importFile(found);
|
|
95
|
+
servers = result.servers; source = result.source; warnings.push(...result.warnings);
|
|
96
|
+
} else {
|
|
97
|
+
const file = args.find(a => !a.startsWith('--')
|
|
98
|
+
&& args[args.indexOf(a) - 1] !== '--format');
|
|
99
|
+
if (!file) { usage(); process.exit(1); }
|
|
100
|
+
const result = importFile(path.resolve(file), flag('format'));
|
|
101
|
+
servers = result.servers; source = result.source; warnings.push(...result.warnings);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log(`\n${BOLD}${source}${RESET} — ${servers.length} server(s)\n`);
|
|
105
|
+
if (!servers.length) {
|
|
106
|
+
console.log(`${YELLOW}Nothing to import.${RESET}\n`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const existing = (await currentServers()).servers.map(s => s.name);
|
|
111
|
+
const { fresh, conflicts } = plan(servers, existing);
|
|
112
|
+
const replace = args.includes('--replace');
|
|
113
|
+
|
|
114
|
+
for (const server of fresh) {
|
|
115
|
+
const where = `${server.user ? `${server.user}@` : ''}${server.host}${server.port ? `:${server.port}` : ''}`;
|
|
116
|
+
console.log(` ${GREEN}+${RESET} ${server.name.padEnd(20)} ${DIM}${where}${RESET}`);
|
|
117
|
+
}
|
|
118
|
+
for (const server of conflicts) {
|
|
119
|
+
console.log(` ${replace ? YELLOW + '~' : DIM + '='}${RESET} ${server.name.padEnd(20)} `
|
|
120
|
+
+ `${DIM}${replace ? 'will be replaced' : 'already configured — left alone'}${RESET}`);
|
|
121
|
+
}
|
|
122
|
+
if (warnings.length) {
|
|
123
|
+
console.log(`\n${YELLOW}Notes:${RESET}`);
|
|
124
|
+
for (const note of warnings.slice(0, 12)) console.log(` ${DIM}${note}${RESET}`);
|
|
125
|
+
if (warnings.length > 12) console.log(` ${DIM}…and ${warnings.length - 12} more${RESET}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const writing = replace ? [...fresh, ...conflicts] : fresh;
|
|
129
|
+
if (!writing.length) {
|
|
130
|
+
console.log(`\n${YELLOW}Everything here is already configured.${RESET} `
|
|
131
|
+
+ `${DIM}Use --replace to overwrite.${RESET}\n`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const answer = await ask(`\nWrite ${writing.length} server(s) to the vault? [y/N] `);
|
|
136
|
+
if (answer !== 'y' && answer !== 'yes') {
|
|
137
|
+
console.log(`${DIM}Nothing written.${RESET}\n`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const store = new SecretStore();
|
|
142
|
+
for (const server of writing) {
|
|
143
|
+
const { name, ...config } = server;
|
|
144
|
+
store.setServer(name, config);
|
|
145
|
+
}
|
|
146
|
+
console.log(`\n${GREEN}${writing.length} server(s) imported.${RESET}`);
|
|
147
|
+
console.log(`${DIM}They have no password or key passphrase yet — you will be asked `
|
|
148
|
+
+ `on first connection, or set one with: ssh-manager vault add <name>${RESET}\n`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function doExport(args) {
|
|
152
|
+
const target = args.find(a => !a.startsWith('--'));
|
|
153
|
+
if (!target) { usage(); process.exit(1); }
|
|
154
|
+
const file = path.resolve(target);
|
|
155
|
+
const { servers, loader } = await currentServers();
|
|
156
|
+
|
|
157
|
+
if (!servers.length) {
|
|
158
|
+
console.error(`${RED}No servers configured.${RESET}`);
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const extension = path.extname(file).toLowerCase();
|
|
163
|
+
switch (extension) {
|
|
164
|
+
case '.xlsx': fs.writeFileSync(file, toXlsx(servers)); break;
|
|
165
|
+
case '.csv': fs.writeFileSync(file, toCsv(servers), 'utf8'); break;
|
|
166
|
+
// .env and .toml are the loader's own writers, so a round trip through this
|
|
167
|
+
// tool produces a file it would itself have written.
|
|
168
|
+
case '.toml': fs.writeFileSync(file, loader.exportToToml(), 'utf8'); break;
|
|
169
|
+
case '.env': fs.writeFileSync(file, loader.exportToEnv(), 'utf8'); break;
|
|
170
|
+
default:
|
|
171
|
+
console.error(`${RED}Don't know how to write ${extension || 'a file with no extension'}.${RESET}`);
|
|
172
|
+
console.error(`${DIM}Use .xlsx, .csv, .env or .toml${RESET}`);
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
console.log(`\n${GREEN}${servers.length} server(s) written:${RESET} ${file}`);
|
|
177
|
+
console.log(`${DIM}No passwords or passphrases are included.${RESET}\n`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
181
|
+
const run = command === 'export' ? doExport : doImport;
|
|
182
|
+
run(command === 'export' ? rest : process.argv.slice(2).filter(a => a !== 'import'))
|
|
183
|
+
.catch(error => {
|
|
184
|
+
console.error(`\n${RED}${error.message}${RESET}\n`);
|
|
185
|
+
process.exit(1);
|
|
186
|
+
});
|