| 246 | } |
| 247 | |
| 248 | fn parse_user_agent(ua: Option<&str>) -> (String, String, String) { |
| 249 | let raw = ua.unwrap_or_default().trim(); |
| 250 | if raw.is_empty() { |
| 251 | return ("unknown".to_string(), "unknown".to_string(), "unknown".to_string()); |
| 252 | } |
| 253 | |
| 254 | let lower = raw.to_ascii_lowercase(); |
| 255 | |
| 256 | let device_type = |
| 257 | if lower.contains("bot") || lower.contains("spider") || lower.contains("crawler") { |
| 258 | "bot" |
| 259 | } else if lower.contains("ipad") |
| 260 | || lower.contains("tablet") |
| 261 | || lower.contains("kindle") |
| 262 | || lower.contains("playbook") |
| 263 | { |
| 264 | "tablet" |
| 265 | } else if lower.contains("mobile") |
| 266 | || lower.contains("iphone") |
| 267 | || lower.contains("ipod") |
| 268 | || lower.contains("windows phone") |
| 269 | { |
| 270 | "mobile" |
| 271 | } else { |
| 272 | "desktop" |
| 273 | }; |
| 274 | |
| 275 | let os_family = if lower.contains("windows nt") { |
| 276 | "Windows" |
| 277 | } else if lower.contains("android") { |
| 278 | "Android" |
| 279 | } else if lower.contains("iphone") || lower.contains("ipad") || lower.contains("cpu iphone") { |
| 280 | "iOS" |
| 281 | } else if lower.contains("mac os x") || lower.contains("macintosh") { |
| 282 | "macOS" |
| 283 | } else if lower.contains("cros") { |
| 284 | "ChromeOS" |
| 285 | } else if lower.contains("linux") { |
| 286 | "Linux" |
| 287 | } else { |
| 288 | "unknown" |
| 289 | }; |
| 290 | |
| 291 | let browser_family = if lower.contains("edg/") { |
| 292 | "Edge" |
| 293 | } else if lower.contains("opr/") || lower.contains("opera") { |
| 294 | "Opera" |
| 295 | } else if lower.contains("firefox/") { |
| 296 | "Firefox" |
| 297 | } else if lower.contains("chrome/") && !lower.contains("edg/") { |
| 298 | "Chrome" |
| 299 | } else if lower.contains("safari/") && !lower.contains("chrome/") && !lower.contains("chromium") |
| 300 | { |
| 301 | "Safari" |
| 302 | } else if lower.contains("msie") || lower.contains("trident/") { |
| 303 | "IE" |
| 304 | } else if lower.contains("curl/") { |
| 305 | "curl" |