42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
import re
|
|
from json import dumps
|
|
|
|
class Parsing:
|
|
def __init__(self, objects, audit):
|
|
self._parsing = dict()
|
|
self._results = dict()
|
|
self._objects = objects
|
|
self._audit = audit
|
|
|
|
def runParsing(self):
|
|
for audit in self._audit:
|
|
if audit['audit'] == 'file':
|
|
with open(audit['value'], 'rb') as fdata:
|
|
self._parseFile(fdata)
|
|
|
|
def _parseFile(self, fdata):
|
|
data = fdata.read()
|
|
lines = data.splitlines()
|
|
|
|
for line in lines:
|
|
self._parsingFile(line, self._objects['sysctl'])
|
|
|
|
def _parsingFile(self, line, item) -> dict:
|
|
"""
|
|
This function parse the line and try to find the item in it
|
|
"""
|
|
res = None
|
|
|
|
line = line.decode("utf-8")
|
|
for entry in item:
|
|
groupLine = re.search(entry['item'], line)
|
|
if groupLine:
|
|
sLine = line.split('=')
|
|
|
|
return res
|
|
|
|
def getResults(self) -> dict:
|
|
result = dict()
|
|
|
|
return result
|