Fix tshark hex parsing and add API key settings UI

Parse tshark GSM field values with int(value, 0) instead of int(value)
to auto-detect hex 0x-prefixed output (e.g. 0x039e for TMSI/LAC/CID).
Without this, every tshark line with hex values fails to parse, causing
0 devices to be captured during monitoring.

Also add API Keys tab to Settings modal for configuring OpenCellID key
via the UI (in addition to env var), with status display and usage bar.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Smittix
2026-02-08 20:35:31 +00:00
parent 98f6d18bea
commit 90e88fc469
4 changed files with 242 additions and 11 deletions

View File

@@ -65,6 +65,15 @@ def lookup_cell_coordinates(mcc: int, mnc: int, lac: int, cid: int) -> dict[str,
return None
def _get_api_key() -> str:
"""Get OpenCellID API key at runtime (env var first, then database)."""
env_key = config.GSM_OPENCELLID_API_KEY
if env_key:
return env_key
from utils.database import get_setting
return get_setting('gsm.opencellid.api_key', '')
def lookup_cell_from_api(mcc: int, mnc: int, lac: int, cid: int) -> dict[str, Any] | None:
"""
Lookup cell tower from OpenCellID API and cache result.
@@ -81,9 +90,14 @@ def lookup_cell_from_api(mcc: int, mnc: int, lac: int, cid: int) -> dict[str, An
Returns None if API call fails or cell not found.
"""
try:
api_key = _get_api_key()
if not api_key:
logger.warning("OpenCellID API key not configured")
return None
api_url = config.GSM_OPENCELLID_API_URL
params = {
'key': config.GSM_OPENCELLID_API_KEY,
'key': api_key,
'mcc': mcc,
'mnc': mnc,
'lac': lac,