Only handle data over pty channel

This commit is contained in:
Dreaded_X 2025-04-10 16:46:23 +02:00
parent 321e5842d3
commit c6c663c4ac
Signed by: Dreaded_X
GPG Key ID: 5A0CBFE3C3377FAA
2 changed files with 21 additions and 7 deletions

View File

@ -1,3 +1,5 @@
use tracing::trace;
#[derive(Debug)] #[derive(Debug)]
pub enum Input { pub enum Input {
Char(char), Char(char),
@ -16,7 +18,10 @@ impl From<&[u8]> for Input {
[27, 91, 65] => Input::Up, [27, 91, 65] => Input::Up,
[27, 91, 66] => Input::Down, [27, 91, 66] => Input::Down,
[13] => Input::Enter, [13] => Input::Enter,
_ => Input::Other, other => {
trace!("{other:?}");
Input::Other
}
} }
} }
} }

View File

@ -23,6 +23,7 @@ pub struct Handler {
tunnels: IndexMap<String, Option<Tunnel>>, tunnels: IndexMap<String, Option<Tunnel>>,
user: Option<String>, user: Option<String>,
pty_channel: Option<ChannelId>,
terminal: Option<Terminal<CrosstermBackend<TerminalHandle>>>, terminal: Option<Terminal<CrosstermBackend<TerminalHandle>>>,
renderer: Renderer, renderer: Renderer,
@ -35,6 +36,7 @@ impl Handler {
all_tunnels, all_tunnels,
tunnels: IndexMap::new(), tunnels: IndexMap::new(),
user: None, user: None,
pty_channel: None,
terminal: None, terminal: None,
renderer: Default::default(), renderer: Default::default(),
selected: None, selected: None,
@ -203,15 +205,20 @@ impl russh::server::Handler for Handler {
async fn data( async fn data(
&mut self, &mut self,
_channel: ChannelId, channel: ChannelId,
data: &[u8], data: &[u8],
_session: &mut Session, _session: &mut Session,
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
let input: Input = data.into(); // Make sure we only handle user input, and not other data send over ssh
trace!(?input, "data"); if let Some(pty_channel) = self.pty_channel
&& pty_channel == channel
{
let input: Input = data.into();
trace!(?input, "input");
if self.handle_input(input).await? { if self.handle_input(input).await? {
self.redraw().await?; self.redraw().await?;
}
} }
Ok(()) Ok(())
@ -308,10 +315,12 @@ impl russh::server::Handler for Handler {
_modes: &[(russh::Pty, u32)], _modes: &[(russh::Pty, u32)],
session: &mut Session, session: &mut Session,
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
trace!(col_width, row_height, "pty_request"); trace!(col_width, row_height, ?channel, "pty_request");
self.resize(col_width, row_height).await?; self.resize(col_width, row_height).await?;
self.pty_channel = Some(channel);
session.channel_success(channel)?; session.channel_success(channel)?;
Ok(()) Ok(())