Handle exit signals with proper cleanup
(signum, frame)
| 19602 | from server_capabilities import get_server_capabilities |
| 19603 | caps = get_server_capabilities(shared_data) |
| 19604 | |
| 19605 | data = request.get_json(silent=True) or {} |
| 19606 | feature = data.get('feature', '') |
| 19607 | |
| 19608 | # Traffic Analysis and the Advanced Vuln CLI scanners (nmap/nuclei/ |
| 19609 | # nikto/sqlmap/whatweb) run on any board, so installing their tools must |
| 19610 | # work on any board too. ZAP is not in this install set — it has its own |
| 19611 | # RAM gate — so there is no longer a server-mode-only install path here. |
| 19612 | if feature not in ['traffic_analysis', 'advanced_vuln']: |
| 19613 | return jsonify({ |
| 19614 | 'success': False, |
| 19615 | 'error': 'Invalid feature specified' |
| 19616 | }), 400 |
| 19617 | |
| 19618 | success, message = caps.install_missing_tools(feature) |
| 19619 | return jsonify({ |
| 19620 | 'success': success, |
| 19621 | 'message': message, |
| 19622 | 'missing_tools': caps.get_missing_tools(feature) |
| 19623 | }) |
| 19624 | |
| 19625 | except ImportError: |
| 19626 | return jsonify({'success': False, 'error': 'Server capabilities module not available'}), 503 |
| 19627 | except Exception as e: |
| 19628 | logger.error(f"Error installing tools: {e}") |
| 19629 | return jsonify({'success': False, 'error': str(e)}), 500 |
| 19630 | |
| 19631 | |
| 19632 | # ============================================================================ |
| 19633 | # TRAFFIC ANALYSIS API ENDPOINTS |
| 19634 | # ============================================================================ |
| 19635 | |
| 19636 | # Global traffic analyzer instance |
| 19637 | _traffic_analyzer_instance = None |
| 19638 | |
| 19639 | def get_traffic_analyzer(): |
| 19640 | """Get or create traffic analyzer instance""" |
| 19641 | global _traffic_analyzer_instance |
| 19642 | if _traffic_analyzer_instance is None: |
| 19643 | try: |
| 19644 | from traffic_analyzer import TrafficAnalyzer |
| 19645 | _traffic_analyzer_instance = TrafficAnalyzer(shared_data) |
| 19646 | shared_data._traffic_analyzer = _traffic_analyzer_instance |
| 19647 | except ImportError: |
| 19648 | return None |
| 19649 | return _traffic_analyzer_instance |
| 19650 | |
| 19651 | |
| 19652 | @app.route('/api/traffic/status') |
| 19653 | def get_traffic_status(): |