Merge pull request #42 from winapps-org/rewrite-freerdp-backend

Add freerdp backend
This commit is contained in:
Oskar Manhart 2023-10-09 15:39:54 +00:00 committed by GitHub
commit 3e8c6dbb94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 11 deletions

View File

@ -1,4 +1,4 @@
use clap::Command; use clap::{arg, Command};
use winapps::freerdp::freerdp_back::Freerdp; use winapps::freerdp::freerdp_back::Freerdp;
use winapps::quickemu::{create_vm, kill_vm, start_vm}; use winapps::quickemu::{create_vm, kill_vm, start_vm};
use winapps::RemoteClient; use winapps::RemoteClient;
@ -11,6 +11,11 @@ fn cli() -> Command {
.allow_external_subcommands(true) .allow_external_subcommands(true)
.subcommand(Command::new("check").about("Checks remote connection")) .subcommand(Command::new("check").about("Checks remote connection"))
.subcommand(Command::new("connect").about("Connects to remote")) .subcommand(Command::new("connect").about("Connects to remote"))
.subcommand(
Command::new("run")
.about("Connects to app on remote")
.arg(arg!(<APP> "App to open")),
)
.subcommand( .subcommand(
Command::new("vm") Command::new("vm")
.about("Manage a windows 10 vm using quickemu") .about("Manage a windows 10 vm using quickemu")
@ -27,17 +32,24 @@ fn main() {
let cli = cli(); let cli = cli();
let matches = cli.clone().get_matches(); let matches = cli.clone().get_matches();
let config = winapps::load_config(None);
let client: &dyn RemoteClient = &Freerdp {}; let client: &dyn RemoteClient = &Freerdp {};
let config = winapps::load_config(None);
match matches.subcommand() { match matches.subcommand() {
Some(("check", _)) => { Some(("check", _)) => {
println!("Checking remote connection"); println!("Checking remote connection");
client.check_depends(config); client.check_depends(config);
} }
Some(("connect", _)) => { Some(("connect", _)) => {
println!("Connecting to remote"); println!("Connecting to remote");
client.run_app(config, "explorer");
client.run_app(config, None);
}
Some(("run", sub_matches)) => {
println!("Connecting to app on remote");
client.run_app(config, sub_matches.get_one::<String>("APP"));
} }
Some(("vm", command)) => { Some(("vm", command)) => {

View File

@ -6,20 +6,57 @@ pub mod freerdp_back {
pub struct Freerdp {} pub struct Freerdp {}
impl RemoteClient for Freerdp { impl RemoteClient for Freerdp {
fn check_depends(&self, _config: Config) { fn check_depends(&self, config: Config) {
let mut xfreerdp = Command::new("xfreerdp"); let mut xfreerdp = Command::new("xfreerdp");
xfreerdp.stdout(Stdio::null()); xfreerdp.stdout(Stdio::null());
xfreerdp.stderr(Stdio::null());
xfreerdp.args(["-h"]); xfreerdp.args(["-h"]);
xfreerdp xfreerdp
.spawn() .spawn()
.expect("Freerdp execution failed! It needs to be installed!"); .expect("Freerdp execution failed! It needs to be installed!");
println!("Freerdp found!"); println!("Freerdp found!");
println!("Checks success!"); println!("All dependencies found!");
println!("Running explorer as test!");
println!("Check yourself if it appears correctly!");
self.run_app(config, Some(&"explorer.exe".to_string()));
println!("Test finished!");
} }
fn run_app(&self, _config: Config, _app: &str) { fn run_app(&self, config: Config, app: Option<&String>) {
todo!() let mut xfreerdp = Command::new("xfreerdp");
xfreerdp.stdout(Stdio::null());
xfreerdp.stderr(Stdio::null());
match app {
Some(exe) => {
xfreerdp.args([
&format!("/app:{}", exe),
&format!("/d:{}", &config.rdp.domain),
&format!("/u:{}", &config.rdp.username),
&format!("/p:{}", &config.rdp.password),
&format!("/v:{}", &config.rdp.host),
"/dynamic-resolution",
"+auto-reconnect",
"+clipboard",
"+home-drive",
]);
}
None => {
xfreerdp.args([
&format!("/d:{}", &config.rdp.domain),
&format!("/u:{}", &config.rdp.username),
&format!("/p:{}", &config.rdp.password),
&format!("/v:{}", &config.rdp.host),
"/dynamic-resolution",
"+auto-reconnect",
"+clipboard",
"+home-drive",
]);
}
}
xfreerdp.spawn().expect("Freerdp execution failed!");
} }
} }
} }

View File

@ -16,7 +16,7 @@ pub mod freerdp;
pub trait RemoteClient { pub trait RemoteClient {
fn check_depends(&self, config: Config); fn check_depends(&self, config: Config);
fn run_app(&self, config: Config, app: &str); fn run_app(&self, config: Config, app: Option<&String>);
} }
#[derive(new, Debug, Deserialize, Serialize)] #[derive(new, Debug, Deserialize, Serialize)]
@ -45,13 +45,13 @@ pub struct HostConfig {
#[derive(new, Debug, Deserialize, Serialize)] #[derive(new, Debug, Deserialize, Serialize)]
pub struct RemoteConfig { pub struct RemoteConfig {
#[new(value = "\"RDPWindows\".to_string()")] #[new(value = "\"127.0.0.1\".to_string()")]
host: String, host: String,
#[new(value = "\"WORKGROUP\".to_string()")] #[new(value = "\"WORKGROUP\".to_string()")]
domain: String, domain: String,
#[new(value = "\"RDPUser\".to_string()")] #[new(value = "\"Quickemu\".to_string()")]
username: String, username: String,
#[new(value = "\"RDPPass\".to_string()")] #[new(value = "\"quickemu\".to_string()")]
password: String, password: String,
} }