65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
|
|
from datetime import datetime
|
|
import jinja2
|
|
|
|
|
|
def generateHtmlReport(data):
|
|
today = datetime.now().isoformat()[0:10].replace("-", "_")
|
|
html = _getHeader()
|
|
html += "<body>" \
|
|
f"<h1>Reports of {today}</h1>"
|
|
dataJinja2 = dict()
|
|
dataJinja2['plugins'] = list()
|
|
|
|
# Env jinja2
|
|
env = jinja2.Environment(
|
|
loader=jinja2.PackageLoader("reports"),
|
|
autoescape=jinja2.select_autoescape()
|
|
)
|
|
# print(env.list_templates())
|
|
tmplIndex = env.get_template("index.html.j2")
|
|
|
|
body = str()
|
|
for plugin in data['system']:
|
|
print(plugin)
|
|
dataJinja2['plugins'].append(f"{plugin}.html.j2")
|
|
|
|
dataJinja2['year'] = '2023'
|
|
rdr = tmplIndex.render(data=dataJinja2)
|
|
|
|
# For sysctl
|
|
#for entry in data['sysctl']:
|
|
# body += f"<h2>Sysctl</h2>"
|
|
|
|
# # For file
|
|
# body += f"<h3>File</h3>"
|
|
#for f in data['sysctl']['file']:
|
|
# body += f"<h4>{data['sysctl']['file']['filename']}</h4>"
|
|
# for vul in data['sysctl']['file']['sysctl']:
|
|
# #print(data['sysctl']['file']['sysctl'][vul])
|
|
# body += f"<h5>{vul}</h5>"
|
|
# body += f"<p>"
|
|
# body += f"Results:<br />"
|
|
#for result in data['sysctl']['file']['sysctl'][vul]:
|
|
# print(result)
|
|
# body += f"Line: {result['lineNumber']}<br />"
|
|
# body += f"Line: {result['line']}<br />"
|
|
# body += f"Level: {result['level']}<br />"
|
|
# body += f"Description: {result['description']}<br /><br />"
|
|
#body += f"</p>"
|
|
|
|
html += body
|
|
#print(body)
|
|
html += "</body></html>"
|
|
with open(f"reports/reports_{today}.html", "w") as f:
|
|
f.write(rdr)
|
|
|
|
def _getHeader() -> str:
|
|
header = "<!doctype html>" \
|
|
"<html>" \
|
|
"<head>" \
|
|
"</head>" \
|
|
|
|
return header
|