46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
use crate::conf::get_config;
|
|
|
|
/// Checks if a domain is present in the blacklist of unwanted domains.
|
|
///
|
|
/// If a match is found, it immediately returns `true`. Otherwise, it returns `false`.
|
|
pub fn check_blacklist(domain: &str) -> bool {
|
|
let conf = get_config();
|
|
let conf = conf.websites.as_ref();
|
|
|
|
// TODO : Block IPs
|
|
// TODO : Test SSRF
|
|
|
|
let blacklisted_domains = conf
|
|
.map(|x| x.BLACKLIST_DOMAINS.as_ref())
|
|
.unwrap_or_default();
|
|
|
|
check_regex(domain, blacklisted_domains.unwrap_or(&Vec::new()))
|
|
}
|
|
|
|
pub fn check_blacklist_path(domain: &str, path: &str) -> bool {
|
|
let conf = get_config();
|
|
let conf = conf.websites.as_ref();
|
|
|
|
if let Some(website) = conf {
|
|
let empty = Vec::new();
|
|
let domain_conf = website.domains.as_ref().unwrap_or(&empty);
|
|
if let Some(domain_conf) = domain_conf.iter().find(|x| x.domain == domain) {
|
|
let empty = Vec::new();
|
|
let blacklist = domain_conf.blacklist_paths.as_ref().unwrap_or(&empty);
|
|
return check_regex(path, blacklist);
|
|
}
|
|
}
|
|
|
|
false
|
|
}
|
|
|
|
pub fn check_regex(input: &str, regexes: &Vec<String>) -> bool {
|
|
for regex in regexes {
|
|
let rgx = regex::Regex::new(regex).unwrap();
|
|
if rgx.is_match(input) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
false
|
|
}
|