mcp-ssh-manager 4.1.0 → 4.3.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +201 -0
  2. package/CLAUDE.md +3 -5
  3. package/Formula/ssh-manager.rb +2 -2
  4. package/INSTALLATION.md +4 -0
  5. package/README.md +31 -5
  6. package/cli/codex.js +67 -0
  7. package/cli/guard.js +69 -0
  8. package/cli/lib/config.sh +102 -37
  9. package/cli/ssh-manager +13 -0
  10. package/cli/ssh-manager.js +1 -1
  11. package/desktop/electron/electron-builder.yml +5 -0
  12. package/desktop/electron/locale.mjs +55 -0
  13. package/desktop/electron/main.js +52 -65
  14. package/desktop/electron/native-menu.mjs +44 -0
  15. package/desktop/electron/native.fr.json +58 -0
  16. package/desktop/electron/native.ja.json +58 -0
  17. package/desktop/electron/native.zh-CN.json +58 -0
  18. package/desktop/electron/package-lock.json +2 -2
  19. package/desktop/electron/package.json +1 -1
  20. package/desktop/electron/smoke-test.mjs +15 -1
  21. package/dist/ui/app.css +1 -1
  22. package/dist/ui/app.js +135 -119
  23. package/docs/MIGRATION.md +1 -1
  24. package/docs/SECURITY_MODES.md +15 -8
  25. package/docs/SEO.md +1 -1
  26. package/package.json +17 -3
  27. package/scripts/language.mjs +172 -0
  28. package/scripts/test-upgrade-from-published.mjs +24 -2
  29. package/server.json +2 -2
  30. package/src/audit.js +6 -15
  31. package/src/background-job.js +44 -0
  32. package/src/backup-manager.js +24 -29
  33. package/src/config-loader.js +5 -1
  34. package/src/control-plane.js +5 -0
  35. package/src/database-manager.js +13 -31
  36. package/src/dump-guard.js +79 -0
  37. package/src/health-monitor.js +8 -4
  38. package/src/index.js +183 -21
  39. package/src/logger.js +3 -1
  40. package/src/quiet-stderr.js +15 -0
  41. package/src/ssh-guard.js +344 -0
  42. package/src/ssh-manager.js +51 -0
  43. package/src/tunnel-manager.js +14 -4
