mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2025-07-16 14:03:28 +02:00
Added IDN support
This commit is contained in:
30
src/main.rs
30
src/main.rs
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user