mirror of
https://github.com/YuzuZensai/Termix.git
synced 2026-09-13 18:58:52 +00:00
* Feature request network graph
* Fixing PR442:
- Fixed:
- UI design elemets
- UI and button colors
- JSON export
- recent activity is default again
- Removed:
- Online/Offline UI labels
- left-click menu on hosts
- Added:
- small pulsing dot inside the hosts to indicate online status like in the left bar
* fix: electron build errors and skip macos job
* fix: testflight submit failure
* fix: made submit job match build type
* fix: resolve Vite build warnings for mixed static/dynamic imports (#473)
* Update Crowdin configuration file
* Update Crowdin configuration file
* fix: resolve Vite build warnings for mixed static/dynamic imports
- Convert all dynamic imports of main-axios.ts to static imports (10 files)
- Convert all dynamic imports of sonner to static imports (4 files)
- Add manual chunking configuration to vite.config.ts for better bundle splitting
- react-vendor: React and React DOM
- ui-vendor: Radix UI, lucide-react, clsx, tailwind-merge
- monaco: Monaco Editor
- codemirror: CodeMirror and related packages
- Increase chunkSizeWarningLimit to 1000kB
This resolves Vite warnings about mixed import strategies preventing
proper code-splitting.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
* fix: file manager incorrectly decoding/encoding when editing files (made base64/utf8 dependent)
* fix: build error on docker
* Handle enter button (#481)
* Update Crowdin configuration file
* Update Crowdin configuration file
* Update Linux Portable section with AUR link (#474)
* fix: file manager incorrectly decoding/encoding when editing files (#476)
* fix: electron build errors and skip macos job
* fix: testflight submit failure
* fix: made submit job match build type
* fix: resolve Vite build warnings for mixed static/dynamic imports (#473)
* Update Crowdin configuration file
* Update Crowdin configuration file
* fix: resolve Vite build warnings for mixed static/dynamic imports
- Convert all dynamic imports of main-axios.ts to static imports (10 files)
- Convert all dynamic imports of sonner to static imports (4 files)
- Add manual chunking configuration to vite.config.ts for better bundle splitting
- react-vendor: React and React DOM
- ui-vendor: Radix UI, lucide-react, clsx, tailwind-merge
- monaco: Monaco Editor
- codemirror: CodeMirror and related packages
- Increase chunkSizeWarningLimit to 1000kB
This resolves Vite warnings about mixed import strategies preventing
proper code-splitting.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
* fix: file manager incorrectly decoding/encoding when editing files (made base64/utf8 dependent)
---------
Co-authored-by: Jefferson Nunn <89030989+jeffersonwarrior@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
* fix: build error on docker (#477)
* fix: electron build errors and skip macos job
* fix: testflight submit failure
* fix: made submit job match build type
* fix: resolve Vite build warnings for mixed static/dynamic imports (#473)
* Update Crowdin configuration file
* Update Crowdin configuration file
* fix: resolve Vite build warnings for mixed static/dynamic imports
- Convert all dynamic imports of main-axios.ts to static imports (10 files)
- Convert all dynamic imports of sonner to static imports (4 files)
- Add manual chunking configuration to vite.config.ts for better bundle splitting
- react-vendor: React and React DOM
- ui-vendor: Radix UI, lucide-react, clsx, tailwind-merge
- monaco: Monaco Editor
- codemirror: CodeMirror and related packages
- Increase chunkSizeWarningLimit to 1000kB
This resolves Vite warnings about mixed import strategies preventing
proper code-splitting.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
* fix: file manager incorrectly decoding/encoding when editing files (made base64/utf8 dependent)
* fix: build error on docker
---------
Co-authored-by: Jefferson Nunn <89030989+jeffersonwarrior@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
* Increase max old space size for npm builds
* Increase Node.js memory limit in Dockerfile
* Remove NODE_OPTIONS from build commands in Dockerfile
* Change runner to blacksmith-4vcpu-ubuntu-2404
* fix: build error on docker
* Add handle on enter button;
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
Co-authored-by: Gaylord Julien <g.j@mailbox.org>
Co-authored-by: Jefferson Nunn <89030989+jeffersonwarrior@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: LukeGus <bugattiguy527@gmail.com>
* fix: remove top tech
* fix: update readme
* fix: prevent long container names from overflowing card (#496)
Added min-w-0 to CardTitle to allow text truncation in flexbox.
Without this, flex items have min-width: auto which prevents
the truncate class from working properly.
Fixes #411
* fix: use SFTP readdir for file listing to support non-Linux systems (#495)
The file manager now uses SFTP readdir as the primary method for
listing files, with ls -la as a fallback. This enables compatibility
with MikroTik RouterOS and other non-Linux systems that don't have
standard shell commands.
Fixes #317
* fix: restore SSH connection timeout to 120s for 2FA authentication (#494)
The timeout was reduced from 120s to 30s in v1.10, causing 2FA login
failures. Users with keyboard-interactive authentication (TOTP/2FA)
need sufficient time to enter their verification codes before the
SSH connection times out.
Fixes #404
* feat: add Docker container healthcheck (#493)
* fix: owner should not be marked as shared when host is shared to their role (#492)
* fix: use correct MIME types for image preview (#491)
* fix: prevent session reset when updating host properties (#490)
* fix: add shell creation timeout and improve error handling (#489)
* fix: set default lineHeight to 1.0 for TUI apps compatibility (#488)
* fix: delete all related data when removing user (#487)
* fix: nginx permission denied on restricted kernels (#486)
* fix: skip existing hosts and credentials during JSON import (#485)
Added duplicate detection for SSH hosts (by ip+port+username) and
credentials (by name) during import. Existing items are now skipped
by default, or updated if replaceExisting option is enabled.
This matches the existing behavior of importDismissedAlerts.
Fixes #389
* feat: add firewall status widget for server stats (#484)
* Feature: PWA (#479)
* feat: add PWA support with offline capabilities
- Add web app manifest with icons and theme configuration
- Add service worker with cache-first strategy for static assets
- Add useServiceWorker hook for SW registration
- Add PWA meta tags and Apple-specific tags to index.html
- Update vite.config.ts for optimal asset caching
* Update package-lock.json
* New Crowdin updates (#472)
* New translations en.json (Romanian)
* New translations en.json (French)
* New translations en.json (Spanish)
* New translations en.json (Afrikaans)
* New translations en.json (Arabic)
* New translations en.json (Catalan)
* New translations en.json (Czech)
* New translations en.json (Danish)
* New translations en.json (German)
* New translations en.json (Greek)
* New translations en.json (Finnish)
* New translations en.json (Hebrew)
* New translations en.json (Hungarian)
* New translations en.json (Italian)
* New translations en.json (Japanese)
* New translations en.json (Korean)
* New translations en.json (Dutch)
* New translations en.json (Norwegian)
* New translations en.json (Polish)
* New translations en.json (Portuguese)
* New translations en.json (Russian)
* New translations en.json (Serbian (Cyrillic))
* New translations en.json (Swedish)
* New translations en.json (Turkish)
* New translations en.json (Ukrainian)
* New translations en.json (Chinese Simplified)
* New translations en.json (English)
* New translations en.json (Vietnamese)
* New translations en.json (German)
* feat: add listening ports widget for server stats (#483)
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
* feat: fix network stats merge and add openapi jsdocs comments
* feat: add workflow/config to auto generate openapi json
* feat: remove locales
* feat: support URL routes to open terminal directly (#156) (#503)
* fix: resolve merge conflict artifacts in dev-1.10.1
- Fix missing closing tags in AppView.tsx NetworkGraphView
- Fix incomplete catch blocks in server-stats.ts and db/index.ts
- Fix missing closing brace in en.json ports section
- Fix HostManagerApp.tsx import path
- Fix stats-widgets.ts type definition
- Fix schema.ts networkTopology table definition
- Add type annotations in user-data-import.ts
* feat: support URL routes to open terminal directly (#156)
- Add /terminal/{hostNameOrId} route for new format
- Keep /hosts/{id}/terminal for backward compatibility
- Smart detection: numeric IDs for ID lookup, otherwise name lookup
- Clean URL after opening to prevent duplicate on refresh
- Show toast error when host not found
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
* feat: add Ctrl+Alt key remapping for browser-blocked shortcuts (#501)
Browsers intercept Ctrl+W/T/N/Q, making them unusable in terminal.
This adds Ctrl+Alt+<key> as an alternative that sends Ctrl+<key>.
- Ctrl+Alt+W → Ctrl+W (nano search, delete word)
- Ctrl+Alt+T → Ctrl+T (transpose chars)
- Ctrl+Alt+N → Ctrl+N (next line)
- Ctrl+Alt+Q → Ctrl+Q (XON flow control)
Fixes Termix-SSH/Support#407
* feat: remove locales
* New Crowdin updates (#504)
* New translations en.json (Romanian)
* New translations en.json (French)
* New translations en.json (Spanish)
* New translations en.json (Afrikaans)
* New translations en.json (Arabic)
* New translations en.json (Catalan)
* New translations en.json (Czech)
* New translations en.json (Danish)
* New translations en.json (German)
* New translations en.json (Greek)
* New translations en.json (Finnish)
* New translations en.json (Hebrew)
* New translations en.json (Hungarian)
* New translations en.json (Italian)
* New translations en.json (Japanese)
* New translations en.json (Korean)
* New translations en.json (Dutch)
* New translations en.json (Norwegian)
* New translations en.json (Polish)
* New translations en.json (Portuguese)
* New translations en.json (Russian)
* New translations en.json (Serbian (Cyrillic))
* New translations en.json (Swedish)
* New translations en.json (Turkish)
* New translations en.json (Ukrainian)
* New translations en.json (Chinese Simplified)
* New translations en.json (English)
* New translations en.json (Vietnamese)
* New translations en.json (German)
* New translations en.json (Norwegian)
* New translations en.json (Romanian)
* New translations en.json (French)
* New translations en.json (Spanish)
* New translations en.json (Arabic)
* New translations en.json (Czech)
* New translations en.json (Danish)
* New translations en.json (Greek)
* New translations en.json (Finnish)
* New translations en.json (Italian)
* New translations en.json (Japanese)
* New translations en.json (Dutch)
* New translations en.json (Norwegian)
* New translations en.json (Polish)
* New translations en.json (Portuguese)
* New translations en.json (Russian)
* New translations en.json (Swedish)
* New translations en.json (Ukrainian)
* New translations en.json (Chinese Simplified)
* New translations en.json (Chinese Traditional)
* New translations en.json (Finnish)
* New translations en.json (Chinese Simplified)
* New translations en.json (Chinese Traditional)
* feat: add option to disable update checker (#502)
* feat: add option to disable update checker
Add a new setting in User Profile > Settings to disable automatic
update checking on startup and dashboard.
- Adds 'Disable Update Check' toggle in profile settings
- Skips GitHub API calls when disabled (reduces network requests)
- Works for both web app and Electron client
Fixes Termix-SSH/Support#410
* feat: remove locales
---------
Co-authored-by: LukeGus <bugattiguy527@gmail.com>
* New Crowdin updates (#505)
* New translations en.json (Romanian)
* New translations en.json (French)
* New translations en.json (Spanish)
* New translations en.json (Afrikaans)
* New translations en.json (Arabic)
* New translations en.json (Catalan)
* New translations en.json (Czech)
* New translations en.json (Danish)
* New translations en.json (German)
* New translations en.json (Greek)
* New translations en.json (Finnish)
* New translations en.json (Hebrew)
* New translations en.json (Hungarian)
* New translations en.json (Italian)
* New translations en.json (Japanese)
* New translations en.json (Korean)
* New translations en.json (Dutch)
* New translations en.json (Norwegian)
* New translations en.json (Polish)
* New translations en.json (Portuguese)
* New translations en.json (Russian)
* New translations en.json (Serbian (Cyrillic))
* New translations en.json (Swedish)
* New translations en.json (Turkish)
* New translations en.json (Ukrainian)
* New translations en.json (Chinese Simplified)
* New translations en.json (English)
* New translations en.json (Vietnamese)
* New translations en.json (German)
* New translations en.json (Norwegian)
* New translations en.json (Romanian)
* New translations en.json (French)
* New translations en.json (Spanish)
* New translations en.json (Arabic)
* New translations en.json (Czech)
* New translations en.json (Danish)
* New translations en.json (Greek)
* New translations en.json (Finnish)
* New translations en.json (Italian)
* New translations en.json (Japanese)
* New translations en.json (Dutch)
* New translations en.json (Norwegian)
* New translations en.json (Polish)
* New translations en.json (Portuguese)
* New translations en.json (Russian)
* New translations en.json (Swedish)
* New translations en.json (Ukrainian)
* New translations en.json (Chinese Simplified)
* New translations en.json (Chinese Traditional)
* New translations en.json (Finnish)
* New translations en.json (Chinese Simplified)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Chinese Traditional)
* New translations en.json (Bulgarian)
* New translations en.json (Indonesian)
* New translations en.json (Hindi)
* feat: add crowdin i18n
* feat: remove locales
* New Crowdin updates (#506)
* New translations en.json (Romanian)
* New translations en.json (French)
* New translations en.json (Spanish)
* New translations en.json (Afrikaans)
* New translations en.json (Arabic)
* New translations en.json (Catalan)
* New translations en.json (Czech)
* New translations en.json (Danish)
* New translations en.json (German)
* New translations en.json (Greek)
* New translations en.json (Finnish)
* New translations en.json (Hebrew)
* New translations en.json (Hungarian)
* New translations en.json (Italian)
* New translations en.json (Japanese)
* New translations en.json (Korean)
* New translations en.json (Dutch)
* New translations en.json (Norwegian)
* New translations en.json (Polish)
* New translations en.json (Portuguese)
* New translations en.json (Russian)
* New translations en.json (Serbian (Cyrillic))
* New translations en.json (Swedish)
* New translations en.json (Turkish)
* New translations en.json (Ukrainian)
* New translations en.json (Chinese Simplified)
* New translations en.json (English)
* New translations en.json (Vietnamese)
* New translations en.json (German)
* New translations en.json (Norwegian)
* New translations en.json (Romanian)
* New translations en.json (French)
* New translations en.json (Spanish)
* New translations en.json (Arabic)
* New translations en.json (Czech)
* New translations en.json (Danish)
* New translations en.json (Greek)
* New translations en.json (Finnish)
* New translations en.json (Italian)
* New translations en.json (Japanese)
* New translations en.json (Dutch)
* New translations en.json (Norwegian)
* New translations en.json (Polish)
* New translations en.json (Portuguese)
* New translations en.json (Russian)
* New translations en.json (Swedish)
* New translations en.json (Ukrainian)
* New translations en.json (Chinese Simplified)
* New translations en.json (Chinese Traditional)
* New translations en.json (Finnish)
* New translations en.json (Chinese Simplified)
* New translations en.json (Chinese Traditional)
* New translations en.json (Chinese Simplified)
* New translations en.json (Chinese Traditional)
* New translations en.json (Bulgarian)
* New translations en.json (Indonesian)
* New translations en.json (Hindi)
* New translations en.json (Romanian)
* New translations en.json (French)
* New translations en.json (Spanish)
* New translations en.json (Afrikaans)
* New translations en.json (Arabic)
* New translations en.json (Catalan)
* New translations en.json (Czech)
* New translations en.json (German)
* New translations en.json (Greek)
* New translations en.json (Finnish)
* New translations en.json (Hebrew)
* New translations en.json (Hungarian)
* New translations en.json (Italian)
* New translations en.json (Japanese)
* New translations en.json (Korean)
* New translations en.json (Dutch)
* New translations en.json (Polish)
* New translations en.json (Portuguese)
* New translations en.json (Russian)
* New translations en.json (Serbian (Cyrillic))
* New translations en.json (Turkish)
* New translations en.json (Ukrainian)
* New translations en.json (Chinese Simplified)
* New translations en.json (Chinese Traditional)
* New translations en.json (Vietnamese)
* New translations en.json (Portuguese, Brazilian)
* New translations en.json (Bulgarian)
* New translations en.json (Indonesian)
* New translations en.json (Hindi)
* New translations en.json (Bengali)
* New translations en.json (Thai)
* feat: update readme
* feat: update readme
* feat: update credential editor to use submitting system and add health monitor
* feat: added toggle for command pallete
* feat: added close button on tab dropdown
* feat: added sidebar management and improved some host manager UI/UX
* feat: re-added missing users.ts route from merge
* feat: add toggle for password reset feature in admin settings (#508)
* feat: add sudo support for file manager operations (#509)
* fix: add sudo support for listFiles and improve permission error handling (#512)
* feat: add sudo support for file manager operations
* fix: add sudo support for listFiles and improve permission error handling
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
* feat: fix sudo password dialog ui, add totp/pass reset limiting, and refreshed users screen when auth is outdated
* feat: add copy password button and fixed new line carriage issues and backend crash for auth key
* feat: added quick connection system (ad-hoc)
* Enter Key for Quick Login (#513)
* feat: added -r and -l support for tunnels
* feat: begin dashboard overhaul by splitting into cards and adding customization
* feat: improved full screen apps, overhauled dashboard, updated server stats ui, etc.
* feat: add auth.tsx suppot for fullscreen
* feat: greatly improve network graph ui/ux and migrated to use translations and theme system
* feat: update to use blacksmith
* feat: improve ui for customized tabs and hide add/edit host/credential when submiting
* feat: add warpgate support with a dialog (terminal only)
* feat: expand warpgate to docker/file manager
* fix: docker not working wtih warpgate and none auth failing for terminal
* fix: prevent owner permission loss when sharing host to own role (#514)
* Update Crowdin configuration file
* Update Crowdin configuration file
* Update Linux Portable section with AUR link (#474)
* fix: file manager incorrectly decoding/encoding when editing files (#476)
* fix: electron build errors and skip macos job
* fix: testflight submit failure
* fix: made submit job match build type
* fix: resolve Vite build warnings for mixed static/dynamic imports (#473)
* Update Crowdin configuration file
* Update Crowdin configuration file
* fix: resolve Vite build warnings for mixed static/dynamic imports
- Convert all dynamic imports of main-axios.ts to static imports (10 files)
- Convert all dynamic imports of sonner to static imports (4 files)
- Add manual chunking configuration to vite.config.ts for better bundle splitting
- react-vendor: React and React DOM
- ui-vendor: Radix UI, lucide-react, clsx, tailwind-merge
- monaco: Monaco Editor
- codemirror: CodeMirror and related packages
- Increase chunkSizeWarningLimit to 1000kB
This resolves Vite warnings about mixed import strategies preventing
proper code-splitting.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
* fix: file manager incorrectly decoding/encoding when editing files (made base64/utf8 dependent)
---------
Co-authored-by: Jefferson Nunn <89030989+jeffersonwarrior@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
* fix: build error on docker (#477)
* fix: electron build errors and skip macos job
* fix: testflight submit failure
* fix: made submit job match build type
* fix: resolve Vite build warnings for mixed static/dynamic imports (#473)
* Update Crowdin configuration file
* Update Crowdin configuration file
* fix: resolve Vite build warnings for mixed static/dynamic imports
- Convert all dynamic imports of main-axios.ts to static imports (10 files)
- Convert all dynamic imports of sonner to static imports (4 files)
- Add manual chunking configuration to vite.config.ts for better bundle splitting
- react-vendor: React and React DOM
- ui-vendor: Radix UI, lucide-react, clsx, tailwind-merge
- monaco: Monaco Editor
- codemirror: CodeMirror and related packages
- Increase chunkSizeWarningLimit to 1000kB
This resolves Vite warnings about mixed import strategies preventing
proper code-splitting.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
* fix: file manager incorrectly decoding/encoding when editing files (made base64/utf8 dependent)
* fix: build error on docker
---------
Co-authored-by: Jefferson Nunn <89030989+jeffersonwarrior@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
* Increase max old space size for npm builds
* Increase Node.js memory limit in Dockerfile
* Remove NODE_OPTIONS from build commands in Dockerfile
* Change runner to blacksmith-4vcpu-ubuntu-2404
* fix: build error on docker
* fix: prevent owner permission loss when sharing host to own role
Fixes #391
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
Co-authored-by: Gaylord Julien <g.j@mailbox.org>
Co-authored-by: Jefferson Nunn <89030989+jeffersonwarrior@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: LukeGus <bugattiguy527@gmail.com>
* fix: SSH key passphrase not passed for Docker and Tunnel (#521)
* perf: optimize Host Manager for large host lists
- Add ServerStatusContext for shared status polling (reduces API calls from N to 1)
- Move TooltipProvider to component root (eliminates N context instances)
- Add pagination with "Show More" button (limits initial DOM nodes per folder)
Fixes performance issues when managing ~1000 hosts with status monitoring enabled.
* fix: SSH key passphrase not passed to ssh2 for Docker and Tunnel
Database field is `key_password` but code used `keyPassword`.
Added fallback to check both field names.
Affected:
- docker.ts: Docker SSH connections with encrypted keys
- tunnel.ts: Tunnel connections with encrypted keys
---------
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
* perf: optimize Host Manager for large host lists (#520)
- Add ServerStatusContext for shared status polling (reduces API calls from N to 1)
- Move TooltipProvider to component root (eliminates N context instances)
- Add pagination with "Show More" button (limits initial DOM nodes per folder)
Fixes performance issues when managing ~1000 hosts with status monitoring enabled.
Co-authored-by: Luke Gustafson <88517757+LukeGus@users.noreply.github.com>
* fix: add missing mimeTypes definition for image preview (#518)
Fixes Termix-SSH/Support#408
* fix: prevent session reset when updating host properties (#517)
Move WebSocket cleanup logic to a separate unmount-only effect to
prevent SSH sessions from being closed when host properties are updated.
Closes Termix-SSH/Support#401
* fix: backend type error
* feat: make terminal connections more resilient, added connection log, and fixed https/proxy reconnection loop (issue #385)
* feat: improved conneciton log ui/logic
* feat: improved conneciton log ui/logic
* feat: expanded connection log to work across all components (readying for release)
* feat: update readme
* feat: update readme
* fix: build error
* fix: build error
* fix: changed ver
* chore: clean up
* chore: continue clean up
* fix: remove attempts remaining and fix electron errors and some connection log ui inconsistencies
* fix: added missing nginx routes and fixed sudo password copy with sudo password autofil field
* fix: update readme and run cleaner
* fix: update readme
* fix: update readme
* fix: update readme
* feat: update chinese readme
---------
Co-authored-by: Steven Josefs <s.josefs@gmx.de>
Co-authored-by: Jefferson Nunn <89030989+jeffersonwarrior@users.noreply.github.com>
Co-authored-by: Termix CI <ci@termix.dev>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Nunzio Marfè <nunzio.marfe@protonmail.com>
Co-authored-by: Gaylord Julien <g.j@mailbox.org>
Co-authored-by: ZacharyZcR <zacharyzcr1984@gmail.com>
Co-authored-by: Aditya Tawade <36890395+aditya-tawade@users.noreply.github.com>
1549 lines
43 KiB
TypeScript
1549 lines
43 KiB
TypeScript
import { WebSocketServer, WebSocket, type RawData } from "ws";
|
|
import {
|
|
Client,
|
|
type ClientChannel,
|
|
type PseudoTtyOptions,
|
|
type ConnectConfig,
|
|
} from "ssh2";
|
|
import { parse as parseUrl } from "url";
|
|
import axios from "axios";
|
|
import { getDb } from "../database/db/index.js";
|
|
import { sshCredentials, sshData } from "../database/db/schema.js";
|
|
import { eq, and } from "drizzle-orm";
|
|
import { sshLogger } from "../utils/logger.js";
|
|
import { SimpleDBOps } from "../utils/simple-db-ops.js";
|
|
import { AuthManager } from "../utils/auth-manager.js";
|
|
import { UserCrypto } from "../utils/user-crypto.js";
|
|
import { createSocks5Connection } from "../utils/socks5-helper.js";
|
|
import { SSHAuthManager } from "./auth-manager.js";
|
|
|
|
interface ConnectToHostData {
|
|
cols: number;
|
|
rows: number;
|
|
hostConfig: {
|
|
id: number;
|
|
ip: string;
|
|
port: number;
|
|
username: string;
|
|
password?: string;
|
|
key?: string;
|
|
keyPassword?: string;
|
|
keyType?: string;
|
|
authType?: string;
|
|
credentialId?: number;
|
|
userId?: string;
|
|
forceKeyboardInteractive?: boolean;
|
|
jumpHosts?: Array<{ hostId: number }>;
|
|
useSocks5?: boolean;
|
|
socks5Host?: string;
|
|
socks5Port?: number;
|
|
socks5Username?: string;
|
|
socks5Password?: string;
|
|
socks5ProxyChain?: unknown;
|
|
};
|
|
initialPath?: string;
|
|
executeCommand?: string;
|
|
}
|
|
|
|
interface ResizeData {
|
|
cols: number;
|
|
rows: number;
|
|
}
|
|
|
|
interface TOTPResponseData {
|
|
code?: string;
|
|
}
|
|
|
|
interface WebSocketMessage {
|
|
type: string;
|
|
data?: ConnectToHostData | ResizeData | TOTPResponseData | string | unknown;
|
|
code?: string;
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
const authManager = AuthManager.getInstance();
|
|
const userCrypto = UserCrypto.getInstance();
|
|
|
|
const userConnections = new Map<string, Set<WebSocket>>();
|
|
|
|
async function resolveJumpHost(
|
|
hostId: number,
|
|
userId: string,
|
|
): Promise<any | null> {
|
|
try {
|
|
const hosts = await SimpleDBOps.select(
|
|
getDb()
|
|
.select()
|
|
.from(sshData)
|
|
.where(and(eq(sshData.id, hostId), eq(sshData.userId, userId))),
|
|
"ssh_data",
|
|
userId,
|
|
);
|
|
|
|
if (hosts.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const host = hosts[0];
|
|
|
|
if (host.credentialId) {
|
|
const credentials = await SimpleDBOps.select(
|
|
getDb()
|
|
.select()
|
|
.from(sshCredentials)
|
|
.where(
|
|
and(
|
|
eq(sshCredentials.id, host.credentialId as number),
|
|
eq(sshCredentials.userId, userId),
|
|
),
|
|
),
|
|
"ssh_credentials",
|
|
userId,
|
|
);
|
|
|
|
if (credentials.length > 0) {
|
|
const credential = credentials[0];
|
|
return {
|
|
...host,
|
|
password: credential.password,
|
|
key:
|
|
credential.private_key || credential.privateKey || credential.key,
|
|
keyPassword: credential.key_password || credential.keyPassword,
|
|
keyType: credential.key_type || credential.keyType,
|
|
authType: credential.auth_type || credential.authType,
|
|
};
|
|
}
|
|
}
|
|
|
|
return host;
|
|
} catch (error) {
|
|
sshLogger.error("Failed to resolve jump host", error, {
|
|
operation: "resolve_jump_host",
|
|
hostId,
|
|
userId,
|
|
});
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function createJumpHostChain(
|
|
jumpHosts: Array<{ hostId: number }>,
|
|
userId: string,
|
|
): Promise<Client | null> {
|
|
if (!jumpHosts || jumpHosts.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
let currentClient: Client | null = null;
|
|
const clients: Client[] = [];
|
|
|
|
try {
|
|
const jumpHostConfigs = await Promise.all(
|
|
jumpHosts.map((jh) => resolveJumpHost(jh.hostId, userId)),
|
|
);
|
|
|
|
for (let i = 0; i < jumpHostConfigs.length; i++) {
|
|
if (!jumpHostConfigs[i]) {
|
|
sshLogger.error(`Jump host ${i + 1} not found`, undefined, {
|
|
operation: "jump_host_chain",
|
|
hostId: jumpHosts[i].hostId,
|
|
});
|
|
clients.forEach((c) => c.end());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
for (let i = 0; i < jumpHostConfigs.length; i++) {
|
|
const jumpHostConfig = jumpHostConfigs[i];
|
|
|
|
const jumpClient = new Client();
|
|
clients.push(jumpClient);
|
|
|
|
const connected = await new Promise<boolean>((resolve) => {
|
|
const timeout = setTimeout(() => {
|
|
resolve(false);
|
|
}, 30000);
|
|
|
|
jumpClient.on("ready", () => {
|
|
clearTimeout(timeout);
|
|
resolve(true);
|
|
});
|
|
|
|
jumpClient.on("error", (err) => {
|
|
clearTimeout(timeout);
|
|
sshLogger.error(`Jump host ${i + 1} connection failed`, err, {
|
|
operation: "jump_host_connect",
|
|
hostId: jumpHostConfig.id,
|
|
ip: jumpHostConfig.ip,
|
|
});
|
|
resolve(false);
|
|
});
|
|
|
|
const connectConfig: any = {
|
|
host: jumpHostConfig.ip,
|
|
port: jumpHostConfig.port || 22,
|
|
username: jumpHostConfig.username,
|
|
tryKeyboard: true,
|
|
readyTimeout: 30000,
|
|
};
|
|
|
|
if (jumpHostConfig.authType === "password" && jumpHostConfig.password) {
|
|
connectConfig.password = jumpHostConfig.password;
|
|
} else if (jumpHostConfig.authType === "key" && jumpHostConfig.key) {
|
|
const cleanKey = jumpHostConfig.key
|
|
.trim()
|
|
.replace(/\r\n/g, "\n")
|
|
.replace(/\r/g, "\n");
|
|
connectConfig.privateKey = Buffer.from(cleanKey, "utf8");
|
|
if (jumpHostConfig.keyPassword) {
|
|
connectConfig.passphrase = jumpHostConfig.keyPassword;
|
|
}
|
|
}
|
|
|
|
if (currentClient) {
|
|
currentClient.forwardOut(
|
|
"127.0.0.1",
|
|
0,
|
|
jumpHostConfig.ip,
|
|
jumpHostConfig.port || 22,
|
|
(err, stream) => {
|
|
if (err) {
|
|
clearTimeout(timeout);
|
|
resolve(false);
|
|
return;
|
|
}
|
|
connectConfig.sock = stream;
|
|
jumpClient.connect(connectConfig);
|
|
},
|
|
);
|
|
} else {
|
|
jumpClient.connect(connectConfig);
|
|
}
|
|
});
|
|
|
|
if (!connected) {
|
|
clients.forEach((c) => c.end());
|
|
return null;
|
|
}
|
|
|
|
currentClient = jumpClient;
|
|
}
|
|
|
|
return currentClient;
|
|
} catch (error) {
|
|
sshLogger.error("Failed to create jump host chain", error, {
|
|
operation: "jump_host_chain",
|
|
});
|
|
clients.forEach((c) => c.end());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
const wss = new WebSocketServer({
|
|
port: 30002,
|
|
verifyClient: async (info) => {
|
|
try {
|
|
const url = parseUrl(info.req.url!, true);
|
|
const token = url.query.token as string;
|
|
|
|
if (!token) {
|
|
return false;
|
|
}
|
|
|
|
const payload = await authManager.verifyJWTToken(token);
|
|
|
|
if (!payload) {
|
|
return false;
|
|
}
|
|
|
|
if (payload.pendingTOTP) {
|
|
return false;
|
|
}
|
|
|
|
const existingConnections = userConnections.get(payload.userId);
|
|
|
|
if (existingConnections && existingConnections.size >= 3) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
} catch (error) {
|
|
sshLogger.error("WebSocket authentication error", error, {
|
|
operation: "websocket_auth_error",
|
|
ip: info.req.socket.remoteAddress,
|
|
});
|
|
return false;
|
|
}
|
|
},
|
|
});
|
|
|
|
wss.on("connection", async (ws: WebSocket, req) => {
|
|
let userId: string | undefined;
|
|
|
|
try {
|
|
const url = parseUrl(req.url!, true);
|
|
const token = url.query.token as string;
|
|
|
|
if (!token) {
|
|
ws.close(1008, "Authentication required");
|
|
return;
|
|
}
|
|
|
|
const payload = await authManager.verifyJWTToken(token);
|
|
if (!payload) {
|
|
ws.close(1008, "Authentication required");
|
|
return;
|
|
}
|
|
|
|
userId = payload.userId;
|
|
} catch (error) {
|
|
sshLogger.error(
|
|
"WebSocket JWT verification failed during connection",
|
|
error,
|
|
{
|
|
operation: "websocket_connection_auth_error",
|
|
ip: req.socket.remoteAddress,
|
|
},
|
|
);
|
|
ws.close(1008, "Authentication required");
|
|
return;
|
|
}
|
|
|
|
const dataKey = userCrypto.getUserDataKey(userId);
|
|
if (!dataKey) {
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "Data locked - re-authenticate with password",
|
|
code: "DATA_LOCKED",
|
|
}),
|
|
);
|
|
ws.close(1008, "Data access required");
|
|
return;
|
|
}
|
|
|
|
if (!userConnections.has(userId)) {
|
|
userConnections.set(userId, new Set());
|
|
}
|
|
const userWs = userConnections.get(userId)!;
|
|
userWs.add(ws);
|
|
|
|
let sshConn: Client | null = null;
|
|
let sshStream: ClientChannel | null = null;
|
|
let keyboardInteractiveFinish: ((responses: string[]) => void) | null = null;
|
|
let totpPromptSent = false;
|
|
let totpTimeout: NodeJS.Timeout | null = null;
|
|
let isKeyboardInteractive = false;
|
|
let keyboardInteractiveResponded = false;
|
|
let isConnecting = false;
|
|
let isConnected = false;
|
|
let isCleaningUp = false;
|
|
let isShellInitializing = false;
|
|
let warpgateAuthPromptSent = false;
|
|
let warpgateAuthTimeout: NodeJS.Timeout | null = null;
|
|
let isAwaitingAuthCredentials = false;
|
|
|
|
ws.on("close", () => {
|
|
const userWs = userConnections.get(userId);
|
|
if (userWs) {
|
|
userWs.delete(ws);
|
|
if (userWs.size === 0) {
|
|
userConnections.delete(userId);
|
|
}
|
|
}
|
|
|
|
cleanupSSH();
|
|
});
|
|
|
|
ws.on("message", (msg: RawData) => {
|
|
const currentDataKey = userCrypto.getUserDataKey(userId);
|
|
if (!currentDataKey) {
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "Data access expired - please re-authenticate",
|
|
code: "DATA_EXPIRED",
|
|
}),
|
|
);
|
|
ws.close(1008, "Data access expired");
|
|
return;
|
|
}
|
|
|
|
let parsed: WebSocketMessage;
|
|
try {
|
|
parsed = JSON.parse(msg.toString()) as WebSocketMessage;
|
|
} catch (e) {
|
|
sshLogger.error("Invalid JSON received", e, {
|
|
operation: "websocket_message_invalid_json",
|
|
userId,
|
|
messageLength: msg.toString().length,
|
|
});
|
|
ws.send(JSON.stringify({ type: "error", message: "Invalid JSON" }));
|
|
return;
|
|
}
|
|
|
|
const { type, data } = parsed;
|
|
|
|
switch (type) {
|
|
case "connectToHost": {
|
|
const connectData = data as ConnectToHostData;
|
|
if (connectData.hostConfig) {
|
|
connectData.hostConfig.userId = userId;
|
|
}
|
|
handleConnectToHost(connectData).catch((error) => {
|
|
sshLogger.error("Failed to connect to host", error, {
|
|
operation: "ssh_connect",
|
|
userId,
|
|
hostId: connectData.hostConfig?.id,
|
|
ip: connectData.hostConfig?.ip,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message:
|
|
"Failed to connect to host: " +
|
|
(error instanceof Error ? error.message : "Unknown error"),
|
|
}),
|
|
);
|
|
});
|
|
break;
|
|
}
|
|
|
|
case "resize": {
|
|
const resizeData = data as ResizeData;
|
|
handleResize(resizeData);
|
|
break;
|
|
}
|
|
|
|
case "disconnect":
|
|
cleanupSSH();
|
|
break;
|
|
|
|
case "input": {
|
|
const inputData = data as string;
|
|
if (sshStream) {
|
|
if (inputData === "\t") {
|
|
sshStream.write(inputData);
|
|
} else if (
|
|
typeof inputData === "string" &&
|
|
inputData.startsWith("\x1b")
|
|
) {
|
|
sshStream.write(inputData);
|
|
} else {
|
|
try {
|
|
sshStream.write(Buffer.from(inputData, "utf8"));
|
|
} catch (error) {
|
|
sshLogger.error("Error writing input to SSH stream", error, {
|
|
operation: "ssh_input_encoding",
|
|
userId,
|
|
dataLength: inputData.length,
|
|
});
|
|
sshStream.write(Buffer.from(inputData, "latin1"));
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
case "ping":
|
|
ws.send(JSON.stringify({ type: "pong" }));
|
|
break;
|
|
|
|
case "totp_response": {
|
|
const totpData = data as TOTPResponseData;
|
|
if (keyboardInteractiveFinish && totpData?.code) {
|
|
if (totpTimeout) {
|
|
clearTimeout(totpTimeout);
|
|
totpTimeout = null;
|
|
}
|
|
const totpCode = totpData.code;
|
|
keyboardInteractiveFinish([totpCode]);
|
|
keyboardInteractiveFinish = null;
|
|
totpPromptSent = false;
|
|
} else {
|
|
sshLogger.warn("TOTP response received but no callback available", {
|
|
operation: "totp_response_error",
|
|
userId,
|
|
hasCallback: !!keyboardInteractiveFinish,
|
|
hasCode: !!totpData?.code,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "TOTP authentication state lost. Please reconnect.",
|
|
}),
|
|
);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case "password_response": {
|
|
const passwordData = data as TOTPResponseData;
|
|
if (keyboardInteractiveFinish && passwordData?.code) {
|
|
if (totpTimeout) {
|
|
clearTimeout(totpTimeout);
|
|
totpTimeout = null;
|
|
}
|
|
const password = passwordData.code;
|
|
keyboardInteractiveFinish([password]);
|
|
keyboardInteractiveFinish = null;
|
|
} else {
|
|
sshLogger.warn(
|
|
"Password response received but no callback available",
|
|
{
|
|
operation: "password_response_error",
|
|
userId,
|
|
hasCallback: !!keyboardInteractiveFinish,
|
|
hasCode: !!passwordData?.code,
|
|
},
|
|
);
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "Password authentication state lost. Please reconnect.",
|
|
}),
|
|
);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case "warpgate_auth_continue": {
|
|
if (keyboardInteractiveFinish) {
|
|
if (warpgateAuthTimeout) {
|
|
clearTimeout(warpgateAuthTimeout);
|
|
warpgateAuthTimeout = null;
|
|
}
|
|
keyboardInteractiveFinish([""]);
|
|
keyboardInteractiveFinish = null;
|
|
warpgateAuthPromptSent = false;
|
|
}
|
|
break;
|
|
}
|
|
|
|
case "reconnect_with_credentials": {
|
|
const credentialsData = data as {
|
|
cols: number;
|
|
rows: number;
|
|
hostConfig: ConnectToHostData["hostConfig"];
|
|
password?: string;
|
|
sshKey?: string;
|
|
keyPassword?: string;
|
|
};
|
|
|
|
if (credentialsData.password) {
|
|
credentialsData.hostConfig.password = credentialsData.password;
|
|
credentialsData.hostConfig.authType = "password";
|
|
(credentialsData.hostConfig as any).userProvidedPassword = true;
|
|
} else if (credentialsData.sshKey) {
|
|
credentialsData.hostConfig.key = credentialsData.sshKey;
|
|
credentialsData.hostConfig.keyPassword = credentialsData.keyPassword;
|
|
credentialsData.hostConfig.authType = "key";
|
|
}
|
|
|
|
isAwaitingAuthCredentials = false;
|
|
cleanupSSH();
|
|
|
|
const reconnectData: ConnectToHostData = {
|
|
cols: credentialsData.cols,
|
|
rows: credentialsData.rows,
|
|
hostConfig: credentialsData.hostConfig,
|
|
};
|
|
|
|
handleConnectToHost(reconnectData).catch((error) => {
|
|
sshLogger.error("Failed to reconnect with credentials", error, {
|
|
operation: "ssh_reconnect_with_credentials",
|
|
userId,
|
|
hostId: credentialsData.hostConfig?.id,
|
|
ip: credentialsData.hostConfig?.ip,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message:
|
|
"Failed to connect with provided credentials: " +
|
|
(error instanceof Error ? error.message : "Unknown error"),
|
|
}),
|
|
);
|
|
});
|
|
break;
|
|
}
|
|
|
|
default:
|
|
sshLogger.warn("Unknown message type received", {
|
|
operation: "websocket_message_unknown_type",
|
|
userId,
|
|
messageType: type,
|
|
});
|
|
}
|
|
});
|
|
|
|
async function handleConnectToHost(data: ConnectToHostData) {
|
|
const { hostConfig, initialPath, executeCommand } = data;
|
|
const {
|
|
id,
|
|
ip,
|
|
port,
|
|
username,
|
|
password,
|
|
key,
|
|
keyPassword,
|
|
keyType,
|
|
authType,
|
|
credentialId,
|
|
} = hostConfig;
|
|
|
|
const sendLog = (
|
|
stage: string,
|
|
level: string,
|
|
message: string,
|
|
details?: Record<string, any>,
|
|
) => {
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "connection_log",
|
|
data: { stage, level, message, details },
|
|
}),
|
|
);
|
|
};
|
|
|
|
if (!username || typeof username !== "string" || username.trim() === "") {
|
|
sshLogger.error("Invalid username provided", undefined, {
|
|
operation: "ssh_connect",
|
|
hostId: id,
|
|
ip,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({ type: "error", message: "Invalid username provided" }),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (!ip || typeof ip !== "string" || ip.trim() === "") {
|
|
sshLogger.error("Invalid IP provided", undefined, {
|
|
operation: "ssh_connect",
|
|
hostId: id,
|
|
username,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({ type: "error", message: "Invalid IP provided" }),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (!port || typeof port !== "number" || port <= 0) {
|
|
sshLogger.error("Invalid port provided", undefined, {
|
|
operation: "ssh_connect",
|
|
hostId: id,
|
|
ip,
|
|
username,
|
|
port,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({ type: "error", message: "Invalid port provided" }),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (isConnecting || isConnected) {
|
|
sshLogger.warn("Connection already in progress or established", {
|
|
operation: "ssh_connect",
|
|
hostId: id,
|
|
isConnecting,
|
|
isConnected,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "Connection already in progress",
|
|
code: "DUPLICATE_CONNECTION",
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
|
|
isConnecting = true;
|
|
sshConn = new Client();
|
|
|
|
sendLog("dns", "info", `Starting address resolution of ${ip}`);
|
|
sendLog("tcp", "info", `Connecting to ${ip} port ${port}`);
|
|
|
|
const connectionTimeout = setTimeout(() => {
|
|
if (sshConn && isConnecting && !isConnected) {
|
|
sshLogger.error("SSH connection timeout", undefined, {
|
|
operation: "ssh_connect",
|
|
hostId: id,
|
|
ip,
|
|
port,
|
|
username,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({ type: "error", message: "SSH connection timeout" }),
|
|
);
|
|
cleanupSSH(connectionTimeout);
|
|
}
|
|
}, 120000);
|
|
|
|
let resolvedCredentials = { password, key, keyPassword, keyType, authType };
|
|
let authMethodNotAvailable = false;
|
|
if (credentialId && id && hostConfig.userId) {
|
|
try {
|
|
const credentials = await SimpleDBOps.select(
|
|
getDb()
|
|
.select()
|
|
.from(sshCredentials)
|
|
.where(
|
|
and(
|
|
eq(sshCredentials.id, credentialId),
|
|
eq(sshCredentials.userId, hostConfig.userId),
|
|
),
|
|
),
|
|
"ssh_credentials",
|
|
hostConfig.userId,
|
|
);
|
|
|
|
if (credentials.length > 0) {
|
|
const credential = credentials[0];
|
|
resolvedCredentials = {
|
|
password: credential.password as string | undefined,
|
|
key: (credential.private_key ||
|
|
credential.privateKey ||
|
|
credential.key) as string | undefined,
|
|
keyPassword: (credential.key_password || credential.keyPassword) as
|
|
| string
|
|
| undefined,
|
|
keyType: (credential.key_type || credential.keyType) as
|
|
| string
|
|
| undefined,
|
|
authType: (credential.auth_type || credential.authType) as
|
|
| string
|
|
| undefined,
|
|
};
|
|
} else {
|
|
sshLogger.warn(`No credentials found for host ${id}`, {
|
|
operation: "ssh_credentials",
|
|
hostId: id,
|
|
credentialId,
|
|
userId: hostConfig.userId,
|
|
});
|
|
}
|
|
} catch (error) {
|
|
sshLogger.warn(`Failed to resolve credentials for host ${id}`, {
|
|
operation: "ssh_credentials",
|
|
hostId: id,
|
|
credentialId,
|
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
});
|
|
}
|
|
} else if (credentialId && id) {
|
|
sshLogger.warn("Missing userId for credential resolution in terminal", {
|
|
operation: "ssh_credentials",
|
|
hostId: id,
|
|
credentialId,
|
|
hasUserId: !!hostConfig.userId,
|
|
});
|
|
}
|
|
|
|
sshConn.on("ready", () => {
|
|
clearTimeout(connectionTimeout);
|
|
|
|
sendLog("handshake", "success", "SSH handshake completed");
|
|
sendLog("auth", "success", `Authentication successful for ${username}`);
|
|
sendLog("connected", "success", "Connection established");
|
|
|
|
const conn = sshConn;
|
|
|
|
if (!conn || isCleaningUp || !sshConn) {
|
|
sshLogger.warn(
|
|
"SSH connection was cleaned up before shell could be created",
|
|
{
|
|
operation: "ssh_shell",
|
|
hostId: id,
|
|
ip,
|
|
port,
|
|
username,
|
|
isCleaningUp,
|
|
connNull: !conn,
|
|
sshConnNull: !sshConn,
|
|
},
|
|
);
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message:
|
|
"SSH connection was closed before terminal could be created",
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
|
|
isShellInitializing = true;
|
|
isConnecting = false;
|
|
isConnected = true;
|
|
|
|
if (!sshConn) {
|
|
sshLogger.error(
|
|
"SSH connection became null right before shell creation",
|
|
{
|
|
operation: "ssh_shell",
|
|
hostId: id,
|
|
},
|
|
);
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "SSH connection lost during setup",
|
|
}),
|
|
);
|
|
isShellInitializing = false;
|
|
return;
|
|
}
|
|
|
|
sshLogger.info("Creating shell", {
|
|
operation: "ssh_shell_start",
|
|
hostId: id,
|
|
ip,
|
|
port,
|
|
username,
|
|
});
|
|
|
|
let shellCallbackReceived = false;
|
|
const shellTimeout = setTimeout(() => {
|
|
if (!shellCallbackReceived && isShellInitializing) {
|
|
sshLogger.error("Shell creation timeout - no response from server", {
|
|
operation: "ssh_shell_timeout",
|
|
hostId: id,
|
|
ip,
|
|
port,
|
|
username,
|
|
});
|
|
isShellInitializing = false;
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message:
|
|
"Shell creation timeout. The server may not support interactive shells or the connection was interrupted.",
|
|
}),
|
|
);
|
|
cleanupSSH(connectionTimeout);
|
|
}
|
|
}, 15000);
|
|
|
|
conn.shell(
|
|
{
|
|
rows: data.rows,
|
|
cols: data.cols,
|
|
term: "xterm-256color",
|
|
} as PseudoTtyOptions,
|
|
(err, stream) => {
|
|
shellCallbackReceived = true;
|
|
clearTimeout(shellTimeout);
|
|
isShellInitializing = false;
|
|
|
|
if (err) {
|
|
sshLogger.error("Shell error", err, {
|
|
operation: "ssh_shell",
|
|
hostId: id,
|
|
ip,
|
|
port,
|
|
username,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "Shell error: " + err.message,
|
|
}),
|
|
);
|
|
cleanupSSH(connectionTimeout);
|
|
return;
|
|
}
|
|
|
|
sshStream = stream;
|
|
|
|
stream.on("data", (data: Buffer) => {
|
|
try {
|
|
const utf8String = data.toString("utf-8");
|
|
ws.send(JSON.stringify({ type: "data", data: utf8String }));
|
|
} catch (error) {
|
|
sshLogger.error("Error encoding terminal data", error, {
|
|
operation: "terminal_data_encoding",
|
|
hostId: id,
|
|
dataLength: data.length,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "data",
|
|
data: data.toString("latin1"),
|
|
}),
|
|
);
|
|
}
|
|
});
|
|
|
|
stream.on("close", () => {
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "disconnected",
|
|
message: "Connection lost",
|
|
}),
|
|
);
|
|
});
|
|
|
|
stream.on("error", (err: Error) => {
|
|
sshLogger.error("SSH stream error", err, {
|
|
operation: "ssh_stream",
|
|
hostId: id,
|
|
ip,
|
|
port,
|
|
username,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "SSH stream error: " + err.message,
|
|
}),
|
|
);
|
|
});
|
|
|
|
if (initialPath && initialPath.trim() !== "") {
|
|
const cdCommand = `cd "${initialPath.replace(/"/g, '\\"')}" && pwd\n`;
|
|
stream.write(cdCommand);
|
|
}
|
|
|
|
if (executeCommand && executeCommand.trim() !== "") {
|
|
setTimeout(() => {
|
|
const command = `${executeCommand}\n`;
|
|
stream.write(command);
|
|
}, 500);
|
|
}
|
|
|
|
ws.send(
|
|
JSON.stringify({ type: "connected", message: "SSH connected" }),
|
|
);
|
|
|
|
if (id && hostConfig.userId) {
|
|
(async () => {
|
|
try {
|
|
const hosts = await SimpleDBOps.select(
|
|
getDb()
|
|
.select()
|
|
.from(sshData)
|
|
.where(
|
|
and(
|
|
eq(sshData.id, id),
|
|
eq(sshData.userId, hostConfig.userId!),
|
|
),
|
|
),
|
|
"ssh_data",
|
|
hostConfig.userId!,
|
|
);
|
|
|
|
const hostName =
|
|
hosts.length > 0 && hosts[0].name
|
|
? hosts[0].name
|
|
: `${username}@${ip}:${port}`;
|
|
|
|
await axios.post(
|
|
"http://localhost:30006/activity/log",
|
|
{
|
|
type: "terminal",
|
|
hostId: id,
|
|
hostName,
|
|
},
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${await authManager.generateJWTToken(hostConfig.userId!)}`,
|
|
},
|
|
},
|
|
);
|
|
} catch (error) {
|
|
sshLogger.warn("Failed to log terminal activity", {
|
|
operation: "activity_log_error",
|
|
userId: hostConfig.userId,
|
|
hostId: id,
|
|
error:
|
|
error instanceof Error ? error.message : "Unknown error",
|
|
});
|
|
}
|
|
})();
|
|
}
|
|
},
|
|
);
|
|
});
|
|
|
|
sshConn.on("error", (err: Error) => {
|
|
clearTimeout(connectionTimeout);
|
|
|
|
sendLog("error", "error", `Connection error: ${err.message}`);
|
|
|
|
sshLogger.error("SSH connection error", err, {
|
|
operation: "ssh_connect",
|
|
hostId: id,
|
|
ip,
|
|
port,
|
|
username,
|
|
authType: resolvedCredentials.authType,
|
|
warpgateAuthPromptSent,
|
|
isKeyboardInteractive,
|
|
hasKeyboardInteractiveFinish: !!keyboardInteractiveFinish,
|
|
keyboardInteractiveResponded,
|
|
});
|
|
|
|
if (
|
|
authMethodNotAvailable &&
|
|
resolvedCredentials.authType === "none" &&
|
|
!isKeyboardInteractive
|
|
) {
|
|
sendLog(
|
|
"auth",
|
|
"error",
|
|
"Server does not support keyboard-interactive authentication",
|
|
);
|
|
clearTimeout(connectionTimeout);
|
|
isAwaitingAuthCredentials = true;
|
|
if (sshConn) {
|
|
try {
|
|
sshConn.end();
|
|
} catch (e) {}
|
|
sshConn = null;
|
|
}
|
|
isConnecting = false;
|
|
isConnected = false;
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "auth_method_not_available",
|
|
message:
|
|
"The server does not support keyboard-interactive authentication. Please provide credentials.",
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (
|
|
resolvedCredentials.authType === "none" &&
|
|
err.message.includes("All configured authentication methods failed") &&
|
|
!isKeyboardInteractive &&
|
|
!keyboardInteractiveResponded
|
|
) {
|
|
clearTimeout(connectionTimeout);
|
|
isAwaitingAuthCredentials = true;
|
|
if (sshConn) {
|
|
try {
|
|
sshConn.end();
|
|
} catch (e) {}
|
|
sshConn = null;
|
|
}
|
|
isConnecting = false;
|
|
isConnected = false;
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "auth_method_not_available",
|
|
message:
|
|
"The server does not support keyboard-interactive authentication. Please provide credentials.",
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (
|
|
isKeyboardInteractive &&
|
|
keyboardInteractiveFinish &&
|
|
err.message.includes("All configured authentication methods failed")
|
|
) {
|
|
sshLogger.warn(
|
|
"Authentication error during keyboard-interactive - SKIPPING cleanup, waiting for user response",
|
|
{
|
|
operation: "ssh_error_during_keyboard_interactive_skip_cleanup",
|
|
hostId: id,
|
|
error: err.message,
|
|
},
|
|
);
|
|
return;
|
|
}
|
|
|
|
sshLogger.error("Proceeding with cleanup after error", {
|
|
operation: "ssh_error_cleanup",
|
|
hostId: id,
|
|
error: err.message,
|
|
});
|
|
|
|
if (
|
|
err.message.includes("authentication") ||
|
|
err.message.includes("Authentication")
|
|
) {
|
|
sendLog("auth", "error", `Authentication failed: ${err.message}`);
|
|
} else {
|
|
sendLog("error", "error", `Connection failed: ${err.message}`);
|
|
}
|
|
|
|
let errorMessage = "SSH error: " + err.message;
|
|
if (err.message.includes("No matching key exchange algorithm")) {
|
|
errorMessage =
|
|
"SSH error: No compatible key exchange algorithm found. This may be due to an older SSH server or network device.";
|
|
} else if (err.message.includes("No matching cipher")) {
|
|
errorMessage =
|
|
"SSH error: No compatible cipher found. This may be due to an older SSH server or network device.";
|
|
} else if (err.message.includes("No matching MAC")) {
|
|
errorMessage =
|
|
"SSH error: No compatible MAC algorithm found. This may be due to an older SSH server or network device.";
|
|
} else if (
|
|
err.message.includes("ENOTFOUND") ||
|
|
err.message.includes("ENOENT")
|
|
) {
|
|
errorMessage =
|
|
"SSH error: Could not resolve hostname or connect to server.";
|
|
} else if (err.message.includes("ECONNREFUSED")) {
|
|
errorMessage =
|
|
"SSH error: Connection refused. The server may not be running or the port may be incorrect.";
|
|
} else if (err.message.includes("ETIMEDOUT")) {
|
|
errorMessage =
|
|
"SSH error: Connection timed out. Check your network connection and server availability.";
|
|
} else if (
|
|
err.message.includes("ECONNRESET") ||
|
|
err.message.includes("EPIPE")
|
|
) {
|
|
errorMessage =
|
|
"SSH error: Connection was reset. This may be due to network issues or server timeout.";
|
|
} else if (
|
|
err.message.includes("authentication failed") ||
|
|
err.message.includes("Permission denied")
|
|
) {
|
|
errorMessage =
|
|
"SSH error: Authentication failed. Please check your username and password/key.";
|
|
}
|
|
|
|
ws.send(JSON.stringify({ type: "error", message: errorMessage }));
|
|
cleanupSSH(connectionTimeout);
|
|
});
|
|
|
|
sshConn.on("close", () => {
|
|
clearTimeout(connectionTimeout);
|
|
|
|
if (isAwaitingAuthCredentials) {
|
|
cleanupSSH(connectionTimeout);
|
|
return;
|
|
}
|
|
|
|
if (isShellInitializing || (isConnected && !sshStream)) {
|
|
sshLogger.warn("SSH connection closed during shell initialization", {
|
|
operation: "ssh_close_during_init",
|
|
hostId: id,
|
|
ip,
|
|
port,
|
|
username,
|
|
isShellInitializing,
|
|
hasStream: !!sshStream,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message:
|
|
"Connection closed during shell initialization. The server may have rejected the shell request.",
|
|
}),
|
|
);
|
|
} else if (!sshStream) {
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "disconnected",
|
|
message: "Connection closed",
|
|
}),
|
|
);
|
|
}
|
|
cleanupSSH(connectionTimeout);
|
|
});
|
|
|
|
const sshAuthManager = new SSHAuthManager({
|
|
userId,
|
|
ws,
|
|
hostId: id || 0,
|
|
isKeyboardInteractive,
|
|
keyboardInteractiveResponded,
|
|
keyboardInteractiveFinish,
|
|
totpPromptSent,
|
|
warpgateAuthPromptSent,
|
|
totpTimeout,
|
|
warpgateAuthTimeout,
|
|
totpAttempts: 0,
|
|
});
|
|
|
|
sshConn.on(
|
|
"keyboard-interactive",
|
|
(
|
|
name: string,
|
|
instructions: string,
|
|
instructionsLang: string,
|
|
prompts: Array<{ prompt: string; echo: boolean }>,
|
|
finish: (responses: string[]) => void,
|
|
) => {
|
|
if (connectionTimeout) {
|
|
clearTimeout(connectionTimeout);
|
|
}
|
|
|
|
sshAuthManager.handleKeyboardInteractive(
|
|
name,
|
|
instructions,
|
|
instructionsLang,
|
|
prompts,
|
|
finish,
|
|
resolvedCredentials as any,
|
|
);
|
|
|
|
isKeyboardInteractive = sshAuthManager.context.isKeyboardInteractive;
|
|
keyboardInteractiveResponded =
|
|
sshAuthManager.context.keyboardInteractiveResponded;
|
|
keyboardInteractiveFinish =
|
|
sshAuthManager.context.keyboardInteractiveFinish;
|
|
totpPromptSent = sshAuthManager.context.totpPromptSent;
|
|
warpgateAuthPromptSent = sshAuthManager.context.warpgateAuthPromptSent;
|
|
totpTimeout = sshAuthManager.context.totpTimeout;
|
|
warpgateAuthTimeout = sshAuthManager.context.warpgateAuthTimeout;
|
|
},
|
|
);
|
|
|
|
const connectConfig: any = {
|
|
host: ip,
|
|
port,
|
|
username,
|
|
tryKeyboard: true,
|
|
keepaliveInterval: 30000,
|
|
keepaliveCountMax: 3,
|
|
readyTimeout: 120000,
|
|
tcpKeepAlive: true,
|
|
tcpKeepAliveInitialDelay: 30000,
|
|
timeout: 120000,
|
|
env: {
|
|
TERM: "xterm-256color",
|
|
LANG: "en_US.UTF-8",
|
|
LC_ALL: "en_US.UTF-8",
|
|
LC_CTYPE: "en_US.UTF-8",
|
|
LC_MESSAGES: "en_US.UTF-8",
|
|
LC_MONETARY: "en_US.UTF-8",
|
|
LC_NUMERIC: "en_US.UTF-8",
|
|
LC_TIME: "en_US.UTF-8",
|
|
LC_COLLATE: "en_US.UTF-8",
|
|
COLORTERM: "truecolor",
|
|
},
|
|
algorithms: {
|
|
kex: [
|
|
"curve25519-sha256",
|
|
"curve25519-sha256@libssh.org",
|
|
"ecdh-sha2-nistp521",
|
|
"ecdh-sha2-nistp384",
|
|
"ecdh-sha2-nistp256",
|
|
"diffie-hellman-group-exchange-sha256",
|
|
"diffie-hellman-group14-sha256",
|
|
"diffie-hellman-group14-sha1",
|
|
"diffie-hellman-group-exchange-sha1",
|
|
"diffie-hellman-group1-sha1",
|
|
],
|
|
serverHostKey: [
|
|
"ssh-ed25519",
|
|
"ecdsa-sha2-nistp521",
|
|
"ecdsa-sha2-nistp384",
|
|
"ecdsa-sha2-nistp256",
|
|
"rsa-sha2-512",
|
|
"rsa-sha2-256",
|
|
"ssh-rsa",
|
|
"ssh-dss",
|
|
],
|
|
cipher: [
|
|
"chacha20-poly1305@openssh.com",
|
|
"aes256-gcm@openssh.com",
|
|
"aes128-gcm@openssh.com",
|
|
"aes256-ctr",
|
|
"aes192-ctr",
|
|
"aes128-ctr",
|
|
"aes256-cbc",
|
|
"aes192-cbc",
|
|
"aes128-cbc",
|
|
"3des-cbc",
|
|
],
|
|
hmac: [
|
|
"hmac-sha2-512-etm@openssh.com",
|
|
"hmac-sha2-256-etm@openssh.com",
|
|
"hmac-sha2-512",
|
|
"hmac-sha2-256",
|
|
"hmac-sha1",
|
|
"hmac-md5",
|
|
],
|
|
compress: ["none", "zlib@openssh.com", "zlib"],
|
|
},
|
|
};
|
|
|
|
if (resolvedCredentials.authType === "none") {
|
|
} else if (resolvedCredentials.authType === "password") {
|
|
if (!resolvedCredentials.password) {
|
|
sshLogger.error(
|
|
"Password authentication requested but no password provided",
|
|
);
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message:
|
|
"Password authentication requested but no password provided",
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
|
|
connectConfig.password = resolvedCredentials.password;
|
|
sendLog("auth", "info", "Using password authentication");
|
|
} else if (
|
|
resolvedCredentials.authType === "key" &&
|
|
resolvedCredentials.key
|
|
) {
|
|
sendLog("auth", "info", "Using SSH key authentication");
|
|
try {
|
|
if (
|
|
!resolvedCredentials.key.includes("-----BEGIN") ||
|
|
!resolvedCredentials.key.includes("-----END")
|
|
) {
|
|
throw new Error("Invalid private key format");
|
|
}
|
|
|
|
const cleanKey = resolvedCredentials.key
|
|
.trim()
|
|
.replace(/\r\n/g, "\n")
|
|
.replace(/\r/g, "\n");
|
|
|
|
connectConfig.privateKey = Buffer.from(cleanKey, "utf8");
|
|
|
|
if (resolvedCredentials.keyPassword) {
|
|
connectConfig.passphrase = resolvedCredentials.keyPassword;
|
|
}
|
|
} catch (keyError) {
|
|
sshLogger.error("SSH key format error: " + keyError.message);
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "SSH key format error: Invalid private key format",
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
} else if (resolvedCredentials.authType === "key") {
|
|
sendLog(
|
|
"auth",
|
|
"error",
|
|
"SSH key authentication requested but no key provided",
|
|
);
|
|
sshLogger.error("SSH key authentication requested but no key provided");
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "SSH key authentication requested but no key provided",
|
|
}),
|
|
);
|
|
return;
|
|
} else {
|
|
sendLog("auth", "info", "Using keyboard-interactive authentication");
|
|
sshLogger.error("No valid authentication method provided");
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "No valid authentication method provided",
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (
|
|
hostConfig.useSocks5 &&
|
|
(hostConfig.socks5Host ||
|
|
(hostConfig.socks5ProxyChain &&
|
|
(hostConfig.socks5ProxyChain as any).length > 0))
|
|
) {
|
|
try {
|
|
const socks5Socket = await createSocks5Connection(ip, port, {
|
|
useSocks5: hostConfig.useSocks5,
|
|
socks5Host: hostConfig.socks5Host,
|
|
socks5Port: hostConfig.socks5Port,
|
|
socks5Username: hostConfig.socks5Username,
|
|
socks5Password: hostConfig.socks5Password,
|
|
socks5ProxyChain: hostConfig.socks5ProxyChain as any,
|
|
});
|
|
|
|
if (socks5Socket) {
|
|
connectConfig.sock = socks5Socket;
|
|
sshConn.connect(connectConfig);
|
|
return;
|
|
}
|
|
} catch (socks5Error) {
|
|
sshLogger.error("SOCKS5 connection failed", socks5Error, {
|
|
operation: "socks5_connect",
|
|
hostId: id,
|
|
proxyHost: hostConfig.socks5Host,
|
|
proxyPort: hostConfig.socks5Port || 1080,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message:
|
|
"SOCKS5 proxy connection failed: " +
|
|
(socks5Error instanceof Error
|
|
? socks5Error.message
|
|
: "Unknown error"),
|
|
}),
|
|
);
|
|
cleanupSSH(connectionTimeout);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (
|
|
hostConfig.jumpHosts &&
|
|
hostConfig.jumpHosts.length > 0 &&
|
|
hostConfig.userId
|
|
) {
|
|
try {
|
|
const jumpClient = await createJumpHostChain(
|
|
hostConfig.jumpHosts,
|
|
hostConfig.userId,
|
|
);
|
|
|
|
if (!jumpClient) {
|
|
sshLogger.error("Failed to establish jump host chain");
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "Failed to connect through jump hosts",
|
|
}),
|
|
);
|
|
cleanupSSH(connectionTimeout);
|
|
return;
|
|
}
|
|
|
|
jumpClient.forwardOut("127.0.0.1", 0, ip, port, (err, stream) => {
|
|
if (err) {
|
|
sshLogger.error("Failed to forward through jump host", err, {
|
|
operation: "ssh_jump_forward",
|
|
hostId: id,
|
|
ip,
|
|
port,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "Failed to forward through jump host: " + err.message,
|
|
}),
|
|
);
|
|
jumpClient.end();
|
|
cleanupSSH(connectionTimeout);
|
|
return;
|
|
}
|
|
|
|
connectConfig.sock = stream;
|
|
sendLog(
|
|
"handshake",
|
|
"info",
|
|
"Starting SSH session through jump host",
|
|
);
|
|
sendLog("auth", "info", `Authenticating as ${username}`);
|
|
sshConn.connect(connectConfig);
|
|
});
|
|
} catch (error) {
|
|
sshLogger.error("Jump host error", error, {
|
|
operation: "ssh_jump_host",
|
|
hostId: id,
|
|
});
|
|
ws.send(
|
|
JSON.stringify({
|
|
type: "error",
|
|
message: "Failed to connect through jump hosts",
|
|
}),
|
|
);
|
|
cleanupSSH(connectionTimeout);
|
|
return;
|
|
}
|
|
} else {
|
|
sendLog("handshake", "info", "Starting SSH session");
|
|
sendLog("auth", "info", `Authenticating as ${username}`);
|
|
sshConn.connect(connectConfig);
|
|
}
|
|
}
|
|
|
|
function handleResize(data: ResizeData) {
|
|
if (sshStream && sshStream.setWindow) {
|
|
sshStream.setWindow(data.rows, data.cols, data.rows, data.cols);
|
|
ws.send(
|
|
JSON.stringify({ type: "resized", cols: data.cols, rows: data.rows }),
|
|
);
|
|
}
|
|
}
|
|
|
|
function cleanupSSH(timeoutId?: NodeJS.Timeout) {
|
|
if (isCleaningUp) {
|
|
return;
|
|
}
|
|
|
|
if (isShellInitializing) {
|
|
sshLogger.warn(
|
|
"Cleanup attempted during shell initialization, deferring",
|
|
{
|
|
operation: "cleanup_deferred",
|
|
userId,
|
|
},
|
|
);
|
|
setTimeout(() => cleanupSSH(timeoutId), 100);
|
|
return;
|
|
}
|
|
|
|
isCleaningUp = true;
|
|
|
|
if (timeoutId) {
|
|
clearTimeout(timeoutId);
|
|
}
|
|
|
|
if (totpTimeout) {
|
|
clearTimeout(totpTimeout);
|
|
totpTimeout = null;
|
|
}
|
|
|
|
if (warpgateAuthTimeout) {
|
|
clearTimeout(warpgateAuthTimeout);
|
|
warpgateAuthTimeout = null;
|
|
}
|
|
|
|
if (sshStream) {
|
|
try {
|
|
sshStream.end();
|
|
} catch (e: unknown) {
|
|
sshLogger.error(
|
|
"Error closing stream: " +
|
|
(e instanceof Error ? e.message : "Unknown error"),
|
|
);
|
|
}
|
|
sshStream = null;
|
|
}
|
|
|
|
if (sshConn) {
|
|
try {
|
|
sshConn.end();
|
|
} catch (e: unknown) {
|
|
sshLogger.error(
|
|
"Error closing connection: " +
|
|
(e instanceof Error ? e.message : "Unknown error"),
|
|
);
|
|
}
|
|
sshConn = null;
|
|
}
|
|
|
|
totpPromptSent = false;
|
|
warpgateAuthPromptSent = false;
|
|
isKeyboardInteractive = false;
|
|
keyboardInteractiveResponded = false;
|
|
keyboardInteractiveFinish = null;
|
|
isConnecting = false;
|
|
isConnected = false;
|
|
isCleaningUp = false;
|
|
isAwaitingAuthCredentials = false;
|
|
}
|
|
|
|
// Note: PTY-level keepalive (writing \x00 to the stream) was removed.
|
|
// It was causing ^@ characters to appear in terminals with echoctl enabled.
|
|
// SSH-level keepalive is configured via connectConfig (keepaliveInterval,
|
|
// keepaliveCountMax, tcpKeepAlive), which handles connection health monitoring
|
|
// without producing visible output on the terminal.
|
|
//
|
|
// See: https://github.com/Termix-SSH/Support/issues/232
|
|
// See: https://github.com/Termix-SSH/Support/issues/309
|
|
});
|