Update main.go#1
Closed
sullrich wants to merge 6 commits into
Closed
Conversation
1. Add new "connect" command to directly SSH into configured tunnels - Implement `connectTunnel` function to handle SSH connections - Update main() to include "connect" in the command switch - Modify printUsage() to include information about the new command 2. Fix Tunnel struct field access in connectTunnel function - Replace t.RemotePort with port extraction from t.RemoteAddress - Add fallback to default "root" user if t.User is not specified 3. Update import statements - Add "strings" package for string manipulation - Remove "strconv" package as it's no longer needed 4. Improve error handling and user feedback - Provide more descriptive error messages for configuration issues - Use log.Fatalf for critical errors to exit the program 5. Enhance code comments for better maintainability These changes allow users to easily connect to their configured tunnels using the "boring connect <tunnel_name>" command, improving the overall functionality and user experience of the boring CLI tool.
When using the 'connect' command to SSH into a host, pasting large amounts of text would cause the session to lock up. This issue was due to the SSH process not being attached to a proper terminal (PTY), leading to improper handling of interactive input/output. This commit fixes the issue by modifying the 'connectTunnel' function to allocate a PTY using the 'github.com/creack/pty' package. By starting the SSH command with a pseudo-terminal and setting the terminal to raw mode, we enable proper input/output handling for interactive sessions, including handling large pasted inputs without freezing. Additional changes: - Handle terminal resizing by listening for SIGWINCH signals and adjusting the PTY size accordingly using 'pty.InheritSize'. - Use 'io.Copy' to forward data between the user's terminal and the SSH process, ensuring seamless interaction. - Default the SSH port to '22' if not specified in the tunnel configuration. - Update error handling to provide clearer messages using the existing 'log' package. Dependencies added: - github.com/creack/pty - golang.org/x/term This ensures that SSH sessions initiated via the 'connect' command behave correctly in an interactive terminal environment.
- Added a check to ensure the tunnel is not reopened if it's already running. This prevents the error "Tunnel could not be opened: tunnel already running" by querying tunnel status before attempting to open it. - Introduced the `-t` flag to allow reconnecting to the SSH session using tmux. When the `-t` flag is passed, the SSH command attaches to or creates a new tmux session (`tmux new-session -A -s boring-session`). - Maintained existing functionality for SSH multiplexing, keep-alive, terminal resizing, and PTY handling. - Preserved signal handling (SIGWINCH) for terminal resizing, raw terminal mode for interactive sessions, and SSH control master multiplexing logic. This ensures smooth reconnections to running tunnels, while allowing users to reconnect via tmux when needed.
Alter the connect command to ssh.
… the application by checking the command line arguments. It also adds dependencies on the `github.com/creack/pty` and `golang.org/x/term` packages in the `go.mod` file.
Author
|
This PR was a bit premature. Will circle back. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add new "connect" command to directly SSH into configured tunnels
connectTunnelfunction to handle SSH connectionsFix Tunnel struct field access in connectTunnel function
Update import statements
Improve error handling and user feedback
Enhance code comments for better maintainability
These changes allow users to easily connect to their configured tunnels using the "boring connect <tunnel_name>" command, improving the overall functionality and user experience of the boring CLI tool.