chore: remove terminal ssh code
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -696,10 +696,7 @@ async fn v1_terminal_proxy(
|
|||||||
match msg {
|
match msg {
|
||||||
Ok(m) => {
|
Ok(m) => {
|
||||||
let m_up = match m {
|
let m_up = match m {
|
||||||
Message::Text(t) => {
|
Message::Text(t) => t.as_bytes().to_vec(),
|
||||||
info!("Got msg: {}", t);
|
|
||||||
t.as_bytes().to_vec()
|
|
||||||
}
|
|
||||||
_ => panic!("todo"),
|
_ => panic!("todo"),
|
||||||
};
|
};
|
||||||
if let Err(e) = ws_upstream.send(m_up).await {
|
if let Err(e) = ws_upstream.send(m_up).await {
|
||||||
@ -723,7 +720,6 @@ async fn v1_terminal_proxy(
|
|||||||
match msg {
|
match msg {
|
||||||
Ok(m) => {
|
Ok(m) => {
|
||||||
let down = String::from_utf8_lossy(&m).into_owned();
|
let down = String::from_utf8_lossy(&m).into_owned();
|
||||||
info!("Got down msg: {}", &down);
|
|
||||||
let m_down = Message::Text(down);
|
let m_down = Message::Text(down);
|
||||||
if let Err(e) = tx_client.send(m_down).await {
|
if let Err(e) = tx_client.send(m_down).await {
|
||||||
bail!("Failed to msg to client: {}", e);
|
bail!("Failed to msg to client: {}", e);
|
||||||
|
@ -19,8 +19,8 @@ use std::io::{Read, Write};
|
|||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||||
use tokio::sync::mpsc::channel;
|
use tokio::sync::mpsc::channel;
|
||||||
@ -664,67 +664,30 @@ impl VmHostClient for ProxmoxClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn connect_terminal(&self, vm: &Vm) -> Result<TerminalStream> {
|
async fn connect_terminal(&self, vm: &Vm) -> Result<TerminalStream> {
|
||||||
// the proxmox api for terminal connection is weird and doesn't work
|
let vm_id: ProxmoxVmId = vm.id.into();
|
||||||
// when I tested it, using ssh instead to run qm terminal command
|
|
||||||
|
|
||||||
if let Some(ssh_config) = &self.ssh {
|
let (mut client_tx, client_rx) = channel::<Vec<u8>>(1024);
|
||||||
let mut ses = SshClient::new()?;
|
let (server_tx, mut server_rx) = channel::<Vec<u8>>(1024);
|
||||||
ses.connect(
|
let shutdown = Arc::new(AtomicBool::new(false));
|
||||||
(self.api.base.host().unwrap().to_string(), 22),
|
tokio::spawn(async move {
|
||||||
&ssh_config.user,
|
// fire calls to read every 100ms
|
||||||
&ssh_config.key,
|
loop {
|
||||||
)
|
tokio::select! {
|
||||||
.await?;
|
Some(buf) = server_rx.recv() => {
|
||||||
|
// echo
|
||||||
let vm_id: ProxmoxVmId = vm.id.into();
|
client_tx.send(buf).await?;
|
||||||
let sock_path = PathBuf::from(&format!("/var/run/qemu-server/{}.serial0", vm_id));
|
|
||||||
let mut chan = ses.tunnel_unix_socket(&sock_path)?;
|
|
||||||
|
|
||||||
let (mut client_tx, client_rx) = channel::<Vec<u8>>(1024);
|
|
||||||
let (server_tx, mut server_rx) = channel::<Vec<u8>>(1024);
|
|
||||||
let shutdown = Arc::new(AtomicBool::new(false));
|
|
||||||
let shut_chan = shutdown.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
let mut w_buf = vec![0; 4096];
|
|
||||||
|
|
||||||
// fire calls to read every 100ms
|
|
||||||
let mut chan_timer = time::interval(Duration::from_millis(100));
|
|
||||||
loop {
|
|
||||||
tokio::select! {
|
|
||||||
Some(buf) = server_rx.recv() => {
|
|
||||||
if let Err(e) = chan.write_all(&buf) {
|
|
||||||
error!("Failed to send data: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ = chan_timer.tick() => {
|
|
||||||
if chan.eof() {
|
|
||||||
info!("SSH connection terminated!");
|
|
||||||
shut_chan.store(true, Ordering::Relaxed);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let r_window = chan.read_window();
|
|
||||||
|
|
||||||
let mut stream = chan.stream(0);
|
|
||||||
if let Ok(r) = stream.read(w_buf.as_mut_slice()) {
|
|
||||||
if r > 0 {
|
|
||||||
if let Err(e) = client_tx.send(w_buf[..r].to_vec()).await {
|
|
||||||
error!("Failed to write data: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
info!("SSH connection terminated!");
|
}
|
||||||
});
|
}
|
||||||
return Ok(TerminalStream{
|
info!("SSH connection terminated!");
|
||||||
shutdown,
|
Ok::<(), anyhow::Error>(())
|
||||||
rx: client_rx,
|
});
|
||||||
tx: server_tx,
|
Ok(TerminalStream {
|
||||||
});
|
shutdown,
|
||||||
}
|
rx: client_rx,
|
||||||
bail!("Cannot use terminal proxy without ssh")
|
tx: server_tx,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user