Vulns: parser results en tableau Package/Version installée/Version requise

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalid MOUTAOUAKIL 2026-04-06 22:51:50 +02:00
parent 31bf62651c
commit 0dc0fc7643

View File

@ -535,15 +535,47 @@ async def qualys_vulns_detail(request: Request, ip: str, db=Depends(get_db)):
html += '</tr>'
# Ligne detail
diag = k.get("diagnosis", "")[:300]
results = d.get("results", "")[:200]
html += f'<tr class="bg-cyber-hover/30"><td colspan="6" class="p-2 text-xs text-gray-400">'
# Parser le results pour en faire un tableau packages
results = d.get("results", "")
if results and ("Installed Version" in results or "Required Version" in results):
# Format: "Package Installed Version Required Version\npkg1 ver1 ver2\npkg2..."
lines = [l.strip() for l in results.replace("\t", " ").split("\n") if l.strip()]
# Retirer la ligne header
pkg_lines = [l for l in lines if not l.startswith("Package") and not l.startswith("Installed")]
if pkg_lines:
html += '<table class="w-full mt-1 mb-2" style="background:#0d1117;border-radius:4px;">'
html += '<thead><tr><th class="p-1 text-left text-gray-500">Package</th>'
html += '<th class="p-1 text-left text-cyber-red">Version installée</th>'
html += '<th class="p-1 text-left text-cyber-green">Version requise</th></tr></thead><tbody>'
for line in pkg_lines:
parts = line.split()
if len(parts) >= 3:
pkg = parts[0]
installed = parts[1]
required = " ".join(parts[2:])
html += f'<tr><td class="p-1 font-mono text-cyber-accent">{pkg}</td>'
html += f'<td class="p-1 font-mono text-cyber-red">{installed}</td>'
html += f'<td class="p-1 font-mono text-cyber-green">{required}</td></tr>'
elif len(parts) >= 1:
html += f'<tr><td colspan="3" class="p-1 font-mono">{line}</td></tr>'
html += '</tbody></table>'
else:
html += f'<b>Résultat :</b> <span class="font-mono">{results[:300]}</span><br>'
elif results:
html += f'<b>Résultat :</b> <span class="font-mono">{results[:300]}</span><br>'
# Diagnosis (nettoyé des tags HTML)
diag = k.get("diagnosis", "")
if diag:
html += f'<b>Detection :</b> {diag}<br>'
if results:
html += f'<b>Resultat :</b> <span class="font-mono">{results}</span><br>'
diag_clean = _re.sub(r'<[^>]+>', ' ', diag).strip()[:300]
html += f'<b>Détection :</b> {diag_clean}<br>'
if k.get("solution"):
html += f'<b>Solution :</b> {k["solution"][:200]}'
sol_clean = _re.sub(r'<[^>]+>', ' ', k["solution"]).strip()[:200]
html += f'<b>Solution :</b> {sol_clean}'
html += '</td></tr>'
html += '</tbody></table></div>'