feat(ui): display OS name and version in SummaryPanel
All checks were successful
Build and Release .deb / build-deb (push) Successful in 21s
All checks were successful
Build and Release .deb / build-deb (push) Successful in 21s
- Add scan_os() to detect OS via lsb_release or /etc/os-release - Store os_info in cache and ScanResult - Display OS info in SummaryPanel below the target name
This commit is contained in:
parent
3bb213a00d
commit
6e707da98d
3 changed files with 35 additions and 1 deletions
|
|
@ -129,6 +129,7 @@ class FullUpdaterApp(App):
|
|||
apt_count=data.get("apt_count", 0),
|
||||
cve_count=data.get("cve_count", 0),
|
||||
cve_total=data.get("cve_total", 0),
|
||||
os_info=data.get("os_info", ""),
|
||||
error=data.get("error", ""),
|
||||
skipped=not data and any(t.target_id == target_id and not t.is_host and not lxc_is_running(t.target_id) for t in self.targets),
|
||||
cache_time=get_cache_timestamp(cache_id)
|
||||
|
|
@ -160,6 +161,7 @@ class FullUpdaterApp(App):
|
|||
"timestamp": datetime.now().isoformat(),
|
||||
"apt_count": 0, "apt_packages": [],
|
||||
"cve_count": 0, "cve_total": 0, "cve_list": [],
|
||||
"os_info": "LXC éteint",
|
||||
"error": "LXC éteint"
|
||||
})
|
||||
self._update_sidebar(target.target_id, result)
|
||||
|
|
@ -178,6 +180,7 @@ class FullUpdaterApp(App):
|
|||
"apt_packages": result.apt_packages,
|
||||
"cve_count": result.cve_count,
|
||||
"cve_total": result.cve_total,
|
||||
"os_info": result.os_info,
|
||||
"cve_list": result.cve_list,
|
||||
"error": result.error
|
||||
})
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ class ScanResult:
|
|||
apt_count: int = 0
|
||||
cve_count: int = 0
|
||||
cve_total: int = 0
|
||||
os_info: str = ""
|
||||
apt_packages: list[dict[str, str]] = field(default_factory=list)
|
||||
cve_list: list[dict[str, str]] = field(default_factory=list)
|
||||
error: str = ""
|
||||
|
|
@ -135,6 +136,28 @@ def lxc_is_running(vmid: str) -> bool:
|
|||
return ok and "running" in stdout.lower()
|
||||
|
||||
|
||||
def scan_os(target: Target) -> str:
|
||||
"""Récupère le nom et la version de l'OS."""
|
||||
if target.is_host:
|
||||
cmd = ["lsb_release", "-ds"]
|
||||
else:
|
||||
cmd = ["pct", "exec", target.target_id, "--", "lsb_release", "-ds"]
|
||||
ok, stdout, _ = run_cmd(cmd, timeout=30)
|
||||
if ok:
|
||||
return stdout.strip()
|
||||
# Fallback si lsb_release n'est pas installé
|
||||
if target.is_host:
|
||||
cmd = ["cat", "/etc/os-release"]
|
||||
else:
|
||||
cmd = ["pct", "exec", target.target_id, "--", "cat", "/etc/os-release"]
|
||||
ok, stdout, _ = run_cmd(cmd, timeout=30)
|
||||
if ok:
|
||||
name = re.search(r'PRETTY_NAME="([^"]+)"', stdout)
|
||||
if name:
|
||||
return name.group(1)
|
||||
return "OS inconnu"
|
||||
|
||||
|
||||
def ensure_debsecan_installed(is_host: bool, vmid: str = "") -> tuple[bool, str]:
|
||||
if is_host:
|
||||
ok, _, _ = run_cmd(["which", "debsecan"])
|
||||
|
|
@ -236,6 +259,10 @@ def scan_target(target: Target, progress_cb: Callable) -> ScanResult:
|
|||
result.error = f"debsecan: {debsecan_err}"
|
||||
progress_cb()
|
||||
|
||||
# Scan OS
|
||||
result.os_info = scan_os(target)
|
||||
progress_cb()
|
||||
|
||||
result.status = "done" if (result.apt_ok and result.cve_ok) else "error"
|
||||
if result.error:
|
||||
result.status = "error"
|
||||
|
|
@ -246,6 +273,7 @@ def scan_target(target: Target, progress_cb: Callable) -> ScanResult:
|
|||
"apt_packages": result.apt_packages,
|
||||
"cve_count": result.cve_count,
|
||||
"cve_total": result.cve_total,
|
||||
"os_info": result.os_info,
|
||||
"cve_list": result.cve_list,
|
||||
"error": result.error
|
||||
})
|
||||
|
|
|
|||
|
|
@ -60,16 +60,18 @@ class SummaryPanel(Vertical):
|
|||
|
||||
with Vertical(id="summary-body"):
|
||||
yield Static("Sélectionnez une cible", id="summary-title")
|
||||
yield Static("", id="summary-os", classes="summary-row")
|
||||
yield Button("Mises à jour : -", id="btn-apt", classes="summary-row", variant="default")
|
||||
yield Button("CVE : -", id="btn-cve", classes="summary-row", variant="default")
|
||||
yield Static("", id="summary-error", classes="summary-row summary-error")
|
||||
yield Button("📦 Mettre à jour", id="btn-upgrade", variant="primary")
|
||||
|
||||
def set_target(self, target_id: str, name: str, apt_count: int, cve_count: int, cve_total: int, error: str, skipped: bool, cache_time: str):
|
||||
def set_target(self, target_id: str, name: str, apt_count: int, cve_count: int, cve_total: int, os_info: str, error: str, skipped: bool, cache_time: str):
|
||||
self._current_target_id = target_id
|
||||
self._current_target_name = name
|
||||
|
||||
title = self.query_one("#summary-title", Static)
|
||||
os_label = self.query_one("#summary-os", Static)
|
||||
apt_btn = self.query_one("#btn-apt", Button)
|
||||
cve_btn = self.query_one("#btn-cve", Button)
|
||||
err_label = self.query_one("#summary-error", Static)
|
||||
|
|
@ -77,6 +79,7 @@ class SummaryPanel(Vertical):
|
|||
cache_label = self.query_one("#summary-cache", Static)
|
||||
|
||||
title.update(name if name else "Sélectionnez une cible")
|
||||
os_label.update(os_info if os_info else "")
|
||||
cache_label.update(f"Cache : {cache_time}" if cache_time else "")
|
||||
|
||||
if skipped:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue