Ask for confirmation (unless -d)
This commit is contained in:
parent
60a0a3a081
commit
90aea947e1
3 changed files with 31 additions and 6 deletions
|
@ -14,3 +14,6 @@ getopts = "0.2"
|
|||
log = "0.4"
|
||||
tokio = { version = "0.2", features = ["full"] }
|
||||
tokio-libtls = "1.1.0-alpha.3"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -35,12 +35,13 @@ use tokio_libtls::prelude::*;
|
|||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(crate) struct Config {
|
||||
keypair: Option<KeyPair>,
|
||||
ca: Option<PathBuf>,
|
||||
timeout: Option<Duration>,
|
||||
servername: Option<String>,
|
||||
address: Option<SocketAddr>,
|
||||
ca: Option<PathBuf>,
|
||||
dont_ask: bool,
|
||||
keypair: Option<KeyPair>,
|
||||
servername: Option<String>,
|
||||
size_limit: usize,
|
||||
timeout: Option<Duration>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -98,6 +99,7 @@ async fn main() {
|
|||
let mut config = Config::new();
|
||||
|
||||
let mut opts = Options::new();
|
||||
opts.optflag("d", "dontask", "don't ask for confirmation (server)");
|
||||
opts.optopt(
|
||||
"a",
|
||||
"address",
|
||||
|
@ -110,8 +112,8 @@ async fn main() {
|
|||
"server name",
|
||||
&config.servername.as_ref().unwrap(),
|
||||
);
|
||||
opts.optopt("f", "file", "send file as client", "filename");
|
||||
opts.optflag("s", "server", "run server");
|
||||
opts.optopt("f", "file", "send a file (client)", "filename");
|
||||
opts.optflag("s", "server", "run as server");
|
||||
opts.optflag("h", "help", "print this help menu");
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
|
@ -127,6 +129,7 @@ async fn main() {
|
|||
if let Some(servername) = matches.opt_str("n") {
|
||||
config.servername = Some(servername);
|
||||
}
|
||||
config.dont_ask = matches.opt_present("d");
|
||||
|
||||
let addr = match config.address {
|
||||
Some(SocketAddr::V6(addr)) => addr.clone(),
|
||||
|
|
|
@ -16,6 +16,7 @@ use crate::Config;
|
|||
use std::{
|
||||
io::{Error, ErrorKind, Result},
|
||||
path::{PathBuf, MAIN_SEPARATOR},
|
||||
process::Command,
|
||||
};
|
||||
use tokio::{
|
||||
fs::{remove_file, File},
|
||||
|
@ -45,6 +46,7 @@ pub(crate) async fn run(config: Config) -> Result<()> {
|
|||
let (tcp, _) = listener.accept().await?;
|
||||
let size_limit = config.size_limit as u64;
|
||||
let peer_addr: String = tcp.peer_addr()?.to_string();
|
||||
let dont_ask = config.dont_ask;
|
||||
let options = options.build();
|
||||
let tls = match AsyncTls::accept_stream(tcp, &tls_config, options).await {
|
||||
Ok(tls) => {
|
||||
|
@ -124,6 +126,23 @@ pub(crate) async fn run(config: Config) -> Result<()> {
|
|||
file_size
|
||||
);
|
||||
|
||||
if !dont_ask {
|
||||
match Command::new("ssh-askpass")
|
||||
.arg(&format!(
|
||||
"Yo! Do you want to accept {} ({} bytes)?",
|
||||
filename.display(),
|
||||
file_size
|
||||
))
|
||||
.output()
|
||||
{
|
||||
Ok(output) if output.status.success() => {}
|
||||
_ => {
|
||||
info!("{} failed: rejected file", peer_addr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create output file
|
||||
let file = match File::create(&filename).await {
|
||||
Ok(f) => f,
|
||||
|
|
Loading…
Reference in a new issue