2019-03-29 13:48:31 +00:00
|
|
|
extern crate actix;
|
|
|
|
|
extern crate actix_web;
|
|
|
|
|
extern crate webterm;
|
2019-07-02 02:33:49 +00:00
|
|
|
extern crate structopt;
|
|
|
|
|
#[macro_use]
|
|
|
|
|
extern crate lazy_static;
|
2019-03-29 13:48:31 +00:00
|
|
|
|
2019-03-29 16:51:42 +00:00
|
|
|
use actix_web::{fs::StaticFiles, server, App};
|
2019-07-02 02:33:49 +00:00
|
|
|
use structopt::StructOpt;
|
2019-03-29 13:48:31 +00:00
|
|
|
use webterm::WebTermExt;
|
|
|
|
|
|
2019-03-29 15:32:35 +00:00
|
|
|
use std::process::Command;
|
|
|
|
|
|
2019-07-02 02:33:49 +00:00
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
|
#[structopt(name = "webterm-server")]
|
|
|
|
|
struct Opt {
|
|
|
|
|
/// The port to listen on
|
|
|
|
|
#[structopt(short, long, default_value = "8080")]
|
|
|
|
|
port: u16,
|
|
|
|
|
|
|
|
|
|
/// The host or IP to listen on
|
|
|
|
|
#[structopt(short, long, default_value = "localhost")]
|
|
|
|
|
host: String,
|
|
|
|
|
|
|
|
|
|
/// The command to execute
|
|
|
|
|
#[structopt(short, long, default_value = "/bin/sh")]
|
|
|
|
|
command: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
static ref OPT: Opt = Opt::from_args();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-03-29 13:48:31 +00:00
|
|
|
fn main() {
|
|
|
|
|
pretty_env_logger::init();
|
|
|
|
|
|
|
|
|
|
server::new(|| {
|
|
|
|
|
App::new()
|
|
|
|
|
.handler(
|
|
|
|
|
"/static",
|
|
|
|
|
StaticFiles::new("node_modules")
|
|
|
|
|
.unwrap()
|
|
|
|
|
.show_files_listing(),
|
|
|
|
|
)
|
2019-03-29 15:32:35 +00:00
|
|
|
.webterm_socket("/websocket", |_req| {
|
2019-07-02 02:33:49 +00:00
|
|
|
let mut cmd = Command::new(OPT.command.clone());
|
2019-03-29 15:32:35 +00:00
|
|
|
cmd.env("TERM", "xterm");
|
|
|
|
|
cmd
|
|
|
|
|
})
|
2019-03-29 16:51:42 +00:00
|
|
|
.webterm_ui("/", "/websocket", "/static")
|
2019-03-29 13:48:31 +00:00
|
|
|
})
|
2019-07-02 02:33:49 +00:00
|
|
|
.bind(format!("{}:{}", OPT.host, OPT.port))
|
2019-03-29 13:48:31 +00:00
|
|
|
.unwrap()
|
|
|
|
|
.run();
|
|
|
|
|
}
|