Compare commits
3 Commits
5045450424
...
53000725c7
Author | SHA1 | Date |
---|---|---|
Thomas Nahuel Rusiecki | 53000725c7 | |
Thomas Nahuel Rusiecki | 1330a231ef | |
Thomas Nahuel Rusiecki | b37617421e |
|
@ -58,7 +58,7 @@
|
||||||
<div class="col-lg-9 col-md-8">{{ object.type }}</div>
|
<div class="col-lg-9 col-md-8">{{ object.type }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if object.is_websnapshot %}
|
{% if object.is_websnapshot and object.last_user_evidence %}
|
||||||
{% for k, v in object.last_user_evidence %}
|
{% for k, v in object.last_user_evidence %}
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-lg-3 col-md-4 label">{{ k }}</div>
|
<div class="col-lg-3 col-md-4 label">{{ k }}</div>
|
||||||
|
|
|
@ -47,17 +47,32 @@ class Command(BaseCommand):
|
||||||
self.open(filepath)
|
self.open(filepath)
|
||||||
|
|
||||||
def open(self, filepath):
|
def open(self, filepath):
|
||||||
|
try:
|
||||||
with open(filepath, 'r') as file:
|
with open(filepath, 'r') as file:
|
||||||
content = json.loads(file.read())
|
content = json.loads(file.read())
|
||||||
path_name = save_in_disk(content, self.user.institution.name)
|
path_name = save_in_disk(content, self.user.institution.name)
|
||||||
|
|
||||||
self.snapshots.append((content, path_name))
|
self.snapshots.append((content, path_name))
|
||||||
|
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
logger.error("JSON decode error in file %s: %s", filepath, e)
|
||||||
|
raise ValueError(f"Invalid JSON format in file {filepath}") from e
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
logger.error("File not found: %s", filepath)
|
||||||
|
raise FileNotFoundError(f"File not found: {filepath}") from e
|
||||||
|
#or we cath'em all
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception("Unexpected error when opening file %s: %s", filepath, e)
|
||||||
|
raise Exception(f"Unexpected error when opening file {filepath}") from e
|
||||||
|
|
||||||
def parsing(self):
|
def parsing(self):
|
||||||
for s, p in self.snapshots:
|
for s, p in self.snapshots:
|
||||||
try:
|
try:
|
||||||
self.devices.append(Build(s, self.user))
|
self.devices.append(Build(s, self.user))
|
||||||
move_json(p, self.user.institution.name)
|
move_json(p, self.user.institution.name)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
if settings.DEBUG:
|
||||||
|
logger.exception("%s", err)
|
||||||
snapshot_id = s.get("uuid", "")
|
snapshot_id = s.get("uuid", "")
|
||||||
txt = "Could not parse snapshot: %s"
|
txt = "It is not possible to parse snapshot: %s"
|
||||||
logger.error(txt, snapshot_id)
|
logger.error(txt, snapshot_id)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import logging
|
||||||
|
|
||||||
from dmidecode import DMIParse
|
from dmidecode import DMIParse
|
||||||
from json_repair import repair_json
|
from json_repair import repair_json
|
||||||
|
from evidence.parse_details import get_lshw_child
|
||||||
|
|
||||||
from evidence.models import Annotation
|
from evidence.models import Annotation
|
||||||
from evidence.xapian import index
|
from evidence.xapian import index
|
||||||
|
@ -12,6 +13,23 @@ from utils.constants import CHASSIS_DH
|
||||||
|
|
||||||
logger = logging.getLogger('django')
|
logger = logging.getLogger('django')
|
||||||
|
|
||||||
|
def get_mac(lshw):
|
||||||
|
try:
|
||||||
|
if type(lshw) is dict:
|
||||||
|
hw = lshw
|
||||||
|
else:
|
||||||
|
hw = json.loads(lshw)
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
hw = json.loads(repair_json(lshw))
|
||||||
|
|
||||||
|
networks = []
|
||||||
|
get_lshw_child(hw, networks, 'network')
|
||||||
|
|
||||||
|
if nets_sorted:
|
||||||
|
mac = nets_sorted[0]['serial']
|
||||||
|
logger.debug("The snapshot has the following MAC: %s" , mac)
|
||||||
|
return mac
|
||||||
|
|
||||||
|
|
||||||
def get_network_cards(child, nets):
|
def get_network_cards(child, nets):
|
||||||
if child['id'] == 'network' and "PCI:" in child.get("businfo"):
|
if child['id'] == 'network' and "PCI:" in child.get("businfo"):
|
||||||
|
|
Loading…
Reference in New Issue