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.
- package/.claude/settings.local.json +87 -0
- package/.flake8 +15 -0
- package/.hooks-config.json +131 -0
- package/.pre-commit-config.yaml +105 -0
- package/CHANGELOG.md +137 -0
- package/CLAUDE.md +190 -0
- package/CONTRIBUTING.md +114 -0
- package/DESCRIPTION +1 -0
- package/INSTALLATION.md +180 -0
- package/LICENSE +21 -0
- package/QUICKSTART.md +77 -0
- package/README.md +718 -0
- package/cli/README.md +286 -0
- package/cli/build.sh +199 -0
- package/cli/commands/server.sh +284 -0
- package/cli/demo.sh +107 -0
- package/cli/install.sh +164 -0
- package/cli/lib/colors.sh +174 -0
- package/cli/lib/config.sh +284 -0
- package/cli/lib/menu.sh +430 -0
- package/cli/migrate.sh +168 -0
- package/cli/ssh-manager +525 -0
- package/docs/ALIASES_AND_HOOKS.md +285 -0
- package/docs/BACKUP_GUIDE.md +500 -0
- package/docs/DEPLOYMENT_GUIDE.md +241 -0
- package/docs/SEO.md +257 -0
- package/examples/backup-workflow.js +481 -0
- package/examples/claude-code-config.example.json +40 -0
- package/examples/codex-ssh-config.example.toml +71 -0
- package/examples/deploy-workflow.py +183 -0
- package/glama.json +6 -0
- package/package.json +85 -0
- package/profiles/README.md +40 -0
- package/profiles/default.json +52 -0
- package/profiles/docker.json +62 -0
- package/profiles/frappe.json +107 -0
- package/profiles/nodejs.json +63 -0
- package/pyproject.toml +17 -0
- package/scripts/setup-hooks.sh +60 -0
- package/scripts/validate.sh +76 -0
- package/src/backup-manager.js +469 -0
- package/src/command-aliases.js +151 -0
- package/src/config-loader.js +281 -0
- package/src/database-manager.js +555 -0
- package/src/deploy-helper.js +176 -0
- package/src/health-monitor.js +428 -0
- package/src/hooks-system.js +327 -0
- package/src/index.js +4499 -0
- package/src/logger.js +276 -0
- package/src/profile-loader.js +187 -0
- package/src/server-aliases.js +150 -0
- package/src/server-groups.js +409 -0
- package/src/session-manager.js +410 -0
- package/src/ssh-key-manager.js +378 -0
- package/src/ssh-manager.js +435 -0
- package/src/tunnel-manager.js +576 -0
package/cli/lib/menu.sh
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Interactive menu library for ssh-manager CLI
|
|
3
|
+
|
|
4
|
+
# Display main menu
|
|
5
|
+
show_main_menu() {
|
|
6
|
+
clear
|
|
7
|
+
print_header "SSH Manager CLI v$VERSION"
|
|
8
|
+
echo
|
|
9
|
+
echo -e " ${CYAN}1)${NC} ${SERVER} Server Management"
|
|
10
|
+
echo " Add, list, test, and manage SSH servers"
|
|
11
|
+
echo
|
|
12
|
+
echo -e " ${CYAN}2)${NC} ${SESSION} Quick Connect"
|
|
13
|
+
echo " Connect to a server via SSH"
|
|
14
|
+
echo
|
|
15
|
+
echo -e " ${CYAN}3)${NC} ${SYNC} File Synchronization"
|
|
16
|
+
echo " Push/pull files with rsync"
|
|
17
|
+
echo
|
|
18
|
+
echo -e " ${CYAN}4)${NC} ${TUNNEL} SSH Tunnels"
|
|
19
|
+
echo " Create and manage SSH tunnels"
|
|
20
|
+
echo
|
|
21
|
+
echo -e " ${CYAN}5)${NC} ${MONITOR} System Monitoring"
|
|
22
|
+
echo " Monitor server resources"
|
|
23
|
+
echo
|
|
24
|
+
echo -e " ${CYAN}6)${NC} ${ROCKET} Execute Commands"
|
|
25
|
+
echo " Run commands on servers"
|
|
26
|
+
echo
|
|
27
|
+
echo -e " ${CYAN}7)${NC} ${GEAR} Configuration"
|
|
28
|
+
echo " Edit settings and preferences"
|
|
29
|
+
echo
|
|
30
|
+
echo -e " ${CYAN}8)${NC} ${INFO} Help & Documentation"
|
|
31
|
+
echo " View help and examples"
|
|
32
|
+
echo
|
|
33
|
+
echo -e " ${CYAN}0)${NC} Exit"
|
|
34
|
+
echo
|
|
35
|
+
echo -e "${GRAY}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
36
|
+
echo -n "Choose an option [0-8]: "
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# Server management submenu
|
|
40
|
+
show_server_menu() {
|
|
41
|
+
clear
|
|
42
|
+
print_header "Server Management"
|
|
43
|
+
echo
|
|
44
|
+
echo -e " ${CYAN}1)${NC} ${CHECK} Add New Server"
|
|
45
|
+
echo " Configure a new SSH server"
|
|
46
|
+
echo
|
|
47
|
+
echo -e " ${CYAN}2)${NC} ${CLIPBOARD} List All Servers"
|
|
48
|
+
echo " Show configured servers"
|
|
49
|
+
echo
|
|
50
|
+
echo -e " ${CYAN}3)${NC} ${WRENCH} Test Connection"
|
|
51
|
+
echo " Test server connectivity"
|
|
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]: "
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# Enhanced server add wizard
|
|
72
|
+
wizard_add_server() {
|
|
73
|
+
clear
|
|
74
|
+
print_header "Add New SSH Server - Setup Wizard"
|
|
75
|
+
echo
|
|
76
|
+
print_info "This wizard will guide you through adding a new SSH server."
|
|
77
|
+
print_info "Press Ctrl+C at any time to cancel."
|
|
78
|
+
echo
|
|
79
|
+
|
|
80
|
+
# Step 1: Server name
|
|
81
|
+
print_subheader "Step 1: Server Identification"
|
|
82
|
+
echo "Choose a short, memorable name for this server."
|
|
83
|
+
echo "Examples: prod1, web-server, database, staging"
|
|
84
|
+
echo
|
|
85
|
+
|
|
86
|
+
local server_name
|
|
87
|
+
while true; do
|
|
88
|
+
prompt_input "Server name" "" "server_name"
|
|
89
|
+
if validate_server_name "$server_name"; then
|
|
90
|
+
# Check if already exists
|
|
91
|
+
if get_server_config "$server_name" "HOST" >/dev/null 2>&1; then
|
|
92
|
+
print_error "Server '$server_name' already exists!"
|
|
93
|
+
if prompt_yes_no "Choose a different name?" "y"; then
|
|
94
|
+
continue
|
|
95
|
+
else
|
|
96
|
+
return 1
|
|
97
|
+
fi
|
|
98
|
+
fi
|
|
99
|
+
break
|
|
100
|
+
fi
|
|
101
|
+
done
|
|
102
|
+
|
|
103
|
+
# Step 2: Connection details
|
|
104
|
+
echo
|
|
105
|
+
print_subheader "Step 2: Connection Details"
|
|
106
|
+
|
|
107
|
+
local host
|
|
108
|
+
echo "Enter the server's hostname or IP address."
|
|
109
|
+
echo "Examples: 192.168.1.100, example.com, server.local"
|
|
110
|
+
prompt_input "Host/IP" "" "host"
|
|
111
|
+
|
|
112
|
+
local user
|
|
113
|
+
echo
|
|
114
|
+
echo "Enter the username for SSH connection."
|
|
115
|
+
echo "Common choices: root, ubuntu, admin, deploy"
|
|
116
|
+
prompt_input "Username" "${USER}" "user"
|
|
117
|
+
|
|
118
|
+
local port
|
|
119
|
+
echo
|
|
120
|
+
echo "Enter the SSH port (standard is 22)."
|
|
121
|
+
prompt_input "SSH Port" "22" "port"
|
|
122
|
+
|
|
123
|
+
# Step 3: Authentication
|
|
124
|
+
echo
|
|
125
|
+
print_subheader "Step 3: Authentication Method"
|
|
126
|
+
echo "How do you want to authenticate?"
|
|
127
|
+
echo
|
|
128
|
+
echo -e " ${CYAN}1)${NC} ${KEY} SSH Key (Recommended)"
|
|
129
|
+
echo " More secure, no password needed"
|
|
130
|
+
echo
|
|
131
|
+
echo -e " ${CYAN}2)${NC} ${LOCK} Password"
|
|
132
|
+
echo " Less secure, password required each time"
|
|
133
|
+
echo
|
|
134
|
+
read -p "Choose [1-2]: " auth_choice
|
|
135
|
+
|
|
136
|
+
local auth_type auth_value
|
|
137
|
+
case "$auth_choice" in
|
|
138
|
+
2)
|
|
139
|
+
auth_type="password"
|
|
140
|
+
echo
|
|
141
|
+
print_warning "Password authentication is less secure than SSH keys."
|
|
142
|
+
prompt_password "Enter password" "auth_value"
|
|
143
|
+
;;
|
|
144
|
+
*)
|
|
145
|
+
auth_type="key"
|
|
146
|
+
echo
|
|
147
|
+
echo "Enter the path to your SSH private key."
|
|
148
|
+
echo "Common locations:"
|
|
149
|
+
echo " • ~/.ssh/id_rsa (default RSA key)"
|
|
150
|
+
echo " • ~/.ssh/id_ed25519 (modern ED25519 key)"
|
|
151
|
+
echo " • ~/.ssh/custom_key (custom key)"
|
|
152
|
+
prompt_input "SSH key path" "$HOME/.ssh/id_rsa" "auth_value"
|
|
153
|
+
auth_value="${auth_value/#\~/$HOME}"
|
|
154
|
+
|
|
155
|
+
# Check if key exists
|
|
156
|
+
if [ ! -f "$auth_value" ]; then
|
|
157
|
+
print_warning "Key file not found: $auth_value"
|
|
158
|
+
if ! prompt_yes_no "Continue anyway?" "n"; then
|
|
159
|
+
return 1
|
|
160
|
+
fi
|
|
161
|
+
fi
|
|
162
|
+
;;
|
|
163
|
+
esac
|
|
164
|
+
|
|
165
|
+
# Step 4: Optional settings
|
|
166
|
+
echo
|
|
167
|
+
print_subheader "Step 4: Optional Settings"
|
|
168
|
+
|
|
169
|
+
local description
|
|
170
|
+
echo "Add a description to help identify this server (optional)."
|
|
171
|
+
echo "Example: Production web server, Database backup, Test environment"
|
|
172
|
+
prompt_input "Description" "" "description"
|
|
173
|
+
|
|
174
|
+
local default_dir
|
|
175
|
+
echo
|
|
176
|
+
echo "Set a default directory for this server (optional)."
|
|
177
|
+
echo "Example: /var/www/html, /home/user/app, /opt/services"
|
|
178
|
+
prompt_input "Default directory" "" "default_dir"
|
|
179
|
+
|
|
180
|
+
# Step 5: Review
|
|
181
|
+
echo
|
|
182
|
+
print_subheader "Step 5: Review Configuration"
|
|
183
|
+
echo
|
|
184
|
+
print_table_row "Name:" "$server_name"
|
|
185
|
+
print_table_row "Host:" "$host"
|
|
186
|
+
print_table_row "User:" "$user"
|
|
187
|
+
print_table_row "Port:" "$port"
|
|
188
|
+
print_table_row "Auth:" "$auth_type"
|
|
189
|
+
if [ "$auth_type" = "key" ]; then
|
|
190
|
+
print_table_row "Key:" "$auth_value"
|
|
191
|
+
else
|
|
192
|
+
print_table_row "Password:" "********"
|
|
193
|
+
fi
|
|
194
|
+
if [ -n "$description" ]; then
|
|
195
|
+
print_table_row "Description:" "$description"
|
|
196
|
+
fi
|
|
197
|
+
if [ -n "$default_dir" ]; then
|
|
198
|
+
print_table_row "Default Dir:" "$default_dir"
|
|
199
|
+
fi
|
|
200
|
+
|
|
201
|
+
echo
|
|
202
|
+
if prompt_yes_no "Save this configuration?" "y"; then
|
|
203
|
+
# Save to .env
|
|
204
|
+
add_server_to_env "$server_name" "$host" "$user" "$auth_type" "$auth_value" "$port" "$description"
|
|
205
|
+
|
|
206
|
+
# Add default directory if specified
|
|
207
|
+
if [ -n "$default_dir" ]; then
|
|
208
|
+
local name_upper="$(echo "$server_name" | tr '[:lower:]' '[:upper:]')"
|
|
209
|
+
echo "SSH_SERVER_${name_upper}_DEFAULT_DIR=$default_dir" >> "$SSH_MANAGER_ENV"
|
|
210
|
+
fi
|
|
211
|
+
|
|
212
|
+
echo
|
|
213
|
+
print_success "Server '$server_name' added successfully!"
|
|
214
|
+
|
|
215
|
+
echo
|
|
216
|
+
if prompt_yes_no "Test connection now?" "y"; then
|
|
217
|
+
echo
|
|
218
|
+
test_ssh_connection "$server_name"
|
|
219
|
+
fi
|
|
220
|
+
|
|
221
|
+
echo
|
|
222
|
+
print_info "Quick commands for '$server_name':"
|
|
223
|
+
echo " • Connect: ssh-manager ssh $server_name"
|
|
224
|
+
echo " • Test: ssh-manager server test $server_name"
|
|
225
|
+
echo " • Execute: ssh-manager exec $server_name \"command\""
|
|
226
|
+
|
|
227
|
+
echo
|
|
228
|
+
read -p "Press Enter to continue..."
|
|
229
|
+
else
|
|
230
|
+
print_info "Configuration cancelled"
|
|
231
|
+
fi
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
# Server selection menu
|
|
235
|
+
select_server_menu() {
|
|
236
|
+
local prompt_text="${1:-Select a server}"
|
|
237
|
+
local servers=($(load_servers))
|
|
238
|
+
|
|
239
|
+
if [ ${#servers[@]} -eq 0 ]; then
|
|
240
|
+
print_warning "No servers configured"
|
|
241
|
+
print_info "Use 'Add New Server' to configure one"
|
|
242
|
+
read -p "Press Enter to continue..."
|
|
243
|
+
return 1
|
|
244
|
+
fi
|
|
245
|
+
|
|
246
|
+
clear
|
|
247
|
+
print_header "$prompt_text"
|
|
248
|
+
echo
|
|
249
|
+
|
|
250
|
+
local i=1
|
|
251
|
+
for server in "${servers[@]}"; do
|
|
252
|
+
local host=$(get_server_config "$server" "HOST")
|
|
253
|
+
local user=$(get_server_config "$server" "USER")
|
|
254
|
+
local desc=$(get_server_config "$server" "DESCRIPTION")
|
|
255
|
+
|
|
256
|
+
echo -e " ${CYAN}$i)${NC} ${SERVER}$server"
|
|
257
|
+
echo " $user@$host"
|
|
258
|
+
if [ -n "$desc" ]; then
|
|
259
|
+
echo " ${GRAY}$desc${NC}"
|
|
260
|
+
fi
|
|
261
|
+
echo
|
|
262
|
+
((i++))
|
|
263
|
+
done
|
|
264
|
+
|
|
265
|
+
echo -e " ${CYAN}0)${NC} Cancel"
|
|
266
|
+
echo
|
|
267
|
+
echo -e "${GRAY}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
268
|
+
echo -n "Choose server [0-${#servers[@]}]: "
|
|
269
|
+
|
|
270
|
+
read choice
|
|
271
|
+
if [[ "$choice" =~ ^[0-9]+$ ]] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#servers[@]} ]; then
|
|
272
|
+
selected_server="${servers[$((choice-1))]}"
|
|
273
|
+
return 0
|
|
274
|
+
else
|
|
275
|
+
return 1
|
|
276
|
+
fi
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
# File sync menu
|
|
280
|
+
show_sync_menu() {
|
|
281
|
+
clear
|
|
282
|
+
print_header "File Synchronization"
|
|
283
|
+
|
|
284
|
+
if ! select_server_menu "Select server for file sync"; then
|
|
285
|
+
return
|
|
286
|
+
fi
|
|
287
|
+
|
|
288
|
+
local server="$selected_server"
|
|
289
|
+
|
|
290
|
+
echo
|
|
291
|
+
print_subheader "Sync Direction"
|
|
292
|
+
echo -e " ${CYAN}1)${NC} ${ARROW} Push (Local → Remote)"
|
|
293
|
+
echo " Upload files to $server"
|
|
294
|
+
echo
|
|
295
|
+
echo -e " ${CYAN}2)${NC} ${ARROW} Pull (Remote → Local)"
|
|
296
|
+
echo " Download files from $server"
|
|
297
|
+
echo
|
|
298
|
+
echo -e " ${CYAN}0)${NC} Cancel"
|
|
299
|
+
echo
|
|
300
|
+
read -p "Choose direction [0-2]: " direction
|
|
301
|
+
|
|
302
|
+
case "$direction" in
|
|
303
|
+
1)
|
|
304
|
+
echo
|
|
305
|
+
local source dest
|
|
306
|
+
prompt_input "Local source path" "." "source"
|
|
307
|
+
prompt_input "Remote destination path" "/tmp/" "dest"
|
|
308
|
+
|
|
309
|
+
echo
|
|
310
|
+
if prompt_yes_no "Dry run first?" "y"; then
|
|
311
|
+
cmd_sync push "$server" "$source" "$dest" --dry-run
|
|
312
|
+
echo
|
|
313
|
+
if prompt_yes_no "Proceed with actual sync?" "y"; then
|
|
314
|
+
cmd_sync push "$server" "$source" "$dest"
|
|
315
|
+
fi
|
|
316
|
+
else
|
|
317
|
+
cmd_sync push "$server" "$source" "$dest"
|
|
318
|
+
fi
|
|
319
|
+
;;
|
|
320
|
+
2)
|
|
321
|
+
echo
|
|
322
|
+
local source dest
|
|
323
|
+
prompt_input "Remote source path" "/tmp/" "source"
|
|
324
|
+
prompt_input "Local destination path" "." "dest"
|
|
325
|
+
|
|
326
|
+
echo
|
|
327
|
+
if prompt_yes_no "Dry run first?" "y"; then
|
|
328
|
+
cmd_sync pull "$server" "$source" "$dest" --dry-run
|
|
329
|
+
echo
|
|
330
|
+
if prompt_yes_no "Proceed with actual sync?" "y"; then
|
|
331
|
+
cmd_sync pull "$server" "$source" "$dest"
|
|
332
|
+
fi
|
|
333
|
+
else
|
|
334
|
+
cmd_sync pull "$server" "$source" "$dest"
|
|
335
|
+
fi
|
|
336
|
+
;;
|
|
337
|
+
esac
|
|
338
|
+
|
|
339
|
+
echo
|
|
340
|
+
read -p "Press Enter to continue..."
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
# Tunnel creation wizard
|
|
344
|
+
wizard_create_tunnel() {
|
|
345
|
+
clear
|
|
346
|
+
print_header "SSH Tunnel Creation Wizard"
|
|
347
|
+
|
|
348
|
+
if ! select_server_menu "Select server for tunnel"; then
|
|
349
|
+
return
|
|
350
|
+
fi
|
|
351
|
+
|
|
352
|
+
local server="$selected_server"
|
|
353
|
+
|
|
354
|
+
echo
|
|
355
|
+
print_subheader "Tunnel Type"
|
|
356
|
+
echo -e " ${CYAN}1)${NC} Local Port Forwarding"
|
|
357
|
+
echo " Access remote service through local port"
|
|
358
|
+
echo " Example: Access remote MySQL on local port 3307"
|
|
359
|
+
echo
|
|
360
|
+
echo -e " ${CYAN}2)${NC} Remote Port Forwarding"
|
|
361
|
+
echo " Expose local service to remote server"
|
|
362
|
+
echo " Example: Let remote access your local web server"
|
|
363
|
+
echo
|
|
364
|
+
echo -e " ${CYAN}3)${NC} Dynamic (SOCKS Proxy)"
|
|
365
|
+
echo " Create SOCKS5 proxy for secure browsing"
|
|
366
|
+
echo " Example: Route browser through SSH server"
|
|
367
|
+
echo
|
|
368
|
+
echo -e " ${CYAN}0)${NC} Cancel"
|
|
369
|
+
echo
|
|
370
|
+
read -p "Choose type [0-3]: " tunnel_type
|
|
371
|
+
|
|
372
|
+
case "$tunnel_type" in
|
|
373
|
+
1)
|
|
374
|
+
echo
|
|
375
|
+
print_info "Local Port Forwarding Setup"
|
|
376
|
+
echo "Access a remote service as if it were local"
|
|
377
|
+
echo
|
|
378
|
+
local local_port remote_host remote_port
|
|
379
|
+
prompt_input "Local port to listen on" "8080" "local_port"
|
|
380
|
+
prompt_input "Remote host (usually localhost)" "localhost" "remote_host"
|
|
381
|
+
prompt_input "Remote port to forward to" "80" "remote_port"
|
|
382
|
+
|
|
383
|
+
echo
|
|
384
|
+
print_info "Creating tunnel: localhost:$local_port → $server → $remote_host:$remote_port"
|
|
385
|
+
cmd_tunnel create "$server" local "$local_port:$remote_host:$remote_port"
|
|
386
|
+
|
|
387
|
+
echo
|
|
388
|
+
print_success "Tunnel created! Access the service at: http://localhost:$local_port"
|
|
389
|
+
;;
|
|
390
|
+
2)
|
|
391
|
+
echo
|
|
392
|
+
print_info "Remote Port Forwarding Setup"
|
|
393
|
+
echo "Expose your local service to the remote server"
|
|
394
|
+
echo
|
|
395
|
+
local remote_port local_host local_port
|
|
396
|
+
prompt_input "Remote port to listen on" "8080" "remote_port"
|
|
397
|
+
prompt_input "Local host (usually localhost)" "localhost" "local_host"
|
|
398
|
+
prompt_input "Local port to forward" "3000" "local_port"
|
|
399
|
+
|
|
400
|
+
echo
|
|
401
|
+
print_info "Creating tunnel: $server:$remote_port → local → $local_host:$local_port"
|
|
402
|
+
cmd_tunnel create "$server" remote "$remote_port:$local_host:$local_port"
|
|
403
|
+
|
|
404
|
+
echo
|
|
405
|
+
print_success "Tunnel created! Remote can access at: $server:$remote_port"
|
|
406
|
+
;;
|
|
407
|
+
3)
|
|
408
|
+
echo
|
|
409
|
+
print_info "SOCKS Proxy Setup"
|
|
410
|
+
echo "Route all traffic through SSH server"
|
|
411
|
+
echo
|
|
412
|
+
local socks_port
|
|
413
|
+
prompt_input "Local SOCKS port" "1080" "socks_port"
|
|
414
|
+
|
|
415
|
+
echo
|
|
416
|
+
print_info "Creating SOCKS5 proxy on port $socks_port"
|
|
417
|
+
cmd_tunnel create "$server" dynamic "$socks_port"
|
|
418
|
+
|
|
419
|
+
echo
|
|
420
|
+
print_success "SOCKS proxy created!"
|
|
421
|
+
print_info "Configure your browser/app to use:"
|
|
422
|
+
echo " • SOCKS Host: localhost"
|
|
423
|
+
echo " • SOCKS Port: $socks_port"
|
|
424
|
+
echo " • SOCKS Type: SOCKS5"
|
|
425
|
+
;;
|
|
426
|
+
esac
|
|
427
|
+
|
|
428
|
+
echo
|
|
429
|
+
read -p "Press Enter to continue..."
|
|
430
|
+
}
|
package/cli/migrate.sh
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Migration script from Python to Bash CLI
|
|
3
|
+
|
|
4
|
+
# Colors
|
|
5
|
+
GREEN='\033[0;32m'
|
|
6
|
+
YELLOW='\033[1;33m'
|
|
7
|
+
BLUE='\033[0;34m'
|
|
8
|
+
RED='\033[0;31m'
|
|
9
|
+
NC='\033[0m'
|
|
10
|
+
|
|
11
|
+
clear
|
|
12
|
+
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
13
|
+
echo -e "${BLUE} Migration: Python → Bash CLI${NC}"
|
|
14
|
+
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
15
|
+
echo
|
|
16
|
+
|
|
17
|
+
# Find .env file
|
|
18
|
+
ENV_LOCATIONS=(
|
|
19
|
+
"../.env"
|
|
20
|
+
"../../mcp-ssh-manager/.env"
|
|
21
|
+
"$HOME/mcp/mcp-ssh-manager/.env"
|
|
22
|
+
".env"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
ENV_FILE=""
|
|
26
|
+
for location in "${ENV_LOCATIONS[@]}"; do
|
|
27
|
+
if [ -f "$location" ]; then
|
|
28
|
+
ENV_FILE="$location"
|
|
29
|
+
break
|
|
30
|
+
fi
|
|
31
|
+
done
|
|
32
|
+
|
|
33
|
+
if [ -z "$ENV_FILE" ]; then
|
|
34
|
+
echo -e "${RED}❌ No .env file found!${NC}"
|
|
35
|
+
echo
|
|
36
|
+
echo "Searched in:"
|
|
37
|
+
for location in "${ENV_LOCATIONS[@]}"; do
|
|
38
|
+
echo " • $location"
|
|
39
|
+
done
|
|
40
|
+
echo
|
|
41
|
+
echo "Please specify the path to your .env file:"
|
|
42
|
+
read -p "Path: " ENV_FILE
|
|
43
|
+
|
|
44
|
+
if [ ! -f "$ENV_FILE" ]; then
|
|
45
|
+
echo -e "${RED}File not found: $ENV_FILE${NC}"
|
|
46
|
+
exit 1
|
|
47
|
+
fi
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
echo -e "${GREEN}✅ Found .env file:${NC} $ENV_FILE"
|
|
51
|
+
echo
|
|
52
|
+
|
|
53
|
+
# Count servers
|
|
54
|
+
SERVER_COUNT=$(grep "^SSH_SERVER_.*_HOST=" "$ENV_FILE" | wc -l | tr -d ' ')
|
|
55
|
+
echo -e "${BLUE}📊 Statistics:${NC}"
|
|
56
|
+
echo " • Servers configured: $SERVER_COUNT"
|
|
57
|
+
echo " • Configuration file: $(realpath "$ENV_FILE")"
|
|
58
|
+
echo
|
|
59
|
+
|
|
60
|
+
# Show servers
|
|
61
|
+
echo -e "${BLUE}🖥️ Your servers:${NC}"
|
|
62
|
+
grep "^SSH_SERVER_.*_HOST=" "$ENV_FILE" | while IFS= read -r line; do
|
|
63
|
+
SERVER_NAME=$(echo "$line" | sed 's/SSH_SERVER_\(.*\)_HOST=.*/\1/' | tr '[:upper:]' '[:lower:]')
|
|
64
|
+
HOST=$(echo "$line" | cut -d'=' -f2-)
|
|
65
|
+
echo " • $SERVER_NAME → $HOST"
|
|
66
|
+
done
|
|
67
|
+
echo
|
|
68
|
+
|
|
69
|
+
# Check if CLI is installed
|
|
70
|
+
if command -v ssh-manager >/dev/null 2>&1; then
|
|
71
|
+
echo -e "${GREEN}✅ Bash CLI is installed${NC}"
|
|
72
|
+
CLI_PATH="ssh-manager"
|
|
73
|
+
else
|
|
74
|
+
echo -e "${YELLOW}⚠️ Bash CLI not installed globally${NC}"
|
|
75
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
76
|
+
CLI_PATH="$SCRIPT_DIR/ssh-manager"
|
|
77
|
+
|
|
78
|
+
if [ ! -f "$CLI_PATH" ]; then
|
|
79
|
+
echo -e "${RED}❌ CLI not found at $CLI_PATH${NC}"
|
|
80
|
+
exit 1
|
|
81
|
+
fi
|
|
82
|
+
|
|
83
|
+
echo -e "${BLUE}Installing CLI...${NC}"
|
|
84
|
+
./install.sh
|
|
85
|
+
|
|
86
|
+
if command -v ssh-manager >/dev/null 2>&1; then
|
|
87
|
+
echo -e "${GREEN}✅ CLI installed successfully${NC}"
|
|
88
|
+
CLI_PATH="ssh-manager"
|
|
89
|
+
fi
|
|
90
|
+
fi
|
|
91
|
+
echo
|
|
92
|
+
|
|
93
|
+
# Create alias for .env path
|
|
94
|
+
echo -e "${BLUE}🔧 Setting up environment...${NC}"
|
|
95
|
+
|
|
96
|
+
# Create wrapper script
|
|
97
|
+
WRAPPER="$HOME/.ssh-manager/ssh-manager-wrapper.sh"
|
|
98
|
+
mkdir -p "$HOME/.ssh-manager"
|
|
99
|
+
|
|
100
|
+
cat > "$WRAPPER" << EOF
|
|
101
|
+
#!/bin/bash
|
|
102
|
+
# Auto-generated wrapper for SSH Manager CLI
|
|
103
|
+
export SSH_MANAGER_ENV="$(realpath "$ENV_FILE")"
|
|
104
|
+
exec ssh-manager "\$@"
|
|
105
|
+
EOF
|
|
106
|
+
|
|
107
|
+
chmod +x "$WRAPPER"
|
|
108
|
+
|
|
109
|
+
echo -e "${GREEN}✅ Environment configured${NC}"
|
|
110
|
+
echo
|
|
111
|
+
|
|
112
|
+
# Add to shell profile
|
|
113
|
+
echo -e "${BLUE}📝 Shell configuration:${NC}"
|
|
114
|
+
echo
|
|
115
|
+
echo "Add this line to your ~/.bashrc or ~/.zshrc:"
|
|
116
|
+
echo
|
|
117
|
+
echo -e "${YELLOW}export SSH_MANAGER_ENV=\"$(realpath "$ENV_FILE")\"${NC}"
|
|
118
|
+
echo
|
|
119
|
+
echo "Or use the wrapper:"
|
|
120
|
+
echo -e "${YELLOW}alias ssh-manager='$WRAPPER'${NC}"
|
|
121
|
+
echo
|
|
122
|
+
|
|
123
|
+
# Test the setup
|
|
124
|
+
echo -e "${BLUE}🧪 Testing configuration...${NC}"
|
|
125
|
+
echo
|
|
126
|
+
|
|
127
|
+
export SSH_MANAGER_ENV="$(realpath "$ENV_FILE")"
|
|
128
|
+
|
|
129
|
+
# Test server list
|
|
130
|
+
if $CLI_PATH server list >/dev/null 2>&1; then
|
|
131
|
+
echo -e "${GREEN}✅ CLI can read your servers${NC}"
|
|
132
|
+
else
|
|
133
|
+
echo -e "${RED}❌ CLI failed to read servers${NC}"
|
|
134
|
+
exit 1
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
echo
|
|
138
|
+
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
139
|
+
echo -e "${GREEN}🎉 Migration complete!${NC}"
|
|
140
|
+
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
141
|
+
echo
|
|
142
|
+
|
|
143
|
+
echo -e "${BLUE}📚 Quick Start:${NC}"
|
|
144
|
+
echo
|
|
145
|
+
echo " 1. Interactive mode (with menu):"
|
|
146
|
+
echo " ${YELLOW}SSH_MANAGER_ENV=\"$(realpath "$ENV_FILE")\" ssh-manager${NC}"
|
|
147
|
+
echo
|
|
148
|
+
echo " 2. Direct commands:"
|
|
149
|
+
echo " ${YELLOW}SSH_MANAGER_ENV=\"$(realpath "$ENV_FILE")\" ssh-manager server list${NC}"
|
|
150
|
+
echo " ${YELLOW}SSH_MANAGER_ENV=\"$(realpath "$ENV_FILE")\" ssh-manager ssh dmis${NC}"
|
|
151
|
+
echo
|
|
152
|
+
echo " 3. Or use the wrapper:"
|
|
153
|
+
echo " ${YELLOW}$WRAPPER${NC}"
|
|
154
|
+
echo
|
|
155
|
+
|
|
156
|
+
echo -e "${BLUE}💡 Features comparison:${NC}"
|
|
157
|
+
echo
|
|
158
|
+
echo " Python CLI → Bash CLI"
|
|
159
|
+
echo " ─────────────────────────────────────────"
|
|
160
|
+
echo " server_manager.py → ssh-manager"
|
|
161
|
+
echo " Option 2 (Add) → ssh-manager server add"
|
|
162
|
+
echo " Option 1 (List) → ssh-manager server list"
|
|
163
|
+
echo " Option 3 (Test) → ssh-manager server test"
|
|
164
|
+
echo " Option 4 (Remove) → ssh-manager server remove"
|
|
165
|
+
echo
|
|
166
|
+
|
|
167
|
+
echo -e "${GREEN}✨ The Bash CLI is 10x faster and has the same features!${NC}"
|
|
168
|
+
echo
|