mcp-ssh-manager 3.0.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 (56) hide show
  1. package/.claude/settings.local.json +87 -0
  2. package/.flake8 +15 -0
  3. package/.hooks-config.json +131 -0
  4. package/.pre-commit-config.yaml +105 -0
  5. package/CHANGELOG.md +137 -0
  6. package/CLAUDE.md +190 -0
  7. package/CONTRIBUTING.md +114 -0
  8. package/DESCRIPTION +1 -0
  9. package/INSTALLATION.md +180 -0
  10. package/LICENSE +21 -0
  11. package/QUICKSTART.md +77 -0
  12. package/README.md +718 -0
  13. package/cli/README.md +286 -0
  14. package/cli/build.sh +199 -0
  15. package/cli/commands/server.sh +284 -0
  16. package/cli/demo.sh +107 -0
  17. package/cli/install.sh +164 -0
  18. package/cli/lib/colors.sh +174 -0
  19. package/cli/lib/config.sh +284 -0
  20. package/cli/lib/menu.sh +430 -0
  21. package/cli/migrate.sh +168 -0
  22. package/cli/ssh-manager +525 -0
  23. package/docs/ALIASES_AND_HOOKS.md +285 -0
  24. package/docs/BACKUP_GUIDE.md +500 -0
  25. package/docs/DEPLOYMENT_GUIDE.md +241 -0
  26. package/docs/SEO.md +257 -0
  27. package/examples/backup-workflow.js +481 -0
  28. package/examples/claude-code-config.example.json +40 -0
  29. package/examples/codex-ssh-config.example.toml +71 -0
  30. package/examples/deploy-workflow.py +183 -0
  31. package/glama.json +6 -0
  32. package/package.json +85 -0
  33. package/profiles/README.md +40 -0
  34. package/profiles/default.json +52 -0
  35. package/profiles/docker.json +62 -0
  36. package/profiles/frappe.json +107 -0
  37. package/profiles/nodejs.json +63 -0
  38. package/pyproject.toml +17 -0
  39. package/scripts/setup-hooks.sh +60 -0
  40. package/scripts/validate.sh +76 -0
  41. package/src/backup-manager.js +469 -0
  42. package/src/command-aliases.js +151 -0
  43. package/src/config-loader.js +281 -0
  44. package/src/database-manager.js +555 -0
  45. package/src/deploy-helper.js +176 -0
  46. package/src/health-monitor.js +428 -0
  47. package/src/hooks-system.js +327 -0
  48. package/src/index.js +4499 -0
  49. package/src/logger.js +276 -0
  50. package/src/profile-loader.js +187 -0
  51. package/src/server-aliases.js +150 -0
  52. package/src/server-groups.js +409 -0
  53. package/src/session-manager.js +410 -0
  54. package/src/ssh-key-manager.js +378 -0
  55. package/src/ssh-manager.js +435 -0
  56. package/src/tunnel-manager.js +576 -0
