Update report
This commit is contained in:
parent
d3ec39c8f1
commit
0cd833db66
33
core/main.py
33
core/main.py
@ -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,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")
|
||||
|
@ -22,7 +22,10 @@
|
||||
<div class="p-5 mb-4 bg-body-tertiary rounded-3">
|
||||
<div class="container-fluid py-5">
|
||||
<h1 class="display-5 fw-bold">Report</h1>
|
||||
<p class="col-md-8 fs-4">Report of the day... blablabla</p>
|
||||
<p class="col-md-8 fs-4">
|
||||
Audit of the system {{ data['hostname'] }} ({{ data['release'] }}).<br />
|
||||
Kernel version: {{ data['kernel'] }}<br />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -4,13 +4,26 @@
|
||||
<div class="accordion" id="accordionSysctl">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header">
|
||||
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#{{ data['sysctl']['file']['sysctl'][item]['accordion-id'] }}" aria-expanded="true" aria-controls="{{ data['sysctl']['file']['sysctl'][item]['accordion-id'] }}">
|
||||
<strong>{{ item }}</strong> <span class="text-bg-danger p-1" style="padding-left:10pt;padding-right:10pt;margin-left:15pt;">{{ data['sysctl']['file']['sysctl'][item]['result']['result'] }}</span>
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#{{ data['sysctl']['file']['sysctl'][item]['accordion-id'] }}" aria-expanded="true" aria-controls="{{ data['sysctl']['file']['sysctl'][item]['accordion-id'] }}">
|
||||
<strong>{{ item }}</strong>
|
||||
{% if data['sysctl']['file']['sysctl'][item]['result']['result'] == 'failed' %}
|
||||
<span class="text-bg-danger p-1" style="padding-left:10pt;padding-right:10pt;margin-left:15pt;">{{ data['sysctl']['file']['sysctl'][item]['result']['result'] }}</span>
|
||||
{% elif data['sysctl']['file']['sysctl'][item]['result']['result'] == 'success' %}
|
||||
<span class="text-bg-success p-1" style="padding-left:10pt;padding-right:10pt;margin-left:15pt;">{{ data['sysctl']['file']['sysctl'][item]['result']['result'] }}</span>
|
||||
{% endif %}
|
||||
</button>
|
||||
</h2>
|
||||
<div id="{{ data['sysctl']['file']['sysctl'][item]['accordion-id'] }}" class="accordion-collapse collapse show" data-bs-parent="#accordionSysctl">
|
||||
<div id="{{ data['sysctl']['file']['sysctl'][item]['accordion-id'] }}" class="accordion-collapse collapse" data-bs-parent="#accordionSysctl">
|
||||
<div class="accordion-body">
|
||||
{{ data['sysctl']['file']['sysctl'][item]['description'] }}
|
||||
{{ data['sysctl']['file']['sysctl'][item]['description'] }}. <br />
|
||||
For resolving the issue, add this line in the <strong>{{ data['sysctl']['file']['filename'] }}</strong> file:
|
||||
<div class="bd-example-snippet bd-code-snippet">
|
||||
<div class="highlight">
|
||||
<pre tabindex="0" class="chroma"><code class="language-shell">
|
||||
{{ data['sysctl']['file']['sysctl'][item]['flag'] }} = {{ data['sysctl']['file']['sysctl'][item]['value'] }}
|
||||
</pre></code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
48
utils.py
48
utils.py
@ -2,6 +2,7 @@
|
||||
|
||||
import re
|
||||
from subprocess import run
|
||||
from socket import gethostname
|
||||
|
||||
|
||||
class ConfigError(Exception):
|
||||
@ -13,23 +14,40 @@ class ConfigError(Exception):
|
||||
super().__init__(self.message)
|
||||
|
||||
def identifySystem():
|
||||
os = None
|
||||
with open('/etc/issue', 'r') as f:
|
||||
line = f.readline()
|
||||
if re.search('Arch Linux', line):
|
||||
os = 'ARCHLINUX'
|
||||
elif re.search('Ubuntu', line):
|
||||
os = 'UBUNTU'
|
||||
elif re.search('Debian', line):
|
||||
os = 'DEBIAN'
|
||||
else:
|
||||
os = 'UNKNOWN'
|
||||
|
||||
return os
|
||||
#os = None
|
||||
#with open('/etc/issue', 'r') as f:
|
||||
# line = f.readline()
|
||||
# if re.search('Arch Linux', line):
|
||||
# os = 'ARCHLINUX'
|
||||
# elif re.search('Ubuntu', line):
|
||||
# os = 'UBUNTU'
|
||||
# elif re.search('Debian', line):
|
||||
# os = 'DEBIAN'
|
||||
# else:
|
||||
# os = 'UNKNOWN'
|
||||
kernelVers = run(['/usr/bin/lsb_release', '-is'], capture_output=True)
|
||||
return kernelVers.stdout.decode('utf-8')
|
||||
|
||||
def getKernelVersion():
|
||||
"""
|
||||
This function get the kernel version Linux
|
||||
"""
|
||||
kernelVers = run(['/usr/bin/uname', '-r'])
|
||||
return kernelVers.stdout
|
||||
kernelVers = run(['/usr/bin/uname', '-r'], capture_output=True)
|
||||
return kernelVers.stdout.decode('utf-8')
|
||||
|
||||
def getCodeName():
|
||||
"""
|
||||
This function get the code name of the system
|
||||
"""
|
||||
kernelVers = run(['/usr/bin/lsb_release', '-cs'], capture_output=True)
|
||||
return kernelVers.stdout.decode('utf-8')
|
||||
|
||||
def getRelease():
|
||||
"""
|
||||
This function get the release name of the system
|
||||
"""
|
||||
kernelVers = run(['/usr/bin/lsb_release', '-rs'], capture_output=True)
|
||||
return kernelVers.stdout.decode('utf-8')
|
||||
|
||||
def getHostname():
|
||||
return gethostname()
|
||||
|
Loading…
Reference in New Issue
Block a user