Add duplicate domain check, closes #5
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s

This commit is contained in:
Neshura 2024-04-10 23:22:11 +02:00
parent a028d4245b
commit 76a567d1bf
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C

View file

@ -146,6 +146,7 @@ impl Config {
let msg = format!("Using {}", path);
directories.push(system_path.to_path_buf());
info!(msg);
Self::check_for_duplicate_domains(&user_config.domain_configs);
Ok((Config {
user: user_config,
system: data,
@ -211,7 +212,7 @@ impl Config {
let new_root = root.join(paths[0]);
println!("{}", &new_root.display());
let ret = unix::fs::chown(&new_root, Some(uid), Some(gid));
let mut new_paths = paths.clone();
new_paths.remove(0);
match Self::fix_path_ownership(new_root, new_paths) {
@ -224,6 +225,32 @@ impl Config {
}
}
}
fn check_for_duplicate_domains(domain_configs: &[DomainLinkConfig]) {
let mut checked_domains: Vec<String> = vec![];
for (cfg_idx, config) in domain_configs.iter().enumerate() {
for (idx, domain) in config.domains.iter().enumerate() {
if !checked_domains.contains(domain) {
if config.domains[idx+1..].contains(domain) {
// Error
let msg = format!("Duplicate Domain use detected for '{domain}");
warn!(msg);
checked_domains.push(domain.clone());
}
else {
for d in domain_configs[cfg_idx+1..].iter() {
if d.domains.contains(domain) {
let msg = format!("Duplicate Domain use detected for '{domain}");
warn!(msg);
checked_domains.push(domain.clone());
break;
}
}
}
}
}
}
}
}
#[actix_web::main]