Public entry point for Wi-Fi manager to switch all storage.
(self, ssid)
| 532 | if scan_results_dir: |
| 533 | os.makedirs(scan_results_dir, exist_ok=True) |
| 534 | self.scan_results_dir = scan_results_dir |
| 535 | if vulnerabilities_dir: |
| 536 | os.makedirs(vulnerabilities_dir, exist_ok=True) |
| 537 | self.vulnerabilities_dir = vulnerabilities_dir |
| 538 | self.vuln_summary_file = os.path.join(vulnerabilities_dir, 'vulnerability_summary.csv') |
| 539 | self.vuln_scan_progress_file = os.path.join(vulnerabilities_dir, 'scan_progress.json') |
| 540 | |
| 541 | def _refresh_credential_files(self): |
| 542 | """Keep credential CSV paths aligned with the active credential directory.""" |
| 543 | self.sshfile = os.path.join(self.crackedpwddir, 'ssh.csv') |
| 544 | self.smbfile = os.path.join(self.crackedpwddir, "smb.csv") |
| 545 | self.telnetfile = os.path.join(self.crackedpwddir, "telnet.csv") |
| 546 | self.ftpfile = os.path.join(self.crackedpwddir, "ftp.csv") |
| 547 | self.sqlfile = os.path.join(self.crackedpwddir, "sql.csv") |
| 548 | self.rdpfile = os.path.join(self.crackedpwddir, "rdp.csv") |
| 549 | |
| 550 | def set_active_network(self, ssid): |
| 551 | """Public entry point for Wi-Fi manager to switch all storage.""" |
| 552 | if not hasattr(self, 'storage_manager'): |
| 553 | return |
| 554 | |
| 555 | # Guard against transient Wi-Fi blips: if the new SSID is None |
| 556 | # (Wi-Fi momentarily lost) but we already have an active real |
| 557 | # network, do NOT switch. A genuine disconnection will be |
| 558 | # handled by the Wi-Fi monitoring loop which performs sustained |
| 559 | # validation before acting. Without this guard, a single |
| 560 | # failed check_wifi_connection() call (common on the resource- |
| 561 | # constrained Pi Zero W2) would call mark_all_hosts_degraded() |
| 562 | # and wipe the entire target list to zero. |
| 563 | if not ssid and self.active_network_ssid: |
| 564 | logger.debug( |
| 565 | f"Ignoring transient SSID=None switch (current network: " |
| 566 | f"{self.active_network_ssid})" |
| 567 | ) |
| 568 | return |
| 569 | |
| 570 | try: |
| 571 | if self.network_intelligence: |
| 572 | self.network_intelligence.save_intelligence_data() |
| 573 | if self.threat_intelligence: |
| 574 | self.threat_intelligence.persist_state() |
| 575 | except Exception as exc: |
| 576 | logger.warning(f"Failed to persist data before network switch: {exc}") |
| 577 | |
| 578 | try: |
| 579 | if self.storage_manager is None: |
| 580 | logger.error("Storage manager not available, cannot switch network") |
| 581 | return |
| 582 | context = self.storage_manager.activate_network(ssid) |
| 583 | except Exception as exc: |
| 584 | logger.error(f"Unable to activate network storage for '{ssid}': {exc}") |
| 585 | return |
| 586 | |
| 587 | # Skip reconfiguration if the slug did not change |
| 588 | if (context.get('slug') == self.active_network_slug and |
| 589 | context.get('ssid') == self.active_network_ssid): |
| 590 | return |
| 591 |
no test coverage detected