diff --git a/Cargo.lock b/Cargo.lock index f3e1ec7..7368dcf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,6 +13,14 @@ name = "adler32" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "aho-corasick" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -267,6 +275,18 @@ name = "endian-type" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "env_logger" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "failure" version = "0.1.5" @@ -370,6 +390,14 @@ name = "httparse" version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "humantime" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hyper" version = "0.12.24" @@ -462,6 +490,8 @@ version = "2.0.0" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "cookie 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)", @@ -508,6 +538,11 @@ name = "matches" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "memchr" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "memoffset" version = "0.2.1" @@ -914,6 +949,26 @@ dependencies = [ "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "regex" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "remove_dir_all" version = "0.5.1" @@ -1168,6 +1223,14 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "termcolor" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "termion" version = "1.5.1" @@ -1186,6 +1249,14 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "time" version = "0.1.42" @@ -1417,6 +1488,11 @@ name = "typed-arena" version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ucd-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicase" version = "1.4.2" @@ -1474,6 +1550,11 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "utf8-ranges" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "uuid" version = "0.7.2" @@ -1531,11 +1612,28 @@ name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winapi-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "wincolor" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ws2_32-sys" version = "0.2.1" @@ -1548,6 +1646,7 @@ dependencies = [ [metadata] "checksum MacTypes-sys 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eaf9f0d0b1cc33a4d2aee14fb4b2eac03462ef4db29c8ac4057327d8a71ad86f" "checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" +"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" @@ -1578,6 +1677,7 @@ dependencies = [ "checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd" "checksum encoding_rs 0.8.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0535f350c60aac0b87ccf28319abc749391e912192255b0c00a2c12c6917bd73" "checksum endian-type 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" +"checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" @@ -1591,6 +1691,7 @@ dependencies = [ "checksum h2 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ddb2b25a33e231484694267af28fec74ac63b5ccf51ee2065a5e313b834d836e" "checksum http 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1a10e5b573b9a0146545010f50772b9e8b1dd0a256564cc4307694c68832a2f5" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" +"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" "checksum hyper 0.12.24 (registry+https://github.com/rust-lang/crates.io-index)" = "fdfa9b401ef6c4229745bb6e9b2529192d07b920eed624cdee2a82348cd550af" "checksum hyper-tls 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "32cd73f14ad370d3b4d4b7dce08f69b81536c82e39fcc89731930fe5788cd661" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" @@ -1605,6 +1706,7 @@ dependencies = [ "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum mime 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "3e27ca21f40a310bd06d9031785f4801710d566c184a6e15bad4f1d9b65f9425" "checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed" @@ -1652,6 +1754,8 @@ dependencies = [ "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +"checksum regex 1.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "559008764a17de49a3146b234641644ed37d118d1ef641a0bb573d146edc6ce0" +"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum reqwest 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)" = "f205a95638627fc0d21c53901671b06f439dc2830311ff11ecdff34ae2d839a8" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" @@ -1681,8 +1785,10 @@ dependencies = [ "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" +"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" +"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "e0500b88064f08bebddd0c0bed39e19f5c567a5f30975bee52b0c0d3e2eeb38c" "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" @@ -1701,6 +1807,7 @@ dependencies = [ "checksum trust-dns-proto 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "09144f0992b0870fa8d2972cc069cbf1e3c0fda64d1f3d45c4d68d0e0b52ad4e" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum typed-arena 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c6c06a92aef38bb4dc5b0df00d68496fc31307c5344c867bb61678c6e1671ec5" +"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d3218ea14b4edcaccfa0df0a64a3792a2c32cc706f1b336e48867f9d3147f90" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" @@ -1709,6 +1816,7 @@ dependencies = [ "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" "checksum uuid 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0238db0c5b605dd1cf51de0f21766f97fba2645897024461d6a00c036819a768" "checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" @@ -1718,5 +1826,7 @@ dependencies = [ "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +"checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" diff --git a/Cargo.toml b/Cargo.toml index 7342c0f..34f9f9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,5 @@ openssl-probe = "0.1.2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" cookie = { version = "0.11.0", features = ["percent-encode"] } +env_logger = "0.6.1" +log = "0.4.6" diff --git a/src/cli.rs b/src/cli.rs index 1dc64f9..eb7c8c3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -7,34 +7,37 @@ use crate::config::Config; use crate::inwx::{Inwx, InwxError}; use crate::dns::{check_txt_record, lookup_real_domain}; -impl From for String { - fn from(inwx_error: InwxError) -> String { - format!("{}", inwx_error) - } -} - -fn execute_api_commands(config: &Config, domain: &str, op: F) -> Result where F: Fn(&mut Inwx) -> Result<(), InwxError> { +fn execute_api_commands(config: &Config, domain: &str, op: F) -> Result where F: Fn(&mut Inwx) -> Result<(), InwxError> { if config.accounts.len() == 0 { - return Err("No accounts configured".to_owned()); + error!("No accounts configured"); + return Err(()); } - let accounts = match(&config.accounts).into_iter().find(|account| - (&account.domains).into_iter().any(|d| domain == d || domain.ends_with(&format!(".{}", d))) + let mut filtered_accounts = Vec::new(); + + match config.accounts.iter().find(|account| + account.domains.iter().any(|d| domain == d || domain.ends_with(&format!(".{}", d))) ) { - Some(account) => vec!(account.clone()), - None => config.accounts.clone() + Some(account) => { + info!("Using account {}", account.username); + filtered_accounts.push(account); + }, + None => { + warn!("Domain not configured: Trying {} configured domains", config.accounts.len()); + filtered_accounts.extend(config.accounts.iter()); + } }; - for account in accounts { + for account in filtered_accounts { let mut success = false; - let mut api = Inwx::new(&account)?; + let mut api = Inwx::new(&account).map_err(|e| error!("{}", e))?; - let mut err = None; match op(&mut api) { Err(InwxError::DomainNotFound) => {}, Err(e) => { - err = Some(e); + error!("{}", e); + return Err(()); }, _ => { success = true; @@ -42,39 +45,36 @@ fn execute_api_commands(config: &Config, domain: &str, op: F) -> Result Result { - let file = File::open(path).map_err(|e| format!("Failed to open config file: {}", e))?; +fn read_config(path: &str) -> Result { + let file = File::open(path).map_err(|e| error!("Failed to open config file: {}", e))?; let reader = BufReader::new(file); - Ok(serde_json::from_reader(reader).map_err(|e| format!("Failed to parse config file: {}", e))?) + Ok(serde_json::from_reader(reader).map_err(|e| error!("Failed to parse config file: {}", e))?) } -fn create(config: &Config, domain: &str, value: &str) -> Result<(), String> { - println!("Creating TXT record..."); +fn create(config: &Config, domain: &str, value: &str) -> Result<(), ()> { + info!("Creating TXT record..."); let is_ote = execute_api_commands(&config, &domain, |api| { api.create_txt_record(&domain, &value)?; Ok(()) })?; - println!("=> done!"); + info!("=> done!"); if !is_ote && !config.options.no_dns_check { - println!("Waiting for the dns record to be publicly visible..."); + info!("Waiting for the dns record to be publicly visible..."); let start = Instant::now(); let mut wait_secs = 5; @@ -82,7 +82,8 @@ fn create(config: &Config, domain: &str, value: &str) -> Result<(), String> { loop { // timeout after 10 minutes if start.elapsed() > Duration::from_secs(60 * 10) { - return Err("timeout!".to_owned()); + error!("=> timeout!"); + return Err(()); } if check_txt_record(&config.options.dns_server, &domain, value) { @@ -94,34 +95,34 @@ fn create(config: &Config, domain: &str, value: &str) -> Result<(), String> { sleep(Duration::from_secs(wait_secs)); } - println!("=> done!"); + info!("=> done!"); } if config.options.wait_interval > 0 { - println!("Waiting {} additional seconds...", &config.options.wait_interval); + info!("Waiting {} additional seconds...", &config.options.wait_interval); sleep(Duration::from_secs(config.options.wait_interval)); - println!("=> done!"); + info!("=> done!"); } Ok(()) } -fn delete(config: &Config, domain: &str) -> Result<(), String> { - println!("Deleting TXT record..."); +fn delete(config: &Config, domain: &str) -> Result<(), ()> { + info!("Deleting TXT record..."); execute_api_commands(&config, &domain, |api| { api.delete_txt_record(&domain)?; Ok(()) })?; - println!("=> done!"); + info!("=> done!"); Ok(()) } -pub fn run() -> Result<(), String> { +pub fn run() -> Result<(), ()> { let mut app = App::new("letsencrypt-inwx") .version("2.0.0") .about("A small cli utility for automating the letsencrypt dns-01 challenge for domains hosted by inwx") diff --git a/src/dns.rs b/src/dns.rs index e98b442..791997c 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -50,6 +50,7 @@ pub fn lookup_real_domain(dns_server: &str, domain: &str) -> String { let mut domain = domain.to_owned(); while let Some(real_name) = check_cname(dns_server, &domain) { + debug!("Using {} for {}", real_name, domain); domain = real_name; if depth >= 10 { diff --git a/src/inwx.rs b/src/inwx.rs index 346a7d7..e4a11e0 100644 --- a/src/inwx.rs +++ b/src/inwx.rs @@ -58,6 +58,8 @@ impl<'a> Inwx<'a> { } ]); + debug!("Logging into account {}", self.account.username); + self.send_request(request)?; Ok(()) @@ -75,10 +77,12 @@ impl<'a> Inwx<'a> { } fn split_domain(&mut self, domain: &str) -> Result<(String, String), InwxError> { + debug!("Splitting domain {}", domain); let page_size = 20; let mut page = 1; loop { + debug!("Requesting page {} of nameserver.list", page); let request = RpcRequest::new("nameserver.list", &[ RpcRequestParameter { name: "pagelimit", @@ -104,14 +108,20 @@ impl<'a> Inwx<'a> { for node in nodes { if let Some(ref text) = node.text() { let domain_root = text.text(); + debug!("Checking domain {}", domain_root); if domain.ends_with(&format!(".{}", domain_root)) { let name = &domain[0..domain.len() - domain_root.len() - 1]; + debug!("Found domain root {}", domain_root); return Ok((domain_root.to_owned(), name.to_owned())); } else if domain == domain_root { + debug!("Found domain root {}", domain_root); + return Ok((domain_root.to_owned(), "".to_owned())); } + + debug!("{} is not the domain root of {}", domain_root, domain); } } } diff --git a/src/main.rs b/src/main.rs index 667247c..c50c860 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,26 +1,21 @@ -extern crate clap; -extern crate openssl_probe; -extern crate serde; -extern crate serde_json; -extern crate cookie; -extern crate reqwest; -extern crate sxd_document; -extern crate sxd_xpath; -extern crate trust_dns; - +#[macro_use] +extern crate log; +use env_logger; +use env_logger::Env; +mod cli; mod config; -mod rpc; -mod inwx; mod dns; -mod cli; +mod inwx; +mod rpc; use std::process::exit; fn main() { + let env = Env::new().filter_or("LOG", "letsencrypt_inwx=info"); + env_logger::init_from_env(env); openssl_probe::init_ssl_cert_env_vars(); - if let Err(msg) = cli::run() { - eprintln!("=> Error: {}", msg); + if cli::run().is_err() { exit(1); } } diff --git a/src/rpc.rs b/src/rpc.rs index 9c36dba..934c558 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -101,6 +101,10 @@ impl RpcRequest { pub fn send(self, url: &str, cookies: &mut CookieJar) -> Result { let client = Client::new(); + if let Ok(body) = std::str::from_utf8(&self.body) { + trace!("Sending request {}", body); + } + let mut request = client .post(url) .body(self.body); @@ -129,6 +133,8 @@ impl RpcResponse { fn new(mut response: Response, method: String, cookies: &mut CookieJar) -> Result { if response.status() == StatusCode::OK { if let Ok(ref response_text) = response.text() { + trace!("Received response {:?}", response_text); + if let Ok(package) = parser::parse(response_text) { let mut success = false;