This commit is contained in:
Joseph Montanaro
2022-12-19 16:20:46 -08:00
parent 3d5cbedae1
commit d77437cda8
4 changed files with 40 additions and 10 deletions

View File

@ -54,7 +54,12 @@ async fn handle(mut stream: TcpStream, app_handle: AppHandle) -> Result<(), Requ
let clients = clientinfo::get_clients(peer_addr.port())?;
let req = Request {id: request_id, clients};
app_handle.emit_all("credentials-request", req)?;
if req.clients.iter().any(|c| app_state.is_banned(c.pid)) {
stream.write(b"HTTP/1.0 403 Access Denied\r\n\r\n").await?;
return Ok(())
}
app_handle.emit_all("credentials-request", &req)?;
let window = app_handle.get_window("main").ok_or(RequestError::NoMainWindow)?;
window.show()?;
window.set_focus()?;
@ -85,6 +90,9 @@ async fn handle(mut stream: TcpStream, app_handle: AppHandle) -> Result<(), Requ
// might need more time than that gives us (especially if entering the passphrase).
// Fortunately most AWS libs automatically retry if the request dies uncompleted, allowing
// us to respond with a proper error status.
for client in req.clients {
app_state.add_ban(client.pid, app_handle.clone());
}
return Ok(());
}