Browse Source

WIP. spawning ssh

master
Jonathan Cobb 4 years ago
parent
commit
1cf9fe6870
2 changed files with 49 additions and 4 deletions
  1. +32
    -4
      src/admin.rs
  2. +17
    -0
      src/net.rs

+ 32
- 4
src/admin.rs View File

@@ -5,6 +5,7 @@
*/ */


use std::net::SocketAddr; use std::net::SocketAddr;
use std::process::{Command, Stdio};
use std::sync::Arc; use std::sync::Arc;


use log::{debug, info, error}; use log::{debug, info, error};
@@ -18,6 +19,7 @@ use warp;
use warp::{Filter}; use warp::{Filter};


use crate::pass::is_correct_password; use crate::pass::is_correct_password;
use crate::net::ssh_command;


#[derive(Debug, Deserialize, Serialize, Clone)] #[derive(Debug, Deserialize, Serialize, Clone)]
struct AdminRegistration { struct AdminRegistration {
@@ -131,10 +133,36 @@ async fn handle_register(registration : AdminRegistration,
let port = port_opt.unwrap(); let port = port_opt.unwrap();
info!("handle_register: received port: {}", port); info!("handle_register: received port: {}", port);
// todo: start or restart ssh service // todo: start or restart ssh service
Ok(warp::reply::with_status(
"successfully registered with bubble",
http::StatusCode::OK,
))
let tunnel = format!("{}:127.0.0.1:{}", port, proxy_port);
let target = format!("bubble-flex@{}", registration.bubble);
let ssh = Command::new(ssh_command())
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg("-Nn")
.arg("-R")
.arg(tunnel)
.arg(target)
.spawn();
if ssh.is_err() {
let err = ssh.err();
if err.is_none() {
error!("handle_register: error spawning ssh");
} else {
error!("handle_register: error spawning ssh: {:?}", err.unwrap());
}
Ok(warp::reply::with_status(
"error spawning ssh",
http::StatusCode::PRECONDITION_FAILED,
))
} else {
let mut child = ssh.unwrap();
// child.kill();
Ok(warp::reply::with_status(
"successfully registered with bubble",
http::StatusCode::OK,
))
}
} }
} }
}, },


+ 17
- 0
src/net.rs View File

@@ -189,3 +189,20 @@ pub fn remove_static_route(ip_string: &String) -> bool {
} }
ok ok
} }

const SSH_WINDOWS: &'static str = "C:\\Windows\\System32\\OpenSSH\\ssh.exe";
const SSH_MACOS: &'static str = "/usr/bin/ssh";
const SSH_LINUX: &'static str = "/usr/bin/ssh";

pub fn ssh_command() -> &'static str {
let platform: Platform = platform();
return match platform {
Platform::Windows => SSH_WINDOWS,
Platform::MacOS => SSH_MACOS,
Platform::Linux => SSH_LINUX,
_ => {
error!("ssh_command: unsupported platform: {:?}", platform);
exit(2);
}
}
}

Loading…
Cancel
Save