aboutsummaryrefslogtreecommitdiff
path: root/src/dns_updater.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-12-11 16:42:00 +0100
committerAlex Auvolat <alex@adnab.me>2022-12-11 16:42:00 +0100
commit2e3442faa9625f706b4131417381d8fd2fb3bda3 (patch)
tree7a757c029c0dd00005c7e0eb59fb46df55fc3aa1 /src/dns_updater.rs
parentb26d4d7bbad7c77f466a00f0bd21e7e4ea09c3b1 (diff)
downloadD53-2e3442faa9625f706b4131417381d8fd2fb3bda3.tar.gz
D53-2e3442faa9625f706b4131417381d8fd2fb3bda3.zip
Fix subdomain matching
Diffstat (limited to 'src/dns_updater.rs')
-rw-r--r--src/dns_updater.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/dns_updater.rs b/src/dns_updater.rs
index e65689d..e525f8a 100644
--- a/src/dns_updater.rs
+++ b/src/dns_updater.rs
@@ -51,7 +51,10 @@ pub async fn dns_updater_task(
}
// Skip entries for unallowed domains
- if !allowed_domains.iter().any(|d| key.dns_path.ends_with(d)) {
+ if !allowed_domains
+ .iter()
+ .any(|d| key.dns_path == *d || key.dns_path.ends_with(&format!(".{}", d)))
+ {
error!(
domain = key.dns_path,
"domain/subdomain/hostname not in allowed list",
@@ -59,7 +62,9 @@ pub async fn dns_updater_task(
continue;
}
- let provider = providers.iter().find(|p| key.dns_path.ends_with(&p.domain));
+ let provider = providers.iter().find(|p| {
+ key.dns_path == p.domain || key.dns_path.ends_with(&format!(".{}", p.domain))
+ });
if let Some(provider) = provider {
if let Err(e) = update_dns_entry(key, value, provider).await {
@@ -87,11 +92,15 @@ async fn update_dns_entry(
value: &DnsEntryValue,
provider: &DomainProvider,
) -> Result<()> {
- let subdomain = key
- .dns_path
- .strip_suffix(&provider.domain)
- .unwrap()
- .trim_end_matches('.');
+ let subdomain = if key.dns_path == provider.domain {
+ None
+ } else {
+ Some(
+ key.dns_path
+ .strip_suffix(&format!(".{}", provider.domain))
+ .unwrap(),
+ )
+ };
info!(
record = key.to_string(),
target = value.to_string(),
@@ -116,7 +125,7 @@ async fn update_dns_entry(
}
provider
.provider
- .update_a(&provider.domain, &subdomain, &targets)
+ .update_a(&provider.domain, subdomain, &targets)
.await?;
}
DnsRecordType::AAAA => {
@@ -129,7 +138,7 @@ async fn update_dns_entry(
}
provider
.provider
- .update_aaaa(&provider.domain, &subdomain, &targets)
+ .update_aaaa(&provider.domain, subdomain, &targets)
.await?;
}
DnsRecordType::CNAME => {
@@ -145,7 +154,7 @@ async fn update_dns_entry(
}
provider
.provider
- .update_cname(&provider.domain, &subdomain, &targets[0])
+ .update_cname(&provider.domain, subdomain, &targets[0])
.await?;
}
}