/** * Copyright 2026 aphrody-code * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { dnsRecon, getChromiumCookies } from "../../../../src/rust/bridge.ts"; import { homedir } from "node:os"; import { join } from "node:path"; import { existsSync } from "node:fs"; export interface EndpointProbeResult { url: string; status: number; latencyMs: number; reachable: boolean; } export interface FutReconSummary { domain: string; subdomains: string[]; probes: EndpointProbeResult[]; } /** * Standard known EA Sports FC Ultimate Team endpoints across worldwide clusters. */ export const KNOWN_EA_UTAS_ENDPOINTS = [ "https://utas.mob.v1.fut.ea.com", "https://utas.external.s2.fut.ea.com", "https://utas.fut.ea.com", "https://accounts.ea.com", "https://gateway.ea.com", "https://futmin.ea.com", ]; /** * Executes DNS reconnaissance via Rust FFI to discover live subdomains and CDN nodes. */ export function reconFutDns(domain = "ea.com"): string[] { try { return dnsRecon(domain); } catch { // Fallback when network or FFI fails return [domain]; } } /** * Finds default Chromium user data directory on Linux / macOS / Windows. */ export function getDefaultChromiumUserDataDir(): string | null { const home = homedir(); const candidates = [ join(home, ".config/google-chrome"), join(home, ".config/chromium"), join(home, ".config/BraveSoftware/Brave-Browser"), join(home, "AppData/Local/Google/Chrome/User Data"), join(home, "AppData/Local/BraveSoftware/Brave-Browser/User Data"), ]; for (const path of candidates) { if (existsSync(path)) return path; } return null; } /** * Harvests EA session cookies directly from local Chromium SQLite cookie jar via Rust FFI. * Enables instant authentication for EaUtasClient without opening a browser or logging in manually. */ export function harvestEaChromiumCookies( customUserDataDir?: string, profile = "Default", ): Record { const dir = customUserDataDir ?? getDefaultChromiumUserDataDir(); if (!dir) return {}; try { const rawCookies = getChromiumCookies(dir, profile, ".ea.com") as Array<{ name?: string; value?: string; }>; const cookies: Record = {}; if (Array.isArray(rawCookies)) { for (const c of rawCookies) { if (c.name && c.value) { cookies[c.name] = c.value; } } } return cookies; } catch { return {}; } } /** * Probes latency and availability of EA UTAS endpoints using Bun's native HTTP stack. */ export async function probeEaEndpoints( endpoints: string[] = KNOWN_EA_UTAS_ENDPOINTS, ): Promise { const results: EndpointProbeResult[] = []; for (const url of endpoints) { const start = performance.now(); try { const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), 3500); const resp = await fetch(url, { method: "GET", signal: controller.signal, headers: { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", }, }); clearTimeout(timeout); const latencyMs = Math.round((performance.now() - start) * 100) / 100; results.push({ url, status: resp.status, latencyMs, reachable: true, }); } catch { const latencyMs = Math.round((performance.now() - start) * 100) / 100; results.push({ url, status: 0, latencyMs, reachable: false, }); } } return results; }