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
package/cli/README.md ADDED
@@ -0,0 +1,286 @@
1
+ # SSH Manager CLI
2
+
3
+ A simple, powerful, and fast Bash-based CLI for managing SSH servers.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **Fast**: Pure Bash, no runtime dependencies
8
+ - 🎨 **Beautiful**: Colored output with emojis
9
+ - 📦 **Simple**: Single command for all operations
10
+ - 🔧 **Powerful**: Tunnels, sync, monitoring, and more
11
+ - 🔌 **Integrated**: Works with MCP SSH Manager server
12
+
13
+ ## Installation
14
+
15
+ ### Quick Install
16
+
17
+ ```bash
18
+ cd cli
19
+ ./install.sh
20
+ ```
21
+
22
+ ### Manual Install
23
+
24
+ ```bash
25
+ # Copy CLI to your home
26
+ cp -r cli ~/.ssh-manager-cli
27
+
28
+ # Create symlink
29
+ sudo ln -s ~/.ssh-manager-cli/ssh-manager /usr/local/bin/ssh-manager
30
+
31
+ # Make executable
32
+ chmod +x ~/.ssh-manager-cli/ssh-manager
33
+ ```
34
+
35
+ ### Dependencies
36
+
37
+ **Required:**
38
+ - `bash` (4.0+)
39
+ - `ssh`
40
+ - `rsync`
41
+
42
+ **Optional:**
43
+ - `jq` - For JSON configuration management
44
+ - `sshpass` - For password authentication testing
45
+
46
+ ## Usage
47
+
48
+ ### Server Management
49
+
50
+ ```bash
51
+ # Add a new server interactively
52
+ ssh-manager server add
53
+
54
+ # List all servers
55
+ ssh-manager server list
56
+
57
+ # Test connection
58
+ ssh-manager server test prod1
59
+
60
+ # Show server details
61
+ ssh-manager server show prod1
62
+
63
+ # Remove a server
64
+ ssh-manager server remove prod1
65
+
66
+ # Edit configuration
67
+ ssh-manager server edit
68
+ ```
69
+
70
+ ### Quick SSH Connection
71
+
72
+ ```bash
73
+ # Connect to a server
74
+ ssh-manager ssh prod1
75
+ ```
76
+
77
+ ### File Synchronization
78
+
79
+ ```bash
80
+ # Push files to server
81
+ ssh-manager sync push prod1 ./app /var/www/app
82
+
83
+ # Pull files from server
84
+ ssh-manager sync pull prod1 /var/log/app.log ./logs/
85
+ ```
86
+
87
+ ### SSH Tunnels
88
+
89
+ ```bash
90
+ # Local port forwarding (access remote service locally)
91
+ ssh-manager tunnel create prod1 local 3307:localhost:3306
92
+
93
+ # Remote port forwarding (expose local service)
94
+ ssh-manager tunnel create prod1 remote 8080:localhost:8080
95
+
96
+ # SOCKS proxy
97
+ ssh-manager tunnel create prod1 dynamic 1080
98
+
99
+ # List active tunnels
100
+ ssh-manager tunnel list
101
+ ```
102
+
103
+ ### Execute Commands
104
+
105
+ ```bash
106
+ # Run command on server
107
+ ssh-manager exec prod1 "uptime"
108
+
109
+ # Run complex commands
110
+ ssh-manager exec prod1 "df -h | grep /var"
111
+ ```
112
+
113
+ ## Configuration
114
+
115
+ ### Server Configuration (.env)
116
+
117
+ Servers are stored in `.env` file in your project root:
118
+
119
+ ```env
120
+ # Production Server
121
+ SSH_SERVER_PROD1_HOST=192.168.1.100
122
+ SSH_SERVER_PROD1_USER=admin
123
+ SSH_SERVER_PROD1_PORT=22
124
+ SSH_SERVER_PROD1_KEYPATH=~/.ssh/id_rsa
125
+ SSH_SERVER_PROD1_DESCRIPTION="Production Web Server"
126
+
127
+ # Database Server
128
+ SSH_SERVER_DB1_HOST=192.168.1.101
129
+ SSH_SERVER_DB1_USER=dbadmin
130
+ SSH_SERVER_DB1_PASSWORD=secret
131
+ SSH_SERVER_DB1_DEFAULT_DIR=/var/lib/mysql
132
+ ```
133
+
134
+ ### CLI Configuration
135
+
136
+ Configuration stored in `~/.ssh-manager/config.json`:
137
+
138
+ ```json
139
+ {
140
+ "default_editor": "nano",
141
+ "default_shell": "/bin/bash",
142
+ "color_output": true,
143
+ "log_level": "info"
144
+ }
145
+ ```
146
+
147
+ ## Examples
148
+
149
+ ### Database Tunnel
150
+
151
+ Access remote MySQL locally:
152
+
153
+ ```bash
154
+ # Create tunnel
155
+ ssh-manager tunnel create prod1 local 3307:localhost:3306
156
+
157
+ # Connect to MySQL
158
+ mysql -h localhost -P 3307 -u root -p
159
+ ```
160
+
161
+ ### Deploy Application
162
+
163
+ ```bash
164
+ # Sync application files
165
+ ssh-manager sync push prod1 ./dist/ /var/www/app/
166
+
167
+ # Restart service
168
+ ssh-manager exec prod1 "sudo systemctl restart app"
169
+
170
+ # Check status
171
+ ssh-manager exec prod1 "systemctl status app"
172
+ ```
173
+
174
+ ### Backup Logs
175
+
176
+ ```bash
177
+ # Create backup directory
178
+ mkdir -p ./backups/$(date +%Y%m%d)
179
+
180
+ # Pull logs
181
+ ssh-manager sync pull prod1 /var/log/app/ ./backups/$(date +%Y%m%d)/
182
+ ```
183
+
184
+ ## Advanced Usage
185
+
186
+ ### Using with MCP Server
187
+
188
+ The CLI works seamlessly with the MCP SSH Manager server:
189
+
190
+ ```bash
191
+ # Use CLI for configuration
192
+ ssh-manager server add
193
+
194
+ # Use MCP tools in Claude for operations
195
+ # The same .env file is shared
196
+ ```
197
+
198
+ ### Scripting
199
+
200
+ ```bash
201
+ #!/bin/bash
202
+ # Deploy script using ssh-manager
203
+
204
+ SERVERS=(prod1 prod2 prod3)
205
+
206
+ for server in "${SERVERS[@]}"; do
207
+ echo "Deploying to $server..."
208
+ ssh-manager sync push $server ./dist/ /var/www/app/
209
+ ssh-manager exec $server "sudo systemctl restart app"
210
+ done
211
+ ```
212
+
213
+ ### Aliases
214
+
215
+ Create shell aliases for common operations:
216
+
217
+ ```bash
218
+ # Add to ~/.bashrc or ~/.zshrc
219
+ alias sml='ssh-manager server list'
220
+ alias smt='ssh-manager server test'
221
+ alias smc='ssh-manager ssh'
222
+
223
+ # Usage
224
+ sml # List servers
225
+ smt prod1 # Test prod1
226
+ smc prod1 # Connect to prod1
227
+ ```
228
+
229
+ ## Comparison with Python CLI
230
+
231
+ | Feature | Bash CLI | Python CLI |
232
+ |---------|----------|------------|
233
+ | Speed | ⚡ Very fast | 🐢 Slower startup |
234
+ | Dependencies | ✅ None (bash/ssh) | ❌ Python packages |
235
+ | Installation | ✅ Simple copy | ❌ pip install |
236
+ | Windows | ❌ WSL needed | ✅ Native |
237
+ | Features | ✅ All essential | ✅ All features |
238
+
239
+ ## Troubleshooting
240
+
241
+ ### Command not found
242
+
243
+ ```bash
244
+ # Check if installed
245
+ which ssh-manager
246
+
247
+ # Add to PATH if needed
248
+ export PATH="$PATH:/usr/local/bin"
249
+ ```
250
+
251
+ ### Permission denied
252
+
253
+ ```bash
254
+ # Make executable
255
+ chmod +x ~/.ssh-manager-cli/ssh-manager
256
+
257
+ # Install with sudo if needed
258
+ sudo ./install.sh
259
+ ```
260
+
261
+ ### Missing dependencies
262
+
263
+ ```bash
264
+ # macOS
265
+ brew install jq
266
+
267
+ # Ubuntu/Debian
268
+ sudo apt-get install jq sshpass
269
+
270
+ # RHEL/CentOS
271
+ sudo yum install jq sshpass
272
+ ```
273
+
274
+ ## Contributing
275
+
276
+ The CLI is part of the MCP SSH Manager project. Contributions welcome!
277
+
278
+ 1. Fork the repository
279
+ 2. Create your feature branch
280
+ 3. Commit your changes
281
+ 4. Push to the branch
282
+ 5. Create a Pull Request
283
+
284
+ ## License
285
+
286
+ MIT License - See LICENSE file for details
package/cli/build.sh ADDED
@@ -0,0 +1,199 @@
1
+ #!/bin/bash
2
+ # Build script for SSH Manager CLI
3
+ # This script prepares and packages the CLI for distribution
4
+
5
+ set -e # Exit on error
6
+
7
+ # Colors for output
8
+ RED=$'\033[0;31m'
9
+ GREEN=$'\033[0;32m'
10
+ YELLOW=$'\033[1;33m'
11
+ BLUE=$'\033[0;34m'
12
+ NC=$'\033[0m'
13
+
14
+ # Directories
15
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16
+ SOURCE_DIR="$SCRIPT_DIR"
17
+ TARGET_DIR="$HOME/.ssh-manager-cli"
18
+ TEMP_BUILD="/tmp/ssh-manager-build-$$"
19
+
20
+ # Version
21
+ VERSION="2.0.2"
22
+
23
+ echo -e "${BLUE}╔════════════════════════════════════════════╗${NC}"
24
+ echo -e "${BLUE}║ SSH Manager CLI Build Script v$VERSION ║${NC}"
25
+ echo -e "${BLUE}╚════════════════════════════════════════════╝${NC}"
26
+ echo
27
+
28
+ # Function to print status
29
+ print_status() {
30
+ echo -e "${GREEN}✓${NC} $1"
31
+ }
32
+
33
+ print_error() {
34
+ echo -e "${RED}✗${NC} $1" >&2
35
+ }
36
+
37
+ print_info() {
38
+ echo -e "${BLUE}ℹ${NC} $1"
39
+ }
40
+
41
+ # Clean up on exit
42
+ cleanup() {
43
+ if [ -d "$TEMP_BUILD" ]; then
44
+ rm -rf "$TEMP_BUILD"
45
+ fi
46
+ }
47
+ trap cleanup EXIT
48
+
49
+ # Step 1: Validate source files
50
+ echo -e "${YELLOW}Step 1: Validating source files...${NC}"
51
+ if [ ! -f "$SOURCE_DIR/ssh-manager" ]; then
52
+ print_error "ssh-manager script not found!"
53
+ exit 1
54
+ fi
55
+
56
+ if [ ! -d "$SOURCE_DIR/lib" ]; then
57
+ print_error "lib directory not found!"
58
+ exit 1
59
+ fi
60
+
61
+ if [ ! -d "$SOURCE_DIR/commands" ]; then
62
+ print_error "commands directory not found!"
63
+ exit 1
64
+ fi
65
+ print_status "Source files validated"
66
+ echo
67
+
68
+ # Step 2: Check syntax
69
+ echo -e "${YELLOW}Step 2: Checking shell syntax...${NC}"
70
+ for file in "$SOURCE_DIR/ssh-manager" "$SOURCE_DIR"/lib/*.sh "$SOURCE_DIR"/commands/*.sh; do
71
+ if [ -f "$file" ]; then
72
+ bash -n "$file" || {
73
+ print_error "Syntax error in $file"
74
+ exit 1
75
+ }
76
+ fi
77
+ done
78
+ print_status "Shell syntax check passed"
79
+ echo
80
+
81
+ # Step 3: Create build directory
82
+ echo -e "${YELLOW}Step 3: Creating build directory...${NC}"
83
+ mkdir -p "$TEMP_BUILD"
84
+ print_status "Build directory created: $TEMP_BUILD"
85
+ echo
86
+
87
+ # Step 4: Copy files to build directory
88
+ echo -e "${YELLOW}Step 4: Copying files to build directory...${NC}"
89
+ cp -r "$SOURCE_DIR"/* "$TEMP_BUILD/"
90
+ print_status "Files copied to build directory"
91
+ echo
92
+
93
+ # Step 5: Set executable permissions
94
+ echo -e "${YELLOW}Step 5: Setting permissions...${NC}"
95
+ chmod +x "$TEMP_BUILD/ssh-manager"
96
+ chmod +x "$TEMP_BUILD/install.sh"
97
+ chmod +x "$TEMP_BUILD/migrate.sh"
98
+ chmod +x "$TEMP_BUILD/demo.sh" 2>/dev/null || true
99
+ print_status "Executable permissions set"
100
+ echo
101
+
102
+ # Step 6: Update version in files
103
+ echo -e "${YELLOW}Step 6: Updating version number...${NC}"
104
+ sed -i.bak "s/VERSION=\".*\"/VERSION=\"$VERSION\"/" "$TEMP_BUILD/ssh-manager"
105
+ rm -f "$TEMP_BUILD/ssh-manager.bak"
106
+ print_status "Version updated to $VERSION"
107
+ echo
108
+
109
+ # Step 7: Validate configuration
110
+ echo -e "${YELLOW}Step 7: Validating configuration...${NC}"
111
+ if [ ! -f "$HOME/mcp/mcp-ssh-manager/.env" ] && [ ! -f "$HOME/.ssh-manager/.env" ]; then
112
+ print_info "No .env file found. You'll need to configure servers after installation."
113
+ else
114
+ print_status "Configuration file found"
115
+ fi
116
+ echo
117
+
118
+ # Step 8: Create installation package
119
+ echo -e "${YELLOW}Step 8: Creating installation package...${NC}"
120
+ if [ "$1" == "--package" ]; then
121
+ PACKAGE_FILE="$SCRIPT_DIR/ssh-manager-cli-${VERSION}.tar.gz"
122
+ cd "$TEMP_BUILD"
123
+ tar -czf "$PACKAGE_FILE" .
124
+ print_status "Package created: $PACKAGE_FILE"
125
+ echo
126
+ fi
127
+
128
+ # Step 9: Install to system (optional)
129
+ if [ "$1" == "--install" ] || [ "$1" == "" ]; then
130
+ echo -e "${YELLOW}Step 9: Installing to system...${NC}"
131
+
132
+ # Backup existing installation if present
133
+ if [ -d "$TARGET_DIR" ]; then
134
+ BACKUP_DIR="$TARGET_DIR.backup.$(date +%Y%m%d_%H%M%S)"
135
+ print_info "Backing up existing installation to $BACKUP_DIR"
136
+ mv "$TARGET_DIR" "$BACKUP_DIR"
137
+ fi
138
+
139
+ # Install new version
140
+ mkdir -p "$TARGET_DIR"
141
+ cp -r "$TEMP_BUILD"/* "$TARGET_DIR/"
142
+
143
+ # Create symlink in PATH if not exists
144
+ if [ ! -L "/usr/local/bin/ssh-manager" ]; then
145
+ if ln -sf "$TARGET_DIR/ssh-manager" "/usr/local/bin/ssh-manager" 2>/dev/null; then
146
+ print_status "Symlink created in /usr/local/bin"
147
+ else
148
+ print_info "Could not create symlink in /usr/local/bin (may need sudo)"
149
+ print_info "You can manually add $TARGET_DIR to your PATH"
150
+ fi
151
+ else
152
+ print_status "Symlink already exists in /usr/local/bin"
153
+ fi
154
+
155
+ print_status "Installation complete!"
156
+ echo
157
+ fi
158
+
159
+ # Step 10: Run tests (optional)
160
+ if [ "$1" == "--test" ]; then
161
+ echo -e "${YELLOW}Step 10: Running tests...${NC}"
162
+
163
+ # Test help command
164
+ if "$TARGET_DIR/ssh-manager" --help >/dev/null 2>&1; then
165
+ print_status "Help command works"
166
+ else
167
+ print_error "Help command failed"
168
+ fi
169
+
170
+ # Test version command
171
+ if "$TARGET_DIR/ssh-manager" --version >/dev/null 2>&1; then
172
+ print_status "Version command works"
173
+ else
174
+ print_error "Version command failed"
175
+ fi
176
+
177
+ echo
178
+ fi
179
+
180
+ # Summary
181
+ echo -e "${BLUE}╔════════════════════════════════════════════╗${NC}"
182
+ echo -e "${BLUE}║ Build Complete! ║${NC}"
183
+ echo -e "${BLUE}╚════════════════════════════════════════════╝${NC}"
184
+ echo
185
+ echo "Usage:"
186
+ echo " ./build.sh # Build and install"
187
+ echo " ./build.sh --install # Build and install"
188
+ echo " ./build.sh --package # Create tar.gz package"
189
+ echo " ./build.sh --test # Build, install and test"
190
+ echo
191
+ echo "To use SSH Manager CLI:"
192
+ echo " ssh-manager # Interactive mode"
193
+ echo " ssh-manager --help # Show help"
194
+ echo
195
+
196
+ # Clean up
197
+ cleanup
198
+
199
+ exit 0