mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2024-12-27 12:18:20 +01:00
First prototype with multiple dns providers
This commit is contained in:
parent
f173eba2ec
commit
cd8c0455dc
103
Cargo.lock
generated
103
Cargo.lock
generated
@ -202,6 +202,12 @@ version = "0.13.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.21.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.3.2"
|
||||||
@ -670,7 +676,7 @@ version = "0.3.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584"
|
checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64 0.13.1",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytes",
|
"bytes",
|
||||||
"headers-core",
|
"headers-core",
|
||||||
@ -1392,6 +1398,21 @@ dependencies = [
|
|||||||
"quick-error",
|
"quick-error",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ring"
|
||||||
|
version = "0.16.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
"spin",
|
||||||
|
"untrusted",
|
||||||
|
"web-sys",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.23"
|
version = "0.1.23"
|
||||||
@ -1411,6 +1432,27 @@ dependencies = [
|
|||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls"
|
||||||
|
version = "0.20.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"ring",
|
||||||
|
"sct",
|
||||||
|
"webpki",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-pemfile"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b"
|
||||||
|
dependencies = [
|
||||||
|
"base64 0.21.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.14"
|
version = "1.0.14"
|
||||||
@ -1438,6 +1480,16 @@ version = "1.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sct"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4"
|
||||||
|
dependencies = [
|
||||||
|
"ring",
|
||||||
|
"untrusted",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.171"
|
version = "1.0.171"
|
||||||
@ -1581,6 +1633,12 @@ dependencies = [
|
|||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spin"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strsim"
|
name = "strsim"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
@ -1712,6 +1770,17 @@ dependencies = [
|
|||||||
"syn 2.0.26",
|
"syn 2.0.26",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-rustls"
|
||||||
|
version = "0.23.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59"
|
||||||
|
dependencies = [
|
||||||
|
"rustls",
|
||||||
|
"tokio",
|
||||||
|
"webpki",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.7.8"
|
version = "0.7.8"
|
||||||
@ -1862,12 +1931,16 @@ dependencies = [
|
|||||||
"ipnet",
|
"ipnet",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"rand",
|
"rand",
|
||||||
|
"rustls",
|
||||||
|
"rustls-pemfile",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tinyvec",
|
"tinyvec",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-rustls",
|
||||||
"tracing",
|
"tracing",
|
||||||
"url",
|
"url",
|
||||||
|
"webpki",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1883,11 +1956,14 @@ dependencies = [
|
|||||||
"lru-cache",
|
"lru-cache",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"resolv-conf",
|
"resolv-conf",
|
||||||
|
"rustls",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tokio-rustls",
|
||||||
"tracing",
|
"tracing",
|
||||||
"trust-dns-proto",
|
"trust-dns-proto",
|
||||||
|
"webpki-roots",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1997,6 +2073,12 @@ dependencies = [
|
|||||||
"tinyvec",
|
"tinyvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "untrusted"
|
||||||
|
version = "0.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "url"
|
name = "url"
|
||||||
version = "2.4.0"
|
version = "2.4.0"
|
||||||
@ -2115,6 +2197,25 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "webpki"
|
||||||
|
version = "0.22.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd"
|
||||||
|
dependencies = [
|
||||||
|
"ring",
|
||||||
|
"untrusted",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "webpki-roots"
|
||||||
|
version = "0.22.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87"
|
||||||
|
dependencies = [
|
||||||
|
"webpki",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "widestring"
|
name = "widestring"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
|
@ -22,5 +22,5 @@ toml = "0.7"
|
|||||||
tower = "0.4"
|
tower = "0.4"
|
||||||
tower-http = { version = "0.4", features = ["fs"] }
|
tower-http = { version = "0.4", features = ["fs"] }
|
||||||
trust-dns-proto = "0.22"
|
trust-dns-proto = "0.22"
|
||||||
trust-dns-resolver = "0.22"
|
trust-dns-resolver = { version = "0.22", features = ["dns-over-rustls"] }
|
||||||
maxminddb = "0.23"
|
maxminddb = "0.23"
|
||||||
|
@ -8,9 +8,7 @@ It is Licensed under the AGPL-v3 license.
|
|||||||
|
|
||||||
Simply run `cargo build` after cloning. The binary should be called `target/debug/echoip-slatecave`.
|
Simply run `cargo build` after cloning. The binary should be called `target/debug/echoip-slatecave`.
|
||||||
|
|
||||||
To make a release build (the one you want to have on your server) run `cargo build --relese`, the binary will end up in `target/release/echoip-slatecave`.
|
To make a release build (the one you want to have on your server) run `cargo build --release`, the binary will end up in `target/release/echoip-slatecave`.
|
||||||
|
|
||||||
NOTE: As of 2023-02-18 You need at least version 1.65 of the rust compiler. Consider using rustup.
|
|
||||||
|
|
||||||
## Usage and configuration
|
## Usage and configuration
|
||||||
|
|
||||||
|
119
src/main.rs
119
src/main.rs
@ -33,6 +33,7 @@ use tokio::signal::unix::{
|
|||||||
};
|
};
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -72,6 +73,16 @@ pub struct SearchQuery {
|
|||||||
query: Option<String>,
|
query: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn default_dns_name() -> String {
|
||||||
|
"default".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize, Clone)]
|
||||||
|
pub struct ResolverQuery {
|
||||||
|
#[serde(default="default_dns_name")]
|
||||||
|
dns: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize, Clone)]
|
#[derive(serde::Deserialize, serde::Serialize, Clone)]
|
||||||
pub struct IpResult {
|
pub struct IpResult {
|
||||||
address: IpAddr,
|
address: IpAddr,
|
||||||
@ -96,7 +107,8 @@ pub struct DigResult {
|
|||||||
|
|
||||||
struct ServiceSharedState {
|
struct ServiceSharedState {
|
||||||
templating_engine: templating_engine::Engine,
|
templating_engine: templating_engine::Engine,
|
||||||
dns_resolver: TokioAsyncResolver,
|
//dns_resolver: TokioAsyncResolver,
|
||||||
|
dns_resolvers: HashMap<String,TokioAsyncResolver>,
|
||||||
asn_db: geoip::MMDBCarrier,
|
asn_db: geoip::MMDBCarrier,
|
||||||
location_db: geoip::MMDBCarrier,
|
location_db: geoip::MMDBCarrier,
|
||||||
config: config::EchoIpServiceConfig,
|
config: config::EchoIpServiceConfig,
|
||||||
@ -238,6 +250,30 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//FIXME: Not release ready,must be configurable and have better error handling.
|
||||||
|
println!("Initalizing Quad9 resolver ...");
|
||||||
|
let quad9_resolver = TokioAsyncResolver::tokio(
|
||||||
|
trust_dns_resolver::config::ResolverConfig::quad9_tls(),
|
||||||
|
Default::default()
|
||||||
|
).unwrap();
|
||||||
|
println!("Initalizing Google resolver ...");
|
||||||
|
let google_resolver = TokioAsyncResolver::tokio(
|
||||||
|
trust_dns_resolver::config::ResolverConfig::google(),
|
||||||
|
Default::default()
|
||||||
|
).unwrap();
|
||||||
|
println!("Initalizing Cloudflare resolver ...");
|
||||||
|
let cloudflare_resolver = TokioAsyncResolver::tokio(
|
||||||
|
trust_dns_resolver::config::ResolverConfig::cloudflare_tls(),
|
||||||
|
Default::default()
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
let mut dns_resolver_map: HashMap<String,TokioAsyncResolver> = HashMap::new();
|
||||||
|
|
||||||
|
dns_resolver_map.insert("default".to_string(), dns_resolver);
|
||||||
|
dns_resolver_map.insert("quad9".to_string(), quad9_resolver);
|
||||||
|
dns_resolver_map.insert("google".to_string(), google_resolver);
|
||||||
|
dns_resolver_map.insert("cloudflare".to_string(), cloudflare_resolver);
|
||||||
|
|
||||||
let listen_on = config.server.listen_on;
|
let listen_on = config.server.listen_on;
|
||||||
let ip_header = config.server.ip_header.clone();
|
let ip_header = config.server.ip_header.clone();
|
||||||
|
|
||||||
@ -245,7 +281,8 @@ async fn main() {
|
|||||||
let shared_state = Arc::new(
|
let shared_state = Arc::new(
|
||||||
ServiceSharedState {
|
ServiceSharedState {
|
||||||
templating_engine: templating_engine,
|
templating_engine: templating_engine,
|
||||||
dns_resolver: dns_resolver,
|
//dns_resolver: dns_resolver,
|
||||||
|
dns_resolvers: dns_resolver_map,
|
||||||
asn_db: asn_db,
|
asn_db: asn_db,
|
||||||
location_db: location_db,
|
location_db: location_db,
|
||||||
config: config.clone(),
|
config: config.clone(),
|
||||||
@ -294,7 +331,7 @@ async fn main() {
|
|||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
println!("Starting Server ...");
|
println!("Starting Server on {} ...",listen_on);
|
||||||
|
|
||||||
axum::Server::bind(&listen_on)
|
axum::Server::bind(&listen_on)
|
||||||
.serve(app.into_make_service_with_connect_info::<std::net::SocketAddr>())
|
.serve(app.into_make_service_with_connect_info::<std::net::SocketAddr>())
|
||||||
@ -367,6 +404,7 @@ async fn user_agent_handler(
|
|||||||
|
|
||||||
async fn handle_default_route(
|
async fn handle_default_route(
|
||||||
Query(search_query): Query<SearchQuery>,
|
Query(search_query): Query<SearchQuery>,
|
||||||
|
Query(resolver_settings): Query<ResolverQuery>,
|
||||||
State(arc_state): State<Arc<ServiceSharedState>>,
|
State(arc_state): State<Arc<ServiceSharedState>>,
|
||||||
Extension(settings): Extension<TemplateSettings>,
|
Extension(settings): Extension<TemplateSettings>,
|
||||||
user_agent_header: Option<TypedHeader<headers::UserAgent>>,
|
user_agent_header: Option<TypedHeader<headers::UserAgent>>,
|
||||||
@ -377,11 +415,17 @@ async fn handle_default_route(
|
|||||||
|
|
||||||
if let Some(search_query) = search_query.query {
|
if let Some(search_query) = search_query.query {
|
||||||
if search_query.trim() != "" {
|
if search_query.trim() != "" {
|
||||||
return handle_search_request(search_query, false, settings, state).await;
|
return handle_search_request(
|
||||||
|
search_query,
|
||||||
|
false,
|
||||||
|
settings,
|
||||||
|
resolver_settings,
|
||||||
|
state
|
||||||
|
).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = get_ip_result(&address, &settings.lang, &state).await;
|
let result = get_ip_result(&address, &settings.lang, &"default".to_string(), &state).await;
|
||||||
|
|
||||||
let user_agent: Option<String> = match user_agent_header {
|
let user_agent: Option<String> = match user_agent_header {
|
||||||
Some(TypedHeader(user_agent)) => Some(user_agent.to_string()),
|
Some(TypedHeader(user_agent)) => Some(user_agent.to_string()),
|
||||||
@ -402,6 +446,7 @@ async fn handle_search_request(
|
|||||||
search_query: String,
|
search_query: String,
|
||||||
this_should_have_been_an_ip: bool,
|
this_should_have_been_an_ip: bool,
|
||||||
settings: TemplateSettings,
|
settings: TemplateSettings,
|
||||||
|
resolver_settings: ResolverQuery,
|
||||||
arc_state: Arc<ServiceSharedState>,
|
arc_state: Arc<ServiceSharedState>,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
|
|
||||||
@ -425,12 +470,15 @@ async fn handle_search_request(
|
|||||||
|
|
||||||
// Try to interpret as an IP-Address
|
// Try to interpret as an IP-Address
|
||||||
if let Ok(address) = search_query.parse() {
|
if let Ok(address) = search_query.parse() {
|
||||||
return handle_ip_request(address, settings, arc_state).await;
|
return handle_ip_request(address, settings, resolver_settings, arc_state).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to treating it as a hostname
|
// Fall back to treating it as a hostname
|
||||||
return handle_dig_request(
|
return handle_dig_request(
|
||||||
search_query.to_string(), settings, arc_state,
|
search_query.to_string(),
|
||||||
|
settings,
|
||||||
|
resolver_settings,
|
||||||
|
arc_state,
|
||||||
!this_should_have_been_an_ip,
|
!this_should_have_been_an_ip,
|
||||||
).await
|
).await
|
||||||
|
|
||||||
@ -439,23 +487,29 @@ async fn handle_search_request(
|
|||||||
async fn handle_ip_route_with_path(
|
async fn handle_ip_route_with_path(
|
||||||
Extension(settings): Extension<TemplateSettings>,
|
Extension(settings): Extension<TemplateSettings>,
|
||||||
State(arc_state): State<Arc<ServiceSharedState>>,
|
State(arc_state): State<Arc<ServiceSharedState>>,
|
||||||
|
Query(resolver_settings): Query<ResolverQuery>,
|
||||||
extract::Path(query): extract::Path<String>,
|
extract::Path(query): extract::Path<String>,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
if let Ok(address) = query.parse() {
|
if let Ok(address) = query.parse() {
|
||||||
return handle_ip_request(address, settings, arc_state).await
|
return handle_ip_request(address, settings, resolver_settings, arc_state).await
|
||||||
} else {
|
} else {
|
||||||
return handle_search_request(query, true, settings, arc_state).await;
|
return handle_search_request(query, true, settings, resolver_settings, arc_state).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_ip_request(
|
async fn handle_ip_request(
|
||||||
address: IpAddr,
|
address: IpAddr,
|
||||||
settings: TemplateSettings,
|
settings: TemplateSettings,
|
||||||
|
resolver_settings: ResolverQuery,
|
||||||
arc_state: Arc<ServiceSharedState>,
|
arc_state: Arc<ServiceSharedState>,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
|
|
||||||
let state = Arc::clone(&arc_state);
|
let state = Arc::clone(&arc_state);
|
||||||
let result = get_ip_result(&address, &settings.lang, &state).await;
|
let result = get_ip_result(
|
||||||
|
&address,
|
||||||
|
&settings.lang,
|
||||||
|
&resolver_settings.dns,
|
||||||
|
&state).await;
|
||||||
|
|
||||||
state.templating_engine.render_view(
|
state.templating_engine.render_view(
|
||||||
&settings,
|
&settings,
|
||||||
@ -466,6 +520,7 @@ async fn handle_ip_request(
|
|||||||
async fn get_ip_result(
|
async fn get_ip_result(
|
||||||
address: &IpAddr,
|
address: &IpAddr,
|
||||||
lang: &String,
|
lang: &String,
|
||||||
|
dns_resolver_name: &String,
|
||||||
state: &ServiceSharedState,
|
state: &ServiceSharedState,
|
||||||
) -> IpResult {
|
) -> IpResult {
|
||||||
|
|
||||||
@ -485,7 +540,11 @@ async fn get_ip_result(
|
|||||||
|
|
||||||
// do reverse lookup
|
// do reverse lookup
|
||||||
let hostname = if state.config.dns.allow_reverse_lookup {
|
let hostname = if state.config.dns.allow_reverse_lookup {
|
||||||
simple_dns::reverse_lookup(&state.dns_resolver, &address).await
|
if let Some(dns_resolver) = &state.dns_resolvers.get(dns_resolver_name) {
|
||||||
|
simple_dns::reverse_lookup(&dns_resolver, &address).await
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@ -521,23 +580,30 @@ async fn get_ip_result(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_dig_route_with_path(
|
async fn handle_dig_route_with_path(
|
||||||
|
Query(resolver_settings): Query<ResolverQuery>,
|
||||||
Extension(settings): Extension<TemplateSettings>,
|
Extension(settings): Extension<TemplateSettings>,
|
||||||
State(arc_state): State<Arc<ServiceSharedState>>,
|
State(arc_state): State<Arc<ServiceSharedState>>,
|
||||||
extract::Path(name): extract::Path<String>,
|
extract::Path(name): extract::Path<String>,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
return handle_dig_request(name, settings, arc_state, true).await
|
return handle_dig_request(name, settings, resolver_settings, arc_state, true).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_dig_request(
|
async fn handle_dig_request(
|
||||||
dig_query: String,
|
dig_query: String,
|
||||||
settings: TemplateSettings,
|
settings: TemplateSettings,
|
||||||
|
resolver_settings: ResolverQuery,
|
||||||
arc_state: Arc<ServiceSharedState>,
|
arc_state: Arc<ServiceSharedState>,
|
||||||
do_full_lookup: bool,
|
do_full_lookup: bool,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
|
|
||||||
let state = Arc::clone(&arc_state);
|
let state = Arc::clone(&arc_state);
|
||||||
|
|
||||||
let dig_result = get_dig_result(&dig_query, &state, do_full_lookup).await;
|
let dig_result = get_dig_result(
|
||||||
|
&dig_query,
|
||||||
|
&resolver_settings.dns,
|
||||||
|
&state,
|
||||||
|
do_full_lookup
|
||||||
|
).await;
|
||||||
|
|
||||||
state.templating_engine.render_view(
|
state.templating_engine.render_view(
|
||||||
&settings,
|
&settings,
|
||||||
@ -547,22 +613,27 @@ async fn handle_dig_request(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_dig_result(
|
async fn get_dig_result(
|
||||||
dig_query: &String,
|
dig_query: &String,
|
||||||
state: &ServiceSharedState,
|
dns_resolver_name: &String,
|
||||||
do_full_lookup: bool,
|
state: &ServiceSharedState,
|
||||||
|
do_full_lookup: bool,
|
||||||
) -> DigResult {
|
) -> DigResult {
|
||||||
let name = &dig_query.trim().trim_end_matches(".").to_string();
|
let name = &dig_query.trim().trim_end_matches(".").to_string();
|
||||||
if match_domain_hidden_list(&name, &state.config.dns.hidden_suffixes) {
|
if match_domain_hidden_list(&name, &state.config.dns.hidden_suffixes) {
|
||||||
Default::default()
|
Default::default()
|
||||||
} else {
|
} else {
|
||||||
let idna_name = IdnaName::from_string(&name);
|
if let Some(dns_resolver) = &state.dns_resolvers.get(dns_resolver_name) {
|
||||||
DigResult {
|
let idna_name = IdnaName::from_string(&name);
|
||||||
records: simple_dns::lookup(
|
DigResult {
|
||||||
&state.dns_resolver,
|
records: simple_dns::lookup(
|
||||||
&(idna_name.idn.clone().unwrap_or(name.to_owned())+"."),
|
&dns_resolver,
|
||||||
do_full_lookup).await,
|
&(idna_name.idn.clone().unwrap_or(name.to_owned())+"."),
|
||||||
idn: idna_name,
|
do_full_lookup).await,
|
||||||
partial_lookup: !do_full_lookup,
|
idn: idna_name,
|
||||||
|
partial_lookup: !do_full_lookup,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Default::default();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,10 +116,10 @@ impl Engine {
|
|||||||
_ => text.into_response(),
|
_ => text.into_response(),
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("There was an error while rendering index.html: {e:?}");
|
println!("There was an error while rendering template {template_name}: {e:?}");
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
"Template error, contact owner or see logs.\n"
|
format!("Template error in {template_name}, contact owner or see logs.\n")
|
||||||
).into_response()
|
).into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user