@@ -0,0 +1,79 @@
1
+ // Backups and restores whose exit code means what it says.
2
+ //
3
+ // `mysqldump ... | gzip > out` reports the exit code of the LAST command of the
4
+ // pipeline: when the dump failed (wrong password, missing database, full disk),
5
+ // gzip still succeeded, the file was an empty archive of 20 bytes, and ssh_db_dump
6
+ // and ssh_backup_create answered success with it. The mirror image on the way in:
7
+ // `gunzip -c dump.gz | mysql` runs mysql on whatever gunzip managed to read, so a
8
+ // truncated archive was restored in part, without an error.
9
+ //
10
+ // Found by reading jaredshuai's fork, which hit the same two defects and fixed them
11
+ // with a temporary file; this keeps the dump streaming (a database can be bigger than
12
+ // the free space on its own disk) by recording the producer's exit status on the side.
13
+ //
14
+ // Both commands are one simple command of single-quoted words (sh -c '<script>' sh
15
+ // <args>), like withRemoteTimeout: the SSH server hands them to the account's login
16
+ // shell, which may be csh or tcsh and would reject `{ }` and `$?` at the top level.
17
+ // The producer and the file names are positional parameters, never spliced into the
18
+ // script, and the producer is the same quoted text that used to run as it was.
19
+ import { shellQuote } from './shell-quote.js';
20
+
21
+ // $1 = file to write, $2 = the producing command, $3 = 1 to compress.
22
+ // The producer's status goes to a file next to the output (no mktemp: it is not on
23
+ // every system, and the folder is known to be writable since the output goes there).
24
+ // A failed run leaves no output file at all, so nothing can be mistaken for a backup.
25
+ const GUARDED_DUMP_SCRIPT = [
26
+ 'out=$1; st="$1.status.$$"; trap \'rm -f "$st"\' EXIT;',
27
+ 'if [ "$3" = 1 ]; then',
28
+ '{ eval "$2"; echo $? > "$st"; } | gzip -c > "$out"; gz=$?;',
29
+ 'read status < "$st" || status=1;',
30
+ 'if [ "$status" != 0 ] || [ "$gz" != 0 ]; then rm -f "$out"; exit 1; fi;',
31
+ 'else eval "$2" > "$out" || { rm -f "$out"; exit 1; }; fi',
32
+ ].join(' ');
33
+
34
+ // $1 = the gzip file, $2 = the command that reads the decompressed stream.
35
+ // A real gzip file is tested whole before a byte reaches the consumer. A file that
36
+ // is not gzip at all (a plain dump a backup left under a .gz name when it was made
37
+ // without compression) is fed as it is, so it is not refused for its name.
38
+ const GUARDED_FEED_SCRIPT = [
39
+ 'f=$1;',
40
+ 'if [ "$(head -c 2 "$f" | od -An -tx1 | tr -d " \\n")" = 1f8b ];',
41
+ 'then gzip -t "$f" || exit 1; gunzip -c "$f" | eval "$2";',
42
+ 'else eval "$2" < "$f"; fi',
43
+ ].join(' ');
44
+
45
+ /**
46
+ * The command that runs `producer` and writes its output to `outputFile`
47
+ * (gzipped when `compress`), and fails, leaving no file, if the producer does.
48
+ * @param {string} producer - A command line already built from quoted words
49
+ * @param {string} outputFile
50
+ * @param {boolean} [compress]
51
+ * @returns {string}
52
+ */
53
+ export function guardedDump(producer, outputFile, compress = true) {
54
+ return `sh -c ${shellQuote(GUARDED_DUMP_SCRIPT)} sh ${shellQuote(outputFile)} ${shellQuote(producer)} ${compress ? '1' : '0'}`;
55
+ }
56
+
57
+ /**
58
+ * The command that feeds a gzip file to `consumer` once the whole file has been
59
+ * verified, and fails without running the consumer if it is corrupt.
60
+ * @param {string} gzipFile
61
+ * @param {string} consumer - A command line already built from quoted words
62
+ * @returns {string}
63
+ */
64
+ export function guardedFeed(gzipFile, consumer) {
65
+ return `sh -c ${shellQuote(GUARDED_FEED_SCRIPT)} sh ${shellQuote(gzipFile)} ${shellQuote(consumer)}`;
66
+ }
67
+
68
+ /**
69
+ * Where mongodump's output ends up when it is compressed: one archive beside the
70
+ * dump directory. The one place that knows it: the dump builders write it, and
71
+ * ssh_backup_create, ssh_backup_restore and ssh_db_dump measure, record and read the
72
+ * same path. They used to disagree (written as <id>.tar.gz, measured and restored as
73
+ * <id>.gz), so a MongoDB backup reported a size of 0 and could not be restored.
74
+ * @param {string} outputDir
75
+ * @returns {string}
76
+ */
77
+ export function mongoArchivePath(outputDir) {
78
+ return `${outputDir}.tar.gz`;
79
+ }
@@ -48,7 +48,7 @@ function buildMemoryCheckCommand() {
48
48
  function buildDiskCheckCommand(mountPoint = '/') {
49
49
  // Returns JSON with disk usage for specific mount point or all
50
50
  if (mountPoint === 'all') {
51
- return 'df -h | awk \'NR>1 {gsub(/%/,"",$5); printf "{\\"mount\\":\\"%s\\",\\"size\\":\\"%s\\",\\"used\\":\\"%s\\",\\"avail\\":\\"%s\\",\\"percent\\":%s}\\n", $6,$2,$3,$4,$5}\'';
51
+ return 'LC_ALL=C df -PTh | awk \'NR>1 {gsub(/%/,"",$6); printf "{\\"filesystem\\":\\"%s\\",\\"mount\\":\\"%s\\",\\"size\\":\\"%s\\",\\"used\\":\\"%s\\",\\"avail\\":\\"%s\\",\\"percent\\":%s}\\n", $2,$7,$3,$4,$5,$6}\'';
52
52
  }
53
53
  return `df -h "${mountPoint}" | awk 'NR>1 {gsub(/%/,"",$5); printf "{\\"mount\\":\\"%s\\",\\"size\\":\\"%s\\",\\"used\\":\\"%s\\",\\"avail\\":\\"%s\\",\\"percent\\":%s}", $6,$2,$3,$4,$5}'`;
54
54
  }
@@ -116,6 +116,10 @@ function parseDiskUsage(output) {
116
116
  for (const line of lines) {
117
117
  try {
118
118
  const disk = JSON.parse(line);
119
+ // Container layers share the backing disk's free space. RAM-backed and
120
+ // read-only image mounts are not independent persistent disks either.
121
+ // Keep / even when the monitored host itself runs inside a container.
122
+ if (disk.mount !== '/' && ['overlay', 'aufs', 'tmpfs', 'devtmpfs', 'squashfs'].includes(disk.filesystem)) continue;
119
123
  disk.status = disk.percent > 90 ? HEALTH_STATUS.CRITICAL : disk.percent > 80 ? HEALTH_STATUS.WARNING : HEALTH_STATUS.HEALTHY;
120
124
  disks.push(disk);
121
125
  } catch (error) {
@@ -322,7 +326,7 @@ export function buildLoadAlertConfigCommand(configPath = '/etc/ssh-manager-alert
322
326
  export function checkAlertThresholds(metrics, thresholds) {
323
327
  const alerts = [];
324
328
 
325
- if (thresholds.cpu && metrics.cpu && metrics.cpu.percent > thresholds.cpu) {
329
+ if (thresholds.cpu && metrics.cpu && metrics.cpu.percent >= thresholds.cpu) {
326
330
  alerts.push({
327
331
  type: 'cpu',
328
332
  severity: 'warning',
@@ -332,7 +336,7 @@ export function checkAlertThresholds(metrics, thresholds) {
332
336
  });
333
337
  }
334
338
 
335
- if (thresholds.memory && metrics.memory && metrics.memory.percent > thresholds.memory) {
339
+ if (thresholds.memory && metrics.memory && metrics.memory.percent >= thresholds.memory) {
336
340
  alerts.push({
337
341
  type: 'memory',
338
342
  severity: 'warning',
@@ -344,7 +348,7 @@ export function checkAlertThresholds(metrics, thresholds) {
344
348
 
345
349
  if (thresholds.disk && metrics.disks) {
346
350
  for (const disk of metrics.disks) {
347
- if (disk.percent > thresholds.disk) {
351
+ if (disk.percent >= thresholds.disk) {
348
352
  alerts.push({
349
353
  type: 'disk',
350
354
  severity: 'warning',