Update gamification stats using lifetime achievements and SQLite database statistics.
(self, persist=True)
| 1958 | f"📋 Stored {len(scan_data or []) if scan_data else 0} hosts for network slug '{slug}'" |
| 1959 | ) |
| 1960 | |
| 1961 | def get_latest_scan_results(self, ssid=None): |
| 1962 | """Retrieve fresh scan results from memory for a specific SSID (defaults to active).""" |
| 1963 | slug = self._slug_for_ssid(ssid or self.active_network_ssid) |
| 1964 | with self._scan_results_lock: |
| 1965 | entry = self._latest_scan_results.get(slug) |
| 1966 | if not entry: |
| 1967 | return None |
| 1968 | data = entry.get('data') |
| 1969 | age_seconds = time.time() - entry.get('timestamp', 0) |
| 1970 | logger.info( |
| 1971 | f"📋 Retrieved {len(data or []) if data else 0} hosts from cache (slug={slug}, age={age_seconds:.1f}s)" |
| 1972 | ) |
| 1973 | return data |
| 1974 | |
| 1975 | def get_cached_network_slugs(self): |
| 1976 | with self._scan_results_lock: |
| 1977 | return list(self._latest_scan_results.keys()) |
| 1978 | |
| 1979 | def read_data(self): |
| 1980 | """ |
| 1981 | Read data from SQLite database. |
| 1982 | Returns data in the same format as CSV for backward compatibility. |
| 1983 | """ |
| 1984 | data = [] |
| 1985 | |
| 1986 | try: |
| 1987 | if self.db is None: |
| 1988 | return [] |
| 1989 | # Read from SQLite database (PRIMARY AND ONLY DATA SOURCE) |
| 1990 | hosts = self.db.get_all_hosts() |
| 1991 | |
| 1992 | if not hosts: |
| 1993 | logger.debug("No hosts found in database") |
| 1994 | return [] |
| 1995 | |
| 1996 | # Convert database format to CSV-compatible format |
| 1997 | for host in hosts: |
| 1998 | # Convert to format expected by orchestrator |
| 1999 | row = { |
| 2000 | 'MAC Address': host.get('mac', ''), |
| 2001 | 'IPs': host.get('ip', ''), |
| 2002 | 'Hostnames': host.get('hostname', ''), |
| 2003 | 'Alive': '1' if host.get('status') == 'alive' else '0', |
| 2004 | 'Ports': host.get('ports', ''), |
| 2005 | 'Failed_Pings': str(host.get('failed_ping_count', 0)), |
| 2006 | 'Services': host.get('services', ''), |
| 2007 | 'Nmap Vulnerabilities': host.get('vulnerabilities', ''), |
| 2008 | 'Alive Count': str(host.get('alive_count', 0)), |
| 2009 | 'Network Profile': host.get('network_profile', ''), |
| 2010 | 'Scanner': host.get('scanner_status', ''), |
| 2011 | 'ssh_connector': host.get('ssh_connector', ''), |
| 2012 | 'rdp_connector': host.get('rdp_connector', ''), |
| 2013 | 'ftp_connector': host.get('ftp_connector', ''), |
| 2014 | 'smb_connector': host.get('smb_connector', ''), |
| 2015 | 'telnet_connector': host.get('telnet_connector', ''), |
| 2016 | 'sql_connector': host.get('sql_connector', ''), |
| 2017 | 'steal_files_ssh': host.get('steal_files_ssh', ''), |
no test coverage detected