mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-06-26 02:04:58 +03:00
fix: update CLI for current client APIs
This commit is contained in:
21
src/cli.rs
21
src/cli.rs
@@ -3,7 +3,7 @@ use async_trait::async_trait;
|
||||
use hbb_common::{
|
||||
config::PeerConfig,
|
||||
config::READ_TIMEOUT,
|
||||
futures::{SinkExt, StreamExt},
|
||||
futures::StreamExt,
|
||||
log,
|
||||
message_proto::*,
|
||||
protobuf::Message as _,
|
||||
@@ -46,6 +46,7 @@ impl Session {
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
session
|
||||
}
|
||||
@@ -53,7 +54,7 @@ impl Session {
|
||||
|
||||
#[async_trait]
|
||||
impl Interface for Session {
|
||||
fn get_login_config_handler(&self) -> Arc<RwLock<LoginConfigHandler>> {
|
||||
fn get_lch(&self) -> Arc<RwLock<LoginConfigHandler>> {
|
||||
return self.lc.clone();
|
||||
}
|
||||
|
||||
@@ -61,14 +62,20 @@ impl Interface for Session {
|
||||
match msgtype {
|
||||
"input-password" => {
|
||||
self.sender
|
||||
.send(Data::Login((self.password.clone(), true)))
|
||||
.send(Data::Login((
|
||||
String::new(),
|
||||
String::new(),
|
||||
self.password.clone(),
|
||||
true,
|
||||
)))
|
||||
.ok();
|
||||
}
|
||||
"re-input-password" => {
|
||||
log::error!("{}: {}", title, text);
|
||||
match rpassword::prompt_password("Enter password: ") {
|
||||
Ok(password) => {
|
||||
let login_data = Data::Login((password, true));
|
||||
let login_data =
|
||||
Data::Login((String::new(), String::new(), password, true));
|
||||
self.sender.send(login_data).ok();
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -93,6 +100,8 @@ impl Interface for Session {
|
||||
self.lc.write().unwrap().handle_peer_info(&pi);
|
||||
}
|
||||
|
||||
fn set_multiple_windows_session(&self, _sessions: Vec<WindowsSession>) {}
|
||||
|
||||
async fn handle_hash(&self, pass: &str, hash: Hash, peer: &mut Stream) {
|
||||
log::info!(
|
||||
"password={}",
|
||||
@@ -137,8 +146,8 @@ pub async fn connect_test(id: &str, key: String, token: String) {
|
||||
Err(err) => {
|
||||
log::error!("Failed to connect {}: {}", &id, err);
|
||||
}
|
||||
Ok((mut stream, direct)) => {
|
||||
log::info!("direct: {}", direct);
|
||||
Ok(((mut stream, _direct, _secure, _kcp, _typ), direct)) => {
|
||||
log::info!("direct: {:?}", direct);
|
||||
// rpassword::prompt_password("Input anything to exit").ok();
|
||||
loop {
|
||||
tokio::select! {
|
||||
|
||||
81
src/main.rs
81
src/main.rs
@@ -38,49 +38,68 @@ fn main() {
|
||||
if !common::global_init() {
|
||||
return;
|
||||
}
|
||||
use clap::App;
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
use hbb_common::log;
|
||||
let args = format!(
|
||||
"-p, --port-forward=[PORT-FORWARD-OPTIONS] 'Format: remote-id:local-port:remote-port[:remote-host]'
|
||||
-c, --connect=[REMOTE_ID] 'test only'
|
||||
-k, --key=[KEY] ''
|
||||
-s, --server=[] 'Start server'",
|
||||
);
|
||||
let matches = App::new("rustdesk")
|
||||
let matches = Command::new("rustdesk")
|
||||
.version(crate::VERSION)
|
||||
.author("Purslane Ltd<info@rustdesk.com>")
|
||||
.about("RustDesk command line tool")
|
||||
.args_from_usage(&args)
|
||||
.arg(
|
||||
Arg::new("port-forward")
|
||||
.short('p')
|
||||
.long("port-forward")
|
||||
.value_name("PORT-FORWARD-OPTIONS")
|
||||
.help("Format: remote-id:local-port:remote-port[:remote-host]"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("connect")
|
||||
.short('c')
|
||||
.long("connect")
|
||||
.value_name("REMOTE_ID")
|
||||
.help("test only"),
|
||||
)
|
||||
.arg(Arg::new("key").short('k').long("key").value_name("KEY"))
|
||||
.arg(
|
||||
Arg::new("server")
|
||||
.short('s')
|
||||
.long("server")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Start server"),
|
||||
)
|
||||
.get_matches();
|
||||
use hbb_common::{config::LocalConfig, env_logger::*};
|
||||
init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info"));
|
||||
if let Some(p) = matches.value_of("port-forward") {
|
||||
let options: Vec<String> = p.split(":").map(|x| x.to_owned()).collect();
|
||||
if let Some(p) = matches.get_one::<String>("port-forward") {
|
||||
let options: Vec<String> = p.split(':').map(|x| x.to_owned()).collect();
|
||||
if options.len() < 3 {
|
||||
log::error!("Wrong port-forward options");
|
||||
return;
|
||||
}
|
||||
let mut port = 0;
|
||||
if let Ok(v) = options[1].parse::<i32>() {
|
||||
port = v;
|
||||
} else {
|
||||
log::error!("Wrong local-port");
|
||||
return;
|
||||
}
|
||||
let mut remote_port = 0;
|
||||
if let Ok(v) = options[2].parse::<i32>() {
|
||||
remote_port = v;
|
||||
} else {
|
||||
log::error!("Wrong remote-port");
|
||||
return;
|
||||
}
|
||||
let port = match options[1].parse::<i32>() {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
log::error!("Wrong local-port");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let remote_port = match options[2].parse::<i32>() {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
log::error!("Wrong remote-port");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let mut remote_host = "localhost".to_owned();
|
||||
if options.len() > 3 {
|
||||
remote_host = options[3].clone();
|
||||
}
|
||||
common::test_rendezvous_server();
|
||||
common::test_nat_type();
|
||||
let key = matches.value_of("key").unwrap_or("").to_owned();
|
||||
let key = matches
|
||||
.get_one::<String>("key")
|
||||
.map(String::as_str)
|
||||
.unwrap_or("")
|
||||
.to_owned();
|
||||
let token = LocalConfig::get_option("access_token");
|
||||
cli::start_one_port_forward(
|
||||
options[0].clone(),
|
||||
@@ -90,13 +109,17 @@ fn main() {
|
||||
key,
|
||||
token,
|
||||
);
|
||||
} else if let Some(p) = matches.value_of("connect") {
|
||||
} else if let Some(p) = matches.get_one::<String>("connect") {
|
||||
common::test_rendezvous_server();
|
||||
common::test_nat_type();
|
||||
let key = matches.value_of("key").unwrap_or("").to_owned();
|
||||
let key = matches
|
||||
.get_one::<String>("key")
|
||||
.map(String::as_str)
|
||||
.unwrap_or("")
|
||||
.to_owned();
|
||||
let token = LocalConfig::get_option("access_token");
|
||||
cli::connect_test(p, key, token);
|
||||
} else if let Some(p) = matches.value_of("server") {
|
||||
} else if matches.get_flag("server") {
|
||||
log::info!("id={}", hbb_common::config::Config::get_id());
|
||||
crate::start_server(true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user