Skip to content

Commit

Permalink
feat(terminal): allow setting login user (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenclaw900 authored Apr 3, 2022
1 parent 807f954 commit fdb4891
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@
# - Default: []
# Please insert the IP addresses/domains and ports of these nodes
# For example: ["example.com:5252", "192.168.1.60:4386"]
#nodes = []
#nodes = []

# User to login to on the terminal
# Use "manual" to show a login prompt instead of auto-login
# - Default: "root"
#terminal_user = "root"
4 changes: 4 additions & 0 deletions src/backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct Config {

#[cfg(feature = "frontend")]
pub nodes: Vec<String>,

pub terminal_user: String,
}

impl Default for Config {
Expand All @@ -41,6 +43,8 @@ impl Default for Config {

#[cfg(feature = "frontend")]
nodes: Vec::new(),

terminal_user: "root".to_string(),
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/backend/src/socket_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,17 @@ pub async fn term_handler(socket: warp::ws::WebSocket) {
}
}

let mut pre_cmd = std::process::Command::new("/bin/login");
let pre_cmd = pre_cmd.env("TERM", "xterm");

let cmd = Arc::new(RwLock::new(
// Use hardcoded bash here until we have better support for other shells
std::process::Command::new("/bin/bash")
.spawn_pty(None)
.unwrap(),
if crate::CONFIG.terminal_user == "manual" {
pre_cmd
} else {
pre_cmd.args(&["-f", &crate::CONFIG.terminal_user])
}
.spawn_pty(None)
.unwrap(),
));
let cmd_write = Arc::clone(&cmd);
let cmd_clone = Arc::clone(&cmd);
Expand Down

0 comments on commit fdb4891

Please sign in to comment.