Skip to content

Commit

Permalink
Version 0.1.0
Browse files Browse the repository at this point in the history
- Initial release
  • Loading branch information
LIAUD Corentin committed Nov 6, 2022
1 parent 0d01019 commit 6f81358
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[package]
description = "Rust local DNS adblocker"
documentation = "README.md"
authors = ["LIAUD Corentin <corentin.liaud@orange.fr>"]
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"
Expand Down Expand Up @@ -49,3 +51,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",
],
]
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* Regularly update input sources
* Making everything `async`
* Increase DNS record TTL for blocked addresses
* Log requests per equipments
14 changes: 7 additions & 7 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
listen_port: 53
14 changes: 14 additions & 0 deletions rhole.service
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/controllers/blacklist_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/requests_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
23 changes: 3 additions & 20 deletions src/models/config.rs
Original file line number Diff line number Diff line change
@@ -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<String, D::Error>
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,
Expand All @@ -42,13 +26,12 @@ pub struct ProxyServer {
#[derive(Debug, Deserialize)]
pub struct Sources {
pub update_interval: u64,
pub entries: Vec<SourceEntry>
pub entries: Vec<SourceEntry>,
}

#[derive(Clone, Debug, Deserialize)]
pub struct SourceEntry {
pub source_type: SourceType,
#[serde(deserialize_with = "check_path_exists")]
pub location: String,
pub comment: String,
}
Expand Down
11 changes: 9 additions & 2 deletions src/utils/log_level.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 6f81358

Please sign in to comment.