mirror of
https://github.com/smittix/intercept.git
synced 2026-04-24 06:40:00 -07:00
- Add Listening Post mode with frequency scanner and audio monitoring - Add dependency warning for aircraft dashboard listen feature - Auto-restart audio when switching frequencies - Fix toolbar overflow on aircraft dashboard custom frequency - Update setup script with full macOS/Debian support - Clean up README and documentation for clarity - Add sox and dump1090 to Dockerfile - Add comprehensive tool reference to HARDWARE.md - Add correlation, settings, and database utilities - Add new test files for routes, validation, correlation, database 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
120 lines
3.7 KiB
Python
120 lines
3.7 KiB
Python
"""Device correlation routes."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from flask import Blueprint, jsonify, request, Response
|
|
|
|
import app as app_module
|
|
from utils.correlation import get_correlations
|
|
from utils.logging import get_logger
|
|
|
|
logger = get_logger('intercept.correlation')
|
|
|
|
correlation_bp = Blueprint('correlation', __name__, url_prefix='/correlation')
|
|
|
|
|
|
@correlation_bp.route('', methods=['GET'])
|
|
def get_device_correlations() -> Response:
|
|
"""
|
|
Get device correlations between WiFi and Bluetooth.
|
|
|
|
Query params:
|
|
min_confidence: Minimum confidence threshold (default 0.5)
|
|
include_historical: Include database correlations (default true)
|
|
"""
|
|
min_confidence = request.args.get('min_confidence', 0.5, type=float)
|
|
include_historical = request.args.get('include_historical', 'true').lower() == 'true'
|
|
|
|
try:
|
|
# Get current device data
|
|
wifi_devices = dict(app_module.wifi_networks)
|
|
wifi_devices.update(dict(app_module.wifi_clients))
|
|
bt_devices = dict(app_module.bt_devices)
|
|
|
|
# Calculate correlations
|
|
correlations = get_correlations(
|
|
wifi_devices=wifi_devices,
|
|
bt_devices=bt_devices,
|
|
min_confidence=min_confidence,
|
|
include_historical=include_historical
|
|
)
|
|
|
|
return jsonify({
|
|
'status': 'success',
|
|
'correlations': correlations,
|
|
'wifi_count': len(wifi_devices),
|
|
'bt_count': len(bt_devices)
|
|
})
|
|
except Exception as e:
|
|
logger.error(f"Error calculating correlations: {e}")
|
|
return jsonify({
|
|
'status': 'error',
|
|
'message': str(e)
|
|
}), 500
|
|
|
|
|
|
@correlation_bp.route('/analyze', methods=['POST'])
|
|
def analyze_correlation() -> Response:
|
|
"""
|
|
Analyze specific device pair for correlation.
|
|
|
|
Request body:
|
|
wifi_mac: WiFi device MAC address
|
|
bt_mac: Bluetooth device MAC address
|
|
"""
|
|
data = request.json or {}
|
|
wifi_mac = data.get('wifi_mac')
|
|
bt_mac = data.get('bt_mac')
|
|
|
|
if not wifi_mac or not bt_mac:
|
|
return jsonify({
|
|
'status': 'error',
|
|
'message': 'wifi_mac and bt_mac are required'
|
|
}), 400
|
|
|
|
try:
|
|
# Get device data
|
|
wifi_device = app_module.wifi_networks.get(wifi_mac)
|
|
if not wifi_device:
|
|
wifi_device = app_module.wifi_clients.get(wifi_mac)
|
|
|
|
bt_device = app_module.bt_devices.get(bt_mac)
|
|
|
|
if not wifi_device:
|
|
return jsonify({
|
|
'status': 'error',
|
|
'message': f'WiFi device {wifi_mac} not found'
|
|
}), 404
|
|
|
|
if not bt_device:
|
|
return jsonify({
|
|
'status': 'error',
|
|
'message': f'Bluetooth device {bt_mac} not found'
|
|
}), 404
|
|
|
|
# Calculate correlation for this specific pair
|
|
correlations = get_correlations(
|
|
wifi_devices={wifi_mac: wifi_device},
|
|
bt_devices={bt_mac: bt_device},
|
|
min_confidence=0.0, # Show even low confidence for analysis
|
|
include_historical=True
|
|
)
|
|
|
|
if correlations:
|
|
return jsonify({
|
|
'status': 'success',
|
|
'correlation': correlations[0]
|
|
})
|
|
else:
|
|
return jsonify({
|
|
'status': 'success',
|
|
'correlation': None,
|
|
'message': 'No correlation detected between these devices'
|
|
})
|
|
except Exception as e:
|
|
logger.error(f"Error analyzing correlation: {e}")
|
|
return jsonify({
|
|
'status': 'error',
|
|
'message': str(e)
|
|
}), 500
|