MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / load_persistent_network_data

Function load_persistent_network_data

webapp_modern.py:5550–5663  ·  view source on GitHub ↗

Load the WiFi-specific network data with fallbacks.

()

Source from the content-addressed store, hash-verified

5548 # Create directory if it doesn't exist
5549 try:
5550 os.makedirs(vuln_results_dir, exist_ok=True)
5551 logger.debug(f"Ensured directory exists: {vuln_results_dir}")
5552 except Exception as e:
5553 logger.warning(f"Could not create vulnerabilities directory: {e}")
5554
5555 if os.path.exists(vuln_results_dir):
5556 try:
5557 files_found = []
5558 for filename in os.listdir(vuln_results_dir):
5559 if filename.endswith('.txt') and not filename.startswith('.'):
5560 files_found.append(filename)
5561 filepath = os.path.join(vuln_results_dir, filename)
5562 try:
5563 with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
5564 content = f.read()
5565 if content.strip():
5566 # Count CVEs or files with vulnerability content
5567 cve_matches = re.findall(r'CVE-\d{4}-\d+', content)
5568 if cve_matches:
5569 vuln_count += len(cve_matches)
5570 logger.debug(f"Found {len(cve_matches)} CVEs in {filename}: {cve_matches}")
5571 elif len(content.strip()) > 50: # File has significant content
5572 vuln_count += 1
5573 logger.debug(f"Found vulnerability content in {filename} (no CVEs)")
5574 except Exception as e:
5575 logger.debug(f"Could not read vulnerability file {filepath}: {e}")
5576 continue
5577
5578 logger.debug(f"Vulnerability files found: {files_found}")
5579 logger.debug(f"Total vulnerability count calculated: {vuln_count}")
5580 except Exception as e:
5581 logger.warning(f"Could not list vulnerabilities directory: {e}")
5582 else:
5583 logger.warning(f"Vulnerabilities directory does not exist: {vuln_results_dir}")
5584
5585 vuln_summary_file = getattr(shared_data, 'vuln_summary_file',
5586 os.path.join('data', 'output', 'vulnerabilities', 'vulnerability_summary.csv'))
5587
5588 if os.path.exists(vuln_summary_file):
5589 try:
5590 if pandas_available:
5591 df = pd.read_csv(vuln_summary_file)
5592 if not df.empty:
5593 for _, row in df.iterrows():
5594 vulnerabilities = safe_str(row.get('Vulnerabilities')).strip()
5595 if vulnerabilities and vulnerabilities.lower() not in {'none', 'nan', 'na', '0'}:
5596 record_host(row.get('IP') or row.get('Hostname'))
5597 else:
5598 with open(vuln_summary_file, 'r', encoding='utf-8', errors='ignore') as summary_file:
5599 reader = csv.DictReader(summary_file)
5600 for row in reader:
5601 vulnerabilities = (row.get('Vulnerabilities') or '').strip()
5602 if vulnerabilities and vulnerabilities.lower() not in {'none', 'nan', 'na', '0'}:
5603 record_host(row.get('IP') or row.get('Hostname'))
5604 except Exception as e:
5605 logger.debug(f"Could not parse vulnerability summary for host count: {e}")
5606
5607 # Update shared data with synchronized count

Callers

nothing calls this directly

Calls 12

update_wifi_network_dataFunction · 0.85
read_wifi_network_dataFunction · 0.85
_extract_valueFunction · 0.85
get_current_wifi_ssidFunction · 0.85
read_dataMethod · 0.80
errorMethod · 0.80
warningMethod · 0.80
appendMethod · 0.80
debugMethod · 0.80
infoMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected