pub const DOCS_URL: &str = "https://utilvo.com/edge-shield";
pub const THREAT_API_URL: &str = "https://utilvo.com/api/edge-shield/threats";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BotInspectionResult {
pub is_bot: bool,
pub is_seo_crawler: bool,
pub reasons: Vec<&'static str>,
}
pub fn inspect_request(ip: &str, user_agent: &str) -> BotInspectionResult {
let ua_lower = user_agent.to_ascii_lowercase();
for seo in ["googlebot", "google-inspectiontool", "bingbot", "adidxbot", "applebot", "duckduckbot", "yandexbot"] {
if ua_lower.contains(seo) {
return BotInspectionResult {
is_bot: false,
is_seo_crawler: true,
reasons: Vec::new(),
};
}
}
let clean_ip = ip.split(',').next().unwrap_or("").trim();
let mut reasons = Vec::new();
if clean_ip.starts_with("43.13")
|| clean_ip.starts_with("43.15")
|| clean_ip.starts_with("43.16")
|| clean_ip.starts_with("43.17")
|| clean_ip.starts_with("47.74.")
|| clean_ip.starts_with("47.82.")
|| clean_ip.starts_with("101.32.")
|| clean_ip.starts_with("101.33.")
|| clean_ip.starts_with("159.138.")
|| clean_ip.starts_with("149.232.")
{
reasons.push("CLOUD_SCRAPER_SUBNET");
}
for bad_ua in ["cpu iphone os 13_2_3", "tokenfoundrybot", "qlyzebot", "bytespider", "petalbot", "headlesschrome"] {
if ua_lower.contains(bad_ua) {
reasons.push("ROGUE_SCRAPER_USER_AGENT");
break;
}
}
BotInspectionResult {
is_bot: !reasons.is_empty(),
is_seo_crawler: false,
reasons,
}
}
pub fn generate_cloudflare_waf_expression() -> &'static str {
"(not cf.client.bot and (ip.src.asnum in {132203 45090 45102 37963 136907} or http.user_agent contains \"CPU iPhone OS 13_2_3\" or http.user_agent contains \"TokenFoundryBot\" or http.user_agent contains \"QlyzeBot\"))"
}