summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock75
-rw-r--r--Cargo.toml2
-rw-r--r--README.md1
-rw-r--r--src/config.rs1
-rw-r--r--src/main.rs27
5 files changed, 91 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0654c77..dcdec98 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -27,6 +27,21 @@ dependencies = [
27] 27]
28 28
29[[package]] 29[[package]]
30name = "android-tzdata"
31version = "0.1.1"
32source = "registry+https://github.com/rust-lang/crates.io-index"
33checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
34
35[[package]]
36name = "android_system_properties"
37version = "0.1.5"
38source = "registry+https://github.com/rust-lang/crates.io-index"
39checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
40dependencies = [
41 "libc",
42]
43
44[[package]]
30name = "arbitrary" 45name = "arbitrary"
31version = "1.3.2" 46version = "1.3.2"
32source = "registry+https://github.com/rust-lang/crates.io-index" 47source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -204,6 +219,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
204checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" 219checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
205 220
206[[package]] 221[[package]]
222name = "chrono"
223version = "0.4.38"
224source = "registry+https://github.com/rust-lang/crates.io-index"
225checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
226dependencies = [
227 "android-tzdata",
228 "iana-time-zone",
229 "num-traits",
230 "windows-targets 0.52.5",
231]
232
233[[package]]
207name = "color-eyre" 234name = "color-eyre"
208version = "0.6.3" 235version = "0.6.3"
209source = "registry+https://github.com/rust-lang/crates.io-index" 236source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -280,6 +307,12 @@ dependencies = [
280] 307]
281 308
282[[package]] 309[[package]]
310name = "core-foundation-sys"
311version = "0.8.6"
312source = "registry+https://github.com/rust-lang/crates.io-index"
313checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
314
315[[package]]
283name = "cpufeatures" 316name = "cpufeatures"
284version = "0.2.12" 317version = "0.2.12"
285source = "registry+https://github.com/rust-lang/crates.io-index" 318source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -655,6 +688,29 @@ dependencies = [
655] 688]
656 689
657[[package]] 690[[package]]
691name = "iana-time-zone"
692version = "0.1.60"
693source = "registry+https://github.com/rust-lang/crates.io-index"
694checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
695dependencies = [
696 "android_system_properties",
697 "core-foundation-sys",
698 "iana-time-zone-haiku",
699 "js-sys",
700 "wasm-bindgen",
701 "windows-core",
702]
703
704[[package]]
705name = "iana-time-zone-haiku"
706version = "0.1.2"
707source = "registry+https://github.com/rust-lang/crates.io-index"
708checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
709dependencies = [
710 "cc",
711]
712
713[[package]]
658name = "icu_collections" 714name = "icu_collections"
659version = "1.5.0" 715version = "1.5.0"
660source = "registry+https://github.com/rust-lang/crates.io-index" 716source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1011,6 +1067,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1011checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" 1067checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
1012 1068
1013[[package]] 1069[[package]]
1070name = "num-traits"
1071version = "0.2.19"
1072source = "registry+https://github.com/rust-lang/crates.io-index"
1073checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
1074dependencies = [
1075 "autocfg",
1076]
1077
1078[[package]]
1014name = "num_cpus" 1079name = "num_cpus"
1015version = "1.16.0" 1080version = "1.16.0"
1016source = "registry+https://github.com/rust-lang/crates.io-index" 1081source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2048,6 +2113,7 @@ version = "0.3.18"
2048source = "registry+https://github.com/rust-lang/crates.io-index" 2113source = "registry+https://github.com/rust-lang/crates.io-index"
2049checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" 2114checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
2050dependencies = [ 2115dependencies = [
2116 "chrono",
2051 "matchers", 2117 "matchers",
2052 "nu-ansi-term", 2118 "nu-ansi-term",
2053 "once_cell", 2119 "once_cell",
@@ -2386,6 +2452,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2386checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 2452checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
2387 2453
2388[[package]] 2454[[package]]
2455name = "windows-core"
2456version = "0.52.0"
2457source = "registry+https://github.com/rust-lang/crates.io-index"
2458checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
2459dependencies = [
2460 "windows-targets 0.52.5",
2461]
2462
2463[[package]]
2389name = "windows-sys" 2464name = "windows-sys"
2390version = "0.48.0" 2465version = "0.48.0"
2391source = "registry+https://github.com/rust-lang/crates.io-index" 2466source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 7b10baa..c633f57 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,7 +9,7 @@ edition = "2021"
9axum = { version = "0.7", features = ["ws"] } 9axum = { version = "0.7", features = ["ws"] }
10tokio = { version = "1.38", features = ["macros", "rt-multi-thread"] } 10tokio = { version = "1.38", features = ["macros", "rt-multi-thread"] }
11tracing = "0.1" 11tracing = "0.1"
12tracing-subscriber = { version = "0.3", features = ["env-filter", "local-time", "time"] } 12tracing-subscriber = { version = "0.3", features = ["env-filter", "local-time", "chrono"] }
13time = { version = "0.3", features = ["macros"] } 13time = { version = "0.3", features = ["macros"] }
14serde = { version = "1.0", features = ["derive"] } 14serde = { version = "1.0", features = ["derive"] }
15serde_json = "1.0" 15serde_json = "1.0"
diff --git a/README.md b/README.md
index 8c2c8c6..790f9c2 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,6 @@ Default `config.toml`:
5serveraddr = "0.0.0.0:7229" # String 5serveraddr = "0.0.0.0:7229" # String
6pingtimeout = 10 # i64 6pingtimeout = 10 # i64
7pingthreshold = 1 # u64 7pingthreshold = 1 # u64
8timeoffset = 0 # i8
9 8
10[auth] 9[auth]
11method = "none" # "none"|"key" 10method = "none" # "none"|"key"
diff --git a/src/config.rs b/src/config.rs
index 7c91c08..18c3bab 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -8,7 +8,6 @@ pub struct Config {
8 pub serveraddr: String, 8 pub serveraddr: String,
9 pub pingtimeout: i64, 9 pub pingtimeout: i64,
10 pub pingthreshold: u64, 10 pub pingthreshold: u64,
11 pub timeoffset: i8,
12 pub auth: Auth, 11 pub auth: Auth,
13} 12}
14 13
diff --git a/src/main.rs b/src/main.rs
index 204c318..b550dd8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,8 @@
1use crate::{ 1use crate::{
2 config::Config, routes::{device, start, status}, services::ping::{BroadcastCommand, StatusMap}, storage::Device 2 config::Config,
3 routes::{device, start, status},
4 services::ping::{BroadcastCommand, StatusMap},
5 storage::Device,
3}; 6};
4use axum::{ 7use axum::{
5 middleware::from_fn_with_state, 8 middleware::from_fn_with_state,
@@ -8,14 +11,9 @@ use axum::{
8}; 11};
9use dashmap::DashMap; 12use dashmap::DashMap;
10use std::{env, sync::Arc}; 13use std::{env, sync::Arc};
11use time::UtcOffset;
12use tokio::sync::broadcast::{channel, Sender}; 14use tokio::sync::broadcast::{channel, Sender};
13use tracing::{info, level_filters::LevelFilter, trace}; 15use tracing::{info, level_filters::LevelFilter, trace};
14use tracing_subscriber::{ 16use tracing_subscriber::{fmt, prelude::*, EnvFilter};
15 fmt::{self, time::OffsetTime},
16 prelude::*,
17 EnvFilter,
18};
19use utoipa::{ 17use utoipa::{
20 openapi::security::{ApiKey, ApiKeyValue, SecurityScheme}, 18 openapi::security::{ApiKey, ApiKeyValue, SecurityScheme},
21 Modify, OpenApi, 19 Modify, OpenApi,
@@ -24,10 +22,10 @@ use utoipa_swagger_ui::SwaggerUi;
24 22
25mod auth; 23mod auth;
26mod config; 24mod config;
27mod storage;
28mod error; 25mod error;
29mod routes; 26mod routes;
30mod services; 27mod services;
28mod storage;
31mod wol; 29mod wol;
32 30
33#[derive(OpenApi)] 31#[derive(OpenApi)]
@@ -73,15 +71,20 @@ async fn main() -> color_eyre::eyre::Result<()> {
73 71
74 let config = Config::load()?; 72 let config = Config::load()?;
75 73
76 let time_format = 74 let writer_time =
77 time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"); 75 tracing_subscriber::fmt::time::ChronoLocal::new("%Y-%m-%d %H:%M:%S%.6f%:z".to_string());
78 let time = OffsetTime::new(UtcOffset::from_hms(config.timeoffset, 0, 0)?, time_format); 76 let time = tracing_subscriber::fmt::time::ChronoLocal::new("%Y-%m-%d %H:%M:%S%:z".to_string());
79 77
80 let file_appender = tracing_appender::rolling::daily("logs", "webol.log"); 78 let file_appender = tracing_appender::rolling::daily("logs", "webol.log");
81 let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); 79 let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
82 80
83 tracing_subscriber::registry() 81 tracing_subscriber::registry()
84 .with(fmt::layer().with_writer(non_blocking).with_ansi(false)) 82 .with(
83 fmt::layer()
84 .with_timer(writer_time)
85 .with_writer(non_blocking)
86 .with_ansi(false),
87 )
85 .with(fmt::layer().with_timer(time)) 88 .with(fmt::layer().with_timer(time))
86 .with( 89 .with(
87 EnvFilter::builder() 90 EnvFilter::builder()