From e424ff6a720e6bd446921a3d83ff3285b5fa1185 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu@web.de> Date: Tue, 21 Apr 2020 23:12:05 +0200 Subject: [PATCH] Prompt user for username and password --- Cargo.lock | 18 ++++++++++++++++++ Cargo.toml | 2 ++ src/main.rs | 7 +++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7132b9a..dbeb0b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,6 +10,8 @@ dependencies = [ "parking_lot", "regex", "reqwest", + "rpassword", + "rprompt", "scraper", "serde_json", "structopt", @@ -1243,6 +1245,22 @@ dependencies = [ "winreg", ] +[[package]] +name = "rpassword" +version = "4.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99371657d3c8e4d816fb6221db98fa408242b0b53bac08f8676a41f8554fe99f" +dependencies = [ + "libc", + "winapi 0.3.8", +] + +[[package]] +name = "rprompt" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b386f4748bdae2aefc96857f5fda07647f851d089420e577831e2a14b45230f8" + [[package]] name = "rustc-demangle" version = "0.1.16" diff --git a/Cargo.toml b/Cargo.toml index e75542f..e20b73a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,5 @@ regex = "1.3.7" lazy_static = "1.4.0" parking_lot = "0.10.2" structopt = "0.3.13" +rpassword = "4.0.5" +rprompt = "1.0.5" diff --git a/src/main.rs b/src/main.rs index 0dc5916..04884cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,7 @@ const ILIAS_URL: &'static str = "https://ilias.studium.kit.edu/"; struct ILIAS { opt: Opt, + // TODO: use these for re-authentication in case of session timeout/invalidation user: String, pass: String, path_prefix: PathBuf, @@ -226,7 +227,7 @@ impl ILIAS { login_soup = BeautifulSoup(otp_response.text, 'lxml') */ let saml = Selector::parse(r#"input[name="SAMLResponse"]"#).unwrap(); - let saml = dom.select(&saml).next().expect("no SAML response"); + let saml = dom.select(&saml).next().expect("no SAML response, incorrect password?"); let relay_state = Selector::parse(r#"input[name="RelayState"]"#).unwrap(); let relay_state = dom.select(&relay_state).next().expect("no relay state"); println!("Logging into ILIAS.."); @@ -287,7 +288,9 @@ async fn main() { *TASKS_RUNNING.lock() -= 1; PANIC_HOOK.lock()(info); })); - let mut ilias = match ILIAS::login::<&str, &str>(opt, env!("ILIAS_USER"), env!("ILIAS_PASS")).await { + let user = rprompt::prompt_reply_stdout("Username: ").unwrap(); + let pass = rpassword::read_password_from_tty(Some("Password: ")).unwrap(); + let mut ilias = match ILIAS::login::<_, String>(opt, user, pass).await { Ok(ilias) => ilias, Err(e) => panic!("error: {:?}", e) };