mirror of
				https://codeberg.org/slatian/service.echoip-slatecave.git
				synced 2025-10-31 17:08:08 +01:00 
			
		
		
		
	Fixed some idn edge cases
This commit is contained in:
		| @@ -11,8 +11,8 @@ use ::idna; | |||||||
| #[derive(Deserialize, Serialize, Copy, Default, Clone, PartialEq)] | #[derive(Deserialize, Serialize, Copy, Default, Clone, PartialEq)] | ||||||
| #[serde(rename_all="lowercase")] | #[serde(rename_all="lowercase")] | ||||||
| pub enum NameType { | pub enum NameType { | ||||||
| 	Ascii, |  | ||||||
| 	#[default] | 	#[default] | ||||||
|  | 	Ascii, | ||||||
| 	Unicode, | 	Unicode, | ||||||
| 	IDN, | 	IDN, | ||||||
| } | } | ||||||
| @@ -33,6 +33,10 @@ pub struct IdnaName { | |||||||
|  |  | ||||||
| impl IdnaName { | impl IdnaName { | ||||||
| 	pub fn from_string(s: &String) -> Self { | 	pub fn from_string(s: &String) -> Self { | ||||||
|  | 		if s == "" { | ||||||
|  | 			return Default::default(); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
| 		let mut original_was = NameType::Unicode; | 		let mut original_was = NameType::Unicode; | ||||||
| 		let unicode: String; | 		let unicode: String; | ||||||
| 		let decoder_error; | 		let decoder_error; | ||||||
|   | |||||||
							
								
								
									
										29
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -73,11 +73,16 @@ pub struct IpResult { | |||||||
| 	ip_info:  AddressInfo, | 	ip_info:  AddressInfo, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // We need this one to hide the partial lookup field when irelevant | ||||||
|  | pub fn not(b: &bool) -> bool { !b } | ||||||
|  |  | ||||||
| #[derive(serde::Deserialize, serde::Serialize, Default, Clone)] | #[derive(serde::Deserialize, serde::Serialize, Default, Clone)] | ||||||
| pub struct DigResult { | pub struct DigResult { | ||||||
| 	records: simple_dns::DnsLookupResult, | 	records: simple_dns::DnsLookupResult, | ||||||
| 	#[serde(skip_serializing_if = "IdnaName::was_ascii")] | 	#[serde(skip_serializing_if = "IdnaName::was_ascii")] | ||||||
| 	idn: IdnaName, | 	idn: IdnaName, | ||||||
|  | 	#[serde(skip_serializing_if = "not")] | ||||||
|  | 	partial_lookup: bool, | ||||||
| } | } | ||||||
|  |  | ||||||
| struct ServiceSharedState { | struct ServiceSharedState { | ||||||
| @@ -311,7 +316,9 @@ async fn handle_default_route( | |||||||
| 	let state = Arc::clone(&arc_state); | 	let state = Arc::clone(&arc_state); | ||||||
|  |  | ||||||
| 	if let Some(search_query) = search_query.query { | 	if let Some(search_query) = search_query.query { | ||||||
| 		return handle_search_request(search_query, false, settings, state).await; | 		if search_query.trim() != "" { | ||||||
|  | 			return handle_search_request(search_query, false, settings, state).await; | ||||||
|  | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	let result = get_ip_result(&address, &settings.lang, &state).await; | 	let result = get_ip_result(&address, &settings.lang, &state).await; | ||||||
| @@ -333,7 +340,7 @@ async fn handle_default_route( | |||||||
|  |  | ||||||
| async fn handle_search_request( | 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, | ||||||
| 	arc_state: Arc<ServiceSharedState>, | 	arc_state: Arc<ServiceSharedState>, | ||||||
| ) -> Response { | ) -> Response { | ||||||
| @@ -362,7 +369,10 @@ async fn handle_search_request( | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Fall back to treating it as a hostname | 	// Fall back to treating it as a hostname | ||||||
| 	return handle_dig_request(search_query.to_string(), settings, arc_state).await | 	return handle_dig_request( | ||||||
|  | 		search_query.to_string(), settings, arc_state, | ||||||
|  | 		!this_should_have_been_an_ip, | ||||||
|  | 	).await | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -455,18 +465,19 @@ async fn handle_dig_route_with_path( | |||||||
| 	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).await | 	return handle_dig_request(name, 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, | ||||||
| 	arc_state: Arc<ServiceSharedState>, | 	arc_state: Arc<ServiceSharedState>, | ||||||
|  | 	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).await; | 	let dig_result = get_dig_result(&dig_query, &state, do_full_lookup).await; | ||||||
|  |  | ||||||
| 	state.templating_engine.render_view( | 	state.templating_engine.render_view( | ||||||
| 		&settings, | 		&settings, | ||||||
| @@ -476,8 +487,9 @@ async fn handle_dig_request( | |||||||
| } | } | ||||||
|  |  | ||||||
| async fn get_dig_result( | async fn get_dig_result( | ||||||
| 	dig_query: &String, | 	dig_query:      &String, | ||||||
| 	state:     &ServiceSharedState, | 	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) { | ||||||
| @@ -488,8 +500,9 @@ async fn get_dig_result( | |||||||
| 			records: simple_dns::lookup( | 			records: simple_dns::lookup( | ||||||
| 				&state.dns_resolver, | 				&state.dns_resolver, | ||||||
| 				&(idna_name.idn.clone().unwrap_or(name.to_owned())+"."), | 				&(idna_name.idn.clone().unwrap_or(name.to_owned())+"."), | ||||||
| 				true).await, | 				do_full_lookup).await, | ||||||
| 			idn: idna_name, | 			idn: idna_name, | ||||||
|  | 			partial_lookup: !do_full_lookup, | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user