mirror of
https://github.com/smittix/intercept.git
synced 2026-05-29 21:09:26 -07:00
Fix agent mode UI state sync for pager, WiFi, and Bluetooth
- Fix device dropdown for agent mode by checking sdr_devices key - Fix pager checkStatus() to use agent endpoint when in agent mode - Fix WiFi checkScanStatus() to be agent-aware - Fix Bluetooth checkScanStatus() to be agent-aware These fixes prevent the UI from reverting to 'stopped' state when the agent is actually running a mode.
This commit is contained in:
@@ -658,22 +658,30 @@ async function refreshAgentDevices(agentId) {
|
||||
console.log('Agent data received:', data);
|
||||
|
||||
if (data.agent && data.agent.interfaces) {
|
||||
const devices = data.agent.interfaces.devices || [];
|
||||
// Agent stores SDR devices in interfaces.sdr_devices (matching local mode)
|
||||
const devices = data.agent.interfaces.sdr_devices || data.agent.interfaces.devices || [];
|
||||
console.log(`Found ${devices.length} devices on agent`);
|
||||
populateDeviceSelect(devices);
|
||||
|
||||
// Update SDR type dropdown if device has sdr_type
|
||||
if (devices.length > 0 && devices[0].sdr_type) {
|
||||
// Auto-select SDR type if devices found
|
||||
if (devices.length > 0) {
|
||||
const firstType = devices[0].sdr_type || 'rtlsdr';
|
||||
const sdrTypeSelect = document.getElementById('sdrTypeSelect');
|
||||
if (sdrTypeSelect) {
|
||||
sdrTypeSelect.value = devices[0].sdr_type;
|
||||
sdrTypeSelect.value = firstType;
|
||||
}
|
||||
}
|
||||
|
||||
// Directly populate device dropdown for agent mode
|
||||
// (Don't use onSDRTypeChanged since currentDeviceList is template-scoped)
|
||||
populateDeviceSelect(devices);
|
||||
} else {
|
||||
console.warn('No interfaces found in agent data');
|
||||
console.warn('No interfaces found in agent data:', data);
|
||||
// Show empty devices
|
||||
populateDeviceSelect([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to refresh agent devices:', error);
|
||||
populateDeviceSelect([]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -650,10 +650,17 @@ const BluetoothMode = (function() {
|
||||
|
||||
async function checkScanStatus() {
|
||||
try {
|
||||
const response = await fetch('/api/bluetooth/scan/status');
|
||||
const data = await response.json();
|
||||
const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local';
|
||||
const endpoint = isAgentMode
|
||||
? `/controller/agents/${currentAgent}/bluetooth/status`
|
||||
: '/api/bluetooth/scan/status';
|
||||
|
||||
if (data.is_scanning) {
|
||||
const response = await fetch(endpoint);
|
||||
const responseData = await response.json();
|
||||
// Handle agent response format (may be nested in 'result')
|
||||
const data = isAgentMode && responseData.result ? responseData.result : responseData;
|
||||
|
||||
if (data.is_scanning || data.running) {
|
||||
setScanning(true);
|
||||
startEventStream();
|
||||
}
|
||||
|
||||
@@ -571,12 +571,19 @@ const WiFiMode = (function() {
|
||||
|
||||
async function checkScanStatus() {
|
||||
try {
|
||||
const response = await fetch(`${CONFIG.apiBase}/scan/status`);
|
||||
const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local';
|
||||
const endpoint = isAgentMode
|
||||
? `/controller/agents/${currentAgent}/wifi/status`
|
||||
: `${CONFIG.apiBase}/scan/status`;
|
||||
|
||||
const response = await fetch(endpoint);
|
||||
if (!response.ok) return;
|
||||
|
||||
const status = await response.json();
|
||||
const data = await response.json();
|
||||
// Handle agent response format (may be nested in 'result')
|
||||
const status = isAgentMode && data.result ? data.result : data;
|
||||
|
||||
if (status.is_scanning) {
|
||||
if (status.is_scanning || status.running) {
|
||||
setScanning(true, status.scan_mode);
|
||||
if (status.scan_mode === 'deep') {
|
||||
startEventStream();
|
||||
|
||||
@@ -3447,13 +3447,22 @@
|
||||
}
|
||||
|
||||
function checkStatus() {
|
||||
fetch('/status')
|
||||
const isAgentMode = typeof currentAgent !== 'undefined' && currentAgent !== 'local';
|
||||
const endpoint = isAgentMode
|
||||
? `/controller/agents/${currentAgent}/pager/status`
|
||||
: '/status';
|
||||
|
||||
fetch(endpoint)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.running !== isRunning) {
|
||||
setRunning(data.running);
|
||||
if (data.running && !eventSource) {
|
||||
startStream();
|
||||
// Handle agent response format (may be nested in 'result')
|
||||
const statusData = isAgentMode && data.result ? data.result : data;
|
||||
const running = statusData.running;
|
||||
|
||||
if (running !== isRunning) {
|
||||
setRunning(running);
|
||||
if (running && !eventSource) {
|
||||
startStream(isAgentMode);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user