diff --git a/Cargo.lock b/Cargo.lock index 5ed6084..fd16366 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,9 +44,9 @@ dependencies = [ [[package]] name = "actix-http" -version = "3.2.0" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfeeac0149fc76f58894a08f221282975f4c6659d2cb31ffd22a3be7a83c5771" +checksum = "6f9ffb6db08c1c3a1f4aef540f1a63193adc73c4fbd40b75a95fc8c5258f6e51" dependencies = [ "actix-codec", "actix-rt", @@ -208,7 +208,7 @@ dependencies = [ "serde_urlencoded", "smallvec", "socket2", - "time 0.3.11", + "time", "url", ] @@ -432,7 +432,6 @@ dependencies = [ "libc", "num-integer", "num-traits", - "time 0.1.44", "winapi", ] @@ -460,9 +459,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.8" +version = "3.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" +checksum = "ab8b79fe3946ceb4a0b1c080b4018992b8d27e9ff363644c1c9b6387c854614d" dependencies = [ "atty", "bitflags", @@ -497,7 +496,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94d4706de1b0fa5b132270cddffa8585166037822e260a944fe161acd137ca05" dependencies = [ "percent-encoding", - "time 0.3.11", + "time", "version_check", ] @@ -531,9 +530,9 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.3" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array 0.14.5", "typenum", @@ -694,7 +693,7 @@ checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -742,9 +741,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hermit-abi" @@ -965,7 +964,7 @@ checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys", ] @@ -1009,9 +1008,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "opaque-debug" @@ -1021,9 +1020,9 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "os_str_bytes" -version = "6.1.0" +version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" +checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" [[package]] name = "parking_lot" @@ -1228,9 +1227,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.6" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ "aho-corasick", "memchr", @@ -1239,9 +1238,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.26" +version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "ring" @@ -1327,18 +1326,18 @@ checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" [[package]] name = "serde" -version = "1.0.138" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" +checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.138" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" +checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" dependencies = [ "proc-macro2", "quote", @@ -1456,12 +1455,11 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "srv" -version = "1.0.1" +version = "1.0.2" dependencies = [ "actix-files", "actix-web", "actix-web-httpauth", - "chrono", "clap", "env_logger", "lazy_static", @@ -1472,6 +1470,7 @@ dependencies = [ "serde", "sha2", "tera", + "time", "toml", "urlencoding", ] @@ -1552,17 +1551,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "time" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "time" version = "0.3.11" @@ -1598,10 +1586,11 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.19.2" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439" +checksum = "57aec3cfa4c296db7255446efb4928a6be304b431a806216105542a67b6ca82e" dependencies = [ + "autocfg", "bytes", "libc", "memchr", @@ -1677,9 +1666,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "ucd-trie" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" +checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c" [[package]] name = "uncased" @@ -1757,9 +1746,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" +checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" [[package]] name = "unicode-normalization" @@ -1811,12 +1800,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1899,9 +1882,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.3" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf" +checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" dependencies = [ "webpki", ] diff --git a/Cargo.toml b/Cargo.toml index 0cbcad2..a0c81e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,13 +3,12 @@ authors = ["Tim_Paik "] description = "simple http server written in rust" edition = "2018" name = "srv" -version = "1.0.1" +version = "1.0.2" [dependencies] actix-files = "0.6" actix-web = {version = "4.1", features = ["rustls"]} actix-web-httpauth = "0.6" -chrono = "0.4" clap = {version = "3.2", features = ["wrap_help", "color", "cargo"]} env_logger = "0.9" lazy_static = "1.4" @@ -20,6 +19,7 @@ rustls-pemfile = "1.0" serde = {version = "1.0", features = ["derive"]} sha2 = "0.10" tera = "1.16" +time = { version = "0.3", features = ["formatting", "parsing"] } toml = "0.5" urlencoding = "2.1" diff --git a/src/main.rs b/src/main.rs index 110652f..14668e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -252,9 +252,11 @@ fn render_index( } }; let modified = match metadata.modified() { - Ok(time) => chrono::DateTime::::from(time) - .format("%Y/%m/%d %H:%M:%S") - .to_string(), + Ok(time) => time::OffsetDateTime::from(time) + .format(time::macros::format_description!( + "[year]/[month]/[day] [hour]:[minute]:[second]" + )) + .unwrap_or_else(|_| "".to_string()), Err(e) => { error!(target: "read_dir", "[ERROR] Read modified time error: {}", e.to_string()); continue; @@ -479,7 +481,6 @@ async fn main() -> std::io::Result<()> { open_in_browser(&url); } - if let Some(matches) = matches.subcommand_matches("doc") { if !matches.is_present("log") { set_var("RUST_LOG", "info,actix_web::middleware::logger=off"); @@ -504,11 +505,15 @@ async fn main() -> std::io::Result<()> { if record.target() == "actix_web::middleware::logger" { let data: Vec<&str> = data.splitn(5, '^').collect(); let time = blue.value( - data[0] - .parse::>() - .unwrap() - .format("%Y/%m/%d %H:%M:%S") - .to_string(), + time::OffsetDateTime::parse( + data[0], + &time::format_description::well_known::Rfc3339, + ) + .unwrap_or(time::OffsetDateTime::UNIX_EPOCH) + .format(time::macros::format_description!( + "[year]/[month]/[day] [hour]:[minute]:[second]" + )) + .unwrap_or_else(|_| "".to_string()), ); let ipaddr = blue.value(data[1]); let status_code = data[2].parse().unwrap_or(500); @@ -550,7 +555,11 @@ async fn main() -> std::io::Result<()> { return writeln!(buf, "\r{}", green.value(data)); } if data == "SIGINT received; starting forced shutdown" { - return writeln!(buf, "\r{}", green.value("[INFO] SIGINT received; starting forced shutdown")); + return writeln!( + buf, + "\r{}", + green.value("[INFO] SIGINT received; starting forced shutdown") + ); // Add '\r' to remove the input ^C } return Ok(()); @@ -570,78 +579,78 @@ async fn main() -> std::io::Result<()> { }) .init(); - let addr = if let Some(matches) = matches.subcommand_matches("doc") { - let mut cargo_toml = match std::fs::File::open("./Cargo.toml") { - Ok(file) => file, - Err(e) => { - error!("[ERROR] {}", e.to_string()); - return Ok(()); - } - }; - let mut contents = String::new(); - match cargo_toml.read_to_string(&mut contents) { - Ok(_) => {} - Err(e) => { - error!("[ERROR] {}", e.to_string()); - return Ok(()); - } - } - let contents: CargoToml = match toml::from_str(&contents) { - Ok(t) => t, - Err(e) => { - error!("[ERROR] {}", e.to_string()); - return Ok(()); - } - }; - let crate_name = contents.package.name; - info!("[INFO] Generating document (may take a while)"); - match std::process::Command::new("cargo").arg("doc").output() { - Ok(output) => { - let output = std::str::from_utf8(&output.stderr).unwrap_or(""); - if output.starts_with("error: could not find `Cargo.toml` in") { - error!("[ERROR] Cargo.toml Not Found"); - return Ok(()); - } else if output.starts_with("error: ") { - error!( - "[ERROR] {}", - output.strip_prefix("error: ").unwrap_or(output) - ); - return Ok(()); - } - } - Err(e) => { - error!("[ERROR] Cargo Error: {}", e.to_string()); - return Ok(()); - } - } - let path = Path::new("./target/doc/"); - let mut index_path = path.to_path_buf(); - index_path.push(crate_name.to_string() + "/index.html"); - if !index_path.exists() || !index_path.is_file() { - error!("[ERROR] Cargo Error: doc path not found"); + let addr = if let Some(matches) = matches.subcommand_matches("doc") { + let mut cargo_toml = match std::fs::File::open("./Cargo.toml") { + Ok(file) => file, + Err(e) => { + error!("[ERROR] {}", e.to_string()); return Ok(()); } - set_var("ROOT", display_path(path)); - let ip = matches - .value_of("address") - .unwrap_or("127.0.0.1") - .to_string(); - let addr = format!("{}:{}", ip, matches.value_of("port").unwrap_or("8000")); - let url = format!( - "http://{}:{}/{}/index.html", - if ip == "0.0.0.0" { "127.0.0.1" } else { &ip }, - matches.value_of("port").unwrap_or("8000"), - crate_name, - ); - if !matches.is_present("noopen") { - open_in_browser(&url); - } - addr - } else { - addr }; - set_var("LISTEN_ADDRESS", addr); - + let mut contents = String::new(); + match cargo_toml.read_to_string(&mut contents) { + Ok(_) => {} + Err(e) => { + error!("[ERROR] {}", e.to_string()); + return Ok(()); + } + } + let contents: CargoToml = match toml::from_str(&contents) { + Ok(t) => t, + Err(e) => { + error!("[ERROR] {}", e.to_string()); + return Ok(()); + } + }; + let crate_name = contents.package.name; + info!("[INFO] Generating document (may take a while)"); + match std::process::Command::new("cargo").arg("doc").output() { + Ok(output) => { + let output = std::str::from_utf8(&output.stderr).unwrap_or(""); + if output.starts_with("error: could not find `Cargo.toml` in") { + error!("[ERROR] Cargo.toml Not Found"); + return Ok(()); + } else if output.starts_with("error: ") { + error!( + "[ERROR] {}", + output.strip_prefix("error: ").unwrap_or(output) + ); + return Ok(()); + } + } + Err(e) => { + error!("[ERROR] Cargo Error: {}", e.to_string()); + return Ok(()); + } + } + let path = Path::new("./target/doc/"); + let mut index_path = path.to_path_buf(); + index_path.push(crate_name.to_string() + "/index.html"); + if !index_path.exists() || !index_path.is_file() { + error!("[ERROR] Cargo Error: doc path not found"); + return Ok(()); + } + set_var("ROOT", display_path(path)); + let ip = matches + .value_of("address") + .unwrap_or("127.0.0.1") + .to_string(); + let addr = format!("{}:{}", ip, matches.value_of("port").unwrap_or("8000")); + let url = format!( + "http://{}:{}/{}/index.html", + if ip == "0.0.0.0" { "127.0.0.1" } else { &ip }, + matches.value_of("port").unwrap_or("8000"), + crate_name, + ); + if !matches.is_present("noopen") { + open_in_browser(&url); + } + addr + } else { + addr + }; + set_var("LISTEN_ADDRESS", addr); + let server = HttpServer::new(move || { let app = App::new() .wrap_fn(|req, srv| { @@ -733,7 +742,10 @@ async fn main() -> std::io::Result<()> { .with_no_client_auth() .with_single_cert(cert, key) .expect("bad certificate/key"); - server.bind_rustls(var("LISTEN_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8000".to_string()), config) + server.bind_rustls( + var("LISTEN_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8000".to_string()), + config, + ) } else { server.bind(var("LISTEN_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8000".to_string())) };