-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
85 lines (63 loc) · 2.3 KB
/
report.py
File metadata and controls
85 lines (63 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
import pandas as pd
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
RESULT_DIR = "results"
TEMPLATE_DIR = "templates"
TEMPLATE_FILE = "report.html.j2"
# ------------------------------------------------------------
# Erweiterte Ampellogik
# ------------------------------------------------------------
def classify(row):
if row.get("error") and str(row["error"]).strip() != "":
return "red"
if not row.get("tls_version"):
return "red"
if str(row.get("hostname_mismatch")).lower() == "true":
return "red"
tls = str(row.get("tls_version", ""))
if tls not in ["TLSv1.2", "TLSv1.3"]:
return "red"
try:
seclevel = int(row.get("seclevel", 0))
except Exception:
seclevel = 0
if seclevel == 0:
return "red"
if seclevel == 1:
return "yellow"
if row.get("cipher") in ["UNKNOWN", "", None]:
return "yellow"
if not row.get("san"):
return "yellow"
return "green"
# ------------------------------------------------------------
# Main
# ------------------------------------------------------------
def main():
result_path = Path(RESULT_DIR)
hosts = {}
for file in result_path.glob("*_tls.csv"):
host = file.name.replace("_tls.csv", "")
tls_file = file
err_file = result_path / f"{host}_errors.csv"
df_tls = pd.read_csv(tls_file)
df_err = pd.read_csv(err_file) if err_file.exists() else pd.DataFrame()
if not df_err.empty:
for col in df_tls.columns:
if col not in df_err.columns:
df_err[col] = ""
df = pd.concat([df_tls, df_err], ignore_index=True)
df["ampel"] = df.apply(classify, axis=1)
df["ampel_sort"] = df["ampel"].map(lambda x: {"red": 0, "yellow": 1, "green": 2}[x])
df = df.sort_values("ampel_sort")
hosts[host] = df
overview = [(host, df["ampel"].min()) for host, df in hosts.items()]
env = Environment(loader=FileSystemLoader(TEMPLATE_DIR))
template = env.get_template(TEMPLATE_FILE)
html = template.render(overview=overview, details=hosts)
with open("report.html", "w", encoding="utf-8") as f:
f.write(html)
print("Report erzeugt: report.html")
if __name__ == "__main__":
main()