Toggle monitor mode on a remote agent's WiFi interface.
(agent_id: int)
| 534 | |
| 535 | @controller_bp.route('/agents/<int:agent_id>/wifi/monitor', methods=['POST']) |
| 536 | def proxy_wifi_monitor(agent_id: int): |
| 537 | """Toggle monitor mode on a remote agent's WiFi interface.""" |
| 538 | agent = get_agent(agent_id) |
| 539 | if not agent: |
| 540 | return api_error('Agent not found', 404) |
| 541 | |
| 542 | data = request.json or {} |
| 543 | |
| 544 | try: |
| 545 | client = create_client_from_agent(agent) |
| 546 | result = client.post('/wifi/monitor', data) |
| 547 | |
| 548 | # Refresh agent capabilities after monitor mode toggle so UI stays in sync |
| 549 | if result.get('status') == 'success': |
| 550 | try: |
| 551 | metadata = client.refresh_metadata() |
| 552 | if metadata.get('healthy'): |
| 553 | caps = metadata.get('capabilities') or {} |
| 554 | agent_interfaces = caps.get('interfaces', {}) |
| 555 | if not agent_interfaces.get('sdr_devices') and caps.get('devices'): |
| 556 | agent_interfaces['sdr_devices'] = caps.get('devices', []) |
| 557 | update_agent( |
| 558 | agent_id, |
| 559 | capabilities=caps.get('modes'), |
| 560 | interfaces=agent_interfaces, |
| 561 | update_last_seen=True |
| 562 | ) |
| 563 | except Exception: |
| 564 | pass # Non-fatal if refresh fails |
| 565 | |
| 566 | return jsonify({ |
| 567 | 'status': result.get('status', 'error'), |
| 568 | 'agent_id': agent_id, |
| 569 | 'agent_name': agent['name'], |
| 570 | 'monitor_interface': result.get('monitor_interface'), |
| 571 | 'message': result.get('message') |
| 572 | }) |
| 573 | |
| 574 | except AgentConnectionError as e: |
| 575 | return api_error(f'Cannot connect to agent: {e}', 503) |
| 576 | except AgentHTTPError as e: |
| 577 | return api_error(f'Agent error: {e}', 502) |
| 578 | |
| 579 | |
| 580 | # ============================================================================= |
nothing calls this directly
no test coverage detected