Fix rdnn block checks

This commit is contained in:
asonix 2021-02-10 00:14:42 -06:00
parent c3d5de600d
commit 2619a93643
2 changed files with 7 additions and 2 deletions

1
.env
View file

@ -1,2 +1,3 @@
HOSTNAME=localhost:8079
PORT=8079
RESTRICTED_MODE=true

View file

@ -169,20 +169,24 @@ impl Inner {
fn is_allowed(&self, domain: &str) -> bool {
let prefix = domain_prefix(domain);
let reverse_domain = domain_key(domain);
if self.restricted_mode {
self.allowed_domains
.scan_prefix(prefix)
.keys()
.filter_map(|res| res.ok())
.any(|rdnn| domain.starts_with(String::from_utf8_lossy(&rdnn).as_ref()))
.any(|rdnn| {
let rdnn_string = String::from_utf8_lossy(&rdnn);
reverse_domain.starts_with(rdnn_string.as_ref())
})
} else {
!self
.blocked_domains
.scan_prefix(prefix)
.keys()
.filter_map(|res| res.ok())
.any(|rdnn| domain.starts_with(String::from_utf8_lossy(&rdnn).as_ref()))
.any(|rdnn| reverse_domain.starts_with(String::from_utf8_lossy(&rdnn).as_ref()))
}
}
}