add logging

This commit is contained in:
Carson McManus 2021-03-27 10:35:52 -04:00
parent bde8a37d3f
commit 8ded30e09e
4 changed files with 136 additions and 44 deletions

111
Cargo.lock generated
View file

@ -30,12 +30,12 @@ dependencies = [
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.14" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
dependencies = [ dependencies = [
"hermit-abi",
"libc", "libc",
"termion",
"winapi", "winapi",
] ]
@ -503,6 +503,12 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "lazy_static"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -590,7 +596,7 @@ version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4"
dependencies = [ dependencies = [
"lazy_static", "lazy_static 1.4.0",
"libc", "libc",
"log", "log",
"openssl", "openssl",
@ -630,7 +636,7 @@ checksum = "5d51546d704f52ef14b3c962b5776e53d5b862e5790e40a350d366c209bd7f7a"
dependencies = [ dependencies = [
"autocfg 0.1.7", "autocfg 0.1.7",
"byteorder", "byteorder",
"lazy_static", "lazy_static 1.4.0",
"libm", "libm",
"num-integer", "num-integer",
"num-iter", "num-iter",
@ -681,6 +687,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "numtoa"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.7.2" version = "1.7.2"
@ -911,6 +923,15 @@ dependencies = [
"bitflags", "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]] [[package]]
name = "regex" name = "regex"
version = "1.4.5" version = "1.4.5"
@ -955,7 +976,7 @@ dependencies = [
"hyper-tls", "hyper-tls",
"ipnet", "ipnet",
"js-sys", "js-sys",
"lazy_static", "lazy_static 1.4.0",
"log", "log",
"mime", "mime",
"native-tls", "native-tls",
@ -993,7 +1014,7 @@ checksum = "3648b669b10afeab18972c105e284a7b953a669b0be3514c27f9b17acab2f9cd"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"digest", "digest",
"lazy_static", "lazy_static 1.4.0",
"num-bigint-dig", "num-bigint-dig",
"num-integer", "num-integer",
"num-iter", "num-iter",
@ -1028,7 +1049,7 @@ version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
dependencies = [ dependencies = [
"lazy_static", "lazy_static 1.4.0",
"winapi", "winapi",
] ]
@ -1187,6 +1208,19 @@ dependencies = [
"version_check", "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]] [[package]]
name = "stdweb" name = "stdweb"
version = "0.4.20" version = "0.4.20"
@ -1243,6 +1277,7 @@ dependencies = [
"base64", "base64",
"clap", "clap",
"hmac-sha1", "hmac-sha1",
"log",
"rand 0.7.3", "rand 0.7.3",
"reqwest", "reqwest",
"rpassword", "rpassword",
@ -1250,6 +1285,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"standback", "standback",
"stderrlog",
"text_io", "text_io",
] ]
@ -1302,6 +1338,27 @@ dependencies = [
"winapi", "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]] [[package]]
name = "text_io" name = "text_io"
version = "0.1.8" version = "0.1.8"
@ -1337,6 +1394,16 @@ dependencies = [
"syn", "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]] [[package]]
name = "time" name = "time"
version = "0.1.43" version = "0.1.43"
@ -1462,7 +1529,7 @@ version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f"
dependencies = [ dependencies = [
"lazy_static", "lazy_static 1.4.0",
] ]
[[package]] [[package]]
@ -1507,6 +1574,15 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
dependencies = [
"void",
]
[[package]] [[package]]
name = "url" name = "url"
version = "2.2.1" version = "2.2.1"
@ -1537,6 +1613,12 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]] [[package]]
name = "want" name = "want"
version = "0.3.0" version = "0.3.0"
@ -1578,7 +1660,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3" checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static 1.4.0",
"log", "log",
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1653,6 +1735,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 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]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"

View file

@ -17,4 +17,6 @@ serde_json = "1.0"
rsa = "0.3" rsa = "0.3"
rand = "0.7.3" # rsa is not compatible with rand 0.8: https://github.com/RustCrypto/RSA/issues/81 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 standback = "0.2.17" # required to fix a compilation error on a transient dependency
clap = "2.33.3" clap = "2.33.3"
log = "0.4.14"
stderrlog = "0.4"

View file

@ -4,6 +4,7 @@ use std::path::Path;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use std::error::Error; use std::error::Error;
use steamguard_cli::SteamGuardAccount; use steamguard_cli::SteamGuardAccount;
use log::*;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct Manifest { pub struct Manifest {
@ -33,6 +34,7 @@ pub struct ManifestEntry {
impl Manifest { impl Manifest {
pub fn load(path: &Path) -> Result<Manifest, Box<dyn Error>> { pub fn load(path: &Path) -> Result<Manifest, Box<dyn Error>> {
debug!("loading manifest: {:?}", &path);
match File::open(path) { match File::open(path) {
Ok(file) => { Ok(file) => {
let reader = BufReader::new(file); let reader = BufReader::new(file);
@ -56,6 +58,7 @@ impl Manifest {
pub fn load_accounts(&mut self) { pub fn load_accounts(&mut self) {
for entry in &self.entries { for entry in &self.entries {
let path = Path::new(&self.folder).join(&entry.filename); let path = Path::new(&self.folder).join(&entry.filename);
debug!("loading account: {:?}", path);
match File::open(path) { match File::open(path) {
Ok(f) => { Ok(f) => {
let reader = BufReader::new(f); let reader = BufReader::new(f);
@ -65,12 +68,12 @@ impl Manifest {
self.accounts.push(account); self.accounts.push(account);
} }
Err(e) => { Err(e) => {
panic!("invalid json") error!("invalid json: {}", e)
} }
} }
} }
Err(e) => { Err(e) => {
panic!(e) error!("unable to open account: {}", e)
} }
} }
} }

View file

@ -5,6 +5,7 @@ use ::std::*;
use text_io::read; use text_io::read;
use std::path::Path; use std::path::Path;
use clap::{App, Arg, crate_version}; use clap::{App, Arg, crate_version};
use log::*;
mod steamapi; mod steamapi;
mod accountmanager; mod accountmanager;
@ -40,6 +41,13 @@ fn main() {
.short("p") .short("p")
.help("Specify your encryption passkey.") .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( .subcommand(
App::new("trade") App::new("trade")
.about("Interactive interface for trade confirmations") .about("Interactive interface for trade confirmations")
@ -52,41 +60,29 @@ fn main() {
) )
.get_matches(); .get_matches();
println!("Hello, world!");
// let server_time = steamapi::get_server_time(); let verbosity = matches.occurrences_of("verbosity") as usize + 2;
// println!("server time: {}", server_time); stderrlog::new()
.verbosity(verbosity)
.module(module_path!()).init().unwrap();
// let mut account = SteamGuardAccount::new(); let path = Path::new(matches.value_of("mafiles-path").unwrap()).join("manifest.json");
// account.shared_secret = parse_shared_secret(String::from("K5I0Fmm+sN0yF41vIslTVm+0nPE=")); let mut manifest: accountmanager::Manifest;
match accountmanager::Manifest::load(path.as_path()) {
// let code = account.generate_code(server_time); Ok(m) => {
// println!("{}", code); manifest = m;
// 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);
}
} }
Err(e) => { 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);
}
} }