#!/usr/bin/env python from argparse import ArgumentParser from core.sysctl import Sysctl 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: parsingConfigFile(args.config, configs) # Report 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) 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 def sysctl(*args) -> dict: sysctl = Sysctl(args[1]) sysctl.runAudit() return sysctl.getReports() @Dispatcher.register_plugins def postfix(*args) -> dict: arguments = args[1] postfix = Postfix() postfix.runAudit() return postfix.getReports() if __name__ == "__main__": main()