Update report
This commit is contained in:
+31
-2
@@ -6,23 +6,42 @@ from core.postfix import Postfix
|
||||
from core.report import generateHtmlReport
|
||||
from core.config import AUDIT_SYSTEM, AUDIT_APPLICATION, generateConfig, parsingConfigFile
|
||||
from core.dispatcher import Dispatcher
|
||||
from utils import getHostname, getKernelVersion, identifySystem, getCodeName, getRelease
|
||||
from os import listdir
|
||||
from os.path import isdir
|
||||
|
||||
|
||||
def checkArguments():
|
||||
args = ArgumentParser(description="Check Gitlab repositories")
|
||||
args.add_argument('-a', '--audit', help="Kind of audit", choices=['system', 'application'])
|
||||
args.add_argument('-p', '--plugins', help="Get all plugins", choices=['system', 'application'])
|
||||
args.add_argument('-c', '--config', help="Config file")
|
||||
return args.parse_args()
|
||||
|
||||
def getAllPlugins(audit):
|
||||
print(f"List all plugins for {audit}")
|
||||
path = str()
|
||||
if audit == "system":
|
||||
path = "audit/system/plugins/"
|
||||
else:
|
||||
path = "audit/applications/"
|
||||
|
||||
for directory in listdir(path):
|
||||
if isdir(f"{path}/{directory}"):
|
||||
print(directory)
|
||||
|
||||
def main():
|
||||
args = checkArguments()
|
||||
|
||||
if args.plugins is not None:
|
||||
getAllPlugins(args.plugins)
|
||||
exit(0)
|
||||
|
||||
# If audit is not specified
|
||||
if args.audit is None:
|
||||
print("Please, you must specify the audit type")
|
||||
exit(1)
|
||||
|
||||
|
||||
# If config file is specified
|
||||
configs = generateConfig()
|
||||
if args.config is not None:
|
||||
@@ -32,19 +51,29 @@ def main():
|
||||
report = dict()
|
||||
report['system'] = dict()
|
||||
|
||||
# Get the hostname of the VM
|
||||
report['hostname'] = getHostname()
|
||||
|
||||
# Get system informations
|
||||
report['kernel'] = getKernelVersion()
|
||||
report['release'] = f"{identifySystem()} {getRelease()} ({getCodeName()}) "
|
||||
|
||||
# Create our dispatcher
|
||||
dispatcher = Dispatcher()
|
||||
|
||||
print(configs)
|
||||
#print(configs)
|
||||
|
||||
if args.audit == "system":
|
||||
print("Auditing the system...")
|
||||
for audit in AUDIT_SYSTEM:
|
||||
if audit not in configs["system"]["exclude_plugins"]:
|
||||
report["system"][audit] = dispatcher.runPlugin(audit, configs["system"][audit])
|
||||
|
||||
if args.audit == "application":
|
||||
print("Auditing the application...")
|
||||
pass
|
||||
|
||||
print("End of the audit. Generating the report")
|
||||
generateHtmlReport(report)
|
||||
|
||||
@Dispatcher.register_plugins
|
||||
|
||||
+6
-38
@@ -6,9 +6,6 @@ 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['title'] = 'Report check system'
|
||||
dataJinja2['plugins'] = list()
|
||||
@@ -23,7 +20,7 @@ def generateHtmlReport(data):
|
||||
|
||||
body = str()
|
||||
for plugin in data['system']:
|
||||
print(plugin)
|
||||
#print(plugin)
|
||||
dataJinja2['plugins'].append(f"{plugin}.html.j2")
|
||||
|
||||
if 'postfix' in dataJinja2['plugins']:
|
||||
@@ -40,44 +37,15 @@ def generateHtmlReport(data):
|
||||
for sysctl in dataJinja2['sysctl']['file']['sysctl']:
|
||||
dataJinja2['sysctl']['file']['sysctl'][sysctl]['accordion-id'] = f"accordion-{index}"
|
||||
index += 1
|
||||
#print(data['system']['sysctl']['file'][sysctl])
|
||||
#for entry in data['system']['sysctl']['file']['sysctl']:
|
||||
# print(entry)
|
||||
# print(data['system']['sysctl']['file']['sysctl'][entry])
|
||||
|
||||
#print(dataJinja2)
|
||||
dataJinja2['year'] = '2023'
|
||||
dataJinja2['hostname'] = data['hostname']
|
||||
dataJinja2['kernel'] = data['kernel']
|
||||
dataJinja2['release'] = data['release']
|
||||
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>"
|
||||
|
||||
#print(body)
|
||||
with open(f"reports/reports_{today}.html", "w") as f:
|
||||
f.write(rdr)
|
||||
|
||||
def _getHeader() -> str:
|
||||
header = "<!doctype html>" \
|
||||
"<html>" \
|
||||
"<head>" \
|
||||
"</head>" \
|
||||
|
||||
return header
|
||||
print("The report is generated at this location: " \
|
||||
f"reports/reports_{today}.html")
|
||||
|
||||
Reference in New Issue
Block a user