61 lines
1.9 KiB
Python
61 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("-", "_")
|
|
dataJinja2 = dict()
|
|
dataJinja2['title'] = 'Report check system'
|
|
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")
|
|
|
|
if 'postfix' in data['system']:
|
|
dataJinja2['postfix'] = dict()
|
|
dataJinja2['postfix']['filename'] = data["system"]["postfix"]["filename"]
|
|
dataJinja2['postfix']['vulnerabilities'] = data['system']['postfix']['postfix']
|
|
|
|
_generateAccordion(dataJinja2['postfix']['vulnerabilities'])
|
|
|
|
if 'sysctl' in data['system']:
|
|
dataJinja2['sysctl'] = dict()
|
|
dataJinja2['sysctl']['file'] = dict()
|
|
dataJinja2['sysctl']['file']['filename'] = data['system']['sysctl']['file']['filename']
|
|
dataJinja2['sysctl']['file']['sysctl'] = data['system']['sysctl']['file']['sysctl']
|
|
|
|
_generateAccordion(dataJinja2['sysctl']['file']['sysctl'])
|
|
|
|
if 'apache' in data['system']:
|
|
pass
|
|
|
|
dataJinja2['year'] = '2023'
|
|
dataJinja2['hostname'] = data['hostname']
|
|
dataJinja2['kernel'] = data['kernel']
|
|
dataJinja2['release'] = data['release']
|
|
rdr = tmplIndex.render(data=dataJinja2)
|
|
|
|
with open(f"reports/reports_{today}.html", "w") as f:
|
|
f.write(rdr)
|
|
|
|
print("The report is generated at this location: " \
|
|
f"reports/reports_{today}.html")
|
|
|
|
def _generateAccordion(obj):
|
|
index = 1
|
|
for entry in obj:
|
|
obj[entry]['accordion-id'] = f"accordion-{index}"
|
|
index += 1
|