check_sys/audit/system/plugins/postfix/parsing.py
2023-09-08 16:34:48 +02:00

72 lines
2.1 KiB
Python

#!/usr/bin/env python3
import re
from json import dumps
from parsing.base import ParsingBase
class Parsing(ParsingBase):
def __init__(self, objects, arguments):
self._parsing = dict()
self._reports = dict()
self._objects = objects
self._postfix_file = arguments["postfix_file"]
def runParsing(self):
# Generate report
self._constructReports()
# 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, fdata):
data = fdata.read()
lines = data.splitlines()
obj = self._objects['regexp'].split("=")
directive = obj[0].strip()
value = obj[1].strip()
print(self._objects)
for line in lines:
line = line.decode('utf-8')
grDirective = re.search(directive, line)
if grDirective:
grValue = re.search(value, line)
if grValue:
print(line)
def _generateReport(self, objects):
# We can generate the report
for postfix in self._reports['postfix']:
self._reports['postfix'][postfix] = objects[postfix]
def _parsingFile(self, line, obj, vulnerabilityFound) -> bool:
"""
This function parse the line and try to find the item in it
"""
result = bool()
return result
def _constructReports(self):
"""
Construct dictionary for result of the tests
Each entry contains:
Key:
- filename: filename of the test
- line: line of the test
- parse: Display the line where the vulnerabilites has been found
- description: description of the vulnerability
- level: high, medium or low
"""
self._reports['postfix'] = dict()
def getResults(self) -> dict:
return self._reports