-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathReport_Generator.py
More file actions
80 lines (67 loc) · 2.76 KB
/
Report_Generator.py
File metadata and controls
80 lines (67 loc) · 2.76 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
import os
import csv
def generate_html_report(csv_file="log.csv", html_file="report.html"):
if not os.path.exists(csv_file):
print(f"{csv_file} does not exist.")
return
with open(csv_file, mode="r") as file:
reader = csv.reader(file)
rows = list(reader)
# Create an HTML file with CSS styling
with open(html_file, "w") as file:
file.write("<html><head><title>DMARC and SPF Log Report</title>")
file.write("<style>")
file.write("body { font-family: Arial, sans-serif; margin: 20px; }")
file.write("h1 { color: #333; }")
file.write(
"table { width: 100%; border-collapse: collapse; margin-top: 20px; }"
)
file.write(
"th, td { padding: 10px; text-align: left; border: 1px solid #ddd; }"
)
file.write("th { background-color: #f2f2f2; }")
file.write("tr:nth-child(even) { background-color: #f9f9f9; }")
file.write("tr:hover { background-color: #f1f1f1; }")
file.write("</style>")
file.write("<script>")
file.write("""
function filterTable() {
const table = document.getElementById('logTable');
const rows = table.getElementsByTagName('tr');
const filterInputs = document.querySelectorAll('input[type="text"]');
for (let i = 1; i < rows.length; i++) {
const cells = rows[i].getElementsByTagName('td');
let showRow = true;
for (let j = 0; j < cells.length; j++) {
const filterValue = filterInputs[j].value.toLowerCase();
const cellText = cells[j].innerText.toLowerCase();
// Check if the cell starts with the filter value
if (filterValue && !cellText.startsWith(filterValue)) {
showRow = false;
break;
}
}
rows[i].style.display = showRow ? '' : 'none';
}
}
""")
file.write("</script>")
file.write("</head><body>")
file.write("<h1>DMARC and SPF Log Report</h1>")
file.write("<table id='logTable'>")
file.write("<tr>")
for header in rows[0]:
file.write(
f"<th>{header} <input type='text' onkeyup='filterTable()' placeholder='Filter A-Z...'></th>"
)
file.write("</tr>")
for row in rows[1:]:
file.write("<tr>")
for column in row:
file.write(f"<td>{column}</td>")
file.write("</tr>")
file.write("</table>")
file.write("</body></html>")
print(f"HTML report generated: {html_file}")
if __name__ == "__main__":
generate_html_report()