Check for system updates using git
()
| 9688 | |
| 9689 | |
| 9690 | # One DatabaseManager per network database, reused across requests. Building |
| 9691 | # a new one re-runs the whole schema/migration pass, and the dashboard asks |
| 9692 | # for these stats every few seconds. |
| 9693 | _network_db_handles: Dict[str, DatabaseManager] = {} |
| 9694 | _network_db_handles_lock = threading.Lock() |
| 9695 | |
| 9696 | |
| 9697 | def _network_db_handle(db_path, network_dir): |
| 9698 | with _network_db_handles_lock: |
| 9699 | handle = _network_db_handles.get(db_path) |
| 9700 | if handle is None: |
| 9701 | handle = DatabaseManager(db_path=db_path, currentdir=shared_data.currentdir, |
| 9702 | data_root=network_dir) |
| 9703 | _network_db_handles[db_path] = handle |
| 9704 | return handle |
| 9705 | |
| 9706 | |
| 9707 | def _calculate_dashboard_stats_from_context(context: Dict[str, str]) -> Dict: |
| 9708 | network_dir = context.get('network_dir') |
| 9709 | db_path = context.get('db_path') |
| 9710 | credentials_dir = context.get('credentials_dir') |
| 9711 | intelligence_dir = context.get('intelligence_dir') |
| 9712 | stats = { |
| 9713 | 'network_ssid': context.get('ssid') or 'default', |
| 9714 | 'network_slug': context.get('slug'), |
| 9715 | 'target_count': 0, |
| 9716 | 'active_target_count': 0, |
| 9717 | 'inactive_target_count': 0, |
| 9718 | 'total_target_count': 0, |
| 9719 | 'new_target_count': 0, |
| 9720 | 'lost_target_count': 0, |
| 9721 | 'new_target_ips': [], |
| 9722 | 'lost_target_ips': [], |
| 9723 | 'port_count': 0, |
| 9724 | 'vulnerability_count': 0, |
| 9725 | 'vulnerable_hosts_count': 0, |
| 9726 | 'credential_count': 0, |
| 9727 | 'data_count': 0, |
| 9728 | 'level': safe_int(shared_data.levelnbr), |
| 9729 | 'points': safe_int(shared_data.coinnbr), |
| 9730 | 'scanned_network_count': safe_int(getattr(shared_data, 'scanned_networks_count', shared_data._calculate_scanned_networks_count()), 0), |
| 9731 | 'last_sync_timestamp': None, |
| 9732 | 'last_sync_iso': None, |
| 9733 | 'last_sync_age_seconds': None, |
| 9734 | } |
| 9735 | |
| 9736 | hosts = [] |
| 9737 | if db_path and os.path.exists(db_path): |
| 9738 | try: |
| 9739 | hosts = _network_db_handle(db_path, network_dir).get_all_hosts() |
| 9740 | except Exception as exc: |
| 9741 | logger.error(f"Unable to read hosts for network context {context.get('slug')}: {exc}") |
| 9742 | |
| 9743 | max_failed = safe_int(shared_data.config.get('network_max_failed_pings', 15), 15) |
| 9744 | max_failed = max(1, max_failed) |
| 9745 | |
| 9746 | vulnerable_hosts = set() |
| 9747 | vuln_count_override, vuln_hosts_override = _load_intelligence_vulnerability_counts(intelligence_dir) |
nothing calls this directly
no test coverage detected