parent
0f6e5f5b10
commit
8df8edeeca
15 changed files with 591 additions and 124 deletions
|
@ -1,17 +1,17 @@
|
|||
use crate::conf::get_config;
|
||||
|
||||
/// Checks if a domain is present in the blacklist of unwanted domains.
|
||||
///
|
||||
/// This function checks the `$BLACKLIST_DOMAINS` environment variable for a comma-separated list of regular expressions to match against.
|
||||
/// If a match is found, it immediately returns `true`. Otherwise, it returns `false`.
|
||||
pub fn check_blacklist(domain: &str) -> bool {
|
||||
let blacklist_raw = std::env::var("BLACKLIST_DOMAINS").unwrap_or_default();
|
||||
let conf = get_config();
|
||||
let conf = conf.websites.as_ref();
|
||||
|
||||
if blacklist_raw.is_empty() {
|
||||
return false;
|
||||
}
|
||||
let blacklisted_domains = conf
|
||||
.map(|x| x.BLACKLIST_DOMAINS.as_ref())
|
||||
.unwrap_or_default();
|
||||
|
||||
let blacklist: Vec<&str> = blacklist_raw.split(',').collect();
|
||||
|
||||
for domain_regex in blacklist {
|
||||
for domain_regex in blacklisted_domains.unwrap_or(&Vec::new()) {
|
||||
let rgx = regex::Regex::new(domain_regex).unwrap();
|
||||
if rgx.is_match(domain) {
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue