From 8ded30e09e187c4b0a83c7a070f1c0b0b966d642 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sat, 27 Mar 2021 10:35:52 -0400 Subject: [PATCH] add logging --- Cargo.lock | 111 ++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 4 +- src/accountmanager.rs | 7 ++- src/main.rs | 58 ++++++++++------------ 4 files changed, 136 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f90ba64..a9bfa56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,12 +30,12 @@ dependencies = [ [[package]] name = "atty" -version = "0.2.14" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" dependencies = [ - "hermit-abi", "libc", + "termion", "winapi", ] @@ -503,6 +503,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" + [[package]] name = "lazy_static" version = "1.4.0" @@ -590,7 +596,7 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ - "lazy_static", + "lazy_static 1.4.0", "libc", "log", "openssl", @@ -630,7 +636,7 @@ checksum = "5d51546d704f52ef14b3c962b5776e53d5b862e5790e40a350d366c209bd7f7a" dependencies = [ "autocfg 0.1.7", "byteorder", - "lazy_static", + "lazy_static 1.4.0", "libm", "num-integer", "num-iter", @@ -681,6 +687,12 @@ dependencies = [ "libc", ] +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" + [[package]] name = "once_cell" version = "1.7.2" @@ -911,6 +923,15 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_termios" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" +dependencies = [ + "redox_syscall", +] + [[package]] name = "regex" version = "1.4.5" @@ -955,7 +976,7 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", + "lazy_static 1.4.0", "log", "mime", "native-tls", @@ -993,7 +1014,7 @@ checksum = "3648b669b10afeab18972c105e284a7b953a669b0be3514c27f9b17acab2f9cd" dependencies = [ "byteorder", "digest", - "lazy_static", + "lazy_static 1.4.0", "num-bigint-dig", "num-integer", "num-iter", @@ -1028,7 +1049,7 @@ version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" dependencies = [ - "lazy_static", + "lazy_static 1.4.0", "winapi", ] @@ -1187,6 +1208,19 @@ dependencies = [ "version_check", ] +[[package]] +name = "stderrlog" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e5ee9b90a5452c570a0b0ac1c99ae9498db7e56e33d74366de7f2a7add7f25" +dependencies = [ + "atty", + "chrono", + "log", + "termcolor", + "thread_local", +] + [[package]] name = "stdweb" version = "0.4.20" @@ -1243,6 +1277,7 @@ dependencies = [ "base64", "clap", "hmac-sha1", + "log", "rand 0.7.3", "reqwest", "rpassword", @@ -1250,6 +1285,7 @@ dependencies = [ "serde", "serde_json", "standback", + "stderrlog", "text_io", ] @@ -1302,6 +1338,27 @@ dependencies = [ "winapi", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "termion" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e" +dependencies = [ + "libc", + "numtoa", + "redox_syscall", + "redox_termios", +] + [[package]] name = "text_io" version = "0.1.8" @@ -1337,6 +1394,16 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14" +dependencies = [ + "lazy_static 0.2.11", + "unreachable", +] + [[package]] name = "time" version = "0.1.43" @@ -1462,7 +1529,7 @@ version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" dependencies = [ - "lazy_static", + "lazy_static 1.4.0", ] [[package]] @@ -1507,6 +1574,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +[[package]] +name = "unreachable" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +dependencies = [ + "void", +] + [[package]] name = "url" version = "2.2.1" @@ -1537,6 +1613,12 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + [[package]] name = "want" version = "0.3.0" @@ -1578,7 +1660,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3" dependencies = [ "bumpalo", - "lazy_static", + "lazy_static 1.4.0", "log", "proc-macro2", "quote", @@ -1653,6 +1735,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 4bd1ec1..fa1c1ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,6 @@ serde_json = "1.0" rsa = "0.3" rand = "0.7.3" # rsa is not compatible with rand 0.8: https://github.com/RustCrypto/RSA/issues/81 standback = "0.2.17" # required to fix a compilation error on a transient dependency -clap = "2.33.3" \ No newline at end of file +clap = "2.33.3" +log = "0.4.14" +stderrlog = "0.4" diff --git a/src/accountmanager.rs b/src/accountmanager.rs index fd8ae2b..8c36dea 100644 --- a/src/accountmanager.rs +++ b/src/accountmanager.rs @@ -4,6 +4,7 @@ use std::path::Path; use serde::{Serialize, Deserialize}; use std::error::Error; use steamguard_cli::SteamGuardAccount; +use log::*; #[derive(Debug, Serialize, Deserialize)] pub struct Manifest { @@ -33,6 +34,7 @@ pub struct ManifestEntry { impl Manifest { pub fn load(path: &Path) -> Result> { + debug!("loading manifest: {:?}", &path); match File::open(path) { Ok(file) => { let reader = BufReader::new(file); @@ -56,6 +58,7 @@ impl Manifest { pub fn load_accounts(&mut self) { for entry in &self.entries { let path = Path::new(&self.folder).join(&entry.filename); + debug!("loading account: {:?}", path); match File::open(path) { Ok(f) => { let reader = BufReader::new(f); @@ -65,12 +68,12 @@ impl Manifest { self.accounts.push(account); } Err(e) => { - panic!("invalid json") + error!("invalid json: {}", e) } } } Err(e) => { - panic!(e) + error!("unable to open account: {}", e) } } } diff --git a/src/main.rs b/src/main.rs index e3bcee3..ec703d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use ::std::*; use text_io::read; use std::path::Path; use clap::{App, Arg, crate_version}; +use log::*; mod steamapi; mod accountmanager; @@ -40,6 +41,13 @@ fn main() { .short("p") .help("Specify your encryption passkey.") ) + .arg( + Arg::with_name("verbosity") + .short("v") + .help("Log what is going on verbosely.") + .takes_value(false) + .multiple(true) + ) .subcommand( App::new("trade") .about("Interactive interface for trade confirmations") @@ -52,41 +60,29 @@ fn main() { ) .get_matches(); - println!("Hello, world!"); - // let server_time = steamapi::get_server_time(); - // println!("server time: {}", server_time); + let verbosity = matches.occurrences_of("verbosity") as usize + 2; + stderrlog::new() + .verbosity(verbosity) + .module(module_path!()).init().unwrap(); - // let mut account = SteamGuardAccount::new(); - // account.shared_secret = parse_shared_secret(String::from("K5I0Fmm+sN0yF41vIslTVm+0nPE=")); - - // let code = account.generate_code(server_time); - // println!("{}", code); - - // print!("Username: "); - // let _ = std::io::stdout().flush(); - // let username: String = read!("{}\n"); - // let password = rpassword::prompt_password_stdout("Password: ").unwrap(); - // // println!("{}:{}", username, password); - // let login = steamapi::UserLogin::new(username, password); - // let result = login.login(); - // println!("result: {:?}", result); - - let path = Path::new("test_maFiles/manifest.json"); - let manifest = accountmanager::Manifest::load(path); - println!("{:?}", manifest); - match manifest { - Ok(mut m) => { - m.load_accounts(); - for account in m.accounts { - println!("{:?}", account); - let server_time = steamapi::get_server_time(); - let code = account.generate_code(server_time); - println!("{}", code); - } + let path = Path::new(matches.value_of("mafiles-path").unwrap()).join("manifest.json"); + let mut manifest: accountmanager::Manifest; + match accountmanager::Manifest::load(path.as_path()) { + Ok(m) => { + manifest = m; } Err(e) => { - println!("{}", e) + error!("Could not load manifest: {}", e); + return; } } + + manifest.load_accounts(); + for account in manifest.accounts { + trace!("{:?}", account); + let server_time = steamapi::get_server_time(); + let code = account.generate_code(server_time); + println!("{}", code); + } }