From 9e5ae61c698c135c02c5dfbfc1197fa582133ad5 Mon Sep 17 00:00:00 2001 From: geoffrey Date: Thu, 7 Sep 2023 21:27:30 +0200 Subject: [PATCH] Parsing postfix --- .../plugins/{apaches => apache}/apaches.py | 0 audit/system/plugins/postfix/parsing.py | 23 +++++++++++++++---- audit/system/plugins/sysctl/parsing.py | 3 +++ core/main.py | 8 ++++--- core/postfix.py | 11 +++++++-- core/sysctl.py | 7 ++---- 6 files changed, 37 insertions(+), 15 deletions(-) rename audit/system/plugins/{apaches => apache}/apaches.py (100%) diff --git a/audit/system/plugins/apaches/apaches.py b/audit/system/plugins/apache/apaches.py similarity index 100% rename from audit/system/plugins/apaches/apaches.py rename to audit/system/plugins/apache/apaches.py diff --git a/audit/system/plugins/postfix/parsing.py b/audit/system/plugins/postfix/parsing.py index ab43b4e..3ed57bb 100644 --- a/audit/system/plugins/postfix/parsing.py +++ b/audit/system/plugins/postfix/parsing.py @@ -6,20 +6,33 @@ from parsing.base import ParsingBase class Parsing(ParsingBase): - def __init__(self, objects): + def __init__(self, objects, arguments): self._parsing = dict() self._reports = dict() self._objects = objects + self._postfix_file = arguments["postfix_file"] + print(self._objects) + print(arguments) def runParsing(self): # Generate report self._constructReports() - - print(self._reports) + # Check if the file exist + try: + with open(self._postfix_file, 'rb') as fdata: + self._parseFile(fdata) + except FileNotFoundError: + print("No postfix file found. Add into the report") + pass - def _parseFile(self): - pass + def _parseFile(self, fdata): + data = fdata.read() + lines = data.splitlines() + + for line in lines: + line = line.decode('utf-8') + print(line) def _generateReport(self, objects): # We can generate the report diff --git a/audit/system/plugins/sysctl/parsing.py b/audit/system/plugins/sysctl/parsing.py index 3a8be2f..adab247 100644 --- a/audit/system/plugins/sysctl/parsing.py +++ b/audit/system/plugins/sysctl/parsing.py @@ -15,6 +15,9 @@ class Parsing(ParsingBase): # Generate report self._constructReports() + # TODO: + # We are not parse file and process. We parse file and process and for each + # line, we try to find in the file and in the process for audit in self._audit: if audit['audit'] == 'file': with open(audit['value'], 'rb') as fdata: diff --git a/core/main.py b/core/main.py index 13e2569..8ff0c8e 100644 --- a/core/main.py +++ b/core/main.py @@ -67,7 +67,10 @@ def main(): 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]) + report["system"][audit] = dispatcher.runPlugin( + audit, + configs["system"][audit] + ) if args.audit == "application": print("Auditing the application...") @@ -84,8 +87,7 @@ def sysctl(*args) -> dict: @Dispatcher.register_plugins def postfix(*args) -> dict: - arguments = args[1] - postfix = Postfix() + postfix = Postfix(args[1]) postfix.runAudit() return postfix.getReports() diff --git a/core/postfix.py b/core/postfix.py index 9cedf9d..9844b09 100644 --- a/core/postfix.py +++ b/core/postfix.py @@ -4,19 +4,26 @@ from audit.system.plugins.postfix.parsing import Parsing from audit.system.plugins.postfix.postfix import postfix class Postfix: - def __init__(self): + def __init__(self, arguments): self._objects = dict() self._reports = dict() + self._arguments = arguments self._postfix() - self._parsing = Parsing(self._objects) + self._parsing = Parsing(self._objects, arguments) def _postfix(self): + """ + Store all data to analyze in the object variable + """ self._objects = postfix() def runAudit(self): print("Running test for postfix") + self._parsing.runParsing() + + self._reports = self._parsing.getResults() def getReports(self) -> dict: return self._reports diff --git a/core/sysctl.py b/core/sysctl.py index 7c6f74e..f219e16 100644 --- a/core/sysctl.py +++ b/core/sysctl.py @@ -28,12 +28,9 @@ class Sysctl: def runAudit(self): print("Running test for sysctl") - # Read /etc/sysctl.conf - self._parsing.runParsing() - #self._reports.append(self._parsing.getResults()) - self._reports = self._parsing.getResults() - # Run process sysctl + self._parsing.runParsing() + self._reports = self._parsing.getResults() def getReports(self) -> dict: return self._reports