mirror of
https://github.com/sadoyan/aralez.git
synced 2026-10-23 06:01:35 +08:00
Polished lookup wait for DNS-01 challenge
This commit is contained in:
@@ -48,7 +48,7 @@ impl DnsProvider for CloudflareProvider {
|
|||||||
|
|
||||||
let record_id = res_json["result"]["id"].as_str().ok_or("missing id")?.to_string();
|
let record_id = res_json["result"]["id"].as_str().ok_or("missing id")?.to_string();
|
||||||
info!("Created TXT record name: {}, id: {}", name, record_id);
|
info!("Created TXT record name: {}, id: {}", name, record_id);
|
||||||
lookup_wait(name, "1.1.1.1", 60).await;
|
lookup_wait(name, Some("1.1.1.1"), 60, value).await;
|
||||||
Ok(record_id)
|
Ok(record_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-14
@@ -7,9 +7,9 @@ use std::net::IpAddr;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
pub async fn lookup_wait(record_name: &str, dns_server_ip: &str, max_wait_secs: u64) -> bool {
|
pub async fn lookup_wait(record_name: &str, dns_server_ip: Option<&str>, max_wait_secs: u64, expected_value: &str) -> bool {
|
||||||
let ip = IpAddr::from_str(dns_server_ip).unwrap_or_else(|_| IpAddr::from([1, 1, 1, 1]));
|
let target_ip = dns_server_ip.and_then(|ip| IpAddr::from_str(ip).ok()).unwrap_or_else(|| IpAddr::from([1, 1, 1, 1]));
|
||||||
let name_server = NameServerConfig::udp(ip);
|
let name_server = NameServerConfig::udp(target_ip);
|
||||||
let config = ResolverConfig::from_name_servers(vec![name_server]);
|
let config = ResolverConfig::from_name_servers(vec![name_server]);
|
||||||
let mut opts = ResolverOpts::default();
|
let mut opts = ResolverOpts::default();
|
||||||
opts.cache_size = 0;
|
opts.cache_size = 0;
|
||||||
@@ -22,12 +22,13 @@ pub async fn lookup_wait(record_name: &str, dns_server_ip: &str, max_wait_secs:
|
|||||||
let start = std::time::Instant::now();
|
let start = std::time::Instant::now();
|
||||||
let poll_interval = Duration::from_secs(3);
|
let poll_interval = Duration::from_secs(3);
|
||||||
while start.elapsed().as_secs() < max_wait_secs {
|
while start.elapsed().as_secs() < max_wait_secs {
|
||||||
match resolver.txt_lookup(record_name).await {
|
if let Ok(txt_lookup) = resolver.txt_lookup(record_name).await {
|
||||||
Ok(txt_lookup) => {
|
for record in txt_lookup.answers() {
|
||||||
for record in txt_lookup.answers() {
|
if let RData::TXT(txt) = &record.data {
|
||||||
if let RData::TXT(txt) = &record.data {
|
for data in &txt.txt_data {
|
||||||
for data in &txt.txt_data {
|
if let Ok(txt_str) = std::str::from_utf8(data) {
|
||||||
if let Ok(txt_str) = std::str::from_utf8(data) {
|
if txt_str == expected_value {
|
||||||
|
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||||
info!("DNS record propagated successfully for {} : {}", record_name, txt_str);
|
info!("DNS record propagated successfully for {} : {}", record_name, txt_str);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -35,13 +36,10 @@ pub async fn lookup_wait(record_name: &str, dns_server_ip: &str, max_wait_secs:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
} else {
|
||||||
info!("Waiting for TXT record {}", record_name);
|
info!("Waiting for TXT record {}", record_name);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tokio::time::sleep(poll_interval).await;
|
tokio::time::sleep(poll_interval).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user