Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/audit_debug_entrees.baseline
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Total de scripts/audit_debug_entrees.py --total (issue #954, SOCLE §8).
# Ne doit pas augmenter : le baisser après avoir instrumenté des fonctions.
259
246
2 changes: 1 addition & 1 deletion scripts/audit_debug_sorties.baseline
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Total de scripts/audit_debug_sorties.py --total (issue #954, SOCLE §8).
# Ne doit pas augmenter : le baisser après avoir instrumenté des fonctions.
710
633
9 changes: 8 additions & 1 deletion src/netcross_gtk4/advanced_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import os
from dataclasses import dataclass

from netcross_core.logging_config import get_logger
from netcross_core.logging_config import get_logger, summarize

logger = get_logger(__name__)

Expand All @@ -40,6 +40,7 @@ class AdvancedSettings:

@property
def security_files(self) -> bool:
logger.debug("AdvancedSettings.security_files: retour bool(…)")
return bool(self.known_destinations or self.known_hosts or self.cve_db)


Expand All @@ -54,6 +55,7 @@ def settings_from_values(
) -> AdvancedSettings:
"""Valeurs des widgets -> reglages : 0 (et 1 pour l'echantillonnage)
veut dire « pas de limite » ou « automatique »."""
logger.debug("settings_from_values: retour AdvancedSettings(…)")
return AdvancedSettings(
max_packets=int(max_packets) or None,
sample_n=int(sample) if int(sample) > 1 else None,
Expand Down Expand Up @@ -81,17 +83,20 @@ def validate(settings: AdvancedSettings, *, security: bool) -> list[str]:
errors.append(f"{option} : fichier introuvable : {path}")
if settings.test_net_external and not security:
errors.append("« Plages TEST-NET externes » necessite « Rapport de securite »")
logger.debug("validate: retour errors={}", summarize(errors, "errors"))
return errors


def load_host_set(path: str | None, option: str) -> frozenset[str] | None:
"""Lit une liste d'IP (meme lecteur que la CLI) ; None sans fichier."""
if not path:
logger.debug("load_host_set: si not path -> retour None")
return None
from netcross_core.discovery.assets import load_baseline_hosts

hosts = load_baseline_hosts(path)
if not hosts:
logger.debug("load_host_set: si not hosts -> levée AdvancedOptionError")
raise AdvancedOptionError(f"{option} : aucune IP lue dans {path} (JSON invalide ou liste vide)")
logger.debug("load_host_set: {} IP dans {}", len(hosts), path)
return frozenset(hosts)
Expand All @@ -101,8 +106,10 @@ def workers_note(workers: int | None, cpu_count: int | None) -> str | None:
"""Avertissement de la CLI quand on demande plus de lecteurs que de coeurs."""
cpus = cpu_count or 1
if workers and workers > cpus:
logger.debug("workers_note: si workers and workers > cpus -> retour chaîne formatée")
return (
f"{workers} lecteurs demandes pour {cpus} coeur(s) : au-dela, les processus tshark se disputent le CPU "
"et la lecture peut ralentir."
)
logger.debug("workers_note: retour None")
return None
4 changes: 4 additions & 0 deletions src/netcross_gtk4/ai_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ class AISettings:
@property
def requested(self) -> bool:
"""Au moins un usage d'analyse demande (comme ``_check_ai_args``)."""
logger.debug("AISettings.requested: retour bool(…)")
return bool(self.baseline_save or self.anomalies or self.training_export or self.classify or self.summary)


def _path(text: str | None) -> str | None:
value = (text or "").strip()
logger.debug("_path: retour os.path.expanduser(value) if value else None")
return os.path.expanduser(value) if value else None


Expand Down Expand Up @@ -116,6 +118,7 @@ def to_options(settings: AISettings) -> Any:
"""``netcross_ai.pipeline.AIOptions`` equivalent (memes champs que la CLI)."""
from netcross_ai.pipeline import AIOptions

logger.debug("to_options: retour AIOptions(…)")
return AIOptions(
baseline_path=settings.anomalies,
baseline_save=settings.baseline_save,
Expand Down Expand Up @@ -143,6 +146,7 @@ def run_ai_section(settings: AISettings, report: Any, all_packets: list) -> tupl
result = run_ai(report, flows, to_options(settings))
except (RuntimeError, ValueError, OSError) as exc:
logger.exception(f"échec dans run_ai_section: {exc}")
logger.debug("run_ai_section: except (RuntimeError, ValueError, OSError) -> retour tuple de 3")
return None, "", [f"Module IA : {exc}"]
logs = [f"Module IA : {len(flows)} flux analyse(s)."]
if settings.report:
Expand Down
1 change: 1 addition & 0 deletions src/netcross_gtk4/analysis_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def _run_pipeline(
advanced = options.advanced or AdvancedSettings()
advanced_errors = validate_advanced(advanced, security=options.security)
if advanced_errors:
logger.debug("_run_pipeline: si advanced_errors -> levée ValueError")
raise ValueError("; ".join(advanced_errors))
known_destinations = load_host_set(advanced.known_destinations, "--known-destinations")
known_hosts = load_host_set(advanced.known_hosts, "--known-hosts")
Expand Down
17 changes: 16 additions & 1 deletion src/netcross_gtk4/batch_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from gi.repository import GLib, Gtk # noqa: E402

from netcross_core.batch import DEFAULT_GROUP_WINDOW, DEFAULT_MIN_COMMON_IPS, DEFAULT_MIN_OVERLAP # noqa: E402
from netcross_core.logging_config import get_logger # noqa: E402
from netcross_core.logging_config import get_logger, summarize # noqa: E402
from netcross_gtk4.capture_tools_window import PathChooser, _grid, _row # noqa: E402
from netcross_report import batch_runner # noqa: E402

Expand All @@ -31,6 +31,7 @@ class BatchWindow(Gtk.Window):
def __init__(
self, parent: Gtk.Window | None = None, start_thread: Callable[[Callable[[], None]], None] | None = None
):
logger.debug("BatchWindow.__init__: entrée")
super().__init__(title="Analyse d'un dossier", default_width=780, default_height=560)
if parent is not None:
self.set_transient_for(parent)
Expand Down Expand Up @@ -82,10 +83,12 @@ def __init__(
getattr(self.status_label, f"set_margin_{side}")(10)
root.append(self.status_label)
self.set_child(root)
logger.debug("BatchWindow.__init__: fin")

# -- reglages --------------------------------------------------------------

def options(self) -> batch_runner.BatchOptions:
logger.debug("BatchWindow.options: retour batch_runner.BatchOptions(…)")
return batch_runner.BatchOptions(
recursive=self.recursive.get_active(),
group=self.group.get_active(),
Expand All @@ -98,12 +101,15 @@ def options(self) -> batch_runner.BatchOptions:
)

def progress_text(self) -> str:
logger.debug("BatchWindow.progress_text: entrée")
buf = self.progress_view.get_buffer()
logger.debug("BatchWindow.progress_text: retour buf.get_text(…)")
return buf.get_text(buf.get_start_iter(), buf.get_end_iter(), False)

def _append_progress(self, message: str) -> bool:
buf = self.progress_view.get_buffer()
buf.insert(buf.get_end_iter(), message + "\n")
logger.debug("BatchWindow._append_progress: retour False")
return False

# -- execution ---------------------------------------------------------------
Expand All @@ -112,16 +118,20 @@ def run_batch_now(self, progress: Callable[[str], None] | None = None) -> str:
"""Lot complet, memes refus que la CLI ; renvoie le message de fin."""
folder = self.input_dir.path
if not folder or not os.path.isdir(folder):
logger.debug("BatchWindow.run_batch_now: si not folder or not os.path.isdir(folder) -> levée ValueError")
raise ValueError(f"--input : dossier introuvable : {folder or '(aucun)'}")
output = self.output_dir.path
if not output:
logger.debug("BatchWindow.run_batch_now: si not output -> levée ValueError")
raise ValueError("choisissez le dossier de sortie (--output)")
options = self.options()
refus = batch_runner.check_options(options)
if refus:
logger.debug("BatchWindow.run_batch_now: si refus -> levée ValueError")
raise ValueError(refus)
captures, ignored = batch_runner.list_captures(folder, options.recursive)
if not captures:
logger.debug("BatchWindow.run_batch_now: si not captures -> levée ValueError")
raise ValueError(f"Aucune capture ({', '.join(batch_runner.CAPTURE_EXTENSIONS)}) dans {folder}.")
report = progress or (lambda msg: GLib.idle_add(self._append_progress, msg))
result = batch_runner.run_batch(captures, ignored, output, options, folder, report)
Expand All @@ -132,10 +142,12 @@ def run_batch_now(self, progress: Callable[[str], None] | None = None) -> str:
f"{len(plan.failures) + len(result.errors)} echec(s). Index : {result.index_path}"
)
logger.info("BatchWindow: {}", message)
logger.debug("BatchWindow.run_batch_now: retour message={}", summarize(message, "message"))
return message

def launch(self) -> None:
if self.running:
logger.debug("BatchWindow.launch: si self.running -> retour")
return
self.running = True
self.run_btn.set_sensitive(False)
Expand All @@ -149,11 +161,14 @@ def _thread() -> None:
logger.warning("BatchWindow: {}", exc)
message = f"Erreur : {exc}"
GLib.idle_add(self._done, message)
logger.debug("BatchWindow.launch._thread: fin")

self._start_thread(_thread)
logger.debug("BatchWindow.launch: fin")

def _done(self, message: str) -> bool:
self.running = False
self.run_btn.set_sensitive(True)
self.status_label.set_text(message)
logger.debug("BatchWindow._done: retour False")
return False
Loading
Loading