diff --git a/Cargo.lock b/Cargo.lock index c5eed1c..a639c1d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -513,7 +513,7 @@ dependencies = [ [[package]] name = "rhole" -version = "0.1.1" +version = "0.1.0" dependencies = [ "anyhow", "bytes", diff --git a/Cargo.toml b/Cargo.toml index e765454..2845b8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,13 @@ [package] description = "Rust local DNS adblocker" documentation = "README.md" +authors = ["LIAUD Corentin "] edition = "2021" license = "MIT" +readme = "README.md" name = "rhole" -version = "0.1.1" +version = "0.1.0" +repository = "https://github.com/cocool97/rhole" [[bin]] name = "rhole" @@ -49,3 +52,29 @@ tokio = { version = "1.21.2", default-features = false, features = [ "net", "rt-multi-thread", ] } + +[package.metadata.generate-rpm] +assets = [ + { source = "config.yml", dest = "/etc/rhole/config.yml", mode = "755", config = true }, + { source = "rhole.service", dest = "/etc/systemd/system/rhole.service", mode = "755" }, + { source = "target/armv7-unknown-linux-musleabihf/release/rhole", dest = "/usr/bin/rhole", mode = "755" }, +] + +[package.metadata.deb] +assets = [ + [ + "config.yml", + "/etc/rhole/config.yml", + "755", + ], + [ + "rhole.service", + "/etc/systemd/system/rhole.service", + "755", + ], + [ + "target/armv7-unknown-linux-musleabihf/release/rhole", + "/usr/bin/rhole", + "755", + ], +] diff --git a/README.md b/README.md index ffd2efc..5e1096b 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,7 @@ This is an in-progress work, many things must still be achieved to reach version * Web monitoring interface * Code audit to improve performances + possible mistakes -* Regularly update input sources \ No newline at end of file +* Regularly update input sources +* Making everything `async` +* Increase DNS record TTL for blocked addresses +* Log requests per equipments \ No newline at end of file diff --git a/config.yml b/config.yml index 8cec868..73efcfe 100644 --- a/config.yml +++ b/config.yml @@ -4,12 +4,12 @@ proxy_server: sources: update_interval: 5 entries: - - source_type: !File - location: hosts.txt - comment: Global hosts file - # - source_type: !Network - # location: http://sbc.io/hosts/alternates/fakenews-gambling-porn-social/hosts - # comment: Remote hosts file + # - source_type: !File + # location: hosts.txt + # comment: Global hosts file + - source_type: !Network + location: http://sbc.io/hosts/alternates/fakenews-gambling-porn-social/hosts + comment: Remote hosts file net: listen_addr: "0.0.0.0" - listen_port: 4053 \ No newline at end of file + listen_port: 53 \ No newline at end of file diff --git a/rhole.service b/rhole.service new file mode 100644 index 0000000..dd5d535 --- /dev/null +++ b/rhole.service @@ -0,0 +1,14 @@ +[Unit] +Description=Highly configurable Rust local DNS adblocker. +After=network.target + +[Service] +User=root +ExecStart=/usr/bin/rhole --config config.yml +Environment="RUST_LOG=rhole=info" +WorkingDirectory=/etc/rhole +Restart=on-failure +AmbientCapabilities=CAP_NET_BIND_SERVICE + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/src/controllers/blacklist_controller.rs b/src/controllers/blacklist_controller.rs index 5fb407e..eebd037 100644 --- a/src/controllers/blacklist_controller.rs +++ b/src/controllers/blacklist_controller.rs @@ -54,7 +54,8 @@ impl BlacklistController { } } - log::debug!("Found {} addresses to blacklist...", blacklist.len()); + log::info!("Initialization finished..."); + log::info!("Found {} addresses to blacklist...", blacklist.len()); Ok(Self { blacklist }) } diff --git a/src/controllers/requests_controller.rs b/src/controllers/requests_controller.rs index 9e0315a..6a372e0 100644 --- a/src/controllers/requests_controller.rs +++ b/src/controllers/requests_controller.rs @@ -66,7 +66,8 @@ impl InboundConnectionsController { // TODO: Check trailing dots if blacklist.contains(question.domain_name.to_string().trim_end_matches('.')) { log::warn!( - "Domain {} is blacklisted. Ignoring it.", + "[{}] Domain {} is blacklisted. Ignoring it.", + origin_addr.ip(), question.domain_name ); diff --git a/src/models/config.rs b/src/models/config.rs index 36a71cc..3ef6bbe 100644 --- a/src/models/config.rs +++ b/src/models/config.rs @@ -1,25 +1,9 @@ -use std::{fmt::Display, io, path::Path}; +use std::{fmt::Display, path::Path}; use anyhow::Result; -use serde::de::Error; -use serde::{Deserialize, Deserializer}; +use serde::Deserialize; use tokio::fs::File; -fn check_path_exists<'de, D>(deserializer: D) -> Result -where - D: Deserializer<'de>, -{ - let location: String = Deserialize::deserialize(deserializer)?; - if Path::new(&location).exists() { - Ok(location) - } else { - Err(D::Error::custom(io::Error::new( - std::io::ErrorKind::NotFound, - format!("No such file or directory: '{}'", location), - ))) - } -} - #[derive(Deserialize)] pub struct Config { pub net: NetConfig, @@ -42,13 +26,12 @@ pub struct ProxyServer { #[derive(Debug, Deserialize)] pub struct Sources { pub update_interval: u64, - pub entries: Vec + pub entries: Vec, } #[derive(Clone, Debug, Deserialize)] pub struct SourceEntry { pub source_type: SourceType, - #[serde(deserialize_with = "check_path_exists")] pub location: String, pub comment: String, } diff --git a/src/utils/log_level.rs b/src/utils/log_level.rs index 18bae8f..06896d4 100644 --- a/src/utils/log_level.rs +++ b/src/utils/log_level.rs @@ -1,5 +1,12 @@ +use std::env; + pub fn set_log_level(debug: bool) { - let level = if debug { "debug" } else { "info" }; - std::env::set_var("RUST_LOG", level); + // Setting RUST_LOG from env if it exists + // If it does not exist, creates special one + if let Err(_) = env::var("RUST_LOG") { + let level = if debug { "debug" } else { "info" }; + std::env::set_var("RUST_LOG", level); + } + env_logger::init(); }