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,174 @@
1
+ #!/bin/bash
2
+ # Colors and formatting library for ssh-manager CLI
3
+
4
+ # Color codes
5
+ export RED=$'\033[0;31m'
6
+ export GREEN=$'\033[0;32m'
7
+ export YELLOW=$'\033[1;33m'
8
+ export BLUE=$'\033[0;34m'
9
+ export MAGENTA=$'\033[0;35m'
10
+ export CYAN=$'\033[0;36m'
11
+ export WHITE=$'\033[1;37m'
12
+ export GRAY=$'\033[0;90m'
13
+ export BOLD=$'\033[1m'
14
+ export NC=$'\033[0m' # No Color
15
+
16
+ # Unicode symbols
17
+ export CHECK="✅"
18
+ export CROSS="❌"
19
+ export WARN="⚠️"
20
+ export INFO="ℹ️ "
21
+ export ARROW="➜"
22
+ export ROCKET="🚀"
23
+ export KEY="🔑"
24
+ export SERVER="🖥️ "
25
+ export FOLDER="📁"
26
+ export SYNC="🔄"
27
+ export MONITOR="📊"
28
+ export TUNNEL="🔧"
29
+ export SESSION="💻"
30
+ export CLIPBOARD="📋"
31
+ export EYE="👁️"
32
+ export GEAR="⚙️ "
33
+ export PENCIL="✏️ "
34
+ export NOTE="📝"
35
+ export WRENCH="🔧"
36
+ export LOCK="🔒"
37
+ export UNLOCK="🔓"
38
+ export STAR="⭐"
39
+ export HEART="❤️"
40
+ export LIGHTBULB="💡"
41
+ export BUG="🐛"
42
+
43
+ # Print functions
44
+ print_success() {
45
+ echo -e "${GREEN}${CHECK} $1${NC}"
46
+ }
47
+
48
+ print_error() {
49
+ echo -e "${RED}${CROSS} $1${NC}" >&2
50
+ }
51
+
52
+ print_warning() {
53
+ echo -e "${YELLOW}${WARN} $1${NC}"
54
+ }
55
+
56
+ print_info() {
57
+ echo -e "${CYAN}${INFO} $1${NC}"
58
+ }
59
+
60
+ print_header() {
61
+ echo -e "\n${BOLD}${BLUE}$1${NC}"
62
+ echo -e "${BLUE}$(printf '%.0s=' {1..60})${NC}"
63
+ }
64
+
65
+ print_subheader() {
66
+ echo -e "\n${BOLD}${CYAN}$1${NC}"
67
+ echo -e "${CYAN}$(printf '%.0s-' {1..40})${NC}"
68
+ }
69
+
70
+ # Table printing with column alignment
71
+ print_table_header() {
72
+ local col1="$1"
73
+ local col2="$2"
74
+ local col3="${3:-}"
75
+
76
+ echo -e "${BOLD}"
77
+ printf "%-20s %-30s %s\n" "$col1" "$col2" "$col3"
78
+ echo -e "$(printf '%.0s-' {1..70})${NC}"
79
+ }
80
+
81
+ print_table_row() {
82
+ local col1="$1"
83
+ local col2="$2"
84
+ local col3="${3:-}"
85
+
86
+ printf "%-20s %-30s %s\n" "$col1" "$col2" "$col3"
87
+ }
88
+
89
+ # Progress spinner
90
+ spinner() {
91
+ local pid=$1
92
+ local delay=0.1
93
+ local spinstr='⣾⣽⣻⢿⡿⣟⣯⣷'
94
+
95
+ while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
96
+ local temp=${spinstr#?}
97
+ printf " [%c] " "$spinstr"
98
+ local spinstr=$temp${spinstr%"$temp"}
99
+ sleep $delay
100
+ printf "\b\b\b\b\b\b"
101
+ done
102
+ printf " \b\b\b\b"
103
+ }
104
+
105
+ # Prompt functions
106
+ prompt_yes_no() {
107
+ local prompt="$1"
108
+ local default="${2:-n}"
109
+
110
+ if [ "$default" = "y" ]; then
111
+ prompt="$prompt [Y/n]: "
112
+ else
113
+ prompt="$prompt [y/N]: "
114
+ fi
115
+
116
+ read -p "$prompt" response
117
+ response=${response:-$default}
118
+
119
+ case "$response" in
120
+ [yY][eE][sS]|[yY])
121
+ return 0
122
+ ;;
123
+ *)
124
+ return 1
125
+ ;;
126
+ esac
127
+ }
128
+
129
+ prompt_input() {
130
+ local prompt="$1"
131
+ local default="$2"
132
+ local var_name="$3"
133
+
134
+ if [ -n "$default" ]; then
135
+ read -p "$prompt [$default]: " input
136
+ input=${input:-$default}
137
+ else
138
+ read -p "$prompt: " input
139
+ fi
140
+
141
+ eval "$var_name='$input'"
142
+ }
143
+
144
+ prompt_password() {
145
+ local prompt="$1"
146
+ local var_name="$2"
147
+
148
+ echo -n "$prompt: "
149
+ read -s password
150
+ echo
151
+ eval "$var_name='$password'"
152
+ }
153
+
154
+ # Status indicators
155
+ show_status() {
156
+ local status="$1"
157
+ case "$status" in
158
+ "active"|"running"|"success")
159
+ echo -e "${GREEN}● $status${NC}"
160
+ ;;
161
+ "inactive"|"stopped")
162
+ echo -e "${GRAY}● $status${NC}"
163
+ ;;
164
+ "failed"|"error")
165
+ echo -e "${RED}● $status${NC}"
166
+ ;;
167
+ "warning"|"degraded")
168
+ echo -e "${YELLOW}● $status${NC}"
169
+ ;;
170
+ *)
171
+ echo "● $status"
172
+ ;;
173
+ esac
174
+ }
@@ -0,0 +1,284 @@
1
+ #!/bin/bash
2
+ # Configuration management library for ssh-manager CLI
3
+
4
+ # Configuration paths
5
+ export SSH_MANAGER_HOME="${SSH_MANAGER_HOME:-$HOME/.ssh-manager}"
6
+ export SSH_MANAGER_CONFIG="$SSH_MANAGER_HOME/config.json"
7
+
8
+ # Resolve .env path - handle both direct and symlinked execution
9
+ if [ -z "$SSH_MANAGER_ENV" ]; then
10
+ if [ -n "$SCRIPT_DIR" ]; then
11
+ # Called from main ssh-manager script
12
+ SSH_MANAGER_ENV="$(dirname "$SCRIPT_DIR")/.env"
13
+ else
14
+ # Called directly - need to resolve path ourselves
15
+ if [ -L "$0" ]; then
16
+ REAL_PATH="$(readlink -f "$0" 2>/dev/null || readlink "$0")"
17
+ else
18
+ REAL_PATH="$0"
19
+ fi
20
+ REAL_DIR="$(cd "$(dirname "$REAL_PATH")" && pwd)"
21
+ SSH_MANAGER_ENV="$(dirname "$(dirname "$REAL_DIR")")/.env"
22
+ fi
23
+ export SSH_MANAGER_ENV
24
+ fi
25
+
26
+ export SSH_MANAGER_ALIASES="$SSH_MANAGER_HOME/aliases.json"
27
+
28
+ # Ensure config directory exists
29
+ init_config() {
30
+ if [ ! -d "$SSH_MANAGER_HOME" ]; then
31
+ mkdir -p "$SSH_MANAGER_HOME"
32
+ print_info "Created config directory: $SSH_MANAGER_HOME"
33
+ fi
34
+
35
+ # Create default config if not exists
36
+ if [ ! -f "$SSH_MANAGER_CONFIG" ]; then
37
+ cat > "$SSH_MANAGER_CONFIG" <<EOF
38
+ {
39
+ "default_editor": "${EDITOR:-nano}",
40
+ "default_shell": "${SHELL:-/bin/bash}",
41
+ "history_file": "$SSH_MANAGER_HOME/history",
42
+ "log_level": "info",
43
+ "color_output": true
44
+ }
45
+ EOF
46
+ print_info "Created default config: $SSH_MANAGER_CONFIG"
47
+ fi
48
+ }
49
+
50
+ # Load configuration value
51
+ get_config() {
52
+ local key="$1"
53
+ local default="$2"
54
+
55
+ if [ -f "$SSH_MANAGER_CONFIG" ] && command -v jq >/dev/null 2>&1; then
56
+ local value=$(jq -r ".$key // null" "$SSH_MANAGER_CONFIG" 2>/dev/null)
57
+ if [ "$value" != "null" ]; then
58
+ echo "$value"
59
+ else
60
+ echo "$default"
61
+ fi
62
+ else
63
+ echo "$default"
64
+ fi
65
+ }
66
+
67
+ # Set configuration value
68
+ set_config() {
69
+ local key="$1"
70
+ local value="$2"
71
+
72
+ if command -v jq >/dev/null 2>&1; then
73
+ local temp=$(mktemp)
74
+ jq ".$key = \"$value\"" "$SSH_MANAGER_CONFIG" > "$temp" && mv "$temp" "$SSH_MANAGER_CONFIG"
75
+ print_success "Updated config: $key = $value"
76
+ else
77
+ print_error "jq is required for config management"
78
+ return 1
79
+ fi
80
+ }
81
+
82
+ # Load servers from .env file
83
+ load_servers() {
84
+ local servers=()
85
+
86
+ if [ ! -f "$SSH_MANAGER_ENV" ]; then
87
+ return 1
88
+ fi
89
+
90
+ # Parse .env file for server definitions
91
+ while IFS= read -r line; do
92
+ if [[ "$line" =~ ^SSH_SERVER_(.+)_HOST= ]]; then
93
+ local server_name="${BASH_REMATCH[1]}"
94
+ # Convert to lowercase
95
+ server_name=$(echo "$server_name" | tr '[:upper:]' '[:lower:]')
96
+ servers+=("$server_name")
97
+ fi
98
+ done < "$SSH_MANAGER_ENV"
99
+
100
+ # Remove duplicates
101
+ printf '%s\n' "${servers[@]}" | sort -u
102
+ }
103
+
104
+ # Get server configuration
105
+ get_server_config() {
106
+ local server="$1"
107
+ local field="$2"
108
+ local server_upper="$(echo "$server" | tr '[:lower:]' '[:upper:]')"
109
+
110
+ if [ ! -f "$SSH_MANAGER_ENV" ]; then
111
+ return 1
112
+ fi
113
+
114
+ local field_upper="$(echo "$field" | tr '[:lower:]' '[:upper:]')"
115
+ local key="SSH_SERVER_${server_upper}_${field_upper}"
116
+ grep "^${key}=" "$SSH_MANAGER_ENV" 2>/dev/null | cut -d'=' -f2- | tr -d '"'
117
+ }
118
+
119
+ # Add server to .env
120
+ add_server_to_env() {
121
+ local name="$1"
122
+ local host="$2"
123
+ local user="$3"
124
+ local auth_type="$4"
125
+ local auth_value="$5"
126
+ local port="${6:-22}"
127
+ local description="${7:-}"
128
+
129
+ local name_upper="$(echo "$name" | tr '[:lower:]' '[:upper:]')"
130
+
131
+ # Check if server already exists
132
+ if grep -q "^SSH_SERVER_${name_upper}_HOST=" "$SSH_MANAGER_ENV" 2>/dev/null; then
133
+ print_error "Server '$name' already exists"
134
+ return 1
135
+ fi
136
+
137
+ # Backup .env file
138
+ cp "$SSH_MANAGER_ENV" "$SSH_MANAGER_ENV.bak"
139
+
140
+ # Add server configuration
141
+ {
142
+ echo ""
143
+ echo "# Server: $name"
144
+ echo "SSH_SERVER_${name_upper}_HOST=$host"
145
+ echo "SSH_SERVER_${name_upper}_USER=$user"
146
+ echo "SSH_SERVER_${name_upper}_PORT=$port"
147
+
148
+ if [ "$auth_type" = "password" ]; then
149
+ echo "SSH_SERVER_${name_upper}_PASSWORD=$auth_value"
150
+ else
151
+ echo "SSH_SERVER_${name_upper}_KEYPATH=$auth_value"
152
+ fi
153
+
154
+ if [ -n "$description" ]; then
155
+ echo "SSH_SERVER_${name_upper}_DESCRIPTION=\"$description\""
156
+ fi
157
+ } >> "$SSH_MANAGER_ENV"
158
+
159
+ print_success "Server '$name' added successfully"
160
+ }
161
+
162
+ # Remove server from .env
163
+ remove_server_from_env() {
164
+ local name="$1"
165
+ local name_upper="$(echo "$name" | tr '[:lower:]' '[:upper:]')"
166
+
167
+ if ! grep -q "^SSH_SERVER_${name_upper}_HOST=" "$SSH_MANAGER_ENV" 2>/dev/null; then
168
+ print_error "Server '$name' not found"
169
+ return 1
170
+ fi
171
+
172
+ # Backup .env file
173
+ cp "$SSH_MANAGER_ENV" "$SSH_MANAGER_ENV.bak"
174
+
175
+ # Remove all lines for this server
176
+ local temp=$(mktemp)
177
+ grep -v "^SSH_SERVER_${name_upper}_" "$SSH_MANAGER_ENV" > "$temp"
178
+ mv "$temp" "$SSH_MANAGER_ENV"
179
+
180
+ print_success "Server '$name' removed successfully"
181
+ }
182
+
183
+ # Test SSH connection
184
+ test_ssh_connection() {
185
+ local server="$1"
186
+ local host=$(get_server_config "$server" "HOST")
187
+ local user=$(get_server_config "$server" "USER")
188
+ local port=$(get_server_config "$server" "PORT")
189
+ local keypath=$(get_server_config "$server" "KEYPATH")
190
+ local password=$(get_server_config "$server" "PASSWORD")
191
+
192
+ port=${port:-22}
193
+
194
+ if [ -z "$host" ] || [ -z "$user" ]; then
195
+ print_error "Server '$server' not found or incomplete configuration"
196
+ return 1
197
+ fi
198
+
199
+ print_info "Testing connection to $server ($user@$host:$port)..."
200
+
201
+ local ssh_opts="-o ConnectTimeout=5 -o StrictHostKeyChecking=no"
202
+
203
+ if [ -n "$keypath" ]; then
204
+ ssh_opts="$ssh_opts -i $keypath"
205
+ fi
206
+
207
+ if [ -n "$password" ]; then
208
+ # Use sshpass if available
209
+ if command -v sshpass >/dev/null 2>&1; then
210
+ sshpass -p "$password" ssh $ssh_opts -p "$port" "$user@$host" "echo 'Connection successful'" 2>/dev/null
211
+ else
212
+ print_warning "sshpass not installed, cannot test password authentication"
213
+ return 1
214
+ fi
215
+ else
216
+ ssh $ssh_opts -p "$port" "$user@$host" "echo 'Connection successful'" 2>/dev/null
217
+ fi
218
+
219
+ if [ $? -eq 0 ]; then
220
+ print_success "Connection successful"
221
+ return 0
222
+ else
223
+ print_error "Connection failed"
224
+ return 1
225
+ fi
226
+ }
227
+
228
+ # Validate server name
229
+ validate_server_name() {
230
+ local name="$1"
231
+
232
+ # Check if name is empty
233
+ if [ -z "$name" ]; then
234
+ print_error "Server name cannot be empty"
235
+ return 1
236
+ fi
237
+
238
+ # Check for invalid characters
239
+ if ! [[ "$name" =~ ^[a-zA-Z0-9_-]+$ ]]; then
240
+ print_error "Server name can only contain letters, numbers, underscore and hyphen"
241
+ return 1
242
+ fi
243
+
244
+ # Check if name starts with a letter
245
+ if ! [[ "$name" =~ ^[a-zA-Z] ]]; then
246
+ print_error "Server name must start with a letter"
247
+ return 1
248
+ fi
249
+
250
+ return 0
251
+ }
252
+
253
+ # Check dependencies
254
+ check_dependencies() {
255
+ local missing=()
256
+
257
+ # Check for required commands
258
+ for cmd in ssh rsync; do
259
+ if ! command -v "$cmd" >/dev/null 2>&1; then
260
+ missing+=("$cmd")
261
+ fi
262
+ done
263
+
264
+ # Check for optional but recommended commands
265
+ local optional=()
266
+ for cmd in jq sshpass; do
267
+ if ! command -v "$cmd" >/dev/null 2>&1; then
268
+ optional+=("$cmd")
269
+ fi
270
+ done
271
+
272
+ if [ ${#missing[@]} -gt 0 ]; then
273
+ print_error "Missing required dependencies: ${missing[*]}"
274
+ print_info "Please install them and try again"
275
+ return 1
276
+ fi
277
+
278
+ if [ ${#optional[@]} -gt 0 ]; then
279
+ print_warning "Missing optional dependencies: ${optional[*]}"
280
+ print_info "Some features may not work without them"
281
+ fi
282
+
283
+ return 0
284
+ }