@@ -0,0 +1,525 @@
1
+ #!/bin/bash
2
+ # SSH Manager CLI - Simple and powerful SSH server management
3
+
4
+ set -e
5
+
6
+ # Script directory - resolve symlinks if necessary
7
+ if [ -L "$0" ]; then
8
+ # Script is a symlink, resolve it
9
+ SCRIPT_PATH="$(readlink -f "$0" 2>/dev/null || readlink "$0")"
10
+ else
11
+ SCRIPT_PATH="$0"
12
+ fi
13
+ SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
14
+
15
+ # Source libraries
16
+ source "$SCRIPT_DIR/lib/colors.sh"
17
+ source "$SCRIPT_DIR/lib/config.sh"
18
+ source "$SCRIPT_DIR/lib/menu.sh"
19
+
20
+ # Source command modules
21
+ source "$SCRIPT_DIR/commands/server.sh"
22
+
23
+ # Version
24
+ VERSION="2.0.2"
25
+
26
+ # Show version
27
+ show_version() {
28
+ echo "SSH Manager CLI v$VERSION"
29
+ echo "Simple and powerful SSH server management"
30
+ }
31
+
32
+ # Show help
33
+ show_help() {
34
+ cat <<EOF
35
+ ${BOLD}SSH Manager CLI${NC} - Simple and powerful SSH server management
36
+
37
+ ${BOLD}USAGE:${NC}
38
+ ssh-manager # Interactive mode (menu)
39
+ ssh-manager -i # Interactive mode (menu)
40
+ ssh-manager <command> # Direct command mode
41
+
42
+ ${BOLD}COMMANDS:${NC}
43
+ ${CYAN}server${NC} Server management
44
+ add Add a new server
45
+ list List all servers
46
+ test Test server connection
47
+ remove Remove a server
48
+ edit Edit server configuration
49
+ show Show server details
50
+
51
+ ${CYAN}sync${NC} File synchronization (rsync)
52
+ push Push files to server
53
+ pull Pull files from server
54
+
55
+ ${CYAN}tunnel${NC} SSH tunnel management
56
+ create Create a new tunnel
57
+ list List active tunnels
58
+ close Close a tunnel
59
+
60
+ ${CYAN}monitor${NC} System monitoring
61
+ cpu Monitor CPU usage
62
+ memory Monitor memory usage
63
+ disk Monitor disk usage
64
+ network Monitor network
65
+
66
+ ${CYAN}session${NC} SSH session management
67
+ start Start interactive session
68
+ list List active sessions
69
+ close Close a session
70
+
71
+ ${CYAN}exec${NC} Execute commands
72
+ run Run command on server
73
+ group Run on server group
74
+
75
+ ${CYAN}config${NC} Configuration
76
+ edit Edit configuration
77
+ show Show configuration
78
+ init Initialize configuration
79
+
80
+ ${BOLD}OPTIONS:${NC}
81
+ -h, --help Show this help message
82
+ -v, --version Show version
83
+ -q, --quiet Quiet mode
84
+ -d, --debug Debug mode
85
+
86
+ ${BOLD}EXAMPLES:${NC}
87
+ # Add a new server
88
+ ssh-manager server add
89
+
90
+ # List all servers
91
+ ssh-manager server list
92
+
93
+ # Test connection to prod1
94
+ ssh-manager server test prod1
95
+
96
+ # Sync files to server
97
+ ssh-manager sync push prod1 ./app /var/www/app
98
+
99
+ # Create SSH tunnel
100
+ ssh-manager tunnel create prod1 local 3307:localhost:3306
101
+
102
+ # Monitor server
103
+ ssh-manager monitor prod1 cpu
104
+
105
+ ${BOLD}CONFIGURATION:${NC}
106
+ Config directory: ${SSH_MANAGER_HOME:-~/.ssh-manager}
107
+ Server config: ${SSH_MANAGER_ENV:-.env}
108
+
109
+ ${BOLD}DOCUMENTATION:${NC}
110
+ https://github.com/bvisible/mcp-ssh-manager
111
+
112
+ EOF
113
+ }
114
+
115
+ # Execute command on server
116
+ cmd_exec() {
117
+ local server="$1"
118
+ shift
119
+ local command="$@"
120
+
121
+ if [ -z "$server" ] || [ -z "$command" ]; then
122
+ print_error "Usage: ssh-manager exec <server> <command>"
123
+ return 1
124
+ fi
125
+
126
+ local host=$(get_server_config "$server" "HOST")
127
+ local user=$(get_server_config "$server" "USER")
128
+ local port=$(get_server_config "$server" "PORT")
129
+ local keypath=$(get_server_config "$server" "KEYPATH")
130
+
131
+ port=${port:-22}
132
+
133
+ if [ -z "$host" ] || [ -z "$user" ]; then
134
+ print_error "Server '$server' not found"
135
+ return 1
136
+ fi
137
+
138
+ local ssh_opts="-p $port"
139
+ if [ -n "$keypath" ]; then
140
+ ssh_opts="$ssh_opts -i $keypath"
141
+ fi
142
+
143
+ print_info "Executing on $server: $command"
144
+ ssh $ssh_opts "$user@$host" "$command"
145
+ }
146
+
147
+ # Sync files using rsync
148
+ cmd_sync() {
149
+ local direction="$1"
150
+ local server="$2"
151
+ local source="$3"
152
+ local dest="$4"
153
+
154
+ if [ -z "$direction" ] || [ -z "$server" ] || [ -z "$source" ] || [ -z "$dest" ]; then
155
+ print_error "Usage: ssh-manager sync <push|pull> <server> <source> <destination>"
156
+ return 1
157
+ fi
158
+
159
+ local host=$(get_server_config "$server" "HOST")
160
+ local user=$(get_server_config "$server" "USER")
161
+ local port=$(get_server_config "$server" "PORT")
162
+ local keypath=$(get_server_config "$server" "KEYPATH")
163
+
164
+ port=${port:-22}
165
+
166
+ if [ -z "$host" ] || [ -z "$user" ]; then
167
+ print_error "Server '$server' not found"
168
+ return 1
169
+ fi
170
+
171
+ local ssh_opts="ssh -p $port"
172
+ if [ -n "$keypath" ]; then
173
+ ssh_opts="$ssh_opts -i $keypath"
174
+ fi
175
+
176
+ local rsync_opts="-avz --progress"
177
+
178
+ case "$direction" in
179
+ push)
180
+ print_info "Pushing $source to $server:$dest"
181
+ rsync $rsync_opts -e "$ssh_opts" "$source" "$user@$host:$dest"
182
+ ;;
183
+ pull)
184
+ print_info "Pulling $server:$source to $dest"
185
+ rsync $rsync_opts -e "$ssh_opts" "$user@$host:$source" "$dest"
186
+ ;;
187
+ *)
188
+ print_error "Invalid direction: $direction (use push or pull)"
189
+ return 1
190
+ ;;
191
+ esac
192
+ }
193
+
194
+ # Quick SSH connection
195
+ cmd_ssh() {
196
+ local server="$1"
197
+
198
+ if [ -z "$server" ]; then
199
+ print_error "Usage: ssh-manager ssh <server>"
200
+ return 1
201
+ fi
202
+
203
+ local host=$(get_server_config "$server" "HOST")
204
+ local user=$(get_server_config "$server" "USER")
205
+ local port=$(get_server_config "$server" "PORT")
206
+ local keypath=$(get_server_config "$server" "KEYPATH")
207
+
208
+ port=${port:-22}
209
+
210
+ if [ -z "$host" ] || [ -z "$user" ]; then
211
+ print_error "Server '$server' not found"
212
+ return 1
213
+ fi
214
+
215
+ local ssh_opts="-p $port"
216
+ if [ -n "$keypath" ]; then
217
+ ssh_opts="$ssh_opts -i $keypath"
218
+ fi
219
+
220
+ print_info "Connecting to $server..."
221
+ ssh $ssh_opts "$user@$host"
222
+ }
223
+
224
+ # Simple tunnel creation
225
+ cmd_tunnel() {
226
+ local action="$1"
227
+ shift
228
+
229
+ case "$action" in
230
+ create)
231
+ local server="$1"
232
+ local type="$2"
233
+ local ports="$3"
234
+
235
+ if [ -z "$server" ] || [ -z "$type" ] || [ -z "$ports" ]; then
236
+ print_error "Usage: ssh-manager tunnel create <server> <local|remote|dynamic> <ports>"
237
+ print_info "Examples:"
238
+ print_info " Local: ssh-manager tunnel create prod1 local 3307:localhost:3306"
239
+ print_info " Remote: ssh-manager tunnel create prod1 remote 8080:localhost:8080"
240
+ print_info " Dynamic: ssh-manager tunnel create prod1 dynamic 1080"
241
+ return 1
242
+ fi
243
+
244
+ local host=$(get_server_config "$server" "HOST")
245
+ local user=$(get_server_config "$server" "USER")
246
+ local port=$(get_server_config "$server" "PORT")
247
+ local keypath=$(get_server_config "$server" "KEYPATH")
248
+
249
+ port=${port:-22}
250
+
251
+ if [ -z "$host" ] || [ -z "$user" ]; then
252
+ print_error "Server '$server' not found"
253
+ return 1
254
+ fi
255
+
256
+ local ssh_opts="-p $port -N -f"
257
+ if [ -n "$keypath" ]; then
258
+ ssh_opts="$ssh_opts -i $keypath"
259
+ fi
260
+
261
+ case "$type" in
262
+ local)
263
+ print_info "Creating local tunnel: $ports"
264
+ ssh $ssh_opts -L "$ports" "$user@$host"
265
+ ;;
266
+ remote)
267
+ print_info "Creating remote tunnel: $ports"
268
+ ssh $ssh_opts -R "$ports" "$user@$host"
269
+ ;;
270
+ dynamic)
271
+ print_info "Creating SOCKS proxy on port $ports"
272
+ ssh $ssh_opts -D "$ports" "$user@$host"
273
+ ;;
274
+ *)
275
+ print_error "Invalid tunnel type: $type"
276
+ return 1
277
+ ;;
278
+ esac
279
+
280
+ if [ $? -eq 0 ]; then
281
+ print_success "Tunnel created successfully"
282
+ else
283
+ print_error "Failed to create tunnel"
284
+ return 1
285
+ fi
286
+ ;;
287
+
288
+ list)
289
+ print_header "Active SSH Tunnels"
290
+ ps aux | grep -E "ssh.*(-L|-R|-D)" | grep -v grep || print_info "No active tunnels"
291
+ ;;
292
+
293
+ *)
294
+ print_error "Unknown tunnel command: $action"
295
+ echo "Available commands: create, list"
296
+ return 1
297
+ ;;
298
+ esac
299
+ }
300
+
301
+ # Main command handler
302
+ main() {
303
+ # Check for help/version flags
304
+ case "$1" in
305
+ -h|--help|help)
306
+ show_help
307
+ exit 0
308
+ ;;
309
+ -v|--version|version)
310
+ show_version
311
+ exit 0
312
+ ;;
313
+ esac
314
+
315
+ # Initialize configuration
316
+ init_config
317
+
318
+ # Check dependencies
319
+ if ! check_dependencies; then
320
+ exit 1
321
+ fi
322
+
323
+ # Get command
324
+ local command="$1"
325
+ shift || true
326
+
327
+ # Handle commands
328
+ case "$command" in
329
+ server)
330
+ cmd_server "$@"
331
+ ;;
332
+ exec)
333
+ cmd_exec "$@"
334
+ ;;
335
+ sync)
336
+ cmd_sync "$@"
337
+ ;;
338
+ ssh|connect)
339
+ cmd_ssh "$@"
340
+ ;;
341
+ tunnel)
342
+ cmd_tunnel "$@"
343
+ ;;
344
+ config)
345
+ case "$1" in
346
+ edit)
347
+ ${EDITOR:-nano} "$SSH_MANAGER_CONFIG"
348
+ ;;
349
+ show)
350
+ cat "$SSH_MANAGER_CONFIG"
351
+ ;;
352
+ init)
353
+ init_config
354
+ ;;
355
+ *)
356
+ print_error "Unknown config command: $1"
357
+ ;;
358
+ esac
359
+ ;;
360
+ ""|-i|--interactive|menu)
361
+ # Interactive mode
362
+ interactive_mode
363
+ ;;
364
+ *)
365
+ print_error "Unknown command: $command"
366
+ echo "Run 'ssh-manager --help' for usage information"
367
+ exit 1
368
+ ;;
369
+ esac
370
+ }
371
+
372
+ # Interactive mode with menu
373
+ interactive_mode() {
374
+ # Initialize configuration
375
+ init_config
376
+
377
+ # Check dependencies
378
+ if ! check_dependencies; then
379
+ exit 1
380
+ fi
381
+
382
+ while true; do
383
+ show_main_menu
384
+ read choice
385
+
386
+ case "$choice" in
387
+ 1)
388
+ # Server Management submenu
389
+ while true; do
390
+ show_server_menu
391
+ read server_choice
392
+
393
+ case "$server_choice" in
394
+ 1)
395
+ wizard_add_server
396
+ ;;
397
+ 2)
398
+ cmd_server_list
399
+ echo
400
+ read -p "Press Enter to continue..."
401
+ ;;
402
+ 3)
403
+ if select_server_menu "Test Connection"; then
404
+ test_ssh_connection "$selected_server"
405
+ echo
406
+ read -p "Press Enter to continue..."
407
+ fi
408
+ ;;
409
+ 4)
410
+ if select_server_menu "Show Server Details"; then
411
+ cmd_server_show "$selected_server"
412
+ echo
413
+ read -p "Press Enter to continue..."
414
+ fi
415
+ ;;
416
+ 5)
417
+ if select_server_menu "Edit Server"; then
418
+ print_info "Edit feature coming soon..."
419
+ echo
420
+ read -p "Press Enter to continue..."
421
+ fi
422
+ ;;
423
+ 6)
424
+ if select_server_menu "Remove Server"; then
425
+ echo
426
+ if prompt_yes_no "Remove server '$selected_server'?" "n"; then
427
+ remove_server_from_env "$selected_server"
428
+ fi
429
+ echo
430
+ read -p "Press Enter to continue..."
431
+ fi
432
+ ;;
433
+ 7)
434
+ cmd_server_edit
435
+ echo
436
+ read -p "Press Enter to continue..."
437
+ ;;
438
+ 0)
439
+ break
440
+ ;;
441
+ esac
442
+ done
443
+ ;;
444
+ 2)
445
+ # Quick Connect
446
+ if select_server_menu "Quick Connect"; then
447
+ print_info "Connecting to $selected_server..."
448
+ cmd_ssh "$selected_server"
449
+ fi
450
+ ;;
451
+ 3)
452
+ # File Sync
453
+ show_sync_menu
454
+ ;;
455
+ 4)
456
+ # SSH Tunnels
457
+ wizard_create_tunnel
458
+ ;;
459
+ 5)
460
+ # System Monitoring
461
+ if select_server_menu "System Monitoring"; then
462
+ echo
463
+ print_subheader "Monitor Type"
464
+ echo " 1) Overview"
465
+ echo " 2) CPU"
466
+ echo " 3) Memory"
467
+ echo " 4) Disk"
468
+ echo " 5) Network"
469
+ echo
470
+ read -p "Choose [1-5]: " monitor_type
471
+
472
+ case "$monitor_type" in
473
+ 1) cmd_exec "$selected_server" "uptime && free -h && df -h" ;;
474
+ 2) cmd_exec "$selected_server" "top -bn1 | head -20" ;;
475
+ 3) cmd_exec "$selected_server" "free -h && ps aux --sort=-%mem | head -10" ;;
476
+ 4) cmd_exec "$selected_server" "df -h && du -sh /* 2>/dev/null | sort -h | tail -10" ;;
477
+ 5) cmd_exec "$selected_server" "netstat -tulpn 2>/dev/null | grep LISTEN" ;;
478
+ esac
479
+ echo
480
+ read -p "Press Enter to continue..."
481
+ fi
482
+ ;;
483
+ 6)
484
+ # Execute Commands
485
+ if select_server_menu "Execute Command"; then
486
+ echo
487
+ local command
488
+ prompt_input "Command to execute" "uptime" "command"
489
+ echo
490
+ cmd_exec "$selected_server" "$command"
491
+ echo
492
+ read -p "Press Enter to continue..."
493
+ fi
494
+ ;;
495
+ 7)
496
+ # Configuration
497
+ clear
498
+ print_header "Configuration"
499
+ echo " 1) Edit CLI config"
500
+ echo " 2) Show CLI config"
501
+ echo " 3) Edit server config (.env)"
502
+ echo " 0) Back"
503
+ echo
504
+ read -p "Choose [0-3]: " config_choice
505
+
506
+ case "$config_choice" in
507
+ 1) ${EDITOR:-nano} "$SSH_MANAGER_CONFIG" ;;
508
+ 2) cat "$SSH_MANAGER_CONFIG"; read -p "Press Enter..." ;;
509
+ 3) cmd_server_edit ;;
510
+ esac
511
+ ;;
512
+ 8)
513
+ # Help
514
+ show_help | less
515
+ ;;
516
+ 0|q|Q)
517
+ print_info "Goodbye!"
518
+ exit 0
519
+ ;;
520
+ esac
521
+ done
522
+ }
523
+
524
+ # Run main function
525
+ main "$@"