issue #1051
This commit is contained in:
parent
6981ae1c20
commit
06ce3661f4
@ -1334,11 +1334,21 @@ fn _input_os_password(p: String, activate: bool, interface: impl Interface) {
|
||||
|
||||
pub async fn handle_hash(
|
||||
lc: Arc<RwLock<LoginConfigHandler>>,
|
||||
password_preset: &str,
|
||||
hash: Hash,
|
||||
interface: &impl Interface,
|
||||
peer: &mut Stream,
|
||||
) {
|
||||
let mut password = lc.read().unwrap().password.clone();
|
||||
if password.is_empty() {
|
||||
if !password_preset.is_empty() {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(password_preset);
|
||||
hasher.update(&hash.salt);
|
||||
let res = hasher.finalize();
|
||||
password = res[..].into();
|
||||
}
|
||||
}
|
||||
if password.is_empty() {
|
||||
password = lc.read().unwrap().config.password.clone();
|
||||
}
|
||||
@ -1384,7 +1394,7 @@ pub trait Interface: Send + Clone + 'static + Sized {
|
||||
fn msgbox(&self, msgtype: &str, title: &str, text: &str);
|
||||
fn handle_login_error(&mut self, err: &str) -> bool;
|
||||
fn handle_peer_info(&mut self, pi: PeerInfo);
|
||||
async fn handle_hash(&mut self, hash: Hash, peer: &mut Stream);
|
||||
async fn handle_hash(&mut self, pass: &str, hash: Hash, peer: &mut Stream);
|
||||
async fn handle_login_from_ui(&mut self, password: String, remember: bool, peer: &mut Stream);
|
||||
async fn handle_test_delay(&mut self, t: TestDelay, peer: &mut Stream);
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ fn run_rdp(port: u16) {
|
||||
|
||||
pub async fn listen(
|
||||
id: String,
|
||||
password: String,
|
||||
port: i32,
|
||||
interface: impl Interface,
|
||||
ui_receiver: mpsc::UnboundedReceiver<Data>,
|
||||
@ -61,8 +62,9 @@ pub async fn listen(
|
||||
Ok((forward, addr)) = listener.accept() => {
|
||||
log::info!("new connection from {:?}", addr);
|
||||
let id = id.clone();
|
||||
let password = password.clone();
|
||||
let mut forward = Framed::new(forward, BytesCodec::new());
|
||||
match connect_and_login(&id, &mut ui_receiver, interface.clone(), &mut forward, key, token, is_rdp).await {
|
||||
match connect_and_login(&id, &password, &mut ui_receiver, interface.clone(), &mut forward, key, token, is_rdp).await {
|
||||
Ok(Some(stream)) => {
|
||||
let interface = interface.clone();
|
||||
tokio::spawn(async move {
|
||||
@ -96,6 +98,7 @@ pub async fn listen(
|
||||
|
||||
async fn connect_and_login(
|
||||
id: &str,
|
||||
password: &str,
|
||||
ui_receiver: &mut mpsc::UnboundedReceiver<Data>,
|
||||
interface: impl Interface,
|
||||
forward: &mut Framed<TcpStream, BytesCodec>,
|
||||
@ -121,7 +124,7 @@ async fn connect_and_login(
|
||||
let msg_in = Message::parse_from_bytes(&bytes)?;
|
||||
match msg_in.union {
|
||||
Some(message::Union::Hash(hash)) => {
|
||||
interface.handle_hash(hash, &mut stream).await;
|
||||
interface.handle_hash(password, hash, &mut stream).await;
|
||||
}
|
||||
Some(message::Union::LoginResponse(lr)) => match lr.union {
|
||||
Some(login_response::Union::Error(err)) => {
|
||||
|
@ -133,10 +133,16 @@ pub fn start(args: &mut [String]) {
|
||||
let mut iter = args.iter();
|
||||
let cmd = iter.next().unwrap().clone();
|
||||
let id = iter.next().unwrap().clone();
|
||||
let pass = iter.next().unwrap_or(&"".to_owned()).clone();
|
||||
let args: Vec<String> = iter.map(|x| x.clone()).collect();
|
||||
frame.set_title(&id);
|
||||
frame.register_behavior("native-remote", move || {
|
||||
Box::new(remote::Handler::new(cmd.clone(), id.clone(), args.clone()))
|
||||
Box::new(remote::Handler::new(
|
||||
cmd.clone(),
|
||||
id.clone(),
|
||||
pass.clone(),
|
||||
args.clone(),
|
||||
))
|
||||
});
|
||||
page = "remote.html";
|
||||
} else {
|
||||
|
@ -87,6 +87,7 @@ pub struct Handler {
|
||||
inner: Arc<RwLock<HandlerInner>>,
|
||||
cmd: String,
|
||||
id: String,
|
||||
password: String,
|
||||
args: Vec<String>,
|
||||
lc: Arc<RwLock<LoginConfigHandler>>,
|
||||
}
|
||||
@ -247,10 +248,11 @@ struct QualityStatus {
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn new(cmd: String, id: String, args: Vec<String>) -> Self {
|
||||
pub fn new(cmd: String, id: String, password: String, args: Vec<String>) -> Self {
|
||||
let me = Self {
|
||||
cmd,
|
||||
id: id.clone(),
|
||||
password: password.clone(),
|
||||
args,
|
||||
..Default::default()
|
||||
};
|
||||
@ -1137,7 +1139,7 @@ impl Handler {
|
||||
|
||||
fn transfer_file(&mut self) {
|
||||
let id = self.get_id();
|
||||
let args = vec!["--file-transfer", &id];
|
||||
let args = vec!["--file-transfer", &id, &self.password];
|
||||
if let Err(err) = crate::run_me(args) {
|
||||
log::error!("Failed to spawn file transfer: {}", err);
|
||||
}
|
||||
@ -1145,7 +1147,7 @@ impl Handler {
|
||||
|
||||
fn tunnel(&mut self) {
|
||||
let id = self.get_id();
|
||||
let args = vec!["--port-forward", &id];
|
||||
let args = vec!["--port-forward", &id, &self.password];
|
||||
if let Err(err) = crate::run_me(args) {
|
||||
log::error!("Failed to spawn IP tunneling: {}", err);
|
||||
}
|
||||
@ -1251,6 +1253,7 @@ async fn start_one_port_forward(
|
||||
handler.lc.write().unwrap().port_forward = (remote_host, remote_port);
|
||||
if let Err(err) = crate::port_forward::listen(
|
||||
handler.id.clone(),
|
||||
handler.password.clone(),
|
||||
port,
|
||||
handler.clone(),
|
||||
receiver,
|
||||
@ -2077,7 +2080,9 @@ impl Remote {
|
||||
self.video_sender.send(MediaData::VideoFrame(vf)).ok();
|
||||
}
|
||||
Some(message::Union::Hash(hash)) => {
|
||||
self.handler.handle_hash(hash, peer).await;
|
||||
self.handler
|
||||
.handle_hash(&self.handler.password.clone(), hash, peer)
|
||||
.await;
|
||||
}
|
||||
Some(message::Union::LoginResponse(lr)) => match lr.union {
|
||||
Some(login_response::Union::Error(err)) => {
|
||||
@ -2637,8 +2642,8 @@ impl Interface for Handler {
|
||||
self.start_keyboard_hook();
|
||||
}
|
||||
|
||||
async fn handle_hash(&mut self, hash: Hash, peer: &mut Stream) {
|
||||
handle_hash(self.lc.clone(), hash, self, peer).await;
|
||||
async fn handle_hash(&mut self, pass: &str, hash: Hash, peer: &mut Stream) {
|
||||
handle_hash(self.lc.clone(), pass, hash, self, peer).await;
|
||||
}
|
||||
|
||||
async fn handle_login_from_ui(&mut self, password: String, remember: bool, peer: &mut Stream) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user