SoCloseSociety/sonar

GitHub: SoCloseSociety/sonar

实时地缘政治 OSINT 情报终端,聚合 20+ 数据源在 3D 地球仪上可视化,结合 LLM 分析与 Polymarket 预测市场信号关联,提供事件追踪和交易机会发现。

Stars: 1 | Forks: 0

# SONAR ### 实时地缘政治情报终端 **开源 OSINT 平台** 聚合 20 多个实时数据源,将事件呈现在 3D 地球仪上,生成与 Polymarket 预测市场相关的交易信号,并实时推送警报。 [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Python 3.12](https://img.shields.io/badge/Python-3.12-3776AB?logo=python&logoColor=white)](https://www.python.org/) [![TypeScript](https://img.shields.io/badge/TypeScript-5.6-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![React 18](https://img.shields.io/badge/React-18-61DAFB?logo=react&logoColor=black)](https://reactjs.org/) [![FastAPI](https://img.shields.io/badge/FastAPI-0.115-009688?logo=fastapi&logoColor=white)](https://fastapi.tiangolo.com/) [![Docker](https://img.shields.io/badge/Docker-Compose-2496ED?logo=docker&logoColor=white)](https://docs.docker.com/compose/) [![PostgreSQL](https://img.shields.io/badge/PostgreSQL-16-4169E1?logo=postgresql&logoColor=white)](https://www.postgresql.org/) [![Stars](https://img.shields.io/github/stars/soclosesociety/sonar?style=social)](https://github.com/soclosesociety/sonar/stargazers) [快速开始](#-quick-start) · [功能](#-features) · [架构](#-architecture) · [配置](#-configuration) · [贡献](#-contributing)
## 截图 | 3D 地球仪 — 实时事件 | 情报流 — 实时 | 仪表板 — 紧张局势 + 信号 | |---|---|---| | ![Globe](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/00dcd4e071004147.png) | ![Intel](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/8f4497cf5e004153.png) | ![Dashboard](https://static.pigsec.cn/wp-content/uploads/repos/2026/06/1ee45538fe004200.png) | ## 功能 - **20 多个实时情报来源**:80 多个 RSS 订阅源、GDELT、Twitter(60 多个账户)、Telegram(38 多个频道)、OpenSky 航班、AISstream 船舶、USGS 地震、NOAA 天气、NASA FIRMS 火灾、ACLED 冲突、Reddit OSINT、政府信息源、网络威胁、Shodan、Polymarket、YouTube 实时新闻、网络摄像头 - **3D 实时地球仪**(Three.js + react-globe.gl),包含事件、航班、船舶、危险源和敏感区域 - **交易信号**:通过事件/市场与 Polymarket 预测市场的关联自动生成 - **LLM 驱动的分析**:通过 Ollama(本地、免费)实现,并提供基于规则的关键词回退机制 - **实时流传输**:通过 Socket.IO + Server-Sent Events 实现 - **Web3 + 邮箱认证**(JWT、bcrypt、ethers.js 钱包签名) - **Telegram bot**:用于警报和管理 - **紧张局势评分**:包含 48 小时历史记录和各地区热力图 - **异常检测**:针对敏感区域附近的航班/船舶模式进行检测 ## 快速开始 ### 前置条件 - Docker & Docker Compose(Mac/Windows 上的 Docker Desktop,或 Linux 上的 Docker Engine) - 4 GB 可用内存,30 GB 可用磁盘空间 ### 3 条命令安装 ``` git clone https://github.com/soclosesociety/sonar.git cd sonar cp .env.example .env ``` 编辑 `.env` — 至少生成强密钥: ``` openssl rand -hex 32 # → paste as SECRET_KEY openssl rand -hex 32 # → paste as JWT_SECRET ``` 然后执行: ``` docker compose up -d ``` 等待约 30 秒让容器变得健康: ``` docker compose ps # 所有 5 个服务应显示 "healthy" ``` 在浏览器中打开 **http://localhost**(nginx 默认在 80 端口运行;如果该端口被占用,请参阅下方的[端口冲突](#port-conflicts))。 ### 首次登录 应用没有默认管理员账户 — 通过 UI (`/register`) 注册你的第一个用户。第一个用户*不会*自动成为管理员;需手动提升权限: ``` docker compose exec postgres \ psql -U sonar -d sonar -c "UPDATE users SET role='admin' WHERE email='you@example.com';" ``` ### 端口冲突 如果端口 80、3000、5432、6379 或 8001 已被占用,请创建 `docker-compose.override.yml`: ``` services: postgres: { ports: !override ["5435:5432"] } redis: { ports: !override ["6383:6379"] } backend: { ports: !override ["8003:8000"] } nginx: { ports: !override ["8090:80"] } ``` 然后执行 `docker compose up -d`。应用将位于 **http://localhost:8090**。 ## 架构 ``` ┌─────────┐ ┌──────────┐ ┌────────────┐ │ nginx │────▶│ frontend │ │ postgres │ │ :80 │ │ :3000 │ │ :5432 │ └─────────┘ └──────────┘ │ +PostGIS │ └─────┬──────┘ ┌──────────────────────────────────────┤ │ backend :8000 │ │ ┌────────────┐ ┌──────────────┐ │ │ │ Ingestion │ │ Analyzer │ │ │ │ 20 sources │ │ Pipeline │ │ │ └─────┬──────┘ └──────┬───────┘ │ │ │ ┌────────┐ │ │ │ └───▶│ Redis │◀──┘ │ │ │ :6379 │ │ │ └────────┘ │ └──────────────────────────────────────┘ ``` ### 技术栈 | 层级 | 技术栈 | |---|---| | 后端 | Python 3.12 · FastAPI 0.115 · SQLAlchemy 2 (异步) + GeoAlchemy2 · Alembic | | 前端 | React 18 · TypeScript 5.6 · Vite 6 · Tailwind 3 · Zustand 5 | | 3D / 地图 | Three.js · react-globe.gl · MapLibre GL · Recharts | | 实时通信 | Socket.IO · Server-Sent Events | | 数据库 | PostgreSQL 16 + PostGIS 3.4 | | 缓存 | Redis 7 | | LLM | Ollama (llama3.2:3b) — 本地、免费、无需 API key | | 认证 | JWT (python-jose) · bcrypt · ethers.js (Web3 钱包) | | 容器 | Docker Compose (5 个服务) | ### 数据流 `IngestionManager._process_event` → `AnalysisPipeline.process` → `RuleBasedSignalGenerator.generate` → Postgres + Redis → Socket.IO/SSE → 前端 store → UI 组件。 ## 配置 所有设置都位于 `.env` 中。完整列表记录在 [.env.example](.env.example) 中。 ### 必需项 - `SECRET_KEY`, `JWT_SECRET` — 使用 `openssl rand -hex 32` 生成 - `POSTGRES_PASSWORD` — 强密码(在生产环境中拒绝使用默认值) ### 推荐(免费 API key) | 来源 | 获取 key 的地址 | |---|---| | OpenSky (航班) | https://opensky-network.org/register | | AISstream (船舶) | https://aisstream.io | | NASA FIRMS (火灾) | https://firms.modaps.eosdis.nasa.gov/api/area/ | | Windy (网络摄像头) | https://api.windy.com | | ACLED (冲突) | https://acleddata.com/register | | Shodan | https://account.shodan.io | | Twitter | https://developer.twitter.com | | YouTube | https://console.cloud.google.com (Data API v3) | 所有数据源都有优雅的回退机制 — 该应用在 **零 API key** 的情况下也能工作,只是获取的数据会较少。 ### LLM(本地、免费) 安装 [Ollama](https://ollama.com),然后拉取模型: ``` ollama pull llama3.2:3b ``` 后端默认通过 `http://host.docker.internal:11434` 与 Ollama 通信。如果 Ollama 宕机,分析器将回退到基于关键词的严重程度评估 — 应用仍会继续工作。 ### 调整阈值 ``` SIGNAL_MIN_CONFIDENCE=0.45 # raise to be stricter on trading signals MISPRICING_MIN_PCT=5 # min % edge to consider a Polymarket mispricing ALERT_MIN_SEVERITY=6 # 1–10 SCAN_INTERVAL_SECONDS=120 # ingestion cycle (lower = more pressure on sources) ``` ## 开发者工作流 ``` # 热重载模式 (Vite + uvicorn --reload) make dev # 日志 make logs # all containers make logs-backend # backend only # 测试 (13 个集成测试) docker compose exec backend pytest tests/test_api.py -v # 前端类型检查 / 构建 cd frontend && npx tsc --noEmit cd frontend && npx vite build # 数据库 make db-shell # psql make migrate # alembic upgrade head make migration msg="add foo column" # alembic autogenerate ``` ### 项目结构 ``` sonar/ ├── backend/ # FastAPI app │ ├── app/ │ │ ├── api/ # REST routers (auth, events, markets, signals, …) │ │ ├── analyzer/ # Pipeline + signal generators │ │ ├── ingestion/ # 20 source modules │ │ ├── auth/ # JWT + wallet + rate limiting │ │ ├── models/ # SQLAlchemy ORM │ │ ├── polymarket/ # Market tracker + opportunity engine │ │ └── telegram_bot/ │ ├── alembic/ # DB migrations │ └── tests/ # pytest integration tests ├── frontend/ │ └── src/ │ ├── components/ # Globe, dashboard, feed, layout… │ ├── pages/ # Login, Intel, Analysis, Settings… │ ├── stores/ # Zustand state │ ├── hooks/ # useWebSocket, etc. │ └── services/ # API + socket clients ├── data/ # Static reference data (geojson, keywords) ├── nginx/ # Reverse proxy config └── docker-compose.yml ``` ## 安全性 - **在任何可访问的环境部署之前,务必更改 `SECRET_KEY`、`JWT_SECRET` 和 `POSTGRES_PASSWORD`** - 登录受速率限制(每个 IP+邮箱每 5 分钟 8 次尝试) - 注册受速率限制(每个 IP 每小时 5 次) - 网络摄像头缩略图代理禁用重定向以防止 SSRF - Bearer token 认证 (JWT) — 前端将 token 存储在 localStorage 中,服务器在每个请求中进行验证 - 管理员端点(`/settings`、`/signals/regenerate` 等)要求 role=admin 请通过 [SECURITY.md](SECURITY.md) 报告漏洞。 ## 许可证 [MIT](LICENSE) — 随意使用、复刻、发布。
由 [**SoCloseSociety**](https://github.com/soclosesociety) 精心构建 · 欢迎贡献 🌍
标签:AI风险缓解, AV绕过, ESC4, FastAPI, OSINT, Python, React, Syscalls, 地缘政治情报, 搜索引擎查询, 无后门, 测试用例, 版权保护, 自动化攻击, 逆向工具