refactor inxi
This commit is contained in:
parent
46bbb940d7
commit
782f6dac51
|
@ -29,9 +29,9 @@ class UploadForm(forms.Form):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file_json = json.loads(file_data)
|
file_json = json.loads(file_data)
|
||||||
Build(file_json, None, check=True)
|
snap = Build(file_json, None, check=True)
|
||||||
exist_annotation = Annotation.objects.filter(
|
exist_annotation = Annotation.objects.filter(
|
||||||
uuid=file_json['uuid']
|
uuid=snap.uuid
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if exist_annotation:
|
if exist_annotation:
|
||||||
|
|
|
@ -68,8 +68,11 @@ class Evidence:
|
||||||
|
|
||||||
def get_doc(self):
|
def get_doc(self):
|
||||||
self.doc = {}
|
self.doc = {}
|
||||||
|
self.inxi = None
|
||||||
|
|
||||||
if not self.owner:
|
if not self.owner:
|
||||||
self.get_owner()
|
self.get_owner()
|
||||||
|
|
||||||
qry = 'uuid:"{}"'.format(self.uuid)
|
qry = 'uuid:"{}"'.format(self.uuid)
|
||||||
matches = search(self.owner, qry, limit=1)
|
matches = search(self.owner, qry, limit=1)
|
||||||
if matches and matches.size() < 0:
|
if matches and matches.size() < 0:
|
||||||
|
@ -89,26 +92,26 @@ class Evidence:
|
||||||
self.inxi = ev["output"]
|
self.inxi = ev["output"]
|
||||||
else:
|
else:
|
||||||
dmidecode_raw = self.doc["data"]["dmidecode"]
|
dmidecode_raw = self.doc["data"]["dmidecode"]
|
||||||
|
inxi_raw = self.doc["data"]["inxi"]
|
||||||
|
self.dmi = DMIParse(dmidecode_raw)
|
||||||
try:
|
try:
|
||||||
self.inxi = json.loads(self.doc["data"]["inxi"])
|
self.inxi = json.loads(inxi_raw)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if self.inxi:
|
||||||
|
try:
|
||||||
|
machine = get_inxi_key(self.inxi, 'Machine')
|
||||||
|
for m in machine:
|
||||||
|
system = get_inxi(m, "System")
|
||||||
|
if system:
|
||||||
|
self.device_manufacturer = system
|
||||||
|
self.device_model = get_inxi(m, "product")
|
||||||
|
self.device_serial_number = get_inxi(m, "serial")
|
||||||
|
self.device_chassis = get_inxi(m, "Type")
|
||||||
|
self.device_version = get_inxi(m, "v")
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.dmi = DMIParse(dmidecode_raw)
|
|
||||||
try:
|
|
||||||
machine = get_inxi_key(self.inxi, 'Machine')
|
|
||||||
for m in machine:
|
|
||||||
system = get_inxi(m, "System")
|
|
||||||
if system:
|
|
||||||
self.device_manufacturer = system
|
|
||||||
self.device_model = get_inxi(m, "product")
|
|
||||||
self.device_serial_number = get_inxi(m, "serial")
|
|
||||||
self.device_chassis = get_inxi(m, "Type")
|
|
||||||
self.device_version = get_inxi(m, "v")
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
|
|
||||||
def get_time(self):
|
def get_time(self):
|
||||||
if not self.doc:
|
if not self.doc:
|
||||||
self.get_doc()
|
self.get_doc()
|
||||||
|
@ -177,7 +180,6 @@ class Evidence:
|
||||||
|
|
||||||
return self.dmi.serial_number().strip()
|
return self.dmi.serial_number().strip()
|
||||||
|
|
||||||
|
|
||||||
def get_version(self):
|
def get_version(self):
|
||||||
if self.inxi:
|
if self.inxi:
|
||||||
return self.device_version
|
return self.device_version
|
||||||
|
|
|
@ -3,21 +3,16 @@ import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dmidecode import DMIParse
|
from dmidecode import DMIParse
|
||||||
from json_repair import repair_json
|
from evidence.parse_details import ParseSnapshot
|
||||||
from django.conf import settings
|
|
||||||
from evidence.parse_details import get_lshw_child, ParseSnapshot
|
|
||||||
|
|
||||||
from evidence.models import Annotation
|
from evidence.models import Annotation
|
||||||
from evidence.xapian import index
|
from evidence.xapian import index
|
||||||
from utils.constants import CHASSIS_DH
|
from evidence.parse_details import get_inxi_key, get_inxi
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
if settings.DPP:
|
if settings.DPP:
|
||||||
from dpp.api_dlt import register_device_dlt, register_passport_dlt
|
from dpp.api_dlt import register_device_dlt, register_passport_dlt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from evidence.parse_details import get_inxi_key, get_inxi
|
|
||||||
|
|
||||||
logger = logging.getLogger('django')
|
logger = logging.getLogger('django')
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,27 +77,16 @@ class Build:
|
||||||
sku = device.get("sku", '')
|
sku = device.get("sku", '')
|
||||||
hid = f"{manufacturer}{model}{chassis}{serial_number}{sku}"
|
hid = f"{manufacturer}{model}{chassis}{serial_number}{sku}"
|
||||||
|
|
||||||
|
|
||||||
self.chid = hashlib.sha3_256(hid.encode()).hexdigest()
|
self.chid = hashlib.sha3_256(hid.encode()).hexdigest()
|
||||||
return self.chid
|
return self.chid
|
||||||
|
|
||||||
def get_chid_dpp(self):
|
def get_chid_dpp(self):
|
||||||
if self.json.get("software") == "workbench-script":
|
if self.json.get("software") == "workbench-script":
|
||||||
dmidecode_raw = self.json["data"]["dmidecode"]
|
device = ParseSnapshot(self.json).device
|
||||||
dmi = DMIParse(dmidecode_raw)
|
|
||||||
|
|
||||||
manufacturer = dmi.manufacturer().strip()
|
|
||||||
model = dmi.model().strip()
|
|
||||||
chassis = self.get_chassis_dh()
|
|
||||||
serial_number = dmi.serial_number()
|
|
||||||
sku = self.get_sku()
|
|
||||||
typ = chassis
|
|
||||||
version = self.get_version()
|
|
||||||
hid = f"{manufacturer}{model}{chassis}{serial_number}{sku}{typ}{version}"
|
|
||||||
else:
|
else:
|
||||||
device = self.json['device']
|
device = self.json['device']
|
||||||
hid = self.get_id_hw_dpp(device)
|
|
||||||
|
|
||||||
|
hid = self.get_id_hw_dpp(device)
|
||||||
self.chid = hashlib.sha3_256(hid.encode("utf-8")).hexdigest()
|
self.chid = hashlib.sha3_256(hid.encode("utf-8")).hexdigest()
|
||||||
return self.chid
|
return self.chid
|
||||||
|
|
||||||
|
@ -161,23 +145,6 @@ class Build:
|
||||||
value=v
|
value=v
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_chassis_dh(self):
|
|
||||||
chassis = self.get_chassis()
|
|
||||||
lower_type = chassis.lower()
|
|
||||||
for k, v in CHASSIS_DH.items():
|
|
||||||
if lower_type in v:
|
|
||||||
return k
|
|
||||||
return self.default
|
|
||||||
|
|
||||||
def get_sku(self):
|
|
||||||
return self.dmi.get("System")[0].get("SKU Number", "n/a").strip()
|
|
||||||
|
|
||||||
def get_chassis(self):
|
|
||||||
return self.dmi.get("Chassis")[0].get("Type", '_virtual') #
|
|
||||||
|
|
||||||
def get_version(self):
|
|
||||||
return self.dmi.get("System")[0].get("Verson", '_virtual')
|
|
||||||
|
|
||||||
def get_hid(self, snapshot):
|
def get_hid(self, snapshot):
|
||||||
try:
|
try:
|
||||||
self.inxi = self.json["data"]["inxi"]
|
self.inxi = self.json["data"]["inxi"]
|
||||||
|
|
Loading…
Reference in a new issue