log forwarding

This commit is contained in:
Astro 2022-09-28 18:13:20 +02:00
parent b6dfad22fb
commit e1043a8c0a
1 changed files with 47 additions and 0 deletions

View File

@ -17,6 +17,7 @@ fn send_str(session: &mut Session, channel: ChannelId, s: String) {
enum ChannelState {
Shell,
Scp,
Forwarding,
}
enum CommandStatus {
@ -162,6 +163,50 @@ impl server::Handler for Handler {
self.finished(session)
}
/// `ssh -R`
fn tcpip_forward(mut self, address: &str, port: u32, session: Session) -> Self::FutureBool {
info!("Reverse-forwarding {}:{}", address, port);
writeln!(self.file(), "Reverse-forwarding {}:{}", address, port)
.unwrap();
let handle = session.handle();
let address = address.to_string();
tokio::spawn(async move {
if let Ok(mut channel) = handle
.channel_open_forwarded_tcpip(address, port, "0.0.0.0", 1)
.await {
let _ = channel.eof().await;
}
});
self.finished_bool(true, session)
}
/// `ssh -L` but doesn't work
fn channel_open_forwarded_tcpip(
mut self,
channel: ChannelId,
host_to_connect: &str,
port_to_connect: u32,
originator_address: &str,
originator_port: u32,
session: Session
) -> Self::FutureBool {
info!(
"Forwarding {}:{} from {}:{}",
host_to_connect, port_to_connect,
originator_address, originator_port,
);
writeln!(
self.file(), "Forwarding {}:{} from {}:{}",
host_to_connect, port_to_connect,
originator_address, originator_port,
).unwrap();
self.channels.insert(channel, ChannelState::Forwarding);
self.finished_bool(true, session)
}
// fn channel_open_session(
// self,
// channel: ChannelId,
@ -241,6 +286,8 @@ impl server::Handler for Handler {
}
}
Some(ChannelState::Forwarding) => {}
None => {
info!("data on unidentified channel {}", channel);
}