()
| 8913 | if network_data: |
| 8914 | logger.debug("Used netkb data as fallback.") |
| 8915 | else: |
| 8916 | network_data = [] |
| 8917 | |
| 8918 | current_ssid = get_current_wifi_ssid() |
| 8919 | logger.info(f"Returning {len(network_data)} network entries for WiFi: {current_ssid}") |
| 8920 | return network_data |
| 8921 | |
| 8922 | |
| 8923 | @app.route('/api/network/stable') |
| 8924 | def get_stable_network_data(): |
| 8925 | """Get stable, aggregated network data for the Network tab from SQLite database""" |
| 8926 | with _network_context_from_request(): |
| 8927 | try: |
| 8928 | db = get_db(currentdir=shared_data.currentdir) |
| 8929 | |
| 8930 | # Get all hosts from SQLite database |
| 8931 | hosts = db.get_all_hosts() |
| 8932 | |
| 8933 | # Also get any recent ARP scan cache data for real-time enrichment |
| 8934 | recent_arp_data = network_scan_cache.get('arp_hosts', {}) |
| 8935 | |
| 8936 | logger.info(f"Loaded {len(hosts)} entries from SQLite database for stable API") |
| 8937 | |
| 8938 | # Merge and enrich the data |
| 8939 | enriched_hosts = [] |
| 8940 | processed_ips = set() |
| 8941 | |
| 8942 | # Process SQLite hosts |
| 8943 | for host in hosts: |
| 8944 | ip = host.get('ip', '').strip() |
| 8945 | # Skip if empty, already processed, or is STANDALONE |
| 8946 | if not ip or ip in processed_ips or ip == 'STANDALONE': |
| 8947 | continue |
| 8948 | |
| 8949 | processed_ips.add(ip) |
| 8950 | |
| 8951 | # Parse ports from semicolon-separated string to list |
| 8952 | ports_str = host.get('ports', '') |
| 8953 | if ports_str: |
| 8954 | ports = [p.strip() for p in ports_str.split(';') if p.strip()] |
| 8955 | else: |
| 8956 | ports = [] |
| 8957 | |
| 8958 | # Determine status based on SQLite status field |
| 8959 | status = host.get('status', 'unknown') |
| 8960 | if status == 'alive': |
| 8961 | host_status = 'up' |
| 8962 | elif status == 'degraded': |
| 8963 | host_status = 'degraded' |
| 8964 | else: |
| 8965 | host_status = 'unknown' |
| 8966 | |
| 8967 | host_data = { |
| 8968 | 'ip': ip, |
| 8969 | 'hostname': _normalize_value(host.get('hostname'), 'Unknown'), |
| 8970 | 'mac': _normalize_value(host.get('mac'), 'Unknown'), |
| 8971 | 'status': host_status, |
| 8972 | 'ports': ';'.join(ports) if ports else 'Unknown', |
nothing calls this directly
no test coverage detected