Added IDN support

This commit is contained in:
Slatian
2023-02-23 00:58:38 +01:00
parent e3054e0158
commit d202ebb14e
5 changed files with 104 additions and 8 deletions

View File

@ -35,11 +35,15 @@ mod geoip;
mod ipinfo;
mod simple_dns;
mod templating_engine;
mod idna;
use crate::geoip::QueryAsn;
use crate::geoip::QueryLocation;
use geoip::AsnResult;
use geoip::LocationResult;
use crate::geoip::{
QueryAsn,
QueryLocation,
AsnResult,
LocationResult,
};
use crate::idna::IdnaName;
use crate::templating_engine::{
View,
@ -69,6 +73,13 @@ pub struct IpResult {
ip_info: AddressInfo,
}
#[derive(serde::Deserialize, serde::Serialize, Default, Clone)]
pub struct DigResult {
records: simple_dns::DnsLookupResult,
#[serde(skip_serializing_if = "IdnaName::was_ascii")]
idna: IdnaName,
}
struct ServiceSharedState {
templating_engine: templating_engine::Engine,
dns_resolver: TokioAsyncResolver,
@ -467,11 +478,18 @@ async fn handle_dig_request(
async fn get_dig_result(
dig_query: &String,
state: &ServiceSharedState,
) -> simple_dns::DnsLookupResult {
) -> DigResult {
let name = &dig_query.trim().trim_end_matches(".").to_string();
if match_domain_hidden_list(&name, &state.config.dns.hidden_suffixes) {
Default::default()
} else {
simple_dns::lookup(&state.dns_resolver, name, true).await
let idna_name = IdnaName::from_string(&name);
DigResult {
records: simple_dns::lookup(
&state.dns_resolver,
&(idna_name.idna.clone().unwrap_or(name.to_owned())+"."),
true).await,
idna: idna_name,
}
}
}