diff --git a/Cargo.lock b/Cargo.lock index 2820634..976ed8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.13" @@ -91,6 +106,12 @@ dependencies = [ "syn", ] +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + [[package]] name = "backtrace" version = "0.3.71" @@ -136,6 +157,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.4", +] + [[package]] name = "clap" version = "4.5.4" @@ -182,6 +217,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "env_filter" version = "0.1.0" @@ -356,6 +397,29 @@ dependencies = [ "tracing", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -437,6 +501,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -464,10 +537,11 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "peerban" -version = "0.1.0" +version = "0.1.1" dependencies = [ "anyhow", "async-trait", + "chrono", "clap", "env_logger", "lazy_static", @@ -917,6 +991,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.4", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 6d6419e..773c936 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "peerban" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -16,6 +16,7 @@ log = "0.4.21" async-trait = "0.1.79" clap = { version = "4.5.4", features = ["derive", "env"] } regex = "1.10.4" +chrono = "0.4.38" [profile.opt] inherits = "release" diff --git a/README.md b/README.md index 5143610..98a1106 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,28 @@ Options: ## Installation +### From Source + ```shell cargo install --git https://github.com/jerrita/peerban ``` - -> Docker & Binary is WIP +### Docker + +```yaml +services: + peerban: + image: ghcr.io/jerrita/peerban:latest + container_name: peerban + restart: unless-stopped + environment: + - BACKEND=qb + - ENDPOINT=http://your-qbittorrent:8080 + - AUTH=user:password + - SCAN=5 + - PT=false # use the same logic on PT trackers, default skip + - CLEAR=false # clear all bans before start, default false + network_mode: host +``` ## Backend Supports @@ -47,7 +64,7 @@ cargo install --git https://github.com/jerrita/peerban ## RoadMap - [x] ProtoType -- [ ] Container +- [x] Containerize - [ ] WebUI - [ ] Rule Hot-Update diff --git a/src/main.rs b/src/main.rs index 47b981d..3695f61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::io::Write; + use clap::Parser; use log::{error, info, warn}; @@ -31,7 +33,21 @@ async fn main() -> Result<(), Box> { if std::env::var("RUST_LOG").is_err() { std::env::set_var("RUST_LOG", "info"); } - env_logger::init(); + env_logger::builder() + .format(|buf, record| { + writeln!(buf, "{} [{}] {}", + chrono::Local::now().format("%Y-%m-%d %H:%M:%S"), + match record.level() { + log::Level::Error => "\x1b[31mERROR\x1b[0m", + log::Level::Warn => "\x1b[33mWARN\x1b[0m", + log::Level::Info => "\x1b[32mINFO\x1b[0m", + log::Level::Debug => "\x1b[34mDEBUG\x1b[0m", + log::Level::Trace => "\x1b[37mTRACE\x1b[0m", + }, + record.args() + ) + }) + .init(); let args = Args::parse(); if args.backend != "qb